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

Open
simbaui4life wants to merge 2 commits from upstream-pr/404 into main
simbaui4life commented 2026-11-27 00:19:01 +00:00 (Migrated from github.com)

Imported from avatarmanz/VIctory-7900XTX. Originally posted by simbaui4life on 2026-11-27T00:19:01Z.


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

<!-- greyfinch-sync:avatarmanz/VIctory-7900XTX:issue:5519016438 --> Imported from [avatarmanz/VIctory-7900XTX](https://github.com/avatarmanz/VIctory-7900XTX/pull/404). Originally posted by [simbaui4life](https://github.com/simbaui4life) on 2026-11-27T00:19:01Z. --- 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)
UwUCammie commented 2026-11-27 00:43:59 +00:00 (Migrated from github.com)

Imported from avatarmanz/VIctory-7900XTX. Originally posted by UwUCammie on 2026-11-27T00:43:59Z.


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

<!-- greyfinch-sync:avatarmanz/VIctory-7900XTX:comment:7206706563 --> Imported from [avatarmanz/VIctory-7900XTX](https://github.com/avatarmanz/VIctory-7900XTX/pull/404#issuecomment-7206706563). Originally posted by [UwUCammie](https://github.com/UwUCammie) on 2026-11-27T00:43:59Z. --- 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)
simbaui4life commented 2026-11-27 15:26:12 +00:00 (Migrated from github.com)

Imported from avatarmanz/VIctory-7900XTX. Originally posted by simbaui4life on 2026-11-27T15:26:12Z.


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).

<!-- greyfinch-sync:avatarmanz/VIctory-7900XTX:comment:7222055033 --> Imported from [avatarmanz/VIctory-7900XTX](https://github.com/avatarmanz/VIctory-7900XTX/pull/404#issuecomment-7222055033). Originally posted by [simbaui4life](https://github.com/simbaui4life) on 2026-11-27T15:26:12Z. --- 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 cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/404:upstream-pr/404'
git switch 'upstream-pr/404'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/404'
git switch 'upstream-pr/404'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/404'
git switch 'upstream-pr/404'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/404'
git switch 'main'
git merge --squash 'upstream-pr/404'
git switch 'main'
git merge --ff-only 'upstream-pr/404'
git switch 'main'
git merge 'upstream-pr/404'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
avatarmanz/VIctory-7900XTX!404
No description provided.