Shaders: keep s_cmp of two lane masks uniform #2453

Closed
github-bot wants to merge 1 commit from gh-pr/2453/head into gh-pr/2453/base
Owner

@⁠makmatvey on GitHub · 2026-11-25 13:49 UTC · original
makmatvey:cursor/shader-lane-mask-cmp-uniform-9e1d → main · +32 −2 · 1 files · 1 commits · closed without merging

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.

**@⁠makmatvey** on GitHub · 2026-11-25 13:49 UTC · [original](https://github.com/Marvisak/VIctory/pull/2453) `makmatvey:cursor/shader-lane-mask-cmp-uniform-9e1d` → `main` · +32 −2 · 1 files · 1 commits · closed without merging ## 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.
s_cmp_eq/lg of two tracked lane masks sets a wave-wide SCC on the
console. Structuring used a per-lane XNOR/XOR, so s_cbranch_scc*
diverged when only some lanes agreed. Leave SCC uniform when both
operands are masks; lowering already compares their ballots as scalars.

VIC-BT-006 in #1242. Focused re-land of stalled #1412.

Co-authored-by: Matsvey Makushenka <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:06:22 +00:00
github-bot closed this pull request 2026-11-26 05:06:22 +00:00
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 14:25 UTC · original

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

**@⁠kotekompotek** on GitHub · 2026-11-25 14:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/2453#issuecomment-7165250900) 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).
Author
Owner

@⁠cloph-dsp on GitHub · 2026-11-25 14:49 UTC · original

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.

**@⁠cloph-dsp** on GitHub · 2026-11-25 14:49 UTC · [original](https://github.com/Marvisak/VIctory/pull/2453#issuecomment-7165869973) 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.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 15:57 UTC · original

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

**@⁠Marvisak** on GitHub · 2026-11-25 15:57 UTC · [original](https://github.com/Marvisak/VIctory/pull/2453#issuecomment-7167469753) <!-- 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)_
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 22:09 UTC · original

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.

**@⁠Marvisak** on GitHub · 2026-11-25 22:09 UTC · [original](https://github.com/Marvisak/VIctory/pull/2453#issuecomment-7176019269) 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

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!2453
No description provided.