Shaders: guarded scalar writes kill stale SGPRs in dead_on_edge #2466
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2468"
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?
Imported from Marvisak/VIctory. Originally posted by VastyViz on 2026-11-25T14:12:02Z.
Problem
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.Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T14:17:35Z.
Review: APPROVED
Verified against
origin/main(940d32f) on Windows 11 + NVIDIA GeForce RTX 5090 and WARP:dead_on_edgeis clean and passes all lower tests.cargo test -p victory-shader emit::lower::tests: 22/22 passed on RTX 5090, 22/22 passed on WARP (includinga_guarded_scalar_write_kills_a_stale_sgpr).cargo clippy -p victory-shader --all-targets -- -D warnings: 0 warnings.cargo xtask policy: 183 files ok.AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T14:57:32Z.
Review: APPROVED
Tested locally: merged into main
940d32f69b,cargo test -p victory-shader --lockedon macOS arm64 — 145 passed, 0 failed, 2 ignored (Windows-gated hardware execution tests not run here). Approving — guarded scalar writes kill stale SGPRs in dead lanes.Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-25T14:49:22Z.
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.Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T15:59:47Z.
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