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

Open
github-bot wants to merge 1 commit from github-bot/gh-788 into main AGit
Owner

@⁠AscilCH on GitHub · 2026-11-25 07:35 UTC · original
AscilCH:fix/shader-structure-sbcnt1-exec-and-wave-width → main · +95 −4 · 1 files · 1 commits · open

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

**@⁠AscilCH** on GitHub · 2026-11-25 07:35 UTC · [original](https://github.com/fxceless/victory-fork/pull/788) `AscilCH:fix/shader-structure-sbcnt1-exec-and-wave-width` → `main` · +95 −4 · 1 files · 1 commits · open ## 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.)*
Fix two bugs in `Lanes::step()` for `s_bcnt1_i32_b*` (`crates/victory-shader/src/structure.rs`):

1. `self.scc_lane.insert(scc, own)` stored `own = b.given(m, e)` instead of `m`.
   When `EXEC` was narrowed inside the block (e.g. `s_and_saveexec_b32 s0, vcc_lo`
   followed by `s_bcnt1_i32_b32 s1, exec_lo`), `given(Lane(vcc), Lane(vcc))`
   collapsed to `Bool::TRUE`, erasing `EXEC` completely. That caused `s_cbranch_scc0`
   to lower to `when = Bool::FALSE` (dead skip branch / unguarded execution even
   when `EXEC == 0`) and caused `Structured::scc_some[scc]` to evaluate to constant
   `true` instead of `waveAnyTrue(Lane(vcc))`. Storing `m` directly preserves
   narrowed `EXEC` for both exits and `scc_some`, while `finish()` still simplifies
   `b.given(when, cond[b])` to a ballot-free uniform condition whenever `EXEC`
   matches block reach.

2. `name.starts_with("s_bcnt1_i32_b")` matched `s_bcnt1_i32_b64` in wave32
   (missing the high dword) and `s_bcnt1_i32_b32` in wave64 (counting only lanes
   0..31 while `operand()` read the 64-bit pair). Require the width suffix to match
   the shader's wave width (`name.strip_prefix("s_bcnt1_i32_b") == Some(width)`),
   matching `s_cmp_eq/lg_u{32,64}` directly above.

Add unit tests covering narrowed-EXEC `s_bcnt1_i32_b32` branch/scc_some tracking
and mismatched-width `s_bcnt1_i32_b{32,64}` rejection in wave32 and wave64.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:51:10 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

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

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-788'
git switch 'github-bot/gh-788'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-788'
git switch 'github-bot/gh-788'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-788'
git switch 'main'
git merge --squash 'github-bot/gh-788'
git switch 'main'
git merge --ff-only 'github-bot/gh-788'
git switch 'main'
git merge 'github-bot/gh-788'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.