Skip to content

Adaptive NVIDIA descriptor heaps and type-safe bindless access guards (#747 / #483) - #1

Open
AimLogin wants to merge 2 commits into
mainfrom
fix/747-adaptive-heaps-and-bindless-guards
Open

AimLogin wants to merge 2 commits into
mainfrom
fix/747-adaptive-heaps-and-bindless-guards

Conversation

@AimLogin

Copy link
Copy Markdown
Owner

Patch proposal for upstream Marvisak/VIctory. Pull request creation there is limited to collaborators, so this PR lives in a fork. It is meant to be read, tested and cherry-picked (in whole or in part) by the maintainers and the authors of the related PRs. It is not meant to be merged here. Base: upstream main ffe310e, unchanged at the time of writing.

1. Summary

Two commits:

  1. 3e3b8c5, GPU: adapt the descriptor heap layout to the host's capacity (NVIDIA capped view heap: 2^16 dynamic slots starve world tables; 2^18 removes the indirect/mesh drops Marvisak/VIctory#747). On a host that caps view heaps at 1,000,000 (NVIDIA), the world's heap now gets 262,144 dynamic slots instead of 65,536. Hosts that take more are unchanged. One file.
  2. cc449ca, GPU, Shaders: bound bindless heap reads with typed null guards (Shaders, GPU: a heap index computed from data stays inside the heap Marvisak/VIctory#483). This builds on the guard scheme of #483 and adds four things:
    • a separate bound for direct (bindless) title reads;
    • bounds on fetched_index;
    • one null guard per kind of read, as the D3D12 spec requires;
    • bound dwords that cost no more root-signature space than needed.

Commit 2 builds on commit 1. Commit 1 builds and passes on its own. On capped hosts it should land together with a bindless bound, because it widens the window in which direct reads hit other draws' tables (see §11).

This improves one subsystem. It does not make the world render: see §12.

2. Background and motivation

3. Adaptive descriptor heap layout (commit 1)

view_layout is a pure function, so every host cap can be tested without hardware.

host before after
takes count + 2^18 (AMD, WARP, uncapped NVIDIA) count + 2^18 unchanged
capped at 1M, title heap fits with ≥ 2^16 to spare count + 2^16 count + (1M − count), ≤ 2^18
capped at 1M, title heap does not fit (world: 1,245,184) 934,464 + 65,536 737,856 + 262,144
takes count + 2^16 but not + 2^18 (cap above 1M) count + 2^16 unchanged

With commit 2 the last 21 of those dynamic slots are guards, so 262,123 remain for tables. The total stays 1,000,000.

Unlike the branch on LAKSHYA-cmd-tech/VIctory and the commit on MfDev0/VIctory listed in §15, uncapped hosts and title heaps that fit are not cut.

4. Separate title and table bounds (commit 2)

heap_bound applies the bound like this:

Past the title slots a capped heap keeps the host's per-draw tables. With one bound, a stale title index reads another draw's descriptor. That is a valid access, so DRED and page faults don't report it. The host fills dword 0 (guard) and dword 1 (title slots) in user_dword on every bind.

5. Fetched descriptor indexing

Per-lane descriptors loaded with global_load (Source::Fetched) go through fetched_index. Marvisak#483 does not bound that path. It now ends in the same heap_bound. Phi, Select, Lanes and LanePhi are bounded per leaf.

6. Typed null descriptor guards

The D3D12 resource binding spec defines a null descriptor only "as long as the type of shader access is compatible with the descriptor type". Its own example, a Texture2D read through a Texture1D null, is "undefined and could result in device reset" (Resource Binding, "NULL Descriptors"). SM 6.6 Dynamic Resources does not address type mismatches in heap reads.

  • HEAP_GUARDS holds 21 null views: 12 SRV kinds (1D–cube-array textures, typed, raw and structured buffers), 8 UAV kinds and a CBV.
  • heap_guard picks the slot from the read's DXIL resource properties at compile time, so the bound targets guard + kind.
  • The host writes them with null_guard into the last slots of the dynamic span, which are never given to a table (guard_slot).

Measured with GPU-based validation on the readback tests in §9 (direct and table reads through raw UAVs), RTX 4060 Ti and WARP:

  • with one null 2D-SRV guard: 20 × "Descriptor type doesn't match shader register type … Descriptor Type in Heap: SRV, Register Type: UAV";
  • with the typed guards: 0 messages.

Only the raw-UAV guard is exercised by those tests. Every other kind is covered by the mapping test (every_heap_read_has_a_guard_of_its_kind) and the spec, not by GBV runs.

Typed nulls for empty table slots are Marvisak#581's (FibbS6), implemented independently. These are for the guard slots. The two are complementary.

7. Root signature cost reduction

D3D12 allows 64 dwords per root signature: 1 per root constant, 2 per root CBV or SRV. A pipeline here has at most 2 translated stages, and a console stage has at most 31 user SGPRs. Placing the bound dwords after the whole layout, as Marvisak#483 does, can grow a stage from 4 to 36 dwords (31 declared, 2 read). Two such stages pass the limit.

lower now places them right after the last dword the program reads:

  • It lowers a second time where that saves space.
  • It keeps the second result only if the reads are identical.
  • Any failure of the second pass keeps the first result.

Cost per stage is now 0 or +4 dwords (rounding to rows of 4), at most +8 per pipeline. Doubly lowered shaders are cached like all others.

A pipeline already at 57–64 dwords can still be pushed over. It is then refused with host root signature refused, visibly, not silently. #644 (nathanbzrr, spill to root CBVs) would cover that case. It reads the same user_data_dwords() and conflicts textually in draw.rs bind.

8. Diagnostics

  • no free dynamic descriptor slots is counted and logged at powers of two, instead of once (L350).
  • Device-removed reports label a heap address as a title, dynamic or guard slot (place_in_heap).
  • The last refused HRESULT is logged again.

9. Test results

Run locally on Windows 11, RTX 4060 Ti (driver 621.01), Rust 1.98.1, and on WARP.

check commit 1 commit 2
cargo test --workspace --locked (hardware) 348 passed, 0 failed, 6 ignored 357 passed, 0 failed, 6 ignored
victory-gpu + victory-shader on WARP (--features victory-gpu/diagnostics) – 188 passed, 0 failed, 2 ignored
clippy --workspace --all-targets --locked -D warnings, with and without --all-features clean clean
cargo xtask policy (also the pre-commit hook) ok ok
rustfmt on changed files no deviation beyond upstream's same

Main is at 342 passed. 4 tests in emit/diff_tests.rs count as passed but skip themselves without the console SDK's dxc.exe; that is unchanged here.

New tests:

10. Negative controls

  • without_a_title_bound_direct_reads_reach_other_draws_tables is part of the suite. With one bound (Shaders, GPU: a heap index computed from data stays inside the heap Marvisak/VIctory#483's semantics) or none, a direct read at 737,856, 934,463, 934,464 or the last dynamic slot writes into another draw's UAV, on hardware and WARP. Only in-heap indices are run unbounded.
  • Mutations run locally and reverted (not in the diff):
    • one bound for direct reads: the readback test fails on hardware, "direct index 737856: left Some(1), right None";
    • fetched_index unbounded: the lowering test fails;
    • bounds after the layout end: both placement tests fail (dwords 31/32 instead of 2/3);
    • the old split: the layout tests fail (65,536 dynamic slots on the 4060 Ti).
  • No out-of-heap index was ever run unbounded on hardware.

11. Dependencies and integration notes

12. Known limitations

  • No world run on this machine, so no measured effect on rendering, draws or frame rate. The world results in NVIDIA capped view heap: 2^16 dynamic slots starve world tables; 2^18 removes the indirect/mesh drops Marvisak/VIctory#747 are other testers' (§13). undeadhuman37 reports that 2^18 alone stops the slot drops but only delays the NVIDIA hang; wave64 compute is suspected as the remaining cause.
  • No AMD hardware tested. The amdxc64.dll crash nullmarsh reported on Shaders, GPU: a heap index computed from data stays inside the heap Marvisak/VIctory#483 is not reproduced and not explained.
  • Title indices beyond the cap read null, not the resource the title meant. Remapping is not implemented.
  • How often the title reads such indices directly is not measured.
  • Table-rooted reads are bounded at the guard base, not at each table's length, so a read past a table's own entries can still reach the next allocation (pre-existing).
  • Root signatures already near 64 dwords can still be refused (§7). If the second lowering pass is rejected, the first one's wider placement is used.
  • GBV was run on raw-UAV reads only (§6).
  • Not a fix for NVIDIA compatibility or for the title as a whole.

13. Credits

No code from those PRs or branches was copied. Commit 2 re-implements Marvisak#483's scheme; everything else is written here.

14. AI assistance disclosure

Analysis, code and text were written with Claude Code (Anthropic). Every test result above was run locally on the hardware named in §9. Code was reviewed by separate read-only review passes before publication. The world measurements cited are other people's and were not reproduced here.

15. Related issues and pull requests

AimLogin and others added 2 commits November 24, 2026 14:02
…k#747)

A host that caps shader-visible view heaps at 1,000,000 (NVIDIA, on
binding tier 3 too) gave the world's view heap (1,245,184 slots) only
2^16 dynamic slots, and its fresh tables ran out inside every
submission (Marvisak#747). The split is now a pure function, `view_layout`:

* a host that takes `count + 2^18`: unchanged;
* capped, title heap fits with at least 2^16 to spare: every title
  slot, the rest dynamic (up to 2^18);
* capped, title heap does not fit: 737,856 title + 262,144 dynamic;
* a host capped above 1,000,000 that takes `count + 2^16`: unchanged.

Also: `no free dynamic descriptor slots` is counted (logged at powers
of two) instead of once, and device-removed reports name title and
dynamic slots.

On NVIDIA this moves the first title index without a host slot from
934,464 to 737,856. Direct heap reads at such indices read the host's
dynamic slots (other draws' tables); the next commit bounds them.
Merge this together with a bindless bound on capped hosts.

Tests: a reference of the old split checked against the new one for
caps of 900k, 1M, 1.31M, 1.4M and none; the world-sized heap on the
device (RTX 4060 Ti: 737,856 + 262,144; WARP: 1,245,184 + 262,144),
exhausted in 140-slot tables, released and retaken.

Diagnosis and the 2^18 proposal: Vaximous (Marvisak#747); 2^18 dynamic slots
and dropping draws without fresh tables: Marvisak#336 (hophaver).

AI-assisted (Claude Code); tests run locally on an RTX 4060 Ti
(driver 621.01) and WARP.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…sak#483)

Builds on the previous commit's heap layout and on the guard scheme of
Marvisak#483 (Vaximous): a user-data dword with the bound heap's guard slot,
past the program's own dwords, and every computed heap index at or
above it reads the guard instead. This adds:

* A second bound for reads straight from the heap (root
  `ResourceHeap`, base 0: a title index): the host's title slots. Past
  them a capped heap keeps its per-draw tables, so one bound let a
  stale title index read another draw's descriptor. Reads through a
  table stay bounded by the guard (fresh tables live past the title
  slots).
* `fetched_index` (per-lane descriptors loaded with `global_load`) is
  bounded too.
* One guard slot per kind of read (`HEAP_GUARDS`: 12 SRV kinds, 8 UAV
  kinds, a CBV). A null view is defined only where it is read as its
  own kind (D3D12 resource binding spec, "NULL Descriptors"); GPU-based
  validation reported 20 type mismatches with a single null 2D SRV
  guard on the readback tests below, none with these. The guards are
  the last slots of a view heap's dynamic span, never given to a table.
* The bound dwords go right past the last dword the program reads
  (lowered a second time where that saves space, kept only if the reads
  are the same; any failure keeps the first result), so a stage's root
  constants grow by 0 or 4 dwords instead of up to 32 (64 dwords for a
  whole root signature; Marvisak#644 would spill the rest).

Tests: GPU readback on a 1,000,000-slot heap laid out as on a capped
host (RTX 4060 Ti and WARP): direct reads past the title slots, at the
guards and past the heap read the null guard; table reads reach their
dynamic slots up to the guards; with one bound (Marvisak#483) or none, direct
reads reach other draws' descriptors (negative control). Lowering tests
for the bound dwords' placement and cost and for `fetched_index`; every
kind of read maps to its own guard; root signatures of 63/64/65 dwords
on the device. Red/green by mutation: one bound for direct reads,
`fetched_index` unbounded, bounds past the layout end.

Typed null descriptors by kind for empty table slots are Marvisak#581's
(FibbS6), independently; these are for the guard slots. Integration
notes from etcetera-yt, h0useadv and walterwallaceson on Marvisak#483 (guard
kept out of the dynamic pool, `count + self.dynamic`) are applied.

AI-assisted (Claude Code); tests run locally on an RTX 4060 Ti
(driver 621.01) and WARP.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant