Shaders/structure: preserve EXEC in s_bcnt1_i32_b* SCC tracking and require matching wave width #788

Open
AscilCH wants to merge 1 commit from upstream-pr/788 into main
AscilCH commented 2026-11-25 07:35:36 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by AscilCH on 2026-11-25T07:35:36Z.


Summary

Fix two s_bcnt1_i32_b* SCC tracking bugs in crates/victory-shader/src/structure.rs (Lanes::step):

  1. Preserving narrowed EXEC in scc_lane (exits and scc_some).

    • Lanes::step() previously inserted own = self.b.given(m, e) into self.scc_lane instead of m. When EXEC was narrowed inside the block (for example v_cmp_eq_u32 vcc, 0, v0; s_and_saveexec_b32 s0, vcc_lo; s_bcnt1_i32_b32 s1, exec_lo), given(Lane(vcc), Lane(vcc)) collapsed to Bool::TRUE, erasing EXEC.
    • As a result, a subsequent s_cbranch_scc0 lowered to when = Bool::FALSE (dead skip branch / unguarded fallthrough even when EXEC == 0), and Structured::scc_some[scc] evaluated to constant true (waveAnyTrue(true)) instead of waveAnyTrue(Lane(vcc)).
    • Insert m directly (self.scc_lane.insert(scc, m)). finish() still simplifies b.given(when, cond[b]) to a ballot-free uniform condition whenever EXEC matches block reach, while preserving narrowed EXEC in both exits and scc_some.
  2. Wave-width matching for s_bcnt1_i32_b{32,64}.

    • name.starts_with("s_bcnt1_i32_b") matched s_bcnt1_i32_b64 in wave32 (ignoring the high dword) and s_bcnt1_i32_b32 in wave64 (counting only lanes 0..31 while operand() read the 64-bit pair).
    • Match the exact wave width with name.strip_prefix("s_bcnt1_i32_b") == Some(width), matching s_cmp_eq/lg_u{32,64} directly above.

Verification

  • cargo test -p victory-shader --locked -- structure::: 14 passed; 0 failed; 0 ignored (including new s_bcnt1_preserves_narrowed_exec_in_exits_and_scc_some and s_bcnt1_ignores_mismatched_wave_width).
  • cargo test -p victory-shader --locked -- emit::tests: 12 passed; 0 failed; 0 ignored.
  • cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings: 0 warnings.
  • cargo xtask policy: 171 files ok.

(AI-assisted; synthetic unit tests only, no game data.)

<!-- greyfinch-sync:fxceless/victory-fork:issue:6599578563 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/788). Originally posted by [AscilCH](https://github.com/AscilCH) on 2026-11-25T07:35:36Z. --- ## Summary Fix two `s_bcnt1_i32_b*` SCC tracking bugs in `crates/victory-shader/src/structure.rs` (`Lanes::step`): 1. **Preserving narrowed `EXEC` in `scc_lane` (`exits` and `scc_some`).** - `Lanes::step()` previously inserted `own = self.b.given(m, e)` into `self.scc_lane` instead of `m`. When `EXEC` was narrowed inside the block (for example `v_cmp_eq_u32 vcc, 0, v0; s_and_saveexec_b32 s0, vcc_lo; s_bcnt1_i32_b32 s1, exec_lo`), `given(Lane(vcc), Lane(vcc))` collapsed to `Bool::TRUE`, erasing `EXEC`. - As a result, a subsequent `s_cbranch_scc0` lowered to `when = Bool::FALSE` (dead skip branch / unguarded fallthrough even when `EXEC == 0`), and `Structured::scc_some[scc]` evaluated to constant `true` (`waveAnyTrue(true)`) instead of `waveAnyTrue(Lane(vcc))`. - Insert `m` directly (`self.scc_lane.insert(scc, m)`). `finish()` still simplifies `b.given(when, cond[b])` to a ballot-free uniform condition whenever `EXEC` matches block reach, while preserving narrowed `EXEC` in both `exits` and `scc_some`. 2. **Wave-width matching for `s_bcnt1_i32_b{32,64}`.** - `name.starts_with("s_bcnt1_i32_b")` matched `s_bcnt1_i32_b64` in wave32 (ignoring the high dword) and `s_bcnt1_i32_b32` in wave64 (counting only lanes `0..31` while `operand()` read the 64-bit pair). - Match the exact wave width with `name.strip_prefix("s_bcnt1_i32_b") == Some(width)`, matching `s_cmp_eq/lg_u{32,64}` directly above. ## Verification - `cargo test -p victory-shader --locked -- structure::`: `14 passed; 0 failed; 0 ignored` (including new `s_bcnt1_preserves_narrowed_exec_in_exits_and_scc_some` and `s_bcnt1_ignores_mismatched_wave_width`). - `cargo test -p victory-shader --locked -- emit::tests`: `12 passed; 0 failed; 0 ignored`. - `cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings`: 0 warnings. - `cargo xtask policy`: `171 files ok`. *(AI-assisted; synthetic unit tests only, no game data.)*
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/788:upstream-pr/788'
git switch 'upstream-pr/788'

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/788'
git switch 'upstream-pr/788'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/788'
git switch 'upstream-pr/788'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/788'
git switch 'main'
git merge --squash 'upstream-pr/788'
git switch 'main'
git merge --ff-only 'upstream-pr/788'
git switch 'main'
git merge 'upstream-pr/788'
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
fxceless/victory-fork!788
No description provided.