Shaders: guard speculative and EXEC-predicated heap descriptor loads (#1595) #1674
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!1674
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1674/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?
@ESAT586 on GitHub · 2026-11-24 20:40 UTC · original
ESAT586:shader/guard-speculative-heap-loads→main· +1517 −191 · 4 files · 1 commits · closed without mergingSummary
Fixes #1595 without hardcoding any slot-0 convention in the translator (so a title or test with a valid CBV in heap slot 0 remains 100% intact).
Root Cause
On Xbox Series (RDNA2), an all-zero/null descriptor in heap slot 0 returns zeros for any buffer/texture read without faulting, so the console compiler regularly hoists heap descriptor reads (
s_load_dwordx4+s_buffer_load_dword*, orbuffer_load_*) ahead of the branch,s_cselect,v_cndmask_b32, orEXEC-masked consumer that checks whether the index is valid (e.g.idx != 0). On PC D3D12, executingcreateHandleFromHeap+cbufferLoadLegacyover an SRV slot (such as[heap 0: Shader(0, Some([42, 2, 5768, ...])) -> null], a null Texture1D SRV) triggers GPU-based validation (Descriptor Type in Heap: SRV, Register Type: CBV) and removes the device on WARP (0x887A0005).Similarly, EXEC-guarded vector
buffer_load*/image_load*(and store/atomic handle creation) previously emittedcreateHandleFromHeapand loads unconditionally before selecting onguard, allowing inactive lanes (includingSource::LanePhi's synthesized index0) to hit an incompatible descriptor.Changes
Exact speculative heap-load guarding (
crates/victory-shader/src/emit/lower.rs):Lower::speculative_guard+Lower::dead_when_falsefor heap-indexed loads (smem,buffer, and explicitimage_load*).LaneExit::Branch),s_cselect_b32/s_cselect_b64/v_cndmask_b32,EXECguards (st.guards[u][j]) reachable through pure lane-local ALU instructions and loop-invariant data phis.dead_when_falsethat whenever a condition is false, replacing the load outputs with zero cannot affect any observable instruction, cross-lane op, preserved VGPR old value, branch, or side effect.s_cmp*,s_cmpk*,s_bitcmp*,v_cmp*) once when all of their inputs are already available before the load.C1 && C2) so a weaker or waterfall-only EXEC guard cannot shadow a stronger downstreamv_cndmask_b32/s_cselect/ branch guard.createHandleFromHeap+ the load viabegin_guarded/end_guarded, closing guarded blocks cleanly on any lowering error.EXEC-guarded handle creation & loads (
crates/victory-shader/src/emit/lower.rs):self.handle(...)and loads insidebegin_guarded(guard)..end_guarded(...)forbufferloads (CBV, format, typed, raw, structured),image_load*,buffer_store,buffer_atomic, andimage_storewhenguard.is_some()(implicit-derivativeimage_sample*is intentionally untouched to preserve pixel quad derivatives).Scalar
s_buffer_load_dword*inside console waterfall loops (crates/victory-shader/src/resource.rs):Fields::Smemloads do not listReg::S(EXEC)ininst.reads;Tracer::waterfallnow resolves their activeEXECmask from the most recent precedingEXECwrite in the waterfall block, so per-lane CBV waterfalls resolve each lane's own index instead of reading lane 0's0index.End-to-end tests (
crates/victory-shader/src/emit/host.rs,crates/victory-shader/src/emit/waterfall_tests.rs):View::NullTexture1dSrv(DXGI_FORMAT_R32_UINT,D3D12_SRV_DIMENSION_TEXTURE1D, null resource — matching #1595's slot 0).dxil.dll, executed on both hardware GPU and WARP):speculative_heap_cbv_before_branch_skips_null_srv_at_slot_0(#1595 direct reproducer:rawBufferLoad->s_cmp_lg_u32-> speculatives_buffer_load_dword->s_cbranch_scc0)speculative_heap_cbv_before_late_cmp_and_cselect_skips_null_srv_at_slot_0(pure ALU + lates_cmp_lg_u32after load +s_cselect_b32)divergent_cndmask_guards_per_lane_heap_cbv_from_null_srv_at_slot_0(32-lane mixed wave waterfall +v_cndmask_b32where even lanes haveidx = 0pointing at null Texture1D SRV and odd lanes read CBV slot 1 — reproduced WARP0x887A0005removal before the fix and passes cleanly after)live_heap_cbv_at_slot_0_is_not_skipped_even_when_index_compared_to_zero(soundness control: valid CBV at slot 0 is still read when live)exec_guarded_buffer_load_skips_inactive_lanes_on_null_srv_at_slot_0(straight-lines_and_saveexec_b32withouts_cbranch_execz)Verification
All tests are synthetic clean-room tests (no game files):
dxil.dll(cargo test -p victory-shader --locked): 125 passed, 0 failed, 1 ignoredcargo clippy --workspace --all-targets --locked -- -D warnings, default &--all-features): 0 warningscargo xtask policy): 154 files okFixes #1595.
@Marvisak on GitHub · 2026-11-25 01:24 UTC · original
Automated triage for the maintainers. Closing because this change is already in
main, ormainhas since replaced the code it patches.1,500 lines guarding speculative heap loads to avoid a CBV handle over a null SRV at slot 0 (#1595); main removed that mismatch at the source: heap-direct constant data is read through raw views and a zero view-stride entry selects a null buffer view (lower.rs
heap_constants,d71c3889).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.
@Marvisak on GitHub · 2026-11-25 01:34 UTC · original
Automated triage for the maintainers.
Needs rebase. This pull request conflicts with
main(conflicting:crates/victory-shader/src/emit/host.rs,crates/victory-shader/src/emit/lower.rs). It will be reviewed once it is rebased onto the currentmain.Generated by Claude Code
Pull request closed