Shaders: s_min/s_max set SCC from the comparison; v_readlane/v_writelane lanes wrap #404

Open
github-bot wants to merge 2 commits from github-bot/gh-404 into main AGit
Owner

@⁠simbaui4life on GitHub · 2026-11-27 00:19 UTC · original
simbaui4life:fix/salu-minmax-scc-lane-masks → main · +65 −5 · 3 files · 2 commits · open

Two lowering faults, found by differential testing of the translator against an independent RDNA2 interpreter on the GPU (the harness is #403; this PR does not need it). One commit on 014d52d.

Cause

  • s_min_{i,u}32 / s_max_{i,u}32 set SCC when S0 is chosen (S0 < S1 for min, S0 > S1 for max). The lowering gave no SCC of its own, so the generic D != 0 was used, and an s_cselect_b32 or s_cbranch_scc0/1 after a min/max took the wrong side whenever the two disagree. Example: s_min_u32 s0, 5, 3 gives SCC 0 on the console and 1 here. Marvisak/VIctory's lowering already sets SCC this way.
  • v_readlane_b32 / v_writelane_b32 take the lane from S1[4:0] (wave32) or S1[5:0] (wave64). Here, a select past the wave read the wrong lane's value or wrote no lane. On the console it wraps.

What this does

  • emit/lower.rs: min/max return the comparison as SCC. readlane/writelane mask a console lane with wave - 1. A computed lane that is a host lane (MaskData::Host, pixel/vertex programs) is left as it was.
  • TRANSLATOR_VERSION 1 → 2. #353 and #354 also go 1 → 2, so whichever lands later needs the next number.
  • Upstream: Marvisak/VIctory#1312 makes the same lane-select change there. It also lets v_writelane write a lane EXEC leaves out, which this PR does not do.

Tested (RTX 4070 Ti, driver 621.01, Windows 11 26200; wave64 programs on 32-lane host waves)

  • This branch alone: cargo clippy -p victory-shader --all-targets -- -D warnings, the same with --all-features, and cargo test -p victory-shader (302 passed, 0 failed).
  • With #403's fuzzer: programs that read SCC after a min/max, or select a lane at or past the wave size, differed from the interpreter before this change and agree after it.

Not tested: in the game (no game data here), AMD hardware, and how many of the title's programs change (victory shaders would say).

No game data in the commits.

🤖 Generated with Claude Code

**@⁠simbaui4life** on GitHub · 2026-11-27 00:19 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/404) `simbaui4life:fix/salu-minmax-scc-lane-masks` → `main` · +65 −5 · 3 files · 2 commits · open Two lowering faults, found by differential testing of the translator against an independent RDNA2 interpreter on the GPU (the harness is #403; this PR does not need it). One commit on `014d52d`. **Cause** - `s_min_{i,u}32` / `s_max_{i,u}32` set SCC when S0 is chosen (S0 < S1 for min, S0 > S1 for max). The lowering gave no SCC of its own, so the generic `D != 0` was used, and an `s_cselect_b32` or `s_cbranch_scc0/1` after a min/max took the wrong side whenever the two disagree. Example: `s_min_u32 s0, 5, 3` gives SCC 0 on the console and 1 here. Marvisak/VIctory's lowering already sets SCC this way. - `v_readlane_b32` / `v_writelane_b32` take the lane from S1[4:0] (wave32) or S1[5:0] (wave64). Here, a select past the wave read the wrong lane's value or wrote no lane. On the console it wraps. **What this does** - `emit/lower.rs`: min/max return the comparison as SCC. readlane/writelane mask a console lane with `wave - 1`. A computed lane that is a host lane (`MaskData::Host`, pixel/vertex programs) is left as it was. - `TRANSLATOR_VERSION` 1 → 2. #353 and #354 also go 1 → 2, so whichever lands later needs the next number. - Upstream: Marvisak/VIctory#1312 makes the same lane-select change there. It also lets `v_writelane` write a lane EXEC leaves out, which this PR does not do. **Tested** (RTX 4070 Ti, driver 621.01, Windows 11 26200; wave64 programs on 32-lane host waves) - This branch alone: `cargo clippy -p victory-shader --all-targets -- -D warnings`, the same with `--all-features`, and `cargo test -p victory-shader` (302 passed, 0 failed). - With #403's fuzzer: programs that read SCC after a min/max, or select a lane at or past the wave size, differed from the interpreter before this change and agree after it. **Not tested:** in the game (no game data here), AMD hardware, and how many of the title's programs change (`victory shaders` would say). No game data in the commits. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
s_min_{i,u}32 and s_max_{i,u}32 set SCC when S0 is chosen (S0 < S1 for min,
S0 > S1 for max). The lowering returned no SCC, so the generic D != 0 was
used: s_cselect or s_cbranch_scc after a min/max took the wrong side
whenever the result was nonzero but S1 was chosen (or zero with S0 chosen).
Marvisak/VIctory's lowering already does this.

v_readlane_b32 and v_writelane_b32 take the lane from S1[4:0] (wave32) or
S1[5:0] (wave64). A select past the wave read 0 or wrote no lane here; it
now wraps as on the console. Lanes that are host lanes (pixel/vertex
programs with a computed lane) are unchanged.

Both were found by differential testing of the translator against an
independent RDNA2 interpreter on the GPU.

TRANSLATOR_VERSION 1 -> 2.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 00:56:43 +00:00
Author
Owner

@⁠UwUCammie on GitHub · 2026-11-27 00:43 UTC · original

I ported this to the AMD fork and found one more place that needs the lane mask. The scalar spill pass runs before lowering, so it used to treat lane 36 and lane 4 as separate slots in wave32. The backport normalizes constant selectors in IR before that pass.

The IR test and both hardware fixtures passed on my RX 7900 XT under Wine with RADV 26.3.1. AMD backport

**@⁠UwUCammie** on GitHub · 2026-11-27 00:43 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/404#issuecomment-7206706563) I ported this to the AMD fork and found one more place that needs the lane mask. The scalar spill pass runs before lowering, so it used to treat lane 36 and lane 4 as separate slots in wave32. The backport normalizes constant selectors in IR before that pass. The IR test and both hardware fixtures passed on my RX 7900 XT under Wine with RADV 26.3.1. [AMD backport](https://github.com/jtrudeau1530/VIctory-7900XTX/pull/38)
v_readlane_b32 / v_writelane_b32 with a constant lane: ir::build and unspill now see
the lane modulo the wave (S1[4:0] in wave32, S1[5:0] in wave64), so the spill tracker
takes lanes 36 and 4 of a wave32 program for the one slot they are on the console.
The lowering already wrapped the lane; unspill, which runs before it, did not.

Found by UwUCammie in the review of #404, and done the same way in
jtrudeau1530/VIctory-7900XTX#38. Test: ir::tests::
a_constant_lane_past_the_wave_is_its_lane_modulo_the_wave (wave32 aliases, wave64
does not; it fails without the change).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Owner

@⁠simbaui4life on GitHub · 2026-11-27 15:26 UTC · original

Thanks, you're right: unspill matched constant lanes before the lowering wrapped them, so in wave32 lanes 36 and 4 were two slots there.

I took your normalization from jtrudeau1530/VIctory-7900XTX#38 into this PR (e86d7a6, credited in the commit): lane_wrapped_fields in ir::build and unspill. The new IR test a_constant_lane_past_the_wave_is_its_lane_modulo_the_wave checks that the lanes alias in wave32 and stay apart in wave64. It fails without the change.

This branch: cargo test -p victory-shader 303 passed, clippy -D warnings clean, also with --all-features (RTX 4070 Ti).

**@⁠simbaui4life** on GitHub · 2026-11-27 15:26 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/404#issuecomment-7222055033) Thanks, you're right: `unspill` matched constant lanes before the lowering wrapped them, so in wave32 lanes 36 and 4 were two slots there. I took your normalization from jtrudeau1530/VIctory-7900XTX#38 into this PR (e86d7a6, credited in the commit): `lane_wrapped_fields` in `ir::build` and `unspill`. The new IR test `a_constant_lane_past_the_wave_is_its_lane_modulo_the_wave` checks that the lanes alias in wave32 and stay apart in wave64. It fails without the change. This branch: `cargo test -p victory-shader` 303 passed, clippy `-D warnings` clean, also with `--all-features` (RTX 4070 Ti).
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/404/head:github-bot/gh-404'
git switch 'github-bot/gh-404'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-404'
git switch 'github-bot/gh-404'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-404'
git switch 'github-bot/gh-404'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-404'
git switch 'main'
git merge --squash 'github-bot/gh-404'
git switch 'main'
git merge --ff-only 'github-bot/gh-404'
git switch 'main'
git merge 'github-bot/gh-404'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.