GPU, Shaders: clamp view/sampler heap indices to dedicated null sentinels and bound StrideTable (#95) #144
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/Belobug--VIctory-Belobug-AMD!144
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-144"
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?
@ESAT586 on GitHub · 2026-11-25 16:48 UTC · original
ESAT586:belobug/fix-amd-heap-bounds-and-staging-uaf→main· +362 −64 · 11 files · 2 commits · openAddresses #95.
Root Causes Found in Code
crates/victory-shader/src/emit/shader.rs):Shader::heap_handle()skipped clamping wheneversampler == true(!sampler), allowing out-of-bounds sampler indices to index past the end ofSamplerDescriptorHeap.crates/victory-gpu/src/descriptor/host.rs): Smaller sampler heaps were not padded toSAMPLERS(2048), and capped sampler heaps handed out the final slot (2047) throughHostHeap::dynamic().crates/victory-gpu/src/descriptor/host.rs): On Tier-3 view heaps (1_245_184 + 1_048_576 == 2_293_760 == OWN_SLOTS),HostHeap::dynamic()could allocate slotOWN_SLOTS - 1(2_293_759) — the exact slot OOB view accesses clamped to. When a temporary dynamic slot (e.g.,constant_atCBV or buffer view) was released without being nulled, clamped OOB image/buffer loads read a stale or mismatched descriptor.OWN_SLOTSclamp & shortStrideTableon smaller/1M-capped heaps (crates/victory-gpu/src/host.rs,crates/victory-gpu/src/descriptor/host.rs,crates/victory-shader/src/emit/mod.rs):Shader::heap_handle()always clamped views toOWN_SLOTS - 1(2_293_759), which is 1.29M descriptors past the end of aPORTABLE_VIEWS(1_000_000) heap.StrideTable::new()allocatedCOUNTS_AT + lendwords instead of covering up to the clamp sentinel, allowingslot_dwordreads atOWN_SLOTS - 1to overrun the root SRV on smaller or capped heaps.crates/victory-gpu/src/texpool.rs,crates/victory-gpu/src/texture.rs):texture.rsoverwrote the D3D12 debug name of sharedtexpool::stagingslabs on every texture upload, making unrelated textures show up in DRED/RGD reports for the shared slab. (Audit ofStaginglifetime confirmed actual GPU lifetime is already guarded byArc<Staging>inHostList/Early/InFlightandStaging::drop -> retire((buffer, slot))withKEEP_FRAMES = 32.)Changes
victory-shader(emit/mod.rs,emit/shader.rs,emit/host.rs,emit/split_tests.rs,emit/image_tests.rs):Targetwithview_slotsandsampler_slots(plusTarget::own_slots(),clamp_view_last(),clamp_sampler_last()) and widenedTarget::key()to 16 bytes so shader cache entries stay separated across 2.29M Tier-3 vs 1M-capped heaps.ClampGuardaroundlower::lower()inemit()(no edits tolower.rs).Shader::heap_handle()to clamp both view and sampler indices viadx.op.binary.i32(umin, opcode40) against the target's sentinel slots.dxil.dllregression testout_of_bounds_view_and_sampler_indices_clamp_to_sentinel_slots.victory-gpu(host.rs,descriptor/host.rs,shader_cache.rs,texpool.rs,texture.rs):Host::target()probesCreateDescriptorHeap(CBV_SRV_UAV, VIEW_SLOTS, SHADER_VISIBLE)once to chooseVIEW_SLOTS(2_294_784) vsPORTABLE_VIEWS(1_000_000) and setssampler_slots = SAMPLER_SLOTS(2048).memory_first - 1(view) andSAMPLERS - 1(sampler) as null sentinels by reducingDYNAMICto(1 << 20) - 1,DYNAMIC_CAPPEDto(1 << 16) - 1, always backing sampler heaps withSAMPLERSdescriptors, and reservingSAMPLERS - 1as a null point sampler.StrideTabletoCOUNTS_AT + len.max(COUNTS_AT)(zero-initialized) soslot_dwordreads at the sentinel never overrun the root SRV.heap.GetDesc().NumDescriptorsinGPU_RANGESfor accurate DRED diagnostics.texpool::stagingslabs once on creation (texpool staging slab ({bytes})) while preserving per-texture debug names on dedicated non-pooled upload buffers.Verification
victory-shader(out_of_bounds_view_and_sampler_indices_clamp_to_sentinel_slots): 1 passed, 0 failed (RTX 3060 Ti + WARP +dxil.dllvalidation).victory-gpuon RTX 3060 Ti (descriptor::,shader_cache::,texture::, skipping pre-existing 1M-cap#130test): 24 passed, 0 failed.victory-gpuwith D3D12 Debug Layer (VICTORY_D3D12_DEBUG=1 RUST_LOG=warn,--features diagnostics): 6 passed, 0 failed, 0 D3D12 warnings/errors.victory-gpuon WARP (VICTORY_D3D12_WARP=1,--features diagnostics, fulldescriptor::,shader_cache::,texture::includingdynamic_slots_are_held_until_released): 25 passed, 0 failed.cargo clippy -p victory-shader -p victory-gpu --all-targets --all-features --locked: 0 warnings in modified code.cargo xtask policy --staged:asset policy: 10 files ok.@KernelSmoker on GitHub · 2026-11-25 18:32 UTC · original
Workspace compile check on PR head
7210c4c(cargo check --workspace --all-targets --locked --offline --target x86_64-pc-windows-gnu, Rust 1.98.1) failed when buildingapps/victory:Using
..targetthere preservesview_slotsandsampler_slotsfrom eitheremit::Target::ANYorHost::new(false)?.target()when--pipelinesis set. All other crates (victory-shader,victory-gpu,victory-hle, etc.) passedcargo check.@ESAT586 on GitHub · 2026-11-25 20:27 UTC · original
Good catch, @KernelSmoker — thanks for running the full workspace check! Fixed in $sha\ by preserving ..target\ in \pps/victory/src/translate.rs:180\ and verified \cargo check --workspace --all-targets --locked\ + \cargo xtask policy --staged\ pass cleanly.
@zGLados on GitHub · 2026-11-25 20:46 UTC · original
Tested in the game on an RX 7700 XT 12 GB (RDNA3), Windows 11, diag build with DRED: on
000ffddthis PR stopped a device loss that came every run (page faults inside freed staging/heap allocations, see #26). Two runs with it, 12 and 16 minutes, no device removal; also merged with #138 (adrianmjim'stest/main-144-138).Same build note as @KernelSmoker above: against current
mainit needs..targetin theemit::Target { lanes_min, lanes_max }initializer inapps/victory/src/translate.rs(the newview_slots/sampler_slotsfields).@ESAT586 on GitHub · 2026-11-25 21:50 UTC · original
Awesome news on the RX 7700 XT 12 GB — 12 and 16 minute runs with zero device removals! Thanks for testing in-game, @zGLados. Commit \
646733a\ (just pushed) includes the ..target\ fix in \pps/victory/src/translate.rs:180\ so the full workspace builds cleanly.@MamaLeVrai on GitHub · 2026-11-26 00:05 UTC · original
Tested on an RX 6950 XT (RDNA2), Windows 11 build 26300, Rust 1.98.1, with this PR (
646733a) merged onmain4f62c2a, release lib tests:mainvictory-gpuvictory-shadervictory-hleNone of the failures is new:
victory-gpu: the extra failure iswatch::tests::written_pages_are_reported_to_every_asker, the flake of #102. The other islist::tests::lists_are_cut_at_waits_that_follow_work, which fails on every release run onmain(#210).victory-shader: the two failures are the RDNA2 wave-size tests that #110 and #204 fix.victory-hle: the fivexmemtests fixed by #93.Merged together with #110, #214 and one more local branch of mine,
victory-shadergives 279 passed and 0 failed in two runs out of two. This PR conflicts with #204 inemit/mod.rs.Why it matters on RDNA2: the RX 6950 XT here lost the device (
0x887A0007) 38 to 77 s after full-world rendering began, in both runs I have logs for (mainand000ffdd, Series X profile). #151 on an RX 6600 lost it at the same place. On #26 (RX 7700 XT, RDNA3),000ffddlost the device at about 7.5 min, while000ffdd+ this PR ran 12 min, andmain+ this PR + #138 ran 16 min, both with no loss. I have builtmain+ this PR for that machine; it has not been run in the game yet, and I will report what it does.harness machine: rx6950xt-w11 | AMD Radeon RX 6950 XT (RDNA2), driver 32.0.21045.29003 | 32 GB RAM | Windows 11 build 26300
AI-assisted (Claude Code); no game data.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.