Shaders, GPU: a heap index computed from data stays inside the heap #483

Closed
github-bot wants to merge 1 commit from gh-pr/483/head into gh-pr/483/base
Owner

@⁠Vaximous on GitHub · 2026-11-24 03:57 UTC · original
Vaximous:gpu/guard-heap-indices → main · +200 −11 · 7 files · 1 commits · closed without merging

Refs #71, #264, #97 (one cause of the NVIDIA world DEVICE_HUNG; not shown to be the only one).

What

Every descriptor-heap index the lowering computes is bounded: an index at or above the bound heap's guard slot reads the guard slot instead. The host reserves one null slot at the end of each view heap for this and passes its index to the shader in a new user-data dword.

Why

Translated programs that load descriptors bindless read an index from a buffer, shift it left by 5 (4 for samplers), add it to the heap or table address and s_load_dwordx4 the descriptor there. Lower::heap_index turned that address into createHandleFromHeap(addr >> 5) with no bound. When the host's copy of the buffer is stale or zero, the index can be anything up to 2^27, far past the host view heap (PORTABLE_VIEWS = 1,000,000 slots on NVIDIA).

An index past the heap is undefined in D3D12, and NVIDIA does not fault on it: measured on an RTX 4070 Ti with the synthetic test below, a store through heap index 2^25 lands in slot 0: the hardware wraps the index onto an unrelated slot. In the title the wrapped slot holds a descriptor of another kind, the dispatch never finishes, and the driver removes the device with DXGI_ERROR_DEVICE_HUNG and no DRED page fault.

What pointed there, in the title on this machine (observed on a local integration branch of main plus many open PRs): the programs that hang have no barriers; VICTORY_SHADER_LOOP_LIMIT=64 still hangs; skipping one of them moves the hang to another program of the same kind (bindless descriptor fetch).

Changes

  • victory-shader, emit/lower.rs: heap_index ends in heap_guard(index, sampler): idx <u guard ? idx : guard (one compare, one select). The guard is read once per program from a user-data dword placed after every dword the program's root parameters reach, recorded as a UserData entry with root type ResourceHeap (view heap) or SamplerHeap. user() is split so the guard read shares the user-data load (user_dword).
  • emit/mod.rs: the binding notes and UserData::root doc describe the new entry. This is a change to the binding scheme the module notes say is announced: a host that fills user data must fill these entries (user_data_dwords() already covers them, so root-signature sizes stay consistent).
  • victory-gpu, descriptor/host.rs: a view heap gets one slot more after its DYNAMIC slots (null from the start, never made); HostHeap::guard_slot() returns it. A sampler heap's guard is its last slot (any sampler reads safely). The capped-heap path reserves the slot inside PORTABLE_VIEWS.
  • draw.rs: user_dword() fills the guard entries from the bound heaps at draw/dispatch (and in the device-removed description); other entries go through user_value as before.
  • Test harness (emit/host.rs): the draw/dispatch view heaps keep a null slot after their views; guard() gives the test helpers the value to fill. diff_tests passes u32::MAX (its views are all in range).

Cost: one compare and select per bindless descriptor fetch, and one user-data dword per stage that does one.

Tested

Machine: RTX 4070 Ti, Ryzen 9 7900X, Windows 11 26300.

  • New test emit::valu_tests::a_heap_index_past_the_heap_reads_the_guard_slot: a one-thread program loads a UAV descriptor at table address + (data << 5) and stores through it, for index 0, 1 (the guard), 2^25 and 0x07FF_FFFF. With the select removed from heap_guard (temporary edit) it fails on hardware: index 0x2000000 writes 7 into slot 0. With the change it passes on hardware and WARP.
  • cargo test -p victory-shader -- --test-threads=1: 70 passed, 0 failed (main: 69 passed; the extra one is the new test).
  • cargo test -p victory-gpu -- --test-threads=1: 43 passed, 1 ignored, 0 failed (same as main).
  • cargo clippy -p victory-shader -p victory-gpu --all-targets: no new warnings (the one existing warning is on main too).
  • cargo xtask policy --staged: ok.

Title (build 1.0.2.1, diag build, scripted Enter presses, VICTORY_D3D12_DRED=1):

  • Local integration branch (main + many open PRs) with this change (where the change was developed): the title ran 220 s in the world with no device removal. The same branch without the change hung with DEVICE_HUNG within seconds of world entry on every run.
  • This branch (plain main + this change), two runs: in the first, the world started about 160 s in and the run reached its 240 s limit (about 80 s in the world) with no device removal. In the second, the device was removed with DEVICE_HUNG (0x887A0006) about 45 s after the world started. DRED breadcrumbs stop at a mesh draw (DispatchMesh), not at one of the bindless compute dispatches this change is about. The guard dwords held the expected values (view heap capped at 1,000,000: guard 999,999; sampler guard 127).
  • Plain main, one run on the same machine for comparison: DEVICE_HUNG about 55 s after the world started, with no breadcrumbs.

So on plain main this change alone does not make the world stable on NVIDIA: another hang remains (mesh path; other open PRs, for example #89 for an invalid render-target view on a 16-bit packed format, address other NVIDIA failures). This PR removes one cause, the wrapped heap index, which the synthetic test reproduces in isolation. Scripted keys only; frame rate in the world is very low here (seconds per frame), so the time in the world is short in every run.

Not tested

  • AMD, Intel: no hardware here. Whether they wrap, fault or read garbage past a heap was not measured; the guard makes it moot for them too, but the title was not run there.
  • WARP in the title (WARP runs only the synthetic test).
  • Interaction with #413 (bindless ResourceDescriptorHeap materialization) and #100 (sampler heap cap at 2,048): neither is merged here. They touch the same files (descriptor/host.rs, draw.rs). #413 makes in-range bindless slots hold the right views; this PR keeps out-of-range indices off unrelated slots, so the two are complementary. With #100 a capped sampler heap's guard is still its last host slot.
  • Related open PRs that do not do this: #411 (heaps required per pipeline), #185 (shadow coherency for directly indexed SRVs, which may make stale indices rarer but cannot bound them), #292 and #452 (loop budgets; they do not help this hang).

AI use: written with Claude Code (Claude Opus 5.5 executing, Claude Fable 5.2 planning), tested on the submitter's hardware.

🤖 Generated with Claude Code

**@⁠Vaximous** on GitHub · 2026-11-24 03:57 UTC · [original](https://github.com/Marvisak/VIctory/pull/483) `Vaximous:gpu/guard-heap-indices` → `main` · +200 −11 · 7 files · 1 commits · closed without merging Refs #71, #264, #97 (one cause of the NVIDIA world `DEVICE_HUNG`; not shown to be the only one). ## What Every descriptor-heap index the lowering computes is bounded: an index at or above the bound heap's *guard slot* reads the guard slot instead. The host reserves one null slot at the end of each view heap for this and passes its index to the shader in a new user-data dword. ## Why Translated programs that load descriptors bindless read an index from a buffer, shift it left by 5 (4 for samplers), add it to the heap or table address and `s_load_dwordx4` the descriptor there. `Lower::heap_index` turned that address into `createHandleFromHeap(addr >> 5)` with no bound. When the host's copy of the buffer is stale or zero, the index can be anything up to 2^27, far past the host view heap (`PORTABLE_VIEWS` = 1,000,000 slots on NVIDIA). An index past the heap is undefined in D3D12, and NVIDIA does not fault on it: measured on an RTX 4070 Ti with the synthetic test below, **a store through heap index 2^25 lands in slot 0**: the hardware wraps the index onto an unrelated slot. In the title the wrapped slot holds a descriptor of another kind, the dispatch never finishes, and the driver removes the device with `DXGI_ERROR_DEVICE_HUNG` and no DRED page fault. What pointed there, in the title on this machine (observed on a local integration branch of main plus many open PRs): the programs that hang have no barriers; `VICTORY_SHADER_LOOP_LIMIT=64` still hangs; skipping one of them moves the hang to another program of the same kind (bindless descriptor fetch). ## Changes - `victory-shader`, `emit/lower.rs`: `heap_index` ends in `heap_guard(index, sampler)`: `idx <u guard ? idx : guard` (one compare, one select). The guard is read once per program from a user-data dword placed after every dword the program's root parameters reach, recorded as a `UserData` entry with root type `ResourceHeap` (view heap) or `SamplerHeap`. `user()` is split so the guard read shares the user-data load (`user_dword`). - `emit/mod.rs`: the binding notes and `UserData::root` doc describe the new entry. This is a change to the binding scheme the module notes say is announced: a host that fills user data must fill these entries (`user_data_dwords()` already covers them, so root-signature sizes stay consistent). - `victory-gpu`, `descriptor/host.rs`: a view heap gets one slot more after its `DYNAMIC` slots (null from the start, never made); `HostHeap::guard_slot()` returns it. A sampler heap's guard is its last slot (any sampler reads safely). The capped-heap path reserves the slot inside `PORTABLE_VIEWS`. - `draw.rs`: `user_dword()` fills the guard entries from the bound heaps at draw/dispatch (and in the device-removed description); other entries go through `user_value` as before. - Test harness (`emit/host.rs`): the draw/dispatch view heaps keep a null slot after their views; `guard()` gives the test helpers the value to fill. `diff_tests` passes `u32::MAX` (its views are all in range). Cost: one compare and select per bindless descriptor fetch, and one user-data dword per stage that does one. ## Tested Machine: RTX 4070 Ti, Ryzen 9 7900X, Windows 11 26300. - New test `emit::valu_tests::a_heap_index_past_the_heap_reads_the_guard_slot`: a one-thread program loads a UAV descriptor at table address + (data << 5) and stores through it, for index 0, 1 (the guard), 2^25 and 0x07FF_FFFF. With the select removed from `heap_guard` (temporary edit) it fails on hardware: `index 0x2000000` writes 7 into slot 0. With the change it passes on hardware and WARP. - `cargo test -p victory-shader -- --test-threads=1`: 70 passed, 0 failed (main: 69 passed; the extra one is the new test). - `cargo test -p victory-gpu -- --test-threads=1`: 43 passed, 1 ignored, 0 failed (same as main). - `cargo clippy -p victory-shader -p victory-gpu --all-targets`: no new warnings (the one existing warning is on main too). - `cargo xtask policy --staged`: ok. Title (build 1.0.2.1, diag build, scripted Enter presses, `VICTORY_D3D12_DRED=1`): - **Local integration branch (main + many open PRs) with this change** (where the change was developed): the title ran 220 s in the world with no device removal. The same branch without the change hung with `DEVICE_HUNG` within seconds of world entry on every run. - **This branch (plain main + this change), two runs**: in the first, the world started about 160 s in and the run reached its 240 s limit (about 80 s in the world) with no device removal. In the second, the device was removed with `DEVICE_HUNG` (0x887A0006) about 45 s after the world started. DRED breadcrumbs stop at a **mesh** draw (`DispatchMesh`), not at one of the bindless compute dispatches this change is about. The guard dwords held the expected values (view heap capped at 1,000,000: guard 999,999; sampler guard 127). - **Plain main, one run on the same machine for comparison**: `DEVICE_HUNG` about 55 s after the world started, with no breadcrumbs. So on plain main this change alone does not make the world stable on NVIDIA: another hang remains (mesh path; other open PRs, for example #89 for an invalid render-target view on a 16-bit packed format, address other NVIDIA failures). This PR removes one cause, the wrapped heap index, which the synthetic test reproduces in isolation. Scripted keys only; frame rate in the world is very low here (seconds per frame), so the time in the world is short in every run. ## Not tested - AMD, Intel: no hardware here. Whether they wrap, fault or read garbage past a heap was not measured; the guard makes it moot for them too, but the title was not run there. - WARP in the title (WARP runs only the synthetic test). - Interaction with #413 (bindless `ResourceDescriptorHeap` materialization) and #100 (sampler heap cap at 2,048): neither is merged here. They touch the same files (`descriptor/host.rs`, `draw.rs`). #413 makes in-range bindless slots hold the right views; this PR keeps out-of-range indices off unrelated slots, so the two are complementary. With #100 a capped sampler heap's guard is still its last host slot. - Related open PRs that do not do this: #411 (heaps required per pipeline), #185 (shadow coherency for directly indexed SRVs, which may make stale indices rarer but cannot bound them), #292 and #452 (loop budgets; they do not help this hang). AI use: written with Claude Code (Claude Opus 5.5 executing, Claude Fable 5.2 planning), tested on the submitter's hardware. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Translated programs that load their descriptors bindless add an index
read from a buffer (shifted to the console's descriptor size) to the
heap or table address, and the lowering turned that address into a
ResourceDescriptorHeap / SamplerDescriptorHeap index with no bound. When
the host's copy of that buffer is stale or zero, the index can be
anything up to 2^27, far past the host heap. An index past a heap is
undefined: on NVIDIA (RTX 4070 Ti) a store through index 2^25 lands in
slot 0, so the hardware wraps it onto an unrelated slot. In a title the
wrapped slot holds a descriptor of another kind, the dispatch never
finishes, and the driver removes the device with DXGI_ERROR_DEVICE_HUNG
and no page fault. Loop limits do not help: the programs that hang have
no barriers and no long loops.

Every heap index the lowering computes now goes through a guard: an
index at or above the bound heap's guard slot reads that slot instead
(an unsigned compare and a select). The guard slot comes in a user-data
dword of its own, after every dword the program's root parameters reach
(a UserData entry of root type ResourceHeap / SamplerHeap). The host
gives each view heap one slot more, after its dynamic slots, null from
the start and never made; a sampler heap's guard is its last slot (any
sampler reads safely). The pipeline's root constants already cover
user_data_dwords(), and draws and dispatches fill the new dwords from
the bound heaps.

Test: a_heap_index_past_the_heap_reads_the_guard_slot (without the
select, the store at index 2^25 lands in slot 0 on NVIDIA). The test
harness keeps a null slot after its views; the helpers fill the guard
dwords.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:05:39 +00:00
github-bot closed this pull request 2026-11-26 04:05:39 +00:00
Author
Owner

@⁠DaviTostes on GitHub · 2026-11-24 04:03 UTC · original

Verified 65a161d on Arch Linux x86_64, Windows MSVC release build under Wine 11.22 (victory-gpu, --test-threads=1): 43 passed, 0 failed, 1 ignored.

Not covered: a heap index computed by the title's data actually clamped at draw time (no game data here).

**@⁠DaviTostes** on GitHub · 2026-11-24 04:03 UTC · [original](https://github.com/Marvisak/VIctory/pull/483#issuecomment-7121660102) Verified `65a161d` on **Arch Linux x86_64**, Windows MSVC release build under **Wine 11.22** (`victory-gpu`, `--test-threads=1`): **43 passed, 0 failed, 1 ignored**. Not covered: a heap index computed by the title's data actually clamped at draw time (no game data here).
Author
Owner

@⁠miniongk on GitHub · 2026-11-24 04:06 UTC · original

Confirmed on an RTX 5080, driver 621.24, Windows 11 26300, using a local Xbox Series 1.0.2.1 copy at 65a161d.

  • emit::valu_tests::a_heap_index_past_the_heap_reads_the_guard_slot: passed in 0.28 s.
  • cargo test --workspace: 265 passed, 0 failed, 4 ignored.
  • The native run still ended in DXGI_ERROR_DEVICE_HUNG; DRED implicated indirect execution and mesh dispatch, consistent with the remaining hang your report describes.

The synthetic guard test works here, but the world is not stable on this hardware yet. Only aggregate counts and error classes shared. AI-assisted (Kimi Code).

**@⁠miniongk** on GitHub · 2026-11-24 04:06 UTC · [original](https://github.com/Marvisak/VIctory/pull/483#issuecomment-7121720054) Confirmed on an RTX 5080, driver 621.24, Windows 11 26300, using a local Xbox Series 1.0.2.1 copy at `65a161d`. - `emit::valu_tests::a_heap_index_past_the_heap_reads_the_guard_slot`: passed in 0.28 s. - `cargo test --workspace`: 265 passed, 0 failed, 4 ignored. - The native run still ended in `DXGI_ERROR_DEVICE_HUNG`; DRED implicated indirect execution and mesh dispatch, consistent with the remaining hang your report describes. The synthetic guard test works here, but the world is not stable on this hardware yet. Only aggregate counts and error classes shared. AI-assisted (Kimi Code).
Author
Owner

@⁠erickbobd on GitHub · 2026-11-24 05:06 UTC · original

Independent synthetic check on RTX 5070 Ti, NVIDIA 617.14, Windows 11 25H2 26200.9974, Rust 1.98.1 / MSVC x64, with the Windows SDK 10.0.26100.0 dxil.dll explicitly selected.

  • a_heap_index_past_the_heap_reads_the_guard_slot passes on hardware and WARP.
  • Negative control: removing only the final select from heap_guard makes the hardware test fail at index 0x02000000: slot 0 receives 7, expected 0. This independently reproduces the wrap on Blackwell. Restoring the select passes.
  • With #336's capped sizing, the heap has 1,000,000 slots, 65,536 dynamic slots, and guard 999,999. A synthetic allocation test consumes the whole dynamic range and verifies that the guard cannot be allocated. Replacing the guard calculation with count + DYNAMIC fails: 1,196,607 versus 999,999.

These were checked on local integration 8693373: main d2a4bae + #493 (including #336), #483 at 65a161d3, #189, #89, #205, #206, #469, #459, #454 and #211. Serial library suites after both mutations were restored: victory-gpu 55 passed / 1 ignored; victory-shader 88 passed. These counts include the other PRs and an additional local allocation test.

No world-stability claim: the local title probe was stopped during loading for low system commit headroom. No game files, captures or logs attached. AI-assisted (Codex).

**@⁠erickbobd** on GitHub · 2026-11-24 05:06 UTC · [original](https://github.com/Marvisak/VIctory/pull/483#issuecomment-7122622783) Independent synthetic check on **RTX 5070 Ti, NVIDIA 617.14, Windows 11 25H2 26200.9974**, Rust 1.98.1 / MSVC x64, with the Windows SDK 10.0.26100.0 `dxil.dll` explicitly selected. - `a_heap_index_past_the_heap_reads_the_guard_slot` passes on hardware and WARP. - Negative control: removing only the final select from `heap_guard` makes the hardware test fail at index `0x02000000`: slot 0 receives **7**, expected **0**. This independently reproduces the wrap on Blackwell. Restoring the select passes. - With #336's capped sizing, the heap has 1,000,000 slots, 65,536 dynamic slots, and guard **999,999**. A synthetic allocation test consumes the whole dynamic range and verifies that the guard cannot be allocated. Replacing the guard calculation with `count + DYNAMIC` fails: 1,196,607 versus 999,999. These were checked on local integration `8693373`: `main d2a4bae` + #493 (including #336), #483 at `65a161d3`, #189, #89, #205, #206, #469, #459, #454 and #211. Serial library suites after both mutations were restored: **victory-gpu 55 passed / 1 ignored; victory-shader 88 passed**. These counts include the other PRs and an additional local allocation test. No world-stability claim: the local title probe was stopped during loading for low system commit headroom. No game files, captures or logs attached. AI-assisted (Codex).
Author
Owner

@⁠wwwwwwww3333333 on GitHub · 2026-11-24 05:23 UTC · original

RDNA2 result, including the negative control. On an AMD RX 6750 XT (RDNA2) / Windows 11 / Rust 1.98.1 MSVC, with this PR at 65a161d:

  • a_heap_index_past_the_heap_reads_the_guard_slot passes on hardware and WARP. There was no no SM 6.6 hardware device; skipped line under --nocapture, so it ran on the card. cargo test -p victory-shader -- --test-threads=1: 70 passed. cargo test -p victory-gpu: 43 passed, 1 ignored.
  • Negative control, same as @⁠erickbobd's: I removed only the final select in heap_guard, so index is used unclamped. The hardware stage then fails with dispatch failed: device removed, and the message is the standard DXGI_ERROR_DEVICE_HUNG text ("the GPU will not respond to more commands, most likely because of an invalid command passed by the calling application"). That reproduced 2 of 2 runs. There was no visible driver reset; the device was lost only inside the test process. Restoring the select passes again (exit 0).

So where NVIDIA wraps an out-of-heap index onto slot 0, RDNA2 loses the device. The panic doesn't say which of the out-of-range cases triggered it. This doesn't prove the AMD world crashes (#59, #304, #557) come from this, but it shows that an unbounded heap index is enough to remove the device on AMD too, not only to corrupt a slot on NVIDIA.

Not runtime-tested with game files. AI-assisted (Claude did the analysis and the one-line control change; I ran the tests on my machine).

**@⁠wwwwwwww3333333** on GitHub · 2026-11-24 05:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/483#issuecomment-7122897062) **RDNA2 result, including the negative control.** On an AMD RX 6750 XT (RDNA2) / Windows 11 / Rust 1.98.1 MSVC, with this PR at `65a161d`: - `a_heap_index_past_the_heap_reads_the_guard_slot` passes on **hardware and WARP**. There was no `no SM 6.6 hardware device; skipped` line under `--nocapture`, so it ran on the card. `cargo test -p victory-shader -- --test-threads=1`: 70 passed. `cargo test -p victory-gpu`: 43 passed, 1 ignored. - **Negative control**, same as @⁠erickbobd's: I removed only the final `select` in `heap_guard`, so `index` is used unclamped. The hardware stage then fails with `dispatch failed: device removed`, and the message is the standard `DXGI_ERROR_DEVICE_HUNG` text ("the GPU will not respond to more commands, most likely because of an invalid command passed by the calling application"). That reproduced 2 of 2 runs. There was no visible driver reset; the device was lost only inside the test process. Restoring the `select` passes again (exit 0). So where NVIDIA wraps an out-of-heap index onto slot 0, RDNA2 **loses the device**. The panic doesn't say which of the out-of-range cases triggered it. This doesn't prove the AMD world crashes (#59, #304, #557) come from this, but it shows that an unbounded heap index is enough to remove the device on AMD too, not only to corrupt a slot on NVIDIA. Not runtime-tested with game files. *AI-assisted (Claude did the analysis and the one-line control change; I ran the tests on my machine).*
Author
Owner

@⁠iurysf on GitHub · 2026-11-24 05:24 UTC · original

On an RTX 4070, GBV on main d2a4bae reports the case this PR guards: id 936, Descriptor heap index out of bounds via direct indexing: Heap Index From HeapStart: [117506306], Num Descriptor Entries: 1000000, Shader Stage: PIXEL. Together with #493, the host device removal we hit every run on main is gone for 300 s (details in my comment on #493). Its tests pass on this machine. I could not isolate this PR in game without #493.

**@⁠iurysf** on GitHub · 2026-11-24 05:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/483#issuecomment-7122922450) On an RTX 4070, GBV on main `d2a4bae` reports the case this PR guards: id 936, `Descriptor heap index out of bounds via direct indexing: Heap Index From HeapStart: [117506306], Num Descriptor Entries: 1000000, Shader Stage: PIXEL`. Together with #493, the host device removal we hit every run on main is gone for 300 s (details in my comment on #493). Its tests pass on this machine. I could not isolate this PR in game without #493.
Author
Owner

@⁠etcetera-yt on GitHub · 2026-11-24 05:36 UTC · original

#483 puts a view heap's guard slot right after the dynamic slots (extra = DYNAMIC + 1,
guard_slot() = count + DYNAMIC). On main that is safe: HostHeap::dynamic hands out slots from a pool sized
DYNAMIC, so the guard is never given to a table.

#86 replaces that pool with one sized from the heap's spare slots (spare = extra). With both merged, the pool is
DYNAMIC + 1 slots long, and dynamic can return the guard slot itself; a table made there overwrites the guard,
so data-computed indices that #483 sends to the guard would read that table instead of a null view.

Whichever of the two lands second needs to keep the guard out of the pool. In my local merge I marked the last
spare slot of a view heap as taken when the heap is made (next: Mutex::new((0, taken)) with taken.last_mut()
set), and dynamic_slots_are_held_until_released and the rest of the victory-gpu tests still pass
(Windows 10 19045, RTX 5060 Ti).

AI use: Claude Code, Claude Opus 5.5.

**@⁠etcetera-yt** on GitHub · 2026-11-24 05:36 UTC · [original](https://github.com/Marvisak/VIctory/pull/483#issuecomment-7123106028) #483 puts a view heap's guard slot right after the dynamic slots (`extra = DYNAMIC + 1`, `guard_slot() = count + DYNAMIC`). On `main` that is safe: `HostHeap::dynamic` hands out slots from a pool sized `DYNAMIC`, so the guard is never given to a table. #86 replaces that pool with one sized from the heap's spare slots (`spare = extra`). With both merged, the pool is `DYNAMIC + 1` slots long, and `dynamic` can return the guard slot itself; a table made there overwrites the guard, so data-computed indices that #483 sends to the guard would read that table instead of a null view. Whichever of the two lands second needs to keep the guard out of the pool. In my local merge I marked the last spare slot of a view heap as taken when the heap is made (`next: Mutex::new((0, taken))` with `taken.last_mut()` set), and `dynamic_slots_are_held_until_released` and the rest of the `victory-gpu` tests still pass (Windows 10 19045, RTX 5060 Ti). AI use: Claude Code, Claude Opus 5.5.
Author
Owner

@⁠Vaximous on GitHub · 2026-11-24 05:58 UTC · original

Thanks, that's right, and I hit the same thing in a local merge of both.

  • On main as this PR stands: the dynamic pool is vec![false; DYNAMIC] and dynamic() only searches 0..DYNAMIC, so the guard at count + DYNAMIC is never handed out.
  • With #86: the pool is sized from the spare slots, so with extra = DYNAMIC + 1 it covers the guard. The fix is what you did: keep one slot out of the pool. In my integration branch (main + #86 + #100 + this PR and many others) view heaps were already fine, because the pool there is sized before the guard is added. The capped sampler heap was not: its guard was the last dynamic slot. I fixed it by making the guard its own slot past the 255 dynamic ones, with a test that no dynamic() request ever returns guard_slot().

Whichever of #86 and this PR lands second should carry that change. If #86 merges first, I'll rebase this PR onto it and add the reservation and the test here.

AI use: Claude Code (Claude Opus 5.5).

**@⁠Vaximous** on GitHub · 2026-11-24 05:58 UTC · [original](https://github.com/Marvisak/VIctory/pull/483#issuecomment-7123449261) Thanks, that's right, and I hit the same thing in a local merge of both. - **On `main` as this PR stands:** the dynamic pool is `vec![false; DYNAMIC]` and `dynamic()` only searches `0..DYNAMIC`, so the guard at `count + DYNAMIC` is never handed out. - **With #86:** the pool is sized from the spare slots, so with `extra = DYNAMIC + 1` it covers the guard. The fix is what you did: keep one slot out of the pool. In my integration branch (main + #86 + #100 + this PR and many others) view heaps were already fine, because the pool there is sized before the guard is added. The **capped sampler heap** was not: its guard was the last dynamic slot. I fixed it by making the guard its own slot past the 255 dynamic ones, with a test that no `dynamic()` request ever returns `guard_slot()`. Whichever of #86 and this PR lands second should carry that change. If #86 merges first, I'll rebase this PR onto it and add the reservation and the test here. AI use: Claude Code (Claude Opus 5.5).
Author
Owner

@⁠walterwallaceson on GitHub · 2026-11-24 06:47 UTC · original

Windows 10 data point for #493 (c48b240) + #483 (65a161d): no device removal on an RTX 3070.

Setup: Windows 10 22H2 (19045.6466), RTX 3070, NVIDIA 621.14, Ryzen 5 5600X, release build, Agility SDK 1.620.2 via #175. Base stack: #175, #233 + #320 + #439 (f653ea4), #55, #89, #336 (e8d3b64), #334 (af2aecf). This GPU caps the view heap at 1,000,000, so #336/#493 take the 2^16 dynamic range. #493 and #483 conflict in descriptor/host.rs; I resolved it as described on #493: #493's DYNAMIC / MIN_DYNAMIC selection plus one guard slot (make(count + DYNAMIC + guard), capped branch PORTABLE_VIEWS - (MIN_DYNAMIC + guard)), the guard kept out of the dynamic pool, and guard_slot() returning count + self.dynamic.

base stack + #493 + #483
device removed yes, ~2–2.5 min into the world (0x887A0006 / DEVICE_HUNG) no, none in ~5.5 min in the world
what renders first mission title card, cutscene subtitles over a black scene the same, then the opening credits text and 2D credit art over the still-black 3D scene, for several minutes
no free dynamic descriptor slots ~8 s into the world ~2 min into the world
draws dropped (no dynamic slots) up to 16384–65536 up to 65536
  • Frame rate in the world 0.2–1.8 fps; 60 slow host submission lines, 0 host pipelines refused, 0 no host texture.
  • What ends the run now is the title, not the GPU: 0x80000003 (a breakpoint) at title +0x5149aec on 7 threads at once, all with the same stack (+0xa5db22, +0x5453ac7, +0x23d0f9a, …). The title then tries to upload a crash report, which VIctory's network policy blocks. I couldn't find that address in an issue yet.
  • cargo test --workspace: #483's a_heap_index_past_the_heap_reads_the_guard_slot fails here with "neither hardware nor WARP SM 6.6 device available", the same Windows 10 cause as the other valu_tests (#362). Otherwise only the known Windows 10 failures.

One run so far.

No game data in this report.

AI-assisted (Claude Code); everything above was run on my machine.

**@⁠walterwallaceson** on GitHub · 2026-11-24 06:47 UTC · [original](https://github.com/Marvisak/VIctory/pull/483#issuecomment-7124292149) Windows 10 data point for #493 (c48b240) + #483 (65a161d): no device removal on an RTX 3070. Setup: Windows 10 22H2 (19045.6466), RTX 3070, NVIDIA 621.14, Ryzen 5 5600X, release build, Agility SDK 1.620.2 via #175. Base stack: #175, #233 + #320 + #439 (f653ea4), #55, #89, #336 (e8d3b64), #334 (af2aecf). This GPU caps the view heap at 1,000,000, so #336/#493 take the 2^16 dynamic range. #493 and #483 conflict in `descriptor/host.rs`; I resolved it as described on #493: #493's `DYNAMIC` / `MIN_DYNAMIC` selection plus one guard slot (`make(count + DYNAMIC + guard)`, capped branch `PORTABLE_VIEWS - (MIN_DYNAMIC + guard)`), the guard kept out of the dynamic pool, and `guard_slot()` returning `count + self.dynamic`. | | base stack | + #493 + #483 | |---|---|---| | device removed | yes, ~2–2.5 min into the world (`0x887A0006` / `DEVICE_HUNG`) | **no**, none in ~5.5 min in the world | | what renders | first mission title card, cutscene subtitles over a black scene | the same, then the opening credits text and 2D credit art over the still-black 3D scene, for several minutes | | `no free dynamic descriptor slots` | ~8 s into the world | ~2 min into the world | | draws dropped (no dynamic slots) | up to 16384–65536 | up to 65536 | - Frame rate in the world 0.2–1.8 fps; 60 `slow host submission` lines, 0 host pipelines refused, 0 `no host texture`. - What ends the run now is the title, not the GPU: `0x80000003` (a breakpoint) at title `+0x5149aec` on 7 threads at once, all with the same stack (`+0xa5db22`, `+0x5453ac7`, `+0x23d0f9a`, …). The title then tries to upload a crash report, which VIctory's network policy blocks. I couldn't find that address in an issue yet. - `cargo test --workspace`: #483's `a_heap_index_past_the_heap_reads_the_guard_slot` fails here with "neither hardware nor WARP SM 6.6 device available", the same Windows 10 cause as the other `valu_tests` (#362). Otherwise only the known Windows 10 failures. One run so far. No game data in this report. AI-assisted (Claude Code); everything above was run on my machine.
Author
Owner

@⁠ghost on GitHub · 2026-11-24 09:27 UTC · original

AMD data point from r4tedx's tester tree, where this PR is merged by hand (7ef2c41): on an RX 9060 XT the title dies seconds into the world inside AMD's driver (amdxc64.dll) from that merge on, and not with it reverted. Bisect and details: #293. Not tested: this PR alone (it conflicts with my base in descriptor/host.rs), so it may be the tree's merge rather than the PR; NVIDIA runs of the tree don't show it.

AI-assisted (Claude Code, Claude Opus 5.5); no game data.

**@⁠ghost** on GitHub · 2026-11-24 09:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/483#issuecomment-7127443554) AMD data point from r4tedx's tester tree, where this PR is merged by hand (`7ef2c41`): on an RX 9060 XT the title dies seconds into the world inside AMD's driver (`amdxc64.dll`) from that merge on, and not with it reverted. Bisect and details: https://git.gtahub.st/github/Marvisak--VIctory/issues/293. Not tested: this PR alone (it conflicts with my base in `descriptor/host.rs`), so it may be the tree's merge rather than the PR; NVIDIA runs of the tree don't show it. AI-assisted (Claude Code, Claude Opus 5.5); no game data.
Author
Owner

@⁠MD5Visual on GitHub · 2026-11-24 10:19 UTC · original

Three runs on an RTX 3090 (24 GB) that all end where this PR says they should - a heap index computed from data, past the heap - so I think this is worth merging on its own evidence, not only as part of the integration tree.

Windows 11 Pro 26200, Ryzen 7 5800X3D, 64 GB, RTX 3090 24 GB, driver 32.0.16.1088 (610.88), title 1.0.2.1 b99f876b..., diagnostics build with DRED, same input sequence each time:

tree heap the host made index the faulting dispatch asked for device removed
main 8e79c80 340,872 slots 0xa67100 = 10,908,160 188 s, after ms=11225 lists=1
lane-mask branch 49d6d98 619,449 slots 0x12e7720 = 19,821,856 203 s, after ms=8956 lists=22
main ffe310e (with #566) 512,640 slots 0xfa5000 = 16,400,384 171 s, after ms=8926 lists=17

Each breadcrumb reads [heap N: null] for a descriptor index five to thirty times past N, in a submission that took 9-11 s, and the device is gone immediately after. Nothing here is memory pressure: 20+ GB of the 24 GB is free at the time.

The third row is current main, so the per-lane descriptor work in #566 does not change this: 118 refused compute pipelines against 117 on 8e79c80, 424 untranslated against 428.

#483 is in r4tedx's integration tree, and that tree is where the no-removal reports on a 5080, a 3080 and a 3070 come from, so as far as I can tell this is the one fix that addresses the failure we can reproduce on Ampere. What I cannot tell from the title's logs is whether the world would then render or stay dark - the reports so far say dark either way.

**@⁠MD5Visual** on GitHub · 2026-11-24 10:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/483#issuecomment-7128625486) Three runs on an RTX 3090 (24 GB) that all end where this PR says they should - a heap index computed from data, past the heap - so I think this is worth merging on its own evidence, not only as part of the integration tree. Windows 11 Pro 26200, Ryzen 7 5800X3D, 64 GB, RTX 3090 24 GB, driver 32.0.16.1088 (610.88), title 1.0.2.1 `b99f876b...`, diagnostics build with DRED, same input sequence each time: | tree | heap the host made | index the faulting dispatch asked for | device removed | |---|---|---|---| | `main 8e79c80` | 340,872 slots | `0xa67100` = 10,908,160 | 188 s, after `ms=11225 lists=1` | | `lane-mask branch 49d6d98` | 619,449 slots | `0x12e7720` = 19,821,856 | 203 s, after `ms=8956 lists=22` | | `main ffe310e` (with #566) | 512,640 slots | `0xfa5000` = 16,400,384 | 171 s, after `ms=8926 lists=17` | Each breadcrumb reads `[heap N: null]` for a descriptor index five to thirty times past `N`, in a submission that took 9-11 s, and the device is gone immediately after. Nothing here is memory pressure: 20+ GB of the 24 GB is free at the time. The third row is current main, so the per-lane descriptor work in #566 does not change this: 118 refused compute pipelines against 117 on `8e79c80`, 424 untranslated against 428. #483 is in r4tedx's integration tree, and that tree is where the no-removal reports on a 5080, a 3080 and a 3070 come from, so as far as I can tell this is the one fix that addresses the failure we can reproduce on Ampere. What I cannot tell from the title's logs is whether the world would then render or stay dark - the reports so far say dark either way.
Author
Owner

@⁠h0useadv on GitHub · 2026-11-24 11:01 UTC · original

RX 9070 XT data point for this PR stacked with #493, plus one merge note for current main.

Merge note. On main ffe310e, this PR conflicts in descriptor/host.rs with #336's three-tier heap sizing: DYNAMIC = 2^18 where the host takes it, otherwise MIN_DYNAMIC = 2^16, then the PORTABLE_VIEWS cap. Taking either side loses something. What I did:

  • heap sizes: each view-heap size gets the guard slot on top: make(count + DYNAMIC + 1), then make(count + MIN_DYNAMIC + 1), and when capped, PORTABLE_VIEWS - MIN_DYNAMIC - 1 title slots;
  • kept, GPU_RANGES and fill_null cover count + extra + 1, so the guard starts null;
  • guard_slot() returns self.count + self.dynamic, not self.count + DYNAMIC. After the merge, DYNAMIC is only right for uncapped heaps. On a heap that fell back to MIN_DYNAMIC, count + DYNAMIC points past the heap: the out-of-range read the guard is meant to prevent.

The valu_tests.rs conflict is just two new tests side by side.

Run (Windows 11 Pro 26300, driver 32.0.32029.2010, 7800X3D; diag build of ffe310e + #493 c48b240 + this PR merged as above; VICTORY_D3D12_DRED=1; scripted Enter presses into the first mission):

build world → device removed page fault
dd54de2 (6 runs) 22 to 149 s all just past the end of a 4 MB title-memory copy
dd54de2 + #493 (2 runs) 195 s, 445 s one unrelated low address; then none
ffe310e + #493 + this PR 453 s none: plain hang, a list stopped at command 176 of 182 (op 42), 32 lists

In the world: about 1 fps, ~2,500 draws/frame with ~500 still waiting on pipelines, 23 slow host submission lines, and audio running throughout. One run, so it doesn't separate this PR's effect from #493's or the 50 new commits on main. It does show the combination merges, builds and runs on RDNA4 with no page faults.

AI-assisted (Claude Code). Logs are VIctory's own output, with no game data.

**@⁠h0useadv** on GitHub · 2026-11-24 11:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/483#issuecomment-7129562449) RX 9070 XT data point for this PR stacked with #493, plus one merge note for current `main`. **Merge note.** On `main` `ffe310e`, this PR conflicts in `descriptor/host.rs` with #336's three-tier heap sizing: `DYNAMIC` = 2^18 where the host takes it, otherwise `MIN_DYNAMIC` = 2^16, then the `PORTABLE_VIEWS` cap. Taking either side loses something. What I did: - **heap sizes:** each view-heap size gets the guard slot on top: `make(count + DYNAMIC + 1)`, then `make(count + MIN_DYNAMIC + 1)`, and when capped, `PORTABLE_VIEWS - MIN_DYNAMIC - 1` title slots; - **`kept`, `GPU_RANGES` and `fill_null`** cover `count + extra + 1`, so the guard starts null; - **`guard_slot()`** returns `self.count + self.dynamic`, not `self.count + DYNAMIC`. After the merge, `DYNAMIC` is only right for uncapped heaps. On a heap that fell back to `MIN_DYNAMIC`, `count + DYNAMIC` points past the heap: the out-of-range read the guard is meant to prevent. The `valu_tests.rs` conflict is just two new tests side by side. **Run** (Windows 11 Pro 26300, driver 32.0.32029.2010, 7800X3D; diag build of `ffe310e` + #493 `c48b240` + this PR merged as above; `VICTORY_D3D12_DRED=1`; scripted Enter presses into the first mission): | build | world → device removed | page fault | |---|---|---| | `dd54de2` (6 runs) | 22 to 149 s | all just past the end of a 4 MB title-memory copy | | `dd54de2` + #493 (2 runs) | 195 s, 445 s | one unrelated low address; then none | | **`ffe310e` + #493 + this PR** | **453 s** | **none**: plain hang, `a list stopped at command 176 of 182 (op 42)`, 32 lists | In the world: about 1 fps, ~2,500 draws/frame with ~500 still waiting on pipelines, 23 `slow host submission` lines, and audio running throughout. One run, so it doesn't separate this PR's effect from #493's or the 50 new commits on `main`. It does show the combination merges, builds and runs on RDNA4 with no page faults. AI-assisted (Claude Code). Logs are VIctory's own output, with no game data.
Author
Owner

@⁠AimLogin on GitHub · 2026-11-24 13:21 UTC · original · edited 2026-11-24 14:18 UTC

<html>

@⁠Vaximous, your guard scheme is the base of an extension I've put up as AimLogin/VIctory#1 (in my fork, because upstream PRs are currently collaborator-only).

The commit is cc449ca. It builds on the #747 heap layout (3e3b8c5) and includes synthetic GPU readback tests.

Please feel free to incorporate any of these changes into your PR, in whole or in part, or integrate them separately. You and the maintainers decide how they should land.

Credit: The guard user dword placed after the user data, the user() / user_dword() split and the original null guard are yours. The integration notes from @⁠etcetera-yt, @⁠h0useadv and @⁠walterwallaceson are applied: the guards are kept out of the dynamic pool, and guard_slot = count + self.dynamic. Thanks also to @⁠erickbobd and @⁠wwwwwwww3333333 for their negative controls on Blackwell and RDNA2.

1. Separate bounds for direct and table reads

heap_bound implementation

A read straight from the heap (root ResourceHeap, base 0, a title index) is bounded by the host's title slots. A read through a table is bounded by the guard base.

On a capped heap, the slots between the title slots and the guards hold the host's per-draw tables. With one bound, a stale title index can access another draw's descriptor. Since the descriptor itself is valid, this need not produce a page fault or a DRED entry.

Synthetic readback on a 1,000,000-slot heap laid out as on a capped host, tested on an RTX 4060 Ti (driver 621.01) and WARP. Each case writes its own marker, and the readback identifies which UAV was written:

Direct index | Single-bound scheme | Two-bound scheme -- | -- | -- 737,855 (title) | Title UAV | Title UAV 737,856 / 934,463 / 934,464 / last dynamic slot | Another draw's UAV | Null guard 999,999 / 1,000,000 / 2^25 / 0x07FF_FFFF | Null guard | Null guard

Four differential tests require an unavailable Xbox SDK compiler, so their actual differential checks were not performed.

Negative controls were performed for single-bound direct accesses, unbounded fetched_index, and placement of bound dwords after the declared layout.

No unbounded out-of-heap access was executed on hardware.

Limitations and integration

  • No world run or AMD hardware validation.

  • No measurement of how frequently the title accesses indices beyond the available title slots.

  • Redirecting out-of-range accesses to null does not recover the intended resources.

  • Individual dynamic table lengths are not enforced.

  • Remaining root-signature overflow cases are not completely resolved.

Integration notes for #644, #688, #581, #413, #493, #86 and #100 are included in the linked fork PR.

This is offered as an extension to your existing work, not as a replacement for your contribution.

AI-assisted (Claude Code); the reported tests were run locally on this machine. No game files used.

</html>@⁠Vaximous, your guard scheme is the base of an extension I've put up as **[[AimLogin/VIctory#1](https://github.com/AimLogin/VIctory/pull/1)](https://github.com/AimLogin/VIctory/pull/1)** (in my fork, because upstream PRs are currently collaborator-only).

The commit is [cc449ca](github.com/AimLogin/VIctory@cc449ca941). It builds on the #747 heap layout ([3e3b8c5](github.com/AimLogin/VIctory@3e3b8c5841)) and includes synthetic GPU readback tests.

Please feel free to incorporate any of these changes into your PR, in whole or in part, or integrate them separately. You and the maintainers decide how they should land.

Credit: The guard user dword placed after the user data, the user() / user_dword() split and the original null guard are yours. The integration notes from @⁠etcetera-yt, @⁠h0useadv and @⁠walterwallaceson are applied: the guards are kept out of the dynamic pool, and guard_slot = count + self.dynamic. Thanks also to @⁠erickbobd and @⁠wwwwwwww3333333 for their negative controls on Blackwell and RDNA2.

1. Separate bounds for direct and table reads

heap_bound implementation

A read straight from the heap (root ResourceHeap, base 0, a title index) is bounded by the host's title slots. A read through a table is bounded by the guard base.

On a capped heap, the slots between the title slots and the guards hold the host's per-draw tables. With one bound, a stale title index can access another draw's descriptor. Since the descriptor itself is valid, this need not produce a page fault or a DRED entry.

Synthetic readback on a 1,000,000-slot heap laid out as on a capped host, tested on an RTX 4060 Ti (driver 621.01) and WARP. Each case writes its own marker, and the readback identifies which UAV was written:

Direct index Single-bound scheme Two-bound scheme
737,855 (title) Title UAV Title UAV
737,856 / 934,463 / 934,464 / last dynamic slot Another draw's UAV Null guard
999,999 / 1,000,000 / 2^25 / 0x07FF_FFFF Null guard Null guard

Fresh tables still reach their own dynamic slots up to the guard base.

One remaining limitation: table-rooted accesses are bounded by the guard base, not by the individual table's length. This does not prevent every possible cross-table access.

2. Bounding fetched_index

Per-lane descriptors loaded with global_load (Source::Fetched) go through fetched_index, which was not bounded in the reviewed version of this PR.

A lowering test on the waterfall fixtures checks that the bound is present. A mutation removing the bound causes the test to fail.

3. A guard per resource kind

HEAP_GUARDS implementation

The D3D12 resource binding specification requires compatible descriptor types for null accesses.

Reference: [D3D12 Resource Binding — NULL Descriptors](https://microsoft.github.io/DirectX-Specs/d3d/ResourceBinding.html).

  • GPU-based validation on the raw-UAV readback tests reported 20 descriptor-type mismatches with a single null Texture2D SRV guard.
  • With the typed guards, the same tests reported 0 GBV messages.
  • The heap now ends in 21 reserved null views: 12 SRV kinds, 8 UAV kinds and one CBV.
  • Each access selects its corresponding guard using a compile-time resource-kind offset.
  • GBV exercised the raw-UAV guard. The other supported kinds are covered by the descriptor construction and a mapping test for every access kind emitted by the lowering.
  • Typed null descriptors for empty table slots are prior work in #581 (@⁠FibbS6). This implementation instead types the reserved guard slots.

Whether a mismatched null descriptor contributed to @⁠nullmarsh's AMD crash remains unknown. I have not tested on AMD hardware.

4. Compact placement of bound dwords

Placing the bounds after the entire declared layout can grow a stage's root-constant block from 4 to 36 dwords (31 user SGPRs declared, two actually read). Two such stages could exceed the 64-dword root-signature limit.

The new implementation places the bounds immediately after the highest dword actually read by the program.

  • Lowering runs a second time where compact placement may save space.
  • The second result is accepted only if the real user-data reads remain identical and do not overlap the bounds.
  • If the second pass fails or is unsuitable, the valid first result is retained.
  • When compact placement is accepted, the increase is 0 or 4 dwords per stage.
  • The fallback can retain the larger constant block.
  • Device tests verify the 63/64/65-dword boundary, including root-CBV costs.

Pipelines already close to the 64-dword limit may still be refused. #644 (@⁠nathanbzrr) provides a complementary approach by spilling oversized constant blocks to root CBVs.

Validation

Check Result
Workspace tests (RTX 4060 Ti) 357 reported passed, 0 failed, 6 ignored
GPU/shader tests on WARP 188 reported passed, 0 failed, 2 ignored
Clippy -D warnings Passed
Clippy with --all-features Passed
Asset policy Passed
GBV descriptor-type mismatches 20 to 0 in the tested raw-UAV paths

Four differential tests require an unavailable Xbox SDK compiler, so their actual differential checks were not performed.

Negative controls were performed for single-bound direct accesses, unbounded fetched_index, and placement of bound dwords after the declared layout.

No unbounded out-of-heap access was executed on hardware.

Limitations and integration

  • No world run or AMD hardware validation.
  • No measurement of how frequently the title accesses indices beyond the available title slots.
  • Redirecting out-of-range accesses to null does not recover the intended resources.
  • Individual dynamic table lengths are not enforced.
  • Remaining root-signature overflow cases are not completely resolved.

Integration notes for #644, #688, #581, #413, #493, #86 and #100 are included in the linked fork PR.

This is offered as an extension to your existing work, not as a replacement for your contribution.

AI-assisted (Claude Code); the reported tests were run locally on this machine. No game files used.

**@⁠AimLogin** on GitHub · 2026-11-24 13:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/483#issuecomment-7132718717) · edited 2026-11-24 14:18 UTC <html> <body> <!--StartFragment--><p><span>@⁠Vaximous, your guard scheme is the base of an extension I've put up as </span><a href="https://github.com/AimLogin/VIctory/pull/1"><strong><span>AimLogin/VIctory#1</span></strong></a><span> (in my fork, because upstream PRs are currently collaborator-only).</span></p><p><span>The commit is </span><a href="https://github.com/AimLogin/VIctory/commit/cc449ca941abea558dc56271c10f7ce0459ab66a"><span>cc449ca</span></a><span>. It builds on the #747 heap layout (</span><a href="https://github.com/AimLogin/VIctory/commit/3e3b8c5841213fbd316a0875c06c5f85cb5200c2"><span>3e3b8c5</span></a><span>) and includes synthetic GPU readback tests.</span></p><p><span>Please feel free to incorporate any of these changes into your PR, in whole or in part, or integrate them separately. You and the maintainers decide how they should land.</span></p><p><strong><span>Credit:</span></strong><span> The guard user dword placed after the user data, the </span><code><span>user()</span></code><span> / </span><code><span>user_dword()</span></code><span> split and the original null guard are yours. The integration notes from @⁠etcetera-yt, @⁠h0useadv and @⁠walterwallaceson are applied: the guards are kept out of the dynamic pool, and </span><code><span>guard_slot = count + self.dynamic</span></code><span>. Thanks also to @⁠erickbobd and @⁠wwwwwwww3333333 for their negative controls on Blackwell and RDNA2.</span></p><h3><span>1. Separate bounds for direct and table reads</span></h3><p><a href="https://github.com/AimLogin/VIctory/blob/cc449ca941abea558dc56271c10f7ce0459ab66a/crates/victory-shader/src/emit/lower.rs#L3668"><code><span>heap_bound</span></code><span> implementation</span></a></p><p><span>A read straight from the heap (root </span><code><span>ResourceHeap</span></code><span>, base 0, a title index) is bounded by the host's title slots. A read through a table is bounded by the guard base.</span></p><p><span>On a capped heap, the slots between the title slots and the guards hold the host's per-draw tables. With one bound, a stale title index can access another draw's descriptor. Since the descriptor itself is valid, this need not produce a page fault or a DRED entry.</span></p><p><span>Synthetic readback on a 1,000,000-slot heap laid out as on a capped host, tested on an RTX 4060 Ti (driver 621.01) and WARP. Each case writes its own marker, and the readback identifies which UAV was written:</span></p> Direct index | Single-bound scheme | Two-bound scheme -- | -- | -- 737,855 (title) | Title UAV | Title UAV 737,856 / 934,463 / 934,464 / last dynamic slot | Another draw's UAV | Null guard 999,999 / 1,000,000 / 2^25 / 0x07FF_FFFF | Null guard | Null guard <p><span>Four differential tests require an unavailable Xbox SDK compiler, so their actual differential checks were not performed.</span></p><p><span>Negative controls were performed for single-bound direct accesses, unbounded </span><code><span>fetched_index</span></code><span>, and placement of bound dwords after the declared layout.</span></p><p><span>No unbounded out-of-heap access was executed on hardware.</span></p><h3><span>Limitations and integration</span></h3><ul><li><p><span>No world run or AMD hardware validation.</span></p></li><li><p><span>No measurement of how frequently the title accesses indices beyond the available title slots.</span></p></li><li><p><span>Redirecting out-of-range accesses to null does not recover the intended resources.</span></p></li><li><p><span>Individual dynamic table lengths are not enforced.</span></p></li><li><p><span>Remaining root-signature overflow cases are not completely resolved.</span></p></li></ul><p><span>Integration notes for #644, #688, #581, #413, #493, #86 and #100 are included in the linked fork PR.</span></p><p><span>This is offered as an extension to your existing work, not as a replacement for your contribution.</span></p><p><span>AI-assisted (Claude Code); the reported tests were run locally on this machine. No game files used.</span></p><!--EndFragment--> </body> </html>@⁠Vaximous, your guard scheme is the base of an extension I've put up as **[[AimLogin/VIctory#1](https://github.com/AimLogin/VIctory/pull/1)](https://github.com/AimLogin/VIctory/pull/1)** (in my fork, because upstream PRs are currently collaborator-only). The commit is [[cc449ca](https://github.com/AimLogin/VIctory/commit/cc449ca941abea558dc56271c10f7ce0459ab66a)](https://github.com/AimLogin/VIctory/commit/cc449ca941abea558dc56271c10f7ce0459ab66a). It builds on the #747 heap layout ([[3e3b8c5](https://github.com/AimLogin/VIctory/commit/3e3b8c5841213fbd316a0875c06c5f85cb5200c2)](https://github.com/AimLogin/VIctory/commit/3e3b8c5841213fbd316a0875c06c5f85cb5200c2)) and includes synthetic GPU readback tests. Please feel free to incorporate any of these changes into your PR, in whole or in part, or integrate them separately. You and the maintainers decide how they should land. **Credit:** The guard user dword placed after the user data, the `user()` / `user_dword()` split and the original null guard are yours. The integration notes from @⁠etcetera-yt, @⁠h0useadv and @⁠walterwallaceson are applied: the guards are kept out of the dynamic pool, and `guard_slot = count + self.dynamic`. Thanks also to @⁠erickbobd and @⁠wwwwwwww3333333 for their negative controls on Blackwell and RDNA2. ### 1. Separate bounds for direct and table reads [`heap_bound` implementation](https://github.com/AimLogin/VIctory/blob/cc449ca941abea558dc56271c10f7ce0459ab66a/crates/victory-shader/src/emit/lower.rs#L3668) A read straight from the heap (root `ResourceHeap`, base 0, a title index) is bounded by the host's title slots. A read through a table is bounded by the guard base. On a capped heap, the slots between the title slots and the guards hold the host's per-draw tables. With one bound, a stale title index can access another draw's descriptor. Since the descriptor itself is valid, this need not produce a page fault or a DRED entry. Synthetic readback on a 1,000,000-slot heap laid out as on a capped host, tested on an RTX 4060 Ti (driver 621.01) and WARP. Each case writes its own marker, and the readback identifies which UAV was written: | Direct index | Single-bound scheme | Two-bound scheme | |---|---|---| | 737,855 (title) | Title UAV | Title UAV | | 737,856 / 934,463 / 934,464 / last dynamic slot | **Another draw's UAV** | Null guard | | 999,999 / 1,000,000 / 2^25 / 0x07FF_FFFF | Null guard | Null guard | Fresh tables still reach their own dynamic slots up to the guard base. One remaining limitation: table-rooted accesses are bounded by the guard base, not by the individual table's length. This does not prevent every possible cross-table access. ### 2. Bounding `fetched_index` Per-lane descriptors loaded with `global_load` (`Source::Fetched`) go through `fetched_index`, which was not bounded in the reviewed version of this PR. A lowering test on the waterfall fixtures checks that the bound is present. A mutation removing the bound causes the test to fail. ### 3. A guard per resource kind [`HEAP_GUARDS` implementation](https://github.com/AimLogin/VIctory/blob/cc449ca941abea558dc56271c10f7ce0459ab66a/crates/victory-shader/src/emit/shader.rs#L24) The D3D12 resource binding specification requires compatible descriptor types for null accesses. Reference: [[D3D12 Resource Binding — NULL Descriptors](https://microsoft.github.io/DirectX-Specs/d3d/ResourceBinding.html)](https://microsoft.github.io/DirectX-Specs/d3d/ResourceBinding.html). - GPU-based validation on the raw-UAV readback tests reported **20 descriptor-type mismatches** with a single null Texture2D SRV guard. - With the typed guards, the same tests reported **0 GBV messages**. - The heap now ends in 21 reserved null views: 12 SRV kinds, 8 UAV kinds and one CBV. - Each access selects its corresponding guard using a compile-time resource-kind offset. - GBV exercised the raw-UAV guard. The other supported kinds are covered by the descriptor construction and a mapping test for every access kind emitted by the lowering. - Typed null descriptors for empty table slots are prior work in #581 (@⁠FibbS6). This implementation instead types the reserved guard slots. Whether a mismatched null descriptor contributed to @⁠nullmarsh's AMD crash remains unknown. I have not tested on AMD hardware. ### 4. Compact placement of bound dwords Placing the bounds after the entire declared layout can grow a stage's root-constant block from 4 to 36 dwords (31 user SGPRs declared, two actually read). Two such stages could exceed the 64-dword root-signature limit. The new implementation places the bounds immediately after the highest dword actually read by the program. - Lowering runs a second time where compact placement may save space. - The second result is accepted only if the real user-data reads remain identical and do not overlap the bounds. - If the second pass fails or is unsuitable, the valid first result is retained. - When compact placement is accepted, the increase is 0 or 4 dwords per stage. - The fallback can retain the larger constant block. - Device tests verify the 63/64/65-dword boundary, including root-CBV costs. Pipelines already close to the 64-dword limit may still be refused. #644 (@⁠nathanbzrr) provides a complementary approach by spilling oversized constant blocks to root CBVs. ### Validation | Check | Result | |---|---| | Workspace tests (RTX 4060 Ti) | 357 reported passed, 0 failed, 6 ignored | | GPU/shader tests on WARP | 188 reported passed, 0 failed, 2 ignored | | Clippy `-D warnings` | Passed | | Clippy with `--all-features` | Passed | | Asset policy | Passed | | GBV descriptor-type mismatches | 20 to 0 in the tested raw-UAV paths | Four differential tests require an unavailable Xbox SDK compiler, so their actual differential checks were not performed. Negative controls were performed for single-bound direct accesses, unbounded `fetched_index`, and placement of bound dwords after the declared layout. No unbounded out-of-heap access was executed on hardware. ### Limitations and integration - No world run or AMD hardware validation. - No measurement of how frequently the title accesses indices beyond the available title slots. - Redirecting out-of-range accesses to null does not recover the intended resources. - Individual dynamic table lengths are not enforced. - Remaining root-signature overflow cases are not completely resolved. Integration notes for #644, #688, #581, #413, #493, #86 and #100 are included in the linked fork PR. This is offered as an extension to your existing work, not as a replacement for your contribution. AI-assisted (Claude Code); the reported tests were run locally on this machine. No game files used.
Author
Owner

@⁠DuarttBR on GitHub · 2026-11-24 15:30 UTC · original

Merge notes from stacking this on current main (ffe310e, which now has #336), in case they save someone time. RTX 3080, Windows 11.

  • HostHeap::new conflicts with #336's sizing. I kept main's sizing (2^18 dynamic slots where the host takes them, else 2^16, else the 1,000,000 cap) and put the guard slot after the dynamic ones: guard_slot() returns count + self.dynamic, and the null fill, kept and GPU_RANGES cover count + extra + 1. On the capped NVIDIA heap the guard is slot 999,999. 036d742
  • Tests merged in main since then don't know the guard entry. The five emit::waterfall_tests assert every user-data entry is a Table, and the harnesses of #160's image tests and #265's scratch tests panic on an unexpected entry. With this PR a program that computes a heap index gets a ResourceHeap entry, so all of them fail. Giving that entry host::guard(root, views, samplers) in each harness fixes them: 83fa35c, d0261c3.

With these, cargo test --workspace passes, and in Series S mode the world ran 5.5 minutes with no device removal on this card (stacked with #493, #189, #333, #489 and others).

AI use: Claude Code (Claude Fable 5.2, Claude Opus 5.5) resolved the merge, ran the tests and drafted this comment; I reviewed and posted it.

**@⁠DuarttBR** on GitHub · 2026-11-24 15:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/483#issuecomment-7136154970) Merge notes from stacking this on current `main` (`ffe310e`, which now has #336), in case they save someone time. RTX 3080, Windows 11. - **`HostHeap::new` conflicts with #336's sizing.** I kept `main`'s sizing (2^18 dynamic slots where the host takes them, else 2^16, else the 1,000,000 cap) and put the guard slot after the dynamic ones: `guard_slot()` returns `count + self.dynamic`, and the null fill, `kept` and `GPU_RANGES` cover `count + extra + 1`. On the capped NVIDIA heap the guard is slot 999,999. [036d742](https://github.com/DuarttBR/VIctory/commit/036d742) - **Tests merged in `main` since then don't know the guard entry.** The five `emit::waterfall_tests` assert every user-data entry is a `Table`, and the harnesses of #160's image tests and #265's scratch tests panic on an unexpected entry. With this PR a program that computes a heap index gets a `ResourceHeap` entry, so all of them fail. Giving that entry `host::guard(root, views, samplers)` in each harness fixes them: [83fa35c](https://github.com/DuarttBR/VIctory/commit/83fa35c), [d0261c3](https://github.com/DuarttBR/VIctory/commit/d0261c3). With these, `cargo test --workspace` passes, and in Series S mode the world ran 5.5 minutes with no device removal on this card (stacked with #493, #189, #333, #489 and others). AI use: Claude Code (Claude Fable 5.2, Claude Opus 5.5) resolved the merge, ran the tests and drafted this comment; I reviewed and posted it.
Author
Owner

@⁠ICE-dev1150 on GitHub · 2026-11-24 16:12 UTC · original

RTX 4070 before/after on current main: same machine, same day, same scripted input.

Setup: RTX 4070 (driver 616.64), Ryzen 7 7800X3D, Windows 11 26300; title 1.0.2.1 b99f876b...; diag build with VICTORY_D3D12_DRED=1; pad unplugged, VICTORY_KEYS pressing Enter.

build launch → world world → device removed world fps
main ffe310e 40 s 70 s 0.5–1.4
ffe310e + #493 + this PR (65a161d) 43 s 350 s mostly 1.2–1.7

main: the list stopped at an ExecuteIndirect (op 5), command 1439 of 3216, mesh ae9ee9074f2e971f / pixel 1cb9d385ac8987c4, with u8=0xa12100 [heap 329992: null]. That is the signature this PR targets.

With the PRs: a plain hang later, with no page fault. The list stopped at a DispatchMesh (op 42), command 121 of 127, mesh 04b9be3756e8f41c / pixel 1af4a50c7fb40c97. It looks like the op 42 hangs on #71 and h0useadv's 453 s run.

Merge: done the way h0useadv and DuarttBR describe. The guard slot sits after the dynamic range, guard_slot() returns count + self.dynamic, and the null fill, kept and GPU_RANGES cover it. I built only the victory binary and did not run the test suite.

Caveats: one run each. The second run had a warm pipeline cache (193 pipelines being made at world entry, against 700–1,150). That explains part of the fps change, but not the longer run.

During the longer run the world stays mostly black. 400–1,700 draws per frame are dropped without a host pipeline while none are being made. The top translation stops are a select on an untracked mask, a descriptor read only as data, and a lane mask read as data. The host refused 141 pipelines.

Driver resets: each removal came with an nvlddmkm event 153 (a driver reset), and the PC recovered.

AI-assisted: I used Claude Code for the merge, the two runs and this write-up.

**@⁠ICE-dev1150** on GitHub · 2026-11-24 16:12 UTC · [original](https://github.com/Marvisak/VIctory/pull/483#issuecomment-7137302143) RTX 4070 before/after on current `main`: same machine, same day, same scripted input. **Setup:** RTX 4070 (driver 616.64), Ryzen 7 7800X3D, Windows 11 26300; title 1.0.2.1 `b99f876b...`; `diag` build with `VICTORY_D3D12_DRED=1`; pad unplugged, `VICTORY_KEYS` pressing Enter. | build | launch → world | world → device removed | world fps | |---|---|---|---| | `main` `ffe310e` | 40 s | **70 s** | 0.5–1.4 | | `ffe310e` + #493 + this PR (`65a161d`) | 43 s | **350 s** | mostly 1.2–1.7 | **`main`:** the list stopped at an ExecuteIndirect (op 5), command 1439 of 3216, mesh `ae9ee9074f2e971f` / pixel `1cb9d385ac8987c4`, with `u8=0xa12100 [heap 329992: null]`. That is the signature this PR targets. **With the PRs:** a plain hang later, with no page fault. The list stopped at a DispatchMesh (op 42), command 121 of 127, mesh `04b9be3756e8f41c` / pixel `1af4a50c7fb40c97`. It looks like the op 42 hangs on #71 and h0useadv's 453 s run. **Merge:** done the way h0useadv and DuarttBR describe. The guard slot sits after the dynamic range, `guard_slot()` returns `count + self.dynamic`, and the null fill, `kept` and `GPU_RANGES` cover it. I built only the `victory` binary and did not run the test suite. **Caveats:** one run each. The second run had a warm pipeline cache (193 pipelines being made at world entry, against 700–1,150). That explains part of the fps change, but not the longer run. **During the longer run the world stays mostly black.** 400–1,700 draws per frame are dropped without a host pipeline while none are being made. The top translation stops are a select on an untracked mask, a descriptor read only as data, and a lane mask read as data. The host refused 141 pipelines. **Driver resets:** each removal came with an `nvlddmkm` event 153 (a driver reset), and the PC recovered. AI-assisted: I used Claude Code for the merge, the two runs and this write-up.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:03 UTC · original

Automated triage for the maintainers. Closing because another open pull request covers the same change.

See #1133. Heap indices past the host heap: main clamps every index to HEAP_VIEWS-1 / HEAP_SAMPLERS-1 and keeps the host heap that large (emit/shader.rs heap_handle). Only a host that caps its heap lower (NVIDIA) is left, and #1133 covers that with a translation-time bound instead of a new user-data dword per draw.

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

**@⁠Marvisak** on GitHub · 2026-11-25 00:03 UTC · [original](https://github.com/Marvisak/VIctory/pull/483#issuecomment-7148085602) Automated triage for the maintainers. Closing because another open pull request covers the same change. See #1133. Heap indices past the host heap: main clamps every index to HEAP_VIEWS-1 / HEAP_SAMPLERS-1 and keeps the host heap that large (emit/shader.rs heap_handle). Only a host that caps its heap lower (NVIDIA) is left, and #1133 covers that with a translation-time bound instead of a new user-data dword per draw. If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!483
No description provided.