Shaders: guarded scalar writes kill stale SGPRs in dead_on_edge #2468

Manually merged
github merged 1 commit from gh-pr/2468/head into gh-pr/2468/base 2026-11-26 05:06:49 +00:00
Owner

@⁠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 UTC

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 from regs when guard.is_none().

On RDNA2 (and in Lower::write_i / Lower::write_placed), EXEC guards only preserve the previous value of VGPR writes (Reg::V(_)). Scalar and SCC writes from guarded VALU instructions — such as v_readfirstlane_b32, v_readlane_b32, v_cmp_*, and carry-out SGPRs — always overwrite their destination register unconditionally. Leaving such an SGPR in regs caused dead_on_edge to reject a subsequent read of the freshly written SGPR as a live use of the earlier stale value.

Fix

  • Update Lower::dead_on_edge so writes to non-VGPR registers (!matches!(r, Reg::V(_))) always remove the register from regs regardless of guard, while guarded VGPR writes continue to keep the register tainted.
  • Add synthetic unit test emit::lower::tests::a_guarded_scalar_write_kills_a_stale_sgpr covering:
    • A stale SGPR overwritten by a guarded v_readfirstlane_b32 before being read (lowers succeeds).
    • Negative controls: removing the guarded overwrite or setting the guard flag on both paths still refuses the shader.

Verification

  • Full title shader archive sweep (26,503 containers, dxil.dll validation):
    • emit: a lane mask read as data: 8 -> 4 (all 4 affected pixel shaders now emit and validate).
    • Vertex & pixel shaders: 14,205 -> 14,209 emitted (+4), 13,338 -> 13,342 validated (+4, 100% validated), 0 regressions across all 26,084 programs.
    • Confirmed D3D12 pipeline creation on an RTX 3080 for an affected pixel shader.
  • 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_sgpr passed, along with 245 passed, 0 failed, 3 ignored (excluding the 3 known NVIDIA main failures from #2317).
  • cargo xtask policy and git diff --check — passed.
**@⁠VastyViz** on GitHub · 2026-11-25 14:12 UTC · [original](https://github.com/Marvisak/VIctory/pull/2468) `VastyViz:shaders/dead-on-edge` → `main` · +45 −3 · 1 files · 1 commits · merged 2026-11-25 21:57 UTC ### 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 from `regs` when `guard.is_none()`. On RDNA2 (and in `Lower::write_i` / `Lower::write_placed`), `EXEC` guards only preserve the previous value of **VGPR** writes (`Reg::V(_)`). Scalar and SCC writes from guarded VALU instructions — such as `v_readfirstlane_b32`, `v_readlane_b32`, `v_cmp_*`, and carry-out SGPRs — always overwrite their destination register unconditionally. Leaving such an SGPR in `regs` caused `dead_on_edge` to reject a subsequent read of the freshly written SGPR as a live use of the earlier stale value. ### Fix - Update `Lower::dead_on_edge` so writes to non-VGPR registers (`!matches!(r, Reg::V(_))`) always remove the register from `regs` regardless of `guard`, while guarded VGPR writes continue to keep the register tainted. - Add synthetic unit test `emit::lower::tests::a_guarded_scalar_write_kills_a_stale_sgpr` covering: - A stale SGPR overwritten by a guarded `v_readfirstlane_b32` before being read (`lowers` succeeds). - Negative controls: removing the guarded overwrite or setting the guard flag on both paths still refuses the shader. ### Verification - Full title shader archive sweep (`26,503` containers, `dxil.dll` validation): - `emit: a lane mask read as data`: `8 -> 4` (all 4 affected pixel shaders now emit and validate). - Vertex & pixel shaders: `14,205 -> 14,209` emitted (`+4`), `13,338 -> 13,342` validated (`+4`, 100% validated), `0` regressions across all `26,084` programs. - Confirmed D3D12 pipeline creation on an RTX 3080 for an affected pixel shader. - `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_sgpr` passed, along with `245 passed, 0 failed, 3 ignored` (excluding the 3 known NVIDIA `main` failures from #2317). - `cargo xtask policy` and `git diff --check` — passed.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:06:47 +00:00
github manually merged commit ca16e454c9 into gh-pr/2468/base 2026-11-26 05:06:49 +00:00
Author
Owner

@⁠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 HEAD clean. 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.

**@⁠cloph-dsp** on GitHub · 2026-11-25 14:49 UTC · [original](https://github.com/Marvisak/VIctory/pull/2468#issuecomment-7165869092) 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 HEAD` clean. 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.
Author
Owner

@⁠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 matches write_placed, which applies the guard only to Reg::V writes, 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

**@⁠Marvisak** on GitHub · 2026-11-25 15:59 UTC · [original](https://github.com/Marvisak/VIctory/pull/2468#issuecomment-7167499119) <!-- victory-triage v1 head=ca16e454c99383417eb1e8a9770c1a1bf8b6495f verdict=merge-candidate at=2026-11-25T15:59:09Z --> 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 matches `write_placed`, which applies the guard only to `Reg::V` writes, 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](https://claude.ai/code)_
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2468
No description provided.