Shaders: keep s_cmp of two lane masks uniform #2451

Closed
makmatvey wants to merge 1 commit from upstream-pr/2453 into main
makmatvey commented 2026-11-25 13:49:25 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by makmatvey on 2026-11-25T13:49:25Z.


What

s_cmp_eq / s_cmp_lg of two tracked lane masks sets a wave-wide SCC on the console (all bits equal / any bit differs). Structuring lowered that to a per-lane XNOR/XOR into scc_lane, so s_cbranch_scc0/1 diverged when only some lanes agreed locally.

Tracked as VIC-BT-006 in #1242. Focused re-land of stalled #1412 (triage: needs rebase); does not include that PR's GPU valu harness changes.

Change

In crates/victory-shader/src/structure.rs, skip the per-lane scc_lane insert when both operands are tracked masks. SCC stays a uniform atom; lowering already compares the ballots as scalar values.

Tests

  • cargo test -p victory-shader --locked --lib structure::tests::branches_comparing_two_lane_masks_are_uniform — pass (fails on main without the skip: Lane vs Uniform)
  • cargo test -p victory-shader --locked --lib structure:: — 12 passed, 1 ignored
  • cargo clippy -p victory-shader --locked -- -D warnings — clean
  • cargo xtask policy — ok

No game data used.

Fixes VIC-BT-006 in #1242.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6605987240 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2453). Originally posted by [makmatvey](https://github.com/makmatvey) on 2026-11-25T13:49:25Z. --- ## What `s_cmp_eq` / `s_cmp_lg` of two tracked lane masks sets a wave-wide SCC on the console (all bits equal / any bit differs). Structuring lowered that to a per-lane XNOR/XOR into `scc_lane`, so `s_cbranch_scc0/1` diverged when only some lanes agreed locally. Tracked as VIC-BT-006 in #1242. Focused re-land of stalled #1412 (`triage: needs rebase`); does not include that PR's GPU valu harness changes. ## Change In `crates/victory-shader/src/structure.rs`, skip the per-lane `scc_lane` insert when both operands are tracked masks. SCC stays a uniform atom; lowering already compares the ballots as scalar values. ## Tests - `cargo test -p victory-shader --locked --lib structure::tests::branches_comparing_two_lane_masks_are_uniform` — pass (fails on `main` without the skip: `Lane` vs `Uniform`) - `cargo test -p victory-shader --locked --lib structure::` — 12 passed, 1 ignored - `cargo clippy -p victory-shader --locked -- -D warnings` — clean - `cargo xtask policy` — ok No game data used. Fixes VIC-BT-006 in #1242.
DenRakEiw commented 2026-11-25 14:07:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T13:54:30Z.

Review: APPROVED


Verified against origin/main (940d32f) on Windows 11 + NVIDIA GeForce RTX 5090 and WARP:

  • Keeping s_cmp of two lane masks uniform in structure.rs is clean and passes all structure tests.
  • cargo test -p victory-shader structure::tests: 12/12 passed on RTX 5090, 12/12 passed on WARP (including branches_comparing_two_lane_masks_are_uniform).
  • cargo clippy -p victory-shader --all-targets -- -D warnings: 0 warnings.
  • cargo xtask policy: 183 files ok.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6058885759 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2453#pullrequestreview-6058885759). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-25T13:54:30Z. **Review:** APPROVED --- Verified against `origin/main` (`940d32f`) on Windows 11 + NVIDIA GeForce RTX 5090 and WARP: - Keeping `s_cmp` of two lane masks uniform in `structure.rs` is clean and passes all structure tests. - `cargo test -p victory-shader structure::tests`: 12/12 passed on RTX 5090, 12/12 passed on WARP (including `branches_comparing_two_lane_masks_are_uniform`). - `cargo clippy -p victory-shader --all-targets -- -D warnings`: 0 warnings. - `cargo xtask policy`: 183 files ok. AI-assisted (Gemini 4 Neon).
catminou4 commented 2026-11-25 15:03:48 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T14:11:06Z.

Review: APPROVED


Tested locally: merged into main 940d32f69b, cargo test -p victory-shader --locked on macOS arm64 — 145 passed, 0 failed, 2 ignored (Windows-gated hardware execution tests not run here). Approving — s_cmp of two lane masks kept uniform.

<!-- greyfinch-sync:Marvisak/VIctory:review:6059173476 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2453#pullrequestreview-6059173476). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T14:11:06Z. **Review:** APPROVED --- Tested locally: merged into main 940d32f69b, `cargo test -p victory-shader --locked` on macOS arm64 — 145 passed, 0 failed, 2 ignored (Windows-gated hardware execution tests not run here). Approving — s_cmp of two lane masks kept uniform.
kotekompotek commented 2026-11-25 15:04:18 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T14:25:16Z.


Correct semantics: s_cmp_eq_u32 vcc, exec compares two ballot values as scalars — the result is a single uniform SCC, not a per-lane relation, so feeding it through the per-lane XOR path would have s_cbranch_scc* report divergent (a wrong branch structure, not just a missed optimization). The !(a_mask && c_mask) gate keeps the per-lane path for the mask-vs-scalar case where it belongs. The test pins the uniform support for both wave widths and both senses (eq/lg).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7165250900 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2453#issuecomment-7165250900). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-25T14:25:16Z. --- Correct semantics: `s_cmp_eq_u32 vcc, exec` compares two ballot values as scalars — the result is a single uniform SCC, not a per-lane relation, so feeding it through the per-lane XOR path would have `s_cbranch_scc*` report divergent (a wrong branch structure, not just a missed optimization). The `!(a_mask && c_mask)` gate keeps the per-lane path for the mask-vs-scalar case where it belongs. The test pins the uniform support for both wave widths and both senses (eq/lg).
cloph-dsp commented 2026-11-25 15:04:26 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-25T14:49:24Z.


Independent local validation (Windows, Rust 1.100.0/MSVC, head 11ce139, no game data): cargo test --locked -p victory-shader --lib -> 248 passed, 0 failed, 3 ignored, exit 0; git diff --check HEAD~1 HEAD clean. The lib test count matches upstream main, so this is a compile/regression check only; I did not independently replay the synthetic s_cmp lane-mask scenario. AI-assisted (Hy4 flash). GPU/driver: N/A for the CPU test run. No game data, assets or extracted content used.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7165869973 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2453#issuecomment-7165869973). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-25T14:49:24Z. --- Independent local validation (Windows, Rust 1.100.0/MSVC, head 11ce139, no game data): `cargo test --locked -p victory-shader --lib` -> 248 passed, 0 failed, 3 ignored, exit 0; `git diff --check HEAD~1 HEAD` clean. The lib test count matches upstream main, so this is a compile/regression check only; I did not independently replay the synthetic s_cmp lane-mask scenario. AI-assisted (Hy4 flash). GPU/driver: N/A for the CPU test run. No game data, assets or extracted content used.
Marvisak commented 2026-11-25 16:09:33 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T15:57:52Z.


Automated triage for the maintainers.

Merge candidate. In crates/victory-shader/src/structure.rs Lanes::step, s_cmp_eq/lg_u32/u64 of two tracked lane masks no longer gets a per-lane XNOR/XOR in scc_lane, so branch falls back to the uniform SCC atom; that matches the ISA (the scalar compare sets one SCC for the wave), whereas the per-lane form let lanes that agree locally take a branch the wave does not. I checked the test's encodings (v_cmp_eq_u32, s_cmp_eq/lg_u32/u64 vcc, exec, s_cbranch_scc1). One observation for later, outside this PR: a mask compared with a constant (e.g. s_cmp_eq_u64 vcc, 0) still takes the per-lane path. CI: passing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7167469753 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2453#issuecomment-7167469753). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T15:57:52Z. --- <!-- victory-triage v1 head=11ce139b88706a2d6ae4f35e8472913c406d250e verdict=merge-candidate at=2026-11-25T15:57:43Z --> Automated triage for the maintainers. Merge candidate. In `crates/victory-shader/src/structure.rs` `Lanes::step`, `s_cmp_eq/lg_u32/u64` of two tracked lane masks no longer gets a per-lane XNOR/XOR in `scc_lane`, so `branch` falls back to the uniform SCC atom; that matches the ISA (the scalar compare sets one SCC for the wave), whereas the per-lane form let lanes that agree locally take a branch the wave does not. I checked the test's encodings (`v_cmp_eq_u32`, `s_cmp_eq/lg_u32/u64 vcc, exec`, `s_cbranch_scc1`). One observation for later, outside this PR: a mask compared with a constant (e.g. `s_cmp_eq_u64 vcc, 0`) still takes the per-lane path. CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
upstream-sync closed this pull request 2026-11-25 23:04:34 +00:00
Marvisak commented 2026-11-25 23:06:00 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T22:09:59Z.


Automated triage for the maintainers, second look (a review against current main, with builds and tests where they could change the verdict).

Closing because it reverses a documented design rule without a case where the rule gives a wrong result, and it breaks mesh programs. structure.rs turns a branch on a wave-wide mask test into a branch on the lane's own bit on purpose. With this change the uniform SCC has to be computed from a mask read as a number, which mesh programs cannot do: a small mesh program (v_cmp_eq_u32 vcc, 0, v2; s_cmp_eq_u32 vcc_lo, exec_lo; s_cbranch_scc1) emits on main and is refused with "a lane mask read as data" with this PR.

If this is mistaken, reply here with what was missed and it will be looked at again. Thank you for the contribution.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7176019269 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2453#issuecomment-7176019269). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T22:09:59Z. --- Automated triage for the maintainers, second look (a review against current `main`, with builds and tests where they could change the verdict). Closing because it reverses a documented design rule without a case where the rule gives a wrong result, and it breaks mesh programs. `structure.rs` turns a branch on a wave-wide mask test into a branch on the lane's own bit on purpose. With this change the uniform SCC has to be computed from a mask read as a number, which mesh programs cannot do: a small mesh program (`v_cmp_eq_u32 vcc, 0, v2; s_cmp_eq_u32 vcc_lo, exec_lo; s_cbranch_scc1`) emits on `main` and is refused with "a lane mask read as data" with this PR. If this is mistaken, reply here with what was missed and it will be looked at again. Thank you for the contribution.

Pull request closed

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
Marvisak/VIctory!2451
No description provided.