Shaders: a mask built up in a loop every lane runs the same way (stacked on #1407) #1420

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

@⁠marquezinii on GitHub · 2026-11-24 17:54 UTC · original
marquezinii:shader/lane-mask-loops → main · +542 −6 · 4 files · 2 commits · open

Stacked on #1407: the first two commits are that pull request's, the last one is this change.

A mask ORed together over a loop and read after it failed with "a lane-mask join of an untracked mask":

s_mov_b32 s20, 0
s_mov_b32 s21, 0
loop:
  v_cmp_eq_u32 vcc_lo, s21, v0
  s_or_b32 s20, s20, vcc_lo
  s_add_i32 s21, s21, 1
  s_cmp_lt_u32 s21, 3
  s_cbranch_scc1 loop
v_mov_b32 v1, s20        ; 0x7 in every lane

The join at the loop's head takes in the 0 written before the loop, which is no mask, so the lowering had no lane bit for that edge. When no branch in the loop depends on the lane (here an SCC test of a scalar counter), each lane goes round as often as the wave and enters the head over the wave's edge, so its own value there is the wave's. structure now records those joins, with the forward joins that #1407 checks edge by edge, as per_lane_joins, and only those take in a number by its lane bit. A loop that lanes leave after different passes (v_cmpx_lt_u32 then s_cbranch_execnz) is still refused: there the wave's s20 keeps growing after a lane has left, so the lane's own copy is not the wave's.

How I checked it

Three tests in lane_mask_tests.rs, on synthetic wave32 programs of 32 lanes:

  • two run on the GPU and compare every lane with the console's result: the loop above read as a number (0x7) and counted with s_bcnt1_i32_b32 (3);
  • one checks that the loop whose lanes leave apart is refused. With the uniform-loop check forced to pass, that test fails, so the check is what refuses it.

On an RTX 5070 (driver 621.40), all eight tests of the file pass. Devices without 32-lane waves (WARP, the CI's adapter) are skipped, as in #1407. cargo test --workspace --locked passes and cargo clippy --workspace --all-targets --locked -- -D warnings is clean.

Not checked: the title's shaders (I have no dump), wave64 on a GPU, and loops with a lane-dependent branch inside that does not leave the loop. Those are still refused, which is safe but stricter than needed.

**@⁠marquezinii** on GitHub · 2026-11-24 17:54 UTC · [original](https://github.com/Marvisak/VIctory/pull/1420) `marquezinii:shader/lane-mask-loops` → `main` · +542 −6 · 4 files · 2 commits · open Stacked on #1407: the first two commits are that pull request's, the last one is this change. A mask ORed together over a loop and read after it failed with "a lane-mask join of an untracked mask": ``` s_mov_b32 s20, 0 s_mov_b32 s21, 0 loop: v_cmp_eq_u32 vcc_lo, s21, v0 s_or_b32 s20, s20, vcc_lo s_add_i32 s21, s21, 1 s_cmp_lt_u32 s21, 3 s_cbranch_scc1 loop v_mov_b32 v1, s20 ; 0x7 in every lane ``` The join at the loop's head takes in the 0 written before the loop, which is no mask, so the lowering had no lane bit for that edge. When no branch in the loop depends on the lane (here an SCC test of a scalar counter), each lane goes round as often as the wave and enters the head over the wave's edge, so its own value there is the wave's. `structure` now records those joins, with the forward joins that #1407 checks edge by edge, as `per_lane_joins`, and only those take in a number by its lane bit. A loop that lanes leave after different passes (`v_cmpx_lt_u32` then `s_cbranch_execnz`) is still refused: there the wave's s20 keeps growing after a lane has left, so the lane's own copy is not the wave's. ### How I checked it Three tests in `lane_mask_tests.rs`, on synthetic wave32 programs of 32 lanes: - two run on the GPU and compare every lane with the console's result: the loop above read as a number (`0x7`) and counted with `s_bcnt1_i32_b32` (3); - one checks that the loop whose lanes leave apart is refused. With the uniform-loop check forced to pass, that test fails, so the check is what refuses it. On an RTX 5070 (driver 621.40), all eight tests of the file pass. Devices without 32-lane waves (WARP, the CI's adapter) are skipped, as in #1407. `cargo test --workspace --locked` passes and `cargo clippy --workspace --all-targets --locked -- -D warnings` is clean. Not checked: the title's shaders (I have no dump), wave64 on a GPU, and loops with a lane-dependent branch inside that does not leave the loop. Those are still refused, which is safe but stricter than needed.
A join of masks read by a VALU instruction (a compare written in a branch,
read after EXEC is restored) is tracked as a mask and read as one, before
the first loop, when every lane's own incoming mask is the wave's: the wave
leaves a join from its last predecessor in program order, so a lane must
find there the mask of every later edge. A constant joined in (s20 = 0
before the branch) is taken by its lane bit in such joins only.

Masks holding lanes elsewhere are left to mask_number, which replays the
scalar operation that writes them. The lane-mask tests run only where
32-lane waves run.
A mask ORed together over a loop (`s20 |= v_cmp(...)` with a scalar
counter) and read after it failed with "a lane-mask join of an untracked
mask": the join at the loop's head takes in the 0 written before it,
which is no mask. When no branch in the loop depends on the lane, each
lane goes round as often as the wave and enters the head over the wave's
edge, so its own value there is the wave's; such joins, and the forward
joins checked edge by edge, are now recorded as per-lane joins, and only
those take in a number by its lane bit. A loop that lanes leave after
different passes is still refused.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:31:03 +00:00
Author
Owner

@⁠geiyiliyabumo on GitHub · 2026-11-24 18:09 UTC · original

Independent verification of \7b7d5fd\ on Windows 11 / AMD Radeon RX 9060 XT (RDNA4, \gfx1200, native wave32 + wave64) / Rust 1.98.1 MSVC:

  • Merge check vs \main\ (\ fe310e): clean
  • \cargo test -p victory-shader --lib lane_mask_tests\ (real RX 9060 XT GPU execution): 8 passed, 0 failed
  • \cargo clippy -p victory-shader --all-targets -- -D warnings\ (default and --all-features): clean
  • \cargo xtask policy: 155 files ok

AI-assisted; synthetic tests only, no game files.

**@⁠geiyiliyabumo** on GitHub · 2026-11-24 18:09 UTC · [original](https://github.com/Marvisak/VIctory/pull/1420#issuecomment-7140250307) Independent verification of \7b7d5fd\ on **Windows 11 / AMD Radeon RX 9060 XT (RDNA4, \gfx1200\, native wave32 + wave64) / Rust 1.98.1 MSVC**: - Merge check vs \main\ (\ fe310e\): clean - \cargo test -p victory-shader --lib lane_mask_tests\ (real RX 9060 XT GPU execution): **8 passed, 0 failed** - \cargo clippy -p victory-shader --all-targets -- -D warnings\ (default and \--all-features\): clean - \cargo xtask policy\: 155 files ok *AI-assisted; synthetic tests only, no game files.*
Author
Owner

@⁠marquezinii on GitHub · 2026-11-24 19:56 UTC · original

On the conflict with #1407: this branch is stacked on it, not a copy. It contains #1407's two commits unchanged, plus one commit for the loops, so the two do not conflict. Merging this one lands both. Merging #1407 first (as a merge, not a squash) leaves only the last commit here. If #1407 is squashed, I'll rebase this one.

**@⁠marquezinii** on GitHub · 2026-11-24 19:56 UTC · [original](https://github.com/Marvisak/VIctory/pull/1420#issuecomment-7142808358) On the conflict with #1407: this branch is stacked on it, not a copy. It contains #1407's two commits unchanged, plus one commit for the loops, so the two do not conflict. Merging this one lands both. Merging #1407 first (as a merge, not a squash) leaves only the last commit here. If #1407 is squashed, I'll rebase this one.
Author
Owner

@⁠sinan-cmyk on GitHub · 2026-11-24 20:44 UTC · original

Offline measurement on a retail dump, and the shader tests on Ada

Result: no count change against main.

Offline. I merged head 7b7d5fd onto main ffe310e (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 21,724 on main, 21,724 with this PR.

5 programs move from "a lane mask holding lanes elsewhere read as data" to later failures.

Tests: with the same merge, cargo test --locked -p victory-shader --lib passed 128, failed 0. The bitcode benchmark is ignored, as on main, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, with VICTORY_WARP unset.

No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

**@⁠sinan-cmyk** on GitHub · 2026-11-24 20:44 UTC · [original](https://github.com/Marvisak/VIctory/pull/1420#issuecomment-7143983260) ### Offline measurement on a retail dump, and the shader tests on Ada **Result: no count change against `main`.** **Offline.** I merged head 7b7d5fd onto `main` ffe310e (clean merge) and ran `victory translate --validate --list` on `shaders.rpf` (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with `main` program by program (25,889 programs). Validated: 21,724 on `main`, 21,724 with this PR. 5 programs move from "a lane mask holding lanes elsewhere read as data" to later failures. **Tests:** with the same merge, `cargo test --locked -p victory-shader --lib` passed 128, failed 0. The bitcode benchmark is ignored, as on `main`, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, with `VICTORY_WARP` unset. No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
Author
Owner

@⁠marquezinii on GitHub · 2026-11-24 21:40 UTC · original

Thanks for running the comparison on this one too. It gives the same 5 programs as #1407 alone, so the loop handling here doesn't move any program on top of it in this build. Their next refusal is what blocks them, not the masks.

If you still have both lists, the reason each of those 5 fails with now would settle where to look next. That one comparison covers both PRs, so there's no need to repeat it on #1407.

**@⁠marquezinii** on GitHub · 2026-11-24 21:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/1420#issuecomment-7145232671) Thanks for running the comparison on this one too. It gives the same 5 programs as #1407 alone, so the loop handling here doesn't move any program on top of it in this build. Their next refusal is what blocks them, not the masks. If you still have both lists, the reason each of those 5 fails with now would settle where to look next. That one comparison covers both PRs, so there's no need to repeat it on #1407.
Author
Owner

@⁠marquezinii on GitHub · 2026-11-24 22:06 UTC · original

Rebased onto main 70564ae, still stacked on #1407 (head 9f57d9c: #1407's two commits, then the loop commit). The only conflict came from main's new fields in the structure builder.

On an RTX 5070, the two loop tests fail on plain main and pass here. cargo test -p victory-shader --locked: 214 passed, and 3 failures that plain main has on this card too (listed on #1407).

**@⁠marquezinii** on GitHub · 2026-11-24 22:06 UTC · [original](https://github.com/Marvisak/VIctory/pull/1420#issuecomment-7145801758) Rebased onto `main` `70564ae`, still stacked on #1407 (head `9f57d9c`: #1407's two commits, then the loop commit). The only conflict came from `main`'s new fields in the structure builder. On an RTX 5070, the two loop tests fail on plain `main` and pass here. `cargo test -p victory-shader --locked`: 214 passed, and 3 failures that plain `main` has on this card too (listed on #1407).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 03:27 UTC · original · edited 2026-11-25 16:04 UTC

Automated triage for the maintainers.

This pull request no longer merges cleanly into main (conflicts in crates/victory-shader/src/emit/lower.rs). It will be reviewed once it is rebased onto the current main. The earlier verdict (needs-work) was for an older state of main.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 03:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/1420#issuecomment-7151926805) · edited 2026-11-25 16:04 UTC <!-- victory-triage v1 head=f9fb9aaa5e6606293decd2034b4ccf042beaaf74 verdict=needs-rebase at=2026-11-25T16:02:10Z --> Automated triage for the maintainers. This pull request no longer merges cleanly into `main` (conflicts in `crates/victory-shader/src/emit/lower.rs`). It will be reviewed once it is rebased onto the current `main`. The earlier verdict (needs-work) was for an older state of `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠marquezinii on GitHub · 2026-11-25 04:41 UTC · original

Restacked on the new #1407 (head f9fb9aa, on main 940d32f): #1407's single commit, then the loop commit. #1407 has dropped its outside fallback, so the per-lane joins here no longer look at it either. A uniform loop's head joins and the forward joins checked edge by edge go into per_lane_joins, and only those take in a number.

On the CI failure: the check job's failing tests are synthetic_tests::gathers_at_a_level_match_the_hardware and permutes_read_the_lane_named_and_zero_from_lanes_left_out, which this branch does not touch. On an RTX 5070, plain main 940d32f fails gathers_at_a_level… and two stride_tests the same way. Here, cargo test -p victory-shader --locked -- lane_mask gives 9 passed, cargo clippy -p victory-shader --all-targets --locked -- -D warnings is clean, and the full crate gives 252 passed with only those 3 main failures.

**@⁠marquezinii** on GitHub · 2026-11-25 04:41 UTC · [original](https://github.com/Marvisak/VIctory/pull/1420#issuecomment-7153074244) Restacked on the new #1407 (head `f9fb9aa`, on `main` `940d32f`): #1407's single commit, then the loop commit. #1407 has dropped its `outside` fallback, so the per-lane joins here no longer look at it either. A uniform loop's head joins and the forward joins checked edge by edge go into `per_lane_joins`, and only those take in a number. On the CI failure: the `check` job's failing tests are `synthetic_tests::gathers_at_a_level_match_the_hardware` and `permutes_read_the_lane_named_and_zero_from_lanes_left_out`, which this branch does not touch. On an RTX 5070, plain `main` `940d32f` fails `gathers_at_a_level…` and two `stride_tests` the same way. Here, `cargo test -p victory-shader --locked -- lane_mask` gives 9 passed, `cargo clippy -p victory-shader --all-targets --locked -- -D warnings` is clean, and the full crate gives 252 passed with only those 3 `main` failures.
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/lower.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1420'
git switch 'github-bot/gh-1420'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1420'
git switch 'github-bot/gh-1420'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1420'
git switch 'main'
git merge --squash 'github-bot/gh-1420'
git switch 'main'
git merge --ff-only 'github-bot/gh-1420'
git switch 'main'
git merge 'github-bot/gh-1420'
git push origin 'main'
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!1420
No description provided.