Shaders: guarded scalar writes kill stale SGPRs in dead_on_edge #2468
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!2468
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2468/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?
@VastyViz on GitHub · 2026-11-25 14:12 UTC · original
VastyViz:shaders/dead-on-edge→main· +45 −3 · 1 files · 1 commits · merged 2026-11-25 21:57 UTCProblem
In
Lower::dead_on_edge(crates/victory-shader/src/emit/lower.rs), an instruction that does not read any tainted register only removed its written registers fromregswhenguard.is_none().On RDNA2 (and in
Lower::write_i/Lower::write_placed),EXECguards only preserve the previous value of VGPR writes (Reg::V(_)). Scalar and SCC writes from guarded VALU instructions — such asv_readfirstlane_b32,v_readlane_b32,v_cmp_*, and carry-out SGPRs — always overwrite their destination register unconditionally. Leaving such an SGPR inregscauseddead_on_edgeto reject a subsequent read of the freshly written SGPR as a live use of the earlier stale value.Fix
Lower::dead_on_edgeso writes to non-VGPR registers (!matches!(r, Reg::V(_))) always remove the register fromregsregardless ofguard, while guarded VGPR writes continue to keep the register tainted.emit::lower::tests::a_guarded_scalar_write_kills_a_stale_sgprcovering:v_readfirstlane_b32before being read (lowerssucceeds).Verification
26,503containers,dxil.dllvalidation):emit: a lane mask read as data:8 -> 4(all 4 affected pixel shaders now emit and validate).14,205 -> 14,209emitted (+4),13,338 -> 13,342validated (+4, 100% validated),0regressions across all26,084programs.cargo clippy --workspace --all-targets --locked -- -D warnings— passed.cargo clippy --workspace --all-targets --all-features --locked -- -D warnings— passed.cargo test -p victory-shader --locked—a_guarded_scalar_write_kills_a_stale_sgprpassed, along with245 passed, 0 failed, 3 ignored(excluding the 3 known NVIDIAmainfailures from #2317).cargo xtask policyandgit diff --check— passed.@cloph-dsp on GitHub · 2026-11-25 14:49 UTC · original
Independent local validation (Windows, Rust 1.100.0/MSVC, head
ca16e45, no game data):cargo test --locked -p victory-shader --lib-> 248 tests passed, 0 failed, 3 ignored, exit 0;git diff --check HEAD~1 HEADclean. No new tests appeared in the lib run (same 248 as main), so this is a compile/regression check rather than validation of a new test. The synthetic dead-edge SGPR scenario in the PR was not independently replayed. AI-assisted (Hy4 flash). GPU/driver: N/A for this CPU test run (hardware/WARP shader tests skipped here). No game data, assets or extracted content used.@Marvisak on GitHub · 2026-11-25 15:59 UTC · original
Automated triage for the maintainers.
In
Lower::dead_on_edge(crates/victory-shader/src/emit/lower.rs), a guarded instruction now ends the tracked stale value for the scalar registers it writes; guarded VGPR writes still keep it. That matcheswrite_placed, which applies the guard only toReg::Vwrites, and the ISA rule that VALU writes to SGPRs (v_readfirstlane_b32,v_cmp_*, carry-outs) do not depend on EXEC. I checked the key encodings in the new test (v_readfirstlane_b32 s6, v0,v_cmpx_eq_u32), and the test includes negative controls that should still be refused. CI passes.Generated by Claude Code