Shaders: clamp ResourceDescriptorHeap and SamplerDescriptorHeap indices to host limits #584
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!584
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/584/head"
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?
@FibbS6 on GitHub · 2026-11-24 05:13 UTC · original
FibbS6:fix/heap-handle-bounds-clamp→main· +8 −1 · 1 files · 1 commits · closed without mergingProblem
Dynamic bindless indices passed to
createHandleFromHeapcan exceed the host descriptor heap bounds (e.g., from uninitialized or out-of-range shader values), causing immediate GPU page faults and device removal on NVIDIA D3D12.Fix
ResourceDescriptorHeapandSamplerDescriptorHeapindices emitted bylower.rsto the configured host heap limits before callingcreateHandleFromHeap.Verification
cargo xtask policy— passed (151 files ok)cargo clippy -p victory-shader --lib -- -D warnings— 0 warningscargo test -p victory-shader -- --test-threads=1—69 passed, 0 failed@schmiticle on GitHub · 2026-11-24 08:15 UTC · original
Black screen before the menu with this PR (RX 9070 XT)
Summary: With #584 applied to
main, Grand Theft Auto VI never reaches the menu. The titlekeeps presenting (~590 fps, 13 draws/frame) but the window stays black and input does nothing.
mainwithout #584 reaches the loading screens on the same machine.Setup
mainatd2a4bae(#129)Results
main(d2a4bae)main+ #584 onlymain+ 182 open PRs up to #560main+ those + #565…#580main+ those + #584Found by bisecting a local stack of open PRs, then confirmed with
main+ #584 alone.Console in the black state
victory_gpu::hostevery 5 s: ~580–597 fps, 1.7 ms/frame, 13 draws/frame, 0 dropped,0 indirect
shaders from the cache and translated so far hits=0 misses=426at frame 65536Guess: the title uses
ResourceDescriptorHeap/SamplerDescriptorHeapindices abovethe clamp, so after clamping, shaders read the wrong descriptors from the first frames.
Happy to test a revised version or capture a
diagbuild log.@MartinIndra02 on GitHub · 2026-11-24 09:19 UTC · original
Root cause of the black screen reported above on RX 9070 XT:
In
crates/victory-shader/src/emit/shader.rs,heap_handlehardcodes1_000_000forResourceDescriptorHeap:The title requests a view heap larger than 1,000,000 slots (1,245,184 slots). On NVIDIA D3D12 the host caps the view heap at 1,000,000 (
host view heap capped at 1000000), but on AMD hosts that allow >1M Tier 3 descriptors, valid indices>= 1_000_000are silently rewritten to slot0.Two related issues with hardcoding the bound and mapping OOB to
0:1_000_000(e.g. smaller heaps or unit tests) is still not bounded to its actual size.0can alias a live descriptor of a different resource type (e.g. texture SRV vs buffer UAV), whereas a dedicated guard/null slot (as in #483) avoids type mismatches.Code review note; no game data. AI-assisted.
@d1ll3x3 on GitHub · 2026-11-24 11:12 UTC · original
tested: #584 with the bound set to the host heap's real size | base:
main@ffe310e+ #431 + #568 + #67 + #493 + #585, plus #609'sStaging/ShadowDropimpls ported onto #431'sretire| on: Windows 11, RX 7800 XT (RDNA3, 16 GB), 32 GB RAM, diag build,VICTORY_D3D12_DRED=1, Xbox Series 1.0.2.1This confirms MartinIndra02's diagnosis from the AMD side, and the clamp itself fixes a real crash on RDNA3 once its bound is right.
The bound has to cover the dynamic slots too. On this host the view heap is the title's 1,245,184 slots plus
DYNAMIC(1 << 18), so 1,507,328 slots (DRED reports the heap as+0x2e00000bytes). With the bound at 1,245,184, the dynamic tables would be clamped as well. Locally I changed only the constant:That is a local value for this GPU. The real fix needs the host heap's size,
count + DYNAMIC(orMIN_DYNAMIC, or the capped count), passed into the translation rather than hard-coded.What it fixes here. Without the clamp, the opening cutscene always ended in a page fault at an address with no allocation, neither live nor recently freed. It hit the same VA in three runs on two builds:
With that pipeline skipped, a second one followed:
slot 16728192, compute26b8bbb2e7ae4dc6, 6x54x1. Both slot numbers are far past the 1.5M-slot heap, so these are garbage heap indices, not freed resources.With the clamp (bound 1,507,328), no
VICTORY_SKIP_PIPELINESfor these two:eeed82b877b44b5f(12x1x1). That shader loopsfor (i = lane; i < n; i += 1024), withnread from a buffer at a data-dependent offset, so a garbagenmakes it run until the TDR.VICTORY_SHADER_LOOP_LIMIT=4096as well: no device removal at all. It is still running in the cutscene after 16 min (frame 2,049) at about 0.4 fps, and the scene is still dark, as the README says.The only skip left was the known mesh hang
04b9be3756e8f41c/1af4a50c7fb40c97(#597, #71).On slot 0: I didn't see a type-mismatch failure from redirecting to slot 0, but I can't rule one out. A null or guard slot as in #483 sounds safer.
AI-assisted (Claude Code).
@MartinIndra02 on GitHub · 2026-11-24 11:40 UTC · original
Following up on the root-cause analysis and @d1ll3x3's RDNA3 verification above, I implemented the dynamic host-heap bound + dedicated null guard slot version on a
main-based branch (ffe310e):05c681c)Design (addresses all three issues with the hardcoded
1_000_000 -> 0clamp)DYNAMICslots, and doesn't know which heap is bound at draw time), shaders that indexResourceDescriptorHeaporSamplerDescriptorHeapload[view_guard, sampler_guard]once in the entry block from a 2-dword root constantb0inHEAP_LIMITS_SPACE = 4(leaving spaces2/3free for#710/#704).HostShader::heap_limits == false, zero root-signature overhead).HostPipelineadds oneD3D12_SHADER_VISIBILITY_ALL2-dword root constant parameter when any stage setsheap_limits, andState::bindpasses[view_heap.guard(), sampler_heap.guard()]for the currently bound host heaps.shader_cache.rsencodes/decodesheap_limitscleanly.0):HostHeapreserves the final slottotal - 1on view heaps (dynamic = DYNAMIC - 1orMIN_DYNAMIC - 1, sototalstays withinPORTABLE_VIEWSwhen capped and coverscount + dynamicon >1M Tier 3 heaps) and appends 1 guard slot on sampler heaps below D3D12's 2048-slot cap (make(count + 1), falling back tocount.saturating_sub(1)at 2048).fill_nullinitializes alltotalslots (including the guard slot), and neithermirrornordynamiccan ever overwrite it.select(index <u guard, index, guard)leaves every valid title & dynamic slot (0..guard) untouched and sends every OOB/wrapped index (>= guard) to the dedicated null guard slot.Verification (Windows 11, RTX 3080 driver
621.24, WARP, Rust1.98.1)emit::waterfall_tests::out_of_bounds_heap_index_clamps_to_null_guard_not_slot_zero(RTX 3080 + WARP): sends lanes 0..16 to slot0(red = 1.0) and lanes 16..32 to OOB slot16384— verifies lanes 0..16 read1.0and lanes 16..32 read0.0from the null guard slot (no page fault, no aliasing to slot0).descriptor::host::tests::host_heap_guard_covers_title_and_dynamic_slots(RTX 3080 +VICTORY_D3D12_DEBUG=1): verifiesguard()sits past both title and dynamic slots on view heaps and past title slots on sampler heaps.cargo test -p victory-shader --lib -- --test-threads=1: 121 passed, 0 failed, 1 ignoredcargo test -p victory-gpu --lib -- --test-threads=1: 51 passed, 0 failed, 1 ignoredcargo clippy -p victory-shader -p victory-gpu --all-targets -- -D warnings(default +--features diagnostics): 0 warningscargo xtask policy: 154 files okReady for @FibbS6 or a collaborator to pick up / open as a PR whenever PRs reopen.
No game data used. AI-assisted; all builds and GPU tests executed on my machine.
@MartinIndra02 on GitHub · 2026-11-24 12:08 UTC · original
Quick in-title confirmation for
fix/shader-heap-bounds-clamp(05c681c) on Windows 11 / RTX 3080 (621.24), diag build withVICTORY_D3D12_DRED=1,VICTORY_SHADER_LOOP_LIMIT=1000(stacked onmainffe310e+#439+#431+#724/#725+#783+#776+#757):1.0 – 1.5 fpsin the world before an unrelated mesh TDR atcommand 80 of 140 (op 42)).No game data posted. AI-assisted; build and title run executed on my machine.
@Marvisak on GitHub · 2026-11-25 00:25 UTC · original
Automated triage for the maintainers. Closing because this change is already in
main, ormainhas since replaced the code it patches.Main clamps heap indices already (emit/shader.rs heap_handle: an index above HEAP_VIEWS-1 reads the last slot, which the host keeps null).
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