Skip to content

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

Open
marquezinii wants to merge 2 commits into
Marvisak:mainfrom
marquezinii:shader/lane-mask-loops
Open

marquezinii wants to merge 2 commits into
Marvisak:mainfrom
marquezinii:shader/lane-mask-loops

Conversation

@marquezinii

@marquezinii marquezinii commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

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.

@geiyiliyabumo

Copy link
Copy Markdown
Contributor

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.

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (ffe310e), cargo test -p victory-shader --locked → 96. GPU/valu execution tests are Windows-gated and were not run here.

Same lane-mask work as #1407 plus the loop cases: a mask built up in a loop every lane runs the same way now reads as a number and counts its lanes (accumulating_loop variants). New lane_mask_tests.rs (380 lines) — Windows-gated hardware cases, not run on macOS (96 green).

Note: conflicts with #1407 (same new file, same helpers/tests); this one is the superset, so landing this one and closing #1407 would avoid a rebase.

@marquezinii

Copy link
Copy Markdown
Contributor Author

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.

@sinan-cmyk

Copy link
Copy Markdown

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

@marquezinii

Copy link
Copy Markdown
Contributor Author

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
marquezinii force-pushed the shader/lane-mask-loops branch from 7b7d5fd to 9f57d9c Compare November 24, 2026 22:05
@marquezinii

Copy link
Copy Markdown
Contributor Author

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

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

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

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.
@marquezinii
marquezinii force-pushed the shader/lane-mask-loops branch from 9f57d9c to f9fb9aa Compare November 25, 2026 04:40
@marquezinii

Copy link
Copy Markdown
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants