GPU/Shaders: Bound bindless title heap accesses and provide typed null guards #1095
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/fxceless--victory-fork!1095
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1095"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@AimLogin on GitHub · 2026-11-25 19:21 UTC · original
AimLogin:bindless-heap-bounds→main· +1937 −76 · 8 files · 4 commits · openSummary
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_LIMITis 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):[0, 737,855)[737,855, 999,999)HostHeap::dynamic), root-UAV one-view tables, raw UAVs of title-memory copies999,999Every slot that is not written holds a null
Texture2DSRV.This leaves two holes:
VIEW_LIMITis kept, the whole dynamic range included.heap_handle:heap_index,fetched_index,lane_heap_index,descriptor_phi, and selects of those.Texture2DSRV is undefined: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)HEAP_GUARDS: 12 SRV kinds, 8 UAV kinds, a constant buffer). The raw-UAV guard is the heap's last slot, so the remainingVIEW_LIMITclamp of host-computed indices (memory()) also meets its own kind.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).2^18 − 21slots and never a guard slot (dynamic,release,guard_slot,table_room).constassertions 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_boundbounds a directResourceHeapread 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.heap_boundselects the constantguard + heap_guard(kind): the null view of the read's own kind.UMininheap_handle. The stride lookup of a bounded slot skips its clamp too.Unchanged
main(see the corpus result).draw.rschanges 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 arecfg(test), and the GBV switch is gated withcfg!(test).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:
Before and after
"Without the fix" is
main's lowering andmain's single untyped null, run through the same tests. That is this branch withview_bounds()returningNoneand the test host'sUNTYPED_GUARDSset totrue(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.victory-shader --lib bindless_(14 tests)VICTORY_D3D12_GBV=1victory-gpu --lib descriptormain: 28)The 10 tests that fail without the fix:
a_direct_index_reaches_its_title_slot_and_no_other_draws_table;The GBV-only test
an_index_out_of_bounds_reads_a_null_of_its_own_kindfails as well. So doesper_lane_heap_indices_are_bounded_too, which is outside thebindless_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:
s_buffer_load;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,mainvs this branch:mainindirect::tests::warp_budget_saturates_without_wraparound_and_preserves_draw_fields. It fails onmainas well, also when run alone.xtask'srepository_passes_policyfails in both of our trees only because of our untracked local build folders.cargo xtask policyitself reports183 files ok.Shader corpus
The title's programs were translated offline with
victory translate --validate --listandVICTORY_VIEW_LIMIT=999999, and validated withdxil.dll1.8.2502.11. The corpus is 26,148 unique programs, 25,953 with a result line.mainmain(0 of 25,700 differ)Other checks
cargo build --release -p victoryandcargo build --profile diag -p victory --features diagnostics: pass.cargo clippy --workspace --all-targets: the same warnings at the same places asmain, none new.cargo fmt --check: no hunk in a line this PR writes.mainitself 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
To see the tests fail without the fix, apply the two-line probe:
view_bounds()inemit/shader.rsreturnNone.UNTYPED_GUARDSinemit/host.rsastrue.Then run the first two commands again.
Cost
Measured
the_bounds_take_no_user_data_or_root_dwords, 56 programs).main'sUMin, so at most one more instruction per read;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:
Runs after that were warm and unaffected.
Known limits
main. The code says so (shortcut:inheap_bound).Texture2DSRV: no longer another draw's view, but not of the read's kind either.emit::host::null_guardsmirrorsdescriptor::host::null_guard, because the translator crate cannot call intovictory-gpu. Both carry a note that they must change together.Interaction with open PRs
HostHeap::mirror): merges cleanly and does not overlap.mainalready, andmainnow sets the limit on every host itself (probe_view_limit). No interaction beyond that.🤖 Generated with Claude Code
@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::StructuredSrvuses 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
96f0267with only the fixture changed: setKind::StructuredSrvstride to 12 and the six data words to[0xBAD, 0xBAD, 0xBAD, value(j), 0xBAD, 0xBAD]. Runningcargo test -p victory-shader --lib structured_buffer_load_meets_a_raw_srv_guard -- --nocapturereturned 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.f6a09d3b) into bindless-heap-bounds 431c982c8306702fe8) into bindless-heap-bounds 2daf92fb68@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
5778e877rather than changingKind::StructuredSrv:Kind::StructuredSrv12keeps 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 -- --nocaptureon an RTX 4060 Ti (driver 621.01) and WARP, with and withoutVICTORY_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) in431c982cto clear the conflict indescriptor/host.rs: main'skeptpieces are sized from the heap's size (guards end the heap), andnext/freekeep the heap's own dynamic count. Main's new wrap-around search test now takes the first dynamic slot fromdyn_start, and two tests read the heap size fromNumDescriptorssincekeptis split.victory-gpuandvictory-shadertests pass;inplace::tests::warp_a_title_buffer_in_place_shows_its_bytes_at_its_offsetoccasionally crashes with an access violation in a full parallel run, and it does so on unmodified mainf6a09d3bas well (1 of 3 runs), so it is not from this branch.AI-assisted.
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.Merge
Merge the changes and update on Forgejo.