Shaders, GPU: clamp descriptor heap indices to bound host heap guard slot #955
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!955
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/955/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?
@MartinIndra02 on GitHub · 2026-11-24 14:27 UTC · original
MartinIndra02:fix/shader-heap-bounds-clamp→main· +371 −50 · 11 files · 1 commits · closed without mergingFollow-up / replacement for #584 (fixing the AMD >1M heap black screen diagnosed in #584 and confirmed on RDNA3 by
@d1ll3x3).Summary
Clamps
ResourceDescriptorHeapandSamplerDescriptorHeapindices at runtime to the bound host heap's dedicated permanently-null guard slot instead of hardcoding1_000_000 -> 0:b0inHEAP_LIMITS_SPACE = 4):ResourceDescriptorHeaporSamplerDescriptorHeapload[view_guard, sampler_guard]once in the entry block from a 2-dword root constant (HEAP_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,State::bindsupplies[view_heap.guard(), sampler_heap.guard()], andshader_cache.rsencodes/decodesheap_limits.HostHeapreserves the final slottotal - 1on view heaps (dynamic = DYNAMIC - 1orMIN_DYNAMIC - 1, staying withinPORTABLE_VIEWSwhen capped and coveringcount + dynamicon >1M Tier 3 AMD heaps) and appends 1 guard slot on sampler heaps below D3D12's 2048-slot cap (make(count + 1)withcount.saturating_sub(1)fallback 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 maps every OOB/wrapped index to the dedicated null guard slot (never aliasing live slot0).Verification (Windows 11, RTX 3080
621.24, WARP, Rust1.98.1)emit::waterfall_tests::out_of_bounds_heap_index_clamps_to_null_guard_not_slot_zero(RTX 3080 + WARP): verifies valid slot0(1.0) and OOB slot16384(0.0from 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).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 okNo game data used. AI-assisted; all builds and GPU tests executed on my machine.
@MichaelSmithAI on GitHub · 2026-11-24 14:45 UTC · original
Five existing waterfall readbacks with valid bindings passed on both
05c681cand our #483-based comparison build on RTX 4090 under Wine/vkd3d-proton 3.2. The #955 heap-layout test also passed: the dynamic allocation ended before the guard, and a 16-slot sampler heap had a separate guard at slot 16.One integration detail from source review: on a capped view heap, the mirrored title descriptors and the host's fresh table allocations have different extents. #483 checks direct title indices against the mirrored descriptor count, while allowing translated table indices to use the dynamic region up to the physical guard. Keeping those bounds distinct preserves both kinds of binding. The readbacks above exercise valid views. The effect on title rendering was not measured in this comparison.
@shortselow-byte on GitHub · 2026-11-24 15:01 UTC · original
Tested at head
05c681c(onmainffe310e) on AMD, since the run above is NVIDIA only: Windows 11, Rust 1.98.1 MSVC, AMD Radeon RX 6900 XT (RDNA2, driver 32.0.21045.16010).out_of_bounds_heap_index_clamps_to_null_guard_not_slot_zero: passed (AMD device and WARP,--test-threads=1).host_heap_guard_covers_title_and_dynamic_slots: passed, also withVICTORY_D3D12_DEBUG=1.cargo test --locked -p victory-shader --lib -- --test-threads=1: 121 passed, 1 ignored.-p victory-gpu --lib: 51 passed, 1 ignored. Whole workspace: 344 passed, 0 failed.cargo clippy --workspace --all-targets --locked -- -D warnings, and with--all-features: clean.The >1M case on AMD. The new heap test uses 64 title slots, so it never reaches the size this PR is about. With a local, unpublished test making a view heap of 1,100,000 title slots, the AMD driver accepted the full
count + DYNAMICheap (1,362,144 slots, not theMIN_DYNAMICorPORTABLE_VIEWSfallbacks):dynamic = 262143,guard = 1362143 = count + dynamic, and taking every dynamic slot ends right at the guard. So the layout holds where AMD actually goes past 1M.Not done: an unclamped control on the AMD device (an out-of-bounds index past a 3-slot heap could hang the driver), and no in-title run.
A question on samplers: when
make(count + 1)fails at D3D12's 2048 cap,guard = count - 1is a live title sampler, so out-of-bounds sampler indices would read that sampler rather than a null one. Is that intended as the least bad option there?@MartinIndra02 on GitHub · 2026-11-24 15:09 UTC · original
@shortselow-byte Thanks a lot for testing on AMD RDNA2 (RX 6900 XT) and especially for verifying the >1M title-slot allocation (
1,100,000->1,362,144,guard = 1,362,143)!Yes,
guard = count.saturating_sub(1)at D3D12's hard 2048 shader-visible sampler heap cap is intentional as the least bad option:SAMPLERheap, so we can't append a dedicated null slot without stealing slot2047from a title that actually uses all 2048 samplers.2047preserves all 2048 title slots while still preventing any out-of-bounds heap read/fault.@shortselow-byte on GitHub · 2026-11-24 15:22 UTC · original
Correction to my comment above: "also with
VICTORY_D3D12_DEBUG=1" means nothing there. That variable only takes effect with--features diagnostics, which I did not pass, and this machine does not have the D3D12 debug layer installed anyway. So the heap test ran on the AMD device without validation; the other results stand.@Zipettte on GitHub · 2026-11-24 15:40 UTC · original
Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at
05c681c:cargo test -p victory-gpu -p victory-shaderpasses, 172 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).Tested with AI assistance (Claude).
@YaBulochka on GitHub · 2026-11-24 17:41 UTC · original
Numbers from a Linux/RADV run that fit this diagnosis (Mesa 26.3.1, RX 7600 XT, Wine 11.22 on a Proton prefix, vkd3d-proton from Proton):
CreateDescriptorHeapfails above 1,000,000 (0x80070057), soHostHeap::newmirrors 934,464 and leaves the rest out;index=934464…1245183.With this PR on top of #994 the artifacts on the loading screen are unchanged: reads are clamped to the guard slot now, but the descriptors in those slots were never mirrored, so a shader that reaches them reads a null view instead of the title's. Happy to test a follow-up that pages the tail of the heap in.
@Marvisak on GitHub · 2026-11-25 00:28 UTC · original
Automated triage for the maintainers. Closing because another open pull request covers the same change.
See #1133. Replacement for #584. Main has the static clamp to HEAP_VIEWS-1; the remaining capped-host case is done more simply by #1133 (the cap as a translation constant, in the cache key) than by a new root-constant space.
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