GPU/Shaders: Bound bindless title heap accesses and provide typed null guards #1095

Open
github-bot wants to merge 4 commits from github-bot/gh-1095 into main AGit
Owner

@⁠AimLogin on GitHub · 2026-11-25 19:21 UTC · original
AimLogin:bindless-heap-bounds → main · +1937 −76 · 8 files · 4 commits · open

Summary

A correctness fix for how translated shaders read the bindless view heap when the host heap has a limit (NVIDIA: 1,000,000 shader-visible views). It is shown by synthetic GPU tests on hardware and WARP, including GPU-based validation.

This PR does not claim any in-game improvement. None of our game logs shows a device removal, a DRED entry or a picture error that this change removes. What it removes is undefined behaviour that a title may or may not trigger: reads and writes through other draws' descriptors, and null descriptors read as the wrong kind.

AI-assisted (Claude Code). Every result below was run on the machine named under Tests.

Problem

heap_handle (crates/victory-shader/src/emit/shader.rs) protects a bindless heap read with one clamp: UMin(index, VIEW_LIMIT). VIEW_LIMIT is the host view heap's last slot (probe_view_limit → set_view_heap_limit).

On main, a capped host view heap is laid out like this (descriptor/host.rs):

Slots (1,000,000-view heap) Contents
[0, 737,855) the title's mirrored slots (the retail title's view heap has 1,245,184)
[737,855, 999,999) the 2^18 dynamic slots: per-draw tables (HostHeap::dynamic), root-UAV one-view tables, raw UAVs of title-memory copies
999,999 the null slot the clamp targets

Every slot that is not written holds a null Texture2D SRV.

This leaves two holes:

  1. A direct heap read past the title's slots reads another draw's descriptor.
    • Every index below VIEW_LIMIT is kept, the whole dynamic range included.
    • This holds on every path that ends in heap_handle: heap_index, fetched_index, lane_heap_index, descriptor_phi, and selects of those.
    • For D3D12 this is an in-bounds access: no fault and no DRED entry, just another draw's view. For a UAV it is a write into another draw's resource.
  2. The clamp target has one kind. D3D12 defines a null descriptor read only "as long as the type of shader access is compatible with the descriptor type" (Resource Binding spec, NULL Descriptors). A UAV, buffer or constant buffer access clamped onto the null Texture2D SRV is undefined:
    • GPU-based validation reports it;
    • in our tests WARP removed the device on such a constant buffer read and on a scalar raw-buffer read.

Change

The bounds are constants of the translated code. The view heap limit is known before the first shader is translated and is already part of the shader-cache key (translation_fingerprint). Every host view heap can therefore end the same way, and a shader can bound its indices with constants. This costs no user data and no root-signature space.

Heap layout (crates/victory-gpu/src/descriptor/host.rs)

  • The title's slots start at 0. The 2^18 dynamic slots now end the heap.
  • The last 21 dynamic slots are guard slots: one null view of each DXIL resource kind (HEAP_GUARDS: 12 SRV kinds, 8 UAV kinds, a constant buffer). The raw-UAV guard is the heap's last slot, so the remaining VIEW_LIMIT clamp of host-computed indices (memory()) also meets its own kind.
  • The host takes the layout from the translator's own figure (view_layout → victory_shader::emit::view_bounds_of) and does not compute it a second time. A unit test that needs no device checks this for both heap sizes and for title heaps smaller and larger than the room (a_view_heap_is_laid_out_by_the_translators_bounds).
  • The allocator hands out 2^18 − 21 slots and never a guard slot (dynamic, release, guard_slot, table_room).
  • Sampler heaps get 2,048 slots, every slot the existing sampler clamp (2,047) can reach.
  • Two const assertions tie the heap sizes to the stride table and to the dynamic slots.

Shader translation (crates/victory-shader/src/emit/{lower,shader}.rs)

  • view_bounds() = (limit + 1 − 2^18, limit + 1 − 21).
  • heap_bound bounds a direct ResourceHeap read by the first constant, so it stops at the title's slots and other draws' tables are protected. It bounds a read through a table by the second, so it stops at the guards.
  • Out of bounds, heap_bound selects the constant guard + heap_guard(kind): the null view of the read's own kind.
  • Indices bounded this way, and selects and phis of them, skip the UMin in heap_handle. The stride lookup of a bounded slot skips its clamp too.

Unchanged

  • Without a limit the translation is byte-identical to main (see the corpus result).
  • User data, root signatures and the clamp of host-computed indices stay as they are.
  • draw.rs changes one line: the length check for fresh tables uses the slots the heap can actually give (table_room).

Files

  • descriptor/host.rs, draw.rs (one line), emit/{lower,shader,mod}.rs.
  • emit/host.rs: the test host. Its additions are cfg(test), and the GBV switch is gated with cfg!(test).
  • Two new test modules.
  • No existing test changes except dynamic_slots_are_held_until_released, whose expected slots move with the layout.

Tests

Machine: NVIDIA GeForce RTX 4060 Ti 16 GB (driver 621.01) and WARP, Windows 11 Pro 26200. Base d510ee4.

The regression tests place views in a synthetic capped heap laid out as the host's:

  • 1,000,000 slots;
  • title slots up to 737,856;
  • guards from 999,979.

Before and after

"Without the fix" is main's lowering and main's single untyped null, run through the same tests. That is this branch with view_bounds() returning None and the test host's UNTYPED_GUARDS set to true (a two-line change, see Reproduce).

The probe uses this PR's test heap. On main's real layout the first leaking index is 737,855, not 737,856.

without the fix with the fix
direct index at the last title slot its slot its slot
direct index 737,856 / 737,857 / 934,463 / 999,978 (other draws' tables) reaches the UAV placed there (HW and WARP) null guard
direct index 999,979 … 2^27 − 1 null null guard of its kind
table reads of dynamic slots reached reached
GBV, out-of-bounds reads, per kind 3 of 3 kind-mismatch messages on hardware; WARP device removed for the constant buffer and the scalar raw read 0 messages on hardware and WARP
victory-shader --lib bindless_ (14 tests) 10 failed, 4 passed 14 passed
the same with VICTORY_D3D12_GBV=1 11 failed, 3 passed 14 passed
victory-gpu --lib descriptor 31 passed, 1 failed (the layout test) 32 passed (main: 28)

The 10 tests that fail without the fix:

  • a_direct_index_reaches_its_title_slot_and_no_other_draws_table;
  • all 9 kind tests.

The GBV-only test an_index_out_of_bounds_reads_a_null_of_its_own_kind fails as well. So does per_lane_heap_indices_are_bounded_too, which is outside the bindless_ filter.

The tests that pass on both sides check that nothing is bounded too much: tables in the dynamic slots, no user data, and the negative control.

Kinds covered under GBV:

  • raw buffer UAV store;
  • typed buffer SRV load;
  • raw buffer SRV load;
  • structured load;
  • constant buffer via s_buffer_load;
  • scalar raw load of a buffer view;
  • 2D texture SRV load;
  • 2D texture UAV store;
  • 64-bit image atomic.

The translator does not lower 64-bit buffer atomics, so there is nothing to test for them.

Whole workspace

cargo test --workspace --no-fail-fast -- --test-threads=1, main vs this branch:

crate main this branch
victory-gpu 181 passed, 1 failed 185 passed, 1 failed
victory-shader 215 passed 231 passed
all others pass identical
  • The one failure in victory-gpu is indirect::tests::warp_budget_saturates_without_wraparound_and_preserves_draw_fields. It fails on main as well, also when run alone.
  • xtask's repository_passes_policy fails in both of our trees only because of our untracked local build folders. cargo xtask policy itself reports 183 files ok.
  • The only difference between the two runs is the tests this PR adds.

Shader corpus

The title's programs were translated offline with victory translate --validate --list and VICTORY_VIEW_LIMIT=999999, and validated with dxil.dll 1.8.2502.11. The corpus is 26,148 unique programs, 25,953 with a result line.

main this branch
translated and validated 25,484 25,484
emitted, rejected by the validator 216 216 (same programs, same reasons)
not translated 253 253 (same programs, same reasons)
DXIL bytes, total 866.2 MB 864.5 MB (−0.20 %)
without a limit – byte-identical to main (0 of 25,700 differ)
  • 24,999 of the 25,700 emitted programs differ: every program that reads views from the heap or a table.
  • Per-program size change: median −40 B, p95 +64 B, maximum +1,408 B (+3.25 %).
  • No program translates or validates differently.
  • Translation wall time is within noise.

Other checks

  • cargo build --release -p victory and cargo build --profile diag -p victory --features diagnostics: pass.
  • cargo clippy --workspace --all-targets: the same warnings at the same places as main, none new.
  • cargo fmt --check: no hunk in a line this PR writes. main itself is not rustfmt-clean, so no formatter was run over the files.
  • cargo xtask policy: ok. The tests are hand-written GFX10 programs; no game data.

Reproduce

cargo test -p victory-shader --lib bindless_ -- --test-threads=1 --nocapture
$env:VICTORY_D3D12_GBV = '1'; cargo test -p victory-shader --lib bindless_ -- --test-threads=1 --nocapture
cargo test -p victory-gpu --lib descriptor -- --test-threads=1

To see the tests fail without the fix, apply the two-line probe:

  1. Make view_bounds() in emit/shader.rs return None.
  2. Start UNTYPED_GUARDS in emit/host.rs as true.

Then run the first two commands again.

Cost

Measured

  • Root signature and user data: +0. A stage that reads 0 to 27 user SGPRs past the heap has identical user data and root constants with and without a limit (the_bounds_take_no_user_data_or_root_dwords, 56 programs).
  • DXIL:
    • a compare and a select per bounded heap read in place of main's UMin, so at most one more instruction per read;
    • the stride clamp of bounded slots is gone;
    • over the corpus the DXIL gets 0.2 % smaller.
  • Dynamic pool: 21 of 2^18 slots.

Not measured: GPU instruction cost, and any in-game frame time.

Cache: one cold run. The translation changes for every program that reads the heap, so the first run after updating translates shaders and builds pipelines afresh. In the first game run of an earlier version of this change:

  • 2,419 pipelines were made;
  • a median of 720 draws a frame were dropped while they were being made;
  • the scene ran at 1.4 fps.

Runs after that were warm and unaffected.

Known limits

  • Not shown in a game run. Whether a title ever issues a direct index past its mirrored slots is unmeasured. A code comment in this fork puts the highest title slot seen at about 720k, below the mirror's end.
  • Title slots past the mirror are still not rendered. On a capped host that is about 507k slots of the retail heap. A read of one now meets a typed null where before it met another draw's view. Rendering them needs a remap of title slots, which is not part of this PR.
  • Tables are bounded by the guards alone, not by their own length. An entry past a table's length, or a title table indexed past the title's slots, still reads the dynamic slots, as on main. The code says so (shortcut: in heap_bound).
  • Uncapped hosts (2^21 views). The slots between the title's and the dynamic ones read a null Texture2D SRV: no longer another draw's view, but not of the read's kind either.
  • The typed-guard tests go through a copy of the host's guard code. emit::host::null_guards mirrors descriptor::host::null_guard, because the translator crate cannot call into victory-gpu. Both carry a note that they must change together.

Interaction with open PRs

  • #1010 (dynamic slots up to 2^20 on uncapped hosts): a semantic conflict, not only a textual one.
    • #1010 sizes the dynamic region from the title's count. This PR needs the region's start to be a constant known before translation.
    • Merged naively, an uncapped host would again let direct reads reach other draws' tables. The new device-less layout test would fail in that case.
    • The two can be combined by deriving the dynamic count from the probed limit alone, for example:
      • capped hosts: 2^18;
      • 2^21 hosts: the heap minus a fixed title reserve, capped at 2^20.
    • Whichever lands second should be rebased onto the other. I am happy to do that rebase.
  • #1054 (the once-only warning in HostHeap::mirror): merges cleanly and does not overlap.
  • #134 (clamp on every host): it conflicts with main already, and main now sets the limit on every host itself (probe_view_limit). No interaction beyond that.
  • #304 (null constant buffer views the host cannot make): a different problem; no overlap in behaviour.

🤖 Generated with Claude Code

**@⁠AimLogin** on GitHub · 2026-11-25 19:21 UTC · [original](https://github.com/fxceless/victory-fork/pull/1095) `AimLogin:bindless-heap-bounds` → `main` · +1937 −76 · 8 files · 4 commits · open ## Summary A correctness fix for how translated shaders read the bindless view heap when the host heap has a limit (NVIDIA: 1,000,000 shader-visible views). It is shown by synthetic GPU tests on hardware and WARP, including GPU-based validation. **This PR does not claim any in-game improvement.** None of our game logs shows a device removal, a DRED entry or a picture error that this change removes. What it removes is undefined behaviour that a title may or may not trigger: reads and writes through other draws' descriptors, and null descriptors read as the wrong kind. AI-assisted (Claude Code). Every result below was run on the machine named under *Tests*. ## Problem `heap_handle` (`crates/victory-shader/src/emit/shader.rs`) protects a bindless heap read with one clamp: `UMin(index, VIEW_LIMIT)`. `VIEW_LIMIT` is the host view heap's last slot (`probe_view_limit` → `set_view_heap_limit`). On `main`, a capped host view heap is laid out like this (`descriptor/host.rs`): | Slots (1,000,000-view heap) | Contents | |---|---| | `[0, 737,855)` | the title's mirrored slots (the retail title's view heap has 1,245,184) | | `[737,855, 999,999)` | the 2^18 dynamic slots: per-draw tables (`HostHeap::dynamic`), root-UAV one-view tables, raw UAVs of title-memory copies | | `999,999` | the null slot the clamp targets | Every slot that is not written holds a null `Texture2D` SRV. This leaves two holes: 1. **A direct heap read past the title's slots reads another draw's descriptor.** - Every index below `VIEW_LIMIT` is kept, the whole dynamic range included. - This holds on every path that ends in `heap_handle`: `heap_index`, `fetched_index`, `lane_heap_index`, `descriptor_phi`, and selects of those. - For D3D12 this is an in-bounds access: no fault and no DRED entry, just another draw's view. For a UAV it is a write into another draw's resource. 2. **The clamp target has one kind.** D3D12 defines a null descriptor read only "as long as the type of shader access is compatible with the descriptor type" (Resource Binding spec, *NULL Descriptors*). A UAV, buffer or constant buffer access clamped onto the null `Texture2D` SRV is undefined: - GPU-based validation reports it; - in our tests WARP removed the device on such a constant buffer read and on a scalar raw-buffer read. ## Change **The bounds are constants of the translated code.** The view heap limit is known before the first shader is translated and is already part of the shader-cache key (`translation_fingerprint`). Every host view heap can therefore end the same way, and a shader can bound its indices with constants. This costs no user data and no root-signature space. **Heap layout** (`crates/victory-gpu/src/descriptor/host.rs`) - The title's slots start at 0. The 2^18 dynamic slots now **end** the heap. - The last 21 dynamic slots are guard slots: one null view of each DXIL resource kind (`HEAP_GUARDS`: 12 SRV kinds, 8 UAV kinds, a constant buffer). The raw-UAV guard is the heap's last slot, so the remaining `VIEW_LIMIT` clamp of host-computed indices (`memory()`) also meets its own kind. - The host takes the layout from the translator's own figure (`view_layout` → `victory_shader::emit::view_bounds_of`) and does not compute it a second time. A unit test that needs no device checks this for both heap sizes and for title heaps smaller and larger than the room (`a_view_heap_is_laid_out_by_the_translators_bounds`). - The allocator hands out `2^18 − 21` slots and never a guard slot (`dynamic`, `release`, `guard_slot`, `table_room`). - Sampler heaps get 2,048 slots, every slot the existing sampler clamp (2,047) can reach. - Two `const` assertions tie the heap sizes to the stride table and to the dynamic slots. **Shader translation** (`crates/victory-shader/src/emit/{lower,shader}.rs`) - `view_bounds()` = `(limit + 1 − 2^18, limit + 1 − 21)`. - `heap_bound` bounds a direct `ResourceHeap` read by the first constant, so it stops at the title's slots and other draws' tables are protected. It bounds a read through a table by the second, so it stops at the guards. - Out of bounds, `heap_bound` selects the constant `guard + heap_guard(kind)`: the null view of the read's own kind. - Indices bounded this way, and selects and phis of them, skip the `UMin` in `heap_handle`. The stride lookup of a bounded slot skips its clamp too. **Unchanged** - Without a limit the translation is byte-identical to `main` (see the corpus result). - User data, root signatures and the clamp of host-computed indices stay as they are. - `draw.rs` changes one line: the length check for fresh tables uses the slots the heap can actually give (`table_room`). **Files** - `descriptor/host.rs`, `draw.rs` (one line), `emit/{lower,shader,mod}.rs`. - `emit/host.rs`: the test host. Its additions are `cfg(test)`, and the GBV switch is gated with `cfg!(test)`. - Two new test modules. - No existing test changes except `dynamic_slots_are_held_until_released`, whose expected slots move with the layout. ## Tests **Machine:** NVIDIA GeForce RTX 4060 Ti 16 GB (driver 621.01) and WARP, Windows 11 Pro 26200. Base `d510ee4`. The regression tests place views in a synthetic capped heap laid out as the host's: - 1,000,000 slots; - title slots up to 737,856; - guards from 999,979. ### Before and after "Without the fix" is `main`'s lowering and `main`'s single untyped null, run through the same tests. That is this branch with `view_bounds()` returning `None` and the test host's `UNTYPED_GUARDS` set to `true` (a two-line change, see *Reproduce*). The probe uses this PR's test heap. On `main`'s real layout the first leaking index is 737,855, not 737,856. | | without the fix | with the fix | |---|---|---| | direct index at the last title slot | its slot | its slot | | direct index 737,856 / 737,857 / 934,463 / 999,978 (other draws' tables) | **reaches the UAV placed there** (HW and WARP) | null guard | | direct index 999,979 … 2^27 − 1 | null | null guard of its kind | | table reads of dynamic slots | reached | reached | | GBV, out-of-bounds reads, per kind | **3 of 3 kind-mismatch messages** on hardware; **WARP device removed** for the constant buffer and the scalar raw read | **0 messages** on hardware and WARP | | `victory-shader --lib bindless_` (14 tests) | **10 failed**, 4 passed | 14 passed | | the same with `VICTORY_D3D12_GBV=1` | **11 failed**, 3 passed | 14 passed | | `victory-gpu --lib descriptor` | 31 passed, 1 failed (the layout test) | 32 passed (`main`: 28) | The 10 tests that fail without the fix: - `a_direct_index_reaches_its_title_slot_and_no_other_draws_table`; - all 9 kind tests. The GBV-only test `an_index_out_of_bounds_reads_a_null_of_its_own_kind` fails as well. So does `per_lane_heap_indices_are_bounded_too`, which is outside the `bindless_` filter. The tests that pass on both sides check that nothing is bounded too much: tables in the dynamic slots, no user data, and the negative control. Kinds covered under GBV: - raw buffer UAV store; - typed buffer SRV load; - raw buffer SRV load; - structured load; - constant buffer via `s_buffer_load`; - scalar raw load of a buffer view; - 2D texture SRV load; - 2D texture UAV store; - 64-bit image atomic. The translator does not lower 64-bit *buffer* atomics, so there is nothing to test for them. ### Whole workspace `cargo test --workspace --no-fail-fast -- --test-threads=1`, `main` vs this branch: | crate | `main` | this branch | |---|---|---| | victory-gpu | 181 passed, 1 failed | 185 passed, 1 failed | | victory-shader | 215 passed | 231 passed | | all others | pass | identical | - The one failure in victory-gpu is `indirect::tests::warp_budget_saturates_without_wraparound_and_preserves_draw_fields`. It fails on `main` as well, also when run alone. - `xtask`'s `repository_passes_policy` fails in both of our trees only because of our untracked local build folders. `cargo xtask policy` itself reports `183 files ok`. - The only difference between the two runs is the tests this PR adds. ### Shader corpus The title's programs were translated offline with `victory translate --validate --list` and `VICTORY_VIEW_LIMIT=999999`, and validated with `dxil.dll` 1.8.2502.11. The corpus is 26,148 unique programs, 25,953 with a result line. | | `main` | this branch | |---|---|---| | translated and validated | 25,484 | 25,484 | | emitted, rejected by the validator | 216 | 216 (same programs, same reasons) | | not translated | 253 | 253 (same programs, same reasons) | | DXIL bytes, total | 866.2 MB | 864.5 MB (−0.20 %) | | without a limit | – | byte-identical to `main` (0 of 25,700 differ) | - 24,999 of the 25,700 emitted programs differ: every program that reads views from the heap or a table. - Per-program size change: median −40 B, p95 +64 B, maximum +1,408 B (+3.25 %). - No program translates or validates differently. - Translation wall time is within noise. ### Other checks - `cargo build --release -p victory` and `cargo build --profile diag -p victory --features diagnostics`: pass. - `cargo clippy --workspace --all-targets`: the same warnings at the same places as `main`, none new. - `cargo fmt --check`: no hunk in a line this PR writes. `main` itself is not rustfmt-clean, so no formatter was run over the files. - `cargo xtask policy`: ok. The tests are hand-written GFX10 programs; no game data. ### Reproduce ```powershell cargo test -p victory-shader --lib bindless_ -- --test-threads=1 --nocapture $env:VICTORY_D3D12_GBV = '1'; cargo test -p victory-shader --lib bindless_ -- --test-threads=1 --nocapture cargo test -p victory-gpu --lib descriptor -- --test-threads=1 ``` To see the tests fail without the fix, apply the two-line probe: 1. Make `view_bounds()` in `emit/shader.rs` return `None`. 2. Start `UNTYPED_GUARDS` in `emit/host.rs` as `true`. Then run the first two commands again. ## Cost **Measured** - **Root signature and user data: +0.** A stage that reads 0 to 27 user SGPRs past the heap has identical user data and root constants with and without a limit (`the_bounds_take_no_user_data_or_root_dwords`, 56 programs). - **DXIL:** - a compare and a select per bounded heap read in place of `main`'s `UMin`, so at most one more instruction per read; - the stride clamp of bounded slots is gone; - over the corpus the DXIL gets 0.2 % smaller. - **Dynamic pool:** 21 of 2^18 slots. **Not measured:** GPU instruction cost, and any in-game frame time. **Cache: one cold run.** The translation changes for every program that reads the heap, so the first run after updating translates shaders and builds pipelines afresh. In the first game run of an earlier version of this change: - 2,419 pipelines were made; - a median of 720 draws a frame were dropped while they were being made; - the scene ran at 1.4 fps. Runs after that were warm and unaffected. ## Known limits - **Not shown in a game run.** Whether a title ever issues a direct index past its mirrored slots is unmeasured. A code comment in this fork puts the highest title slot seen at about 720k, below the mirror's end. - **Title slots past the mirror are still not rendered.** On a capped host that is about 507k slots of the retail heap. A read of one now meets a typed null where before it met another draw's view. Rendering them needs a remap of title slots, which is not part of this PR. - **Tables are bounded by the guards alone, not by their own length.** An entry past a table's length, or a title table indexed past the title's slots, still reads the dynamic slots, as on `main`. The code says so (`shortcut:` in `heap_bound`). - **Uncapped hosts (2^21 views).** The slots between the title's and the dynamic ones read a null `Texture2D` SRV: no longer another draw's view, but not of the read's kind either. - **The typed-guard tests go through a copy of the host's guard code.** `emit::host::null_guards` mirrors `descriptor::host::null_guard`, because the translator crate cannot call into `victory-gpu`. Both carry a note that they must change together. ## Interaction with open PRs - **#1010** (dynamic slots up to 2^20 on uncapped hosts): **a semantic conflict, not only a textual one.** - #1010 sizes the dynamic region from the title's count. This PR needs the region's start to be a constant known before translation. - Merged naively, an uncapped host would again let direct reads reach other draws' tables. The new device-less layout test would fail in that case. - The two can be combined by deriving the dynamic count from the probed limit alone, for example: - capped hosts: 2^18; - 2^21 hosts: the heap minus a fixed title reserve, capped at 2^20. - Whichever lands second should be rebased onto the other. I am happy to do that rebase. - **#1054** (the once-only warning in `HostHeap::mirror`): merges cleanly and does not overlap. - **#134** (clamp on every host): it conflicts with `main` already, and `main` now sets the limit on every host itself (`probe_view_limit`). No interaction beyond that. - **#304** (null constant buffer views the host cannot make): a different problem; no overlap in behaviour. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A translated shader's view index was only clamped to the host heap's
last slot. On a capped host heap (NVIDIA: 1,000,000 views) every index
below it was kept, the host's dynamic slots included: a direct heap read
past the title's slots read (or wrote through) a view another draw had
made there. The clamp's target was one null Texture2D SRV whatever the
read's kind, which D3D12 leaves undefined for any other kind (GPU-based
validation reports it; WARP removed the device on a constant buffer read).

The bounds are now constants of the translated code, known with the heap
limit before the first shader is translated (and in the cache key with
it): every host view heap ends with its 2^18 dynamic slots, the last 21
of them one null view of each resource kind. A view index the code
computes is bounded by the title's slots when read straight from the
heap and by the first guard when read through a table; out of bounds it
reads the null of its own kind. No user data, no root-signature space;
without a limit the translation is byte for byte what it was.

The host lays its heaps out by the translator's own figure
(view_bounds_of), checked without a device; sampler heaps have all 2,048
slots a clamped sampler index reaches.

Shown by synthetic tests on an RTX 4060 Ti and WARP, GPU-based validation
included. Not shown in any game run: no log of ours has an error this
removes.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:57:21 +00:00
Author
Owner

@⁠Dathinel on GitHub · 2026-11-25 21:22 UTC · original · edited 2026-11-25 21:30 UTC

A cross-fork regression fixture for the NVIDIA tests: in bindless_kinds_tests.rs, Kind::StructuredSrv uses a 4-byte logical stride and the fixture binds a raw host SRV. At stride 4, advancing one element and advancing one dword give the same address. A useful additional in-bounds control for that case would keep the raw host SRV, set the slot stride to 12, and put different sentinels at bytes 4 and 12. An indexed read of element 1 should return the byte-12 sentinel. The existing out-of-bounds guard assertions could stay as they are.

Two public NVIDIA results explain why the host view matters here. Marvisak/VIctory#437 reports 0 before / 86 after with a raw host SRV at byte 20. r4tedx/VIctory#18 tests a genuinely structured host SRV with stride 12 and a load crossing the element boundary on an RTX 5070 Ti. These are different bindings. The latter provides a useful fixture shape without requiring a change to this fork's raw-view policy.

Tested on PR head 96f0267 with only the fixture changed: set Kind::StructuredSrv stride to 12 and the six data words to [0xBAD, 0xBAD, 0xBAD, value(j), 0xBAD, 0xBAD]. Running cargo test -p victory-shader --lib structured_buffer_load_meets_a_raw_srv_guard -- --nocapture returned the expected value for slot 737855 and zero for indices 737856, 934463 and 33554432 on both the RTX 3050 Laptop and WARP. The functional check passed in 0.67 s. Optional GPU-based validation was off for this run. AI-assisted.

**@⁠Dathinel** on GitHub · 2026-11-25 21:22 UTC · [original](https://github.com/fxceless/victory-fork/pull/1095#issuecomment-7174991184) · edited 2026-11-25 21:30 UTC A cross-fork regression fixture for the NVIDIA tests: in `bindless_kinds_tests.rs`, `Kind::StructuredSrv` uses a 4-byte logical stride and the fixture binds a raw host SRV. At stride 4, advancing one element and advancing one dword give the same address. A useful additional **in-bounds** control for that case would keep the raw host SRV, set the slot stride to 12, and put different sentinels at bytes 4 and 12. An indexed read of element 1 should return the byte-12 sentinel. The existing out-of-bounds guard assertions could stay as they are. Two public NVIDIA results explain why the host view matters here. [Marvisak/VIctory#437](https://github.com/Marvisak/VIctory/pull/437) reports 0 before / 86 after with a raw host SRV at byte 20. [r4tedx/VIctory#18](https://github.com/r4tedx/VIctory/pull/18) tests a genuinely structured host SRV with stride 12 and a load crossing the element boundary on an RTX 5070 Ti. These are different bindings. The latter provides a useful fixture shape without requiring a change to this fork's raw-view policy. Tested on PR head `96f0267` with only the fixture changed: set `Kind::StructuredSrv` stride to 12 and the six data words to `[0xBAD, 0xBAD, 0xBAD, value(j), 0xBAD, 0xBAD]`. Running `cargo test -p victory-shader --lib structured_buffer_load_meets_a_raw_srv_guard -- --nocapture` returned the expected value for slot 737855 and zero for indices 737856, 934463 and 33554432 on both the RTX 3050 Laptop and WARP. The functional check passed in 0.67 s. Optional GPU-based validation was off for this run. AI-assisted.
One conflict, in crates/victory-gpu/src/descriptor/host.rs:

- HostHeap:🆕 main's `kept` in KEPT_PIECES pieces (and `kept_one`),
  sized from the heap's `size` (the guards end the heap, so it is no
  longer `count + extra`); `next` and `free` keep the heap's own number of
  dynamic slots, `dynamic`, not DYNAMIC.
- HostHeap::dynamic: main's search (a run across the starting place is
  found, refusals counted by cause); its end is already `self.dynamic`.

Tests brought along:
- main's a_free_run_across_the_place_the_search_starts_from_is_found takes
  the first dynamic slot from the heap (`dyn_start`) instead of 4: on a
  capped heap the dynamic slots begin where the guards end the heap.
- the guard-slot and sampler-heap tests read the heap's size from the
  D3D12 heap (NumDescriptors), since `kept` is in pieces now.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
At the 4-byte stride of Kind::StructuredSrv one element and one dword are
the same step, so that case cannot tell the two apart. Kind::StructuredSrv12
keeps the raw host SRV and the program (element 1, idxen) and gives the
placed slots a stride of 12 in the stride table: element 1 is byte 12,
which holds the value, and byte 4 holds a sentinel no case accepts. The
out-of-bounds indices and the guard checks are the same as for every kind.

Suggested in review by Dathinel. On an RTX 4060 Ti (driver 621.01) and
WARP, with and without VICTORY_D3D12_GBV: index 737855 reads the value,
737856, 934463 and 33554432 read zero; no message about a descriptor's
kind with the typed guards.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Two conflicts, both additions at the same place:
- emit/shader.rs: main's USER_DISPATCH_SPREAD after this branch's heap
  guards, HEAP_DYNAMIC and view bounds.
- emit/mod.rs: the shader export list is the union of both.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Owner

@⁠AimLogin on GitHub · 2026-11-26 10:20 UTC · original

Thanks @⁠Dathinel, good catch: at stride 4 the structured case cannot tell an element step from a dword step.

Added as its own case in 5778e877 rather than changing Kind::StructuredSrv: Kind::StructuredSrv12 keeps the raw host SRV and the same program (element 1, idxen), puts 12 in the stride table for the placed slots, and fills each view with [0xBAD, 0xBAD, 0xBAD, value(j), 0xBAD, 0xBAD], so a read at byte 4 fails the check and only byte 12 passes. The out-of-bounds indices and guard checks are the shared ones.

cargo test -p victory-shader --lib structured_buffer_load_at_a_12_byte_stride_meets_a_raw_srv_guard -- --nocapture on an RTX 4060 Ti (driver 621.01) and WARP, with and without VICTORY_D3D12_GBV=1: 737855 reads the value; 737856, 934463 and 33554432 read zero; no descriptor-kind messages with the typed guards.

Also merged main (f6a09d3b) in 431c982c to clear the conflict in descriptor/host.rs: main's kept pieces are sized from the heap's size (guards end the heap), and next/free keep the heap's own dynamic count. Main's new wrap-around search test now takes the first dynamic slot from dyn_start, and two tests read the heap size from NumDescriptors since kept is split. victory-gpu and victory-shader tests pass; inplace::tests::warp_a_title_buffer_in_place_shows_its_bytes_at_its_offset occasionally crashes with an access violation in a full parallel run, and it does so on unmodified main f6a09d3b as well (1 of 3 runs), so it is not from this branch.

AI-assisted.

**@⁠AimLogin** on GitHub · 2026-11-26 10:20 UTC · [original](https://github.com/fxceless/victory-fork/pull/1095#issuecomment-7189244945) Thanks @⁠Dathinel, good catch: at stride 4 the structured case cannot tell an element step from a dword step. Added as its own case in 5778e877 rather than changing `Kind::StructuredSrv`: `Kind::StructuredSrv12` keeps the raw host SRV and the same program (element 1, idxen), puts 12 in the stride table for the placed slots, and fills each view with `[0xBAD, 0xBAD, 0xBAD, value(j), 0xBAD, 0xBAD]`, so a read at byte 4 fails the check and only byte 12 passes. The out-of-bounds indices and guard checks are the shared ones. `cargo test -p victory-shader --lib structured_buffer_load_at_a_12_byte_stride_meets_a_raw_srv_guard -- --nocapture` on an RTX 4060 Ti (driver 621.01) and WARP, with and without `VICTORY_D3D12_GBV=1`: 737855 reads the value; 737856, 934463 and 33554432 read zero; no descriptor-kind messages with the typed guards. Also merged main (f6a09d3b) in 431c982c to clear the conflict in `descriptor/host.rs`: main's `kept` pieces are sized from the heap's size (guards end the heap), and `next`/`free` keep the heap's own dynamic count. Main's new wrap-around search test now takes the first dynamic slot from `dyn_start`, and two tests read the heap size from `NumDescriptors` since `kept` is split. `victory-gpu` and `victory-shader` tests pass; `inplace::tests::warp_a_title_buffer_in_place_shows_its_bytes_at_its_offset` occasionally crashes with an access violation in a full parallel run, and it does so on unmodified main f6a09d3b as well (1 of 3 runs), so it is not from this branch. AI-assisted.
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/descriptor/host.rs
  • crates/victory-shader/src/emit/mod.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1095/head:github-bot/gh-1095'
git switch 'github-bot/gh-1095'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1095'
git switch 'github-bot/gh-1095'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1095'
git switch 'github-bot/gh-1095'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1095'
git switch 'main'
git merge --squash 'github-bot/gh-1095'
git switch 'main'
git merge --ff-only 'github-bot/gh-1095'
git switch 'main'
git merge 'github-bot/gh-1095'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.