Shaders: SCC of a lane mask operation counts the console's bits outside a partial group (on #3917) #4400

Open
github-bot wants to merge 3 commits from github-bot/gh-4399 into main AGit
Owner

@⁠tyr0nsur on GitHub · 2026-11-30 19:50 UTC · original
tyr0nsur:claude/scc-of-mask-outside-group → main · +563 −23 · 2 files · 3 commits · draft

Depends on #3917. Refs #3916. The current head layers the SCC and wave32 follow-ups on the mask lowering from #3917. dyshay is retained as author of the base mask commit.

What it changes

The second part of #3916 that #3917 left open (scc_some, offered in #3916 by @⁠dyshay). SCC of a scalar mask operation read as data was the host lanes' waveAnyTrue, ANDed with the dispatch's active lanes. On the console, SCC is whether any of the 64 bits is set, and the complement of a compare holds the bits of the lanes that are not in the group. With every lane of a group of 96 passing the compare, s_not_b64 of it sets SCC in the second console wave (its lanes 32..63 are outside the group), and the translation gave 0.

  • scc_some takes those lanes' bits as mask_dword does since #3917. A lane past the dispatched count takes its bit from outside_pair. The lanes past the group's end, which no host lane asks for, are ORed in after the halves exchange (fill_outside_lanes on a zero ballot).
  • scc_mask: the mask followed is the one the SCC-writing instruction writes (its lowest scalar destination, or EXEC for a _saveexec_b64). Where outside_pair cannot follow it (a join, a load, an instruction with no scalar destination), the answer is as before.
  • outside_lane_bit: the per-lane selection mask_dword had inline, now shared by both.
  • outside_dword (from #3917) now follows _b32 operations as well as _b64 ones (684da387). Without that, a wave32 console's mask gave up and kept the host's zeros: in a group of 48, s_bcnt1_i32_b32 of the complement of a compare counted 16 where the console counts 32. A _b32 operation works on its dword as a _b64 one does on each of its two. scc_mask takes EXEC for a _saveexec_b32 as well.
  • The folded path is not touched. A mask that reaches the operation through a join (phi) is still not followed and keeps the old answer.

How it was tested

  • Current head 28699f6e, based on 7d93ee07, has the exact tree of the rebase that passed all 52 selected cases in cargo test --locked -p victory-shader --lib -- emit::folded_tests mask on Windows with an RTX 4060. Previous results below refer to the earlier stack.

  • GPU: RTX 4060 8 GB, driver 621.14, Windows 11 26300. Wave sizes: console wave64 on 32-lane host waves (TEST_HOST_WAVE 32), default switches (folding off).

  • New test the_scc_of_a_mask_complement_counts_the_lanes_outside_the_group_by_default: the program of #3917's test, with s_cselect_b32 reading the SCC of s_not_b64 vcc and of s_andn2_b64 exec, vcc, for s0 in 0, 20, 70 and 96.

    • Before: lane 64, SCC of the complement, 0 where the console has 1 (s0 = 96).
    • After: every lane matches the console. The SCC of exec andn2 vcc (no bit outside the group) stays 0 there.
  • More tests: a_wave32_mask_complement_counts_the_lanes_outside_the_group_by_default (wave32, group of 48, SCC and s_bcnt1_i32_b32 of s_not_b32 vcc_lo; failed with 16 for 32 before 684da387), and the_scc_of_a_saveexec_counts_the_lanes_outside_the_group_by_default (SCC of s_nand_saveexec_b64, EXEC put back before the stores).

  • WARP refuses this program at pipeline creation, as it does #3917's test, so the test runs on hardware only and returns early without a device.

  • cargo test -p victory-shader --locked --lib: 466 passed, 0 failed.

  • cargo clippy -p victory-shader --all-targets on this base (41adb551, #3917's) reports only findings in lower/analysis.rs and native.rs that this does not touch.

A second review by GPT-6.2 raised the _b32 gap and the extra tests; I checked each point against the code and the tests above.

  • Windows CI: the check job failed the victory-loader CLZERO free-memory test. The assertion is reproducible when the fixture's released address is reoccupied. The separate test fix and reproducer are in #4633.

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related: #3916, #3917.

🤖 Generated with Claude Code

**@⁠tyr0nsur** on GitHub · 2026-11-30 19:50 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4399) `tyr0nsur:claude/scc-of-mask-outside-group` → `main` · +563 −23 · 2 files · 3 commits · draft Depends on #3917. Refs #3916. The current head layers the SCC and wave32 follow-ups on the mask lowering from #3917. dyshay is retained as author of the base mask commit. ## What it changes The second part of #3916 that #3917 left open (`scc_some`, offered in #3916 by @⁠dyshay). SCC of a scalar mask operation read as data was the host lanes' `waveAnyTrue`, ANDed with the dispatch's active lanes. On the console, SCC is whether any of the 64 bits is set, and the complement of a compare holds the bits of the lanes that are not in the group. With every lane of a group of 96 passing the compare, `s_not_b64` of it sets SCC in the second console wave (its lanes 32..63 are outside the group), and the translation gave 0. - `scc_some` takes those lanes' bits as `mask_dword` does since #3917. A lane past the dispatched count takes its bit from `outside_pair`. The lanes past the group's end, which no host lane asks for, are ORed in after the halves exchange (`fill_outside_lanes` on a zero ballot). - `scc_mask`: the mask followed is the one the SCC-writing instruction writes (its lowest scalar destination, or EXEC for a `_saveexec_b64`). Where `outside_pair` cannot follow it (a join, a load, an instruction with no scalar destination), the answer is as before. - `outside_lane_bit`: the per-lane selection `mask_dword` had inline, now shared by both. - `outside_dword` (from #3917) now follows `_b32` operations as well as `_b64` ones (684da387). Without that, a wave32 console's mask gave up and kept the host's zeros: in a group of 48, `s_bcnt1_i32_b32` of the complement of a compare counted 16 where the console counts 32. A `_b32` operation works on its dword as a `_b64` one does on each of its two. `scc_mask` takes EXEC for a `_saveexec_b32` as well. - The folded path is not touched. A mask that reaches the operation through a join (phi) is still not followed and keeps the old answer. ## How it was tested - Current head `28699f6e`, based on `7d93ee07`, has the exact tree of the rebase that passed all 52 selected cases in `cargo test --locked -p victory-shader --lib -- emit::folded_tests mask` on Windows with an RTX 4060. Previous results below refer to the earlier stack. - GPU: RTX 4060 8 GB, driver 621.14, Windows 11 26300. Wave sizes: console wave64 on 32-lane host waves (`TEST_HOST_WAVE` 32), default switches (folding off). - New test `the_scc_of_a_mask_complement_counts_the_lanes_outside_the_group_by_default`: the program of #3917's test, with `s_cselect_b32` reading the SCC of `s_not_b64 vcc` and of `s_andn2_b64 exec, vcc`, for `s0` in 0, 20, 70 and 96. - Before: lane 64, SCC of the complement, 0 where the console has 1 (`s0` = 96). - After: every lane matches the console. The SCC of `exec andn2 vcc` (no bit outside the group) stays 0 there. - More tests: `a_wave32_mask_complement_counts_the_lanes_outside_the_group_by_default` (wave32, group of 48, SCC and `s_bcnt1_i32_b32` of `s_not_b32 vcc_lo`; failed with 16 for 32 before 684da387), and `the_scc_of_a_saveexec_counts_the_lanes_outside_the_group_by_default` (SCC of `s_nand_saveexec_b64`, EXEC put back before the stores). - WARP refuses this program at pipeline creation, as it does #3917's test, so the test runs on hardware only and returns early without a device. - `cargo test -p victory-shader --locked --lib`: 466 passed, 0 failed. - `cargo clippy -p victory-shader --all-targets` on this base (41adb551, #3917's) reports only findings in `lower/analysis.rs` and `native.rs` that this does not touch. A second review by GPT-6.2 raised the `_b32` gap and the extra tests; I checked each point against the code and the tests above. - Windows CI: the [check job](https://github.com/trustno1-coder/VIctory-NVIDIA/actions/runs/46540897894/job/142278968283) failed the `victory-loader` CLZERO free-memory test. The assertion is reproducible when the fixture's released address is reoccupied. The separate test fix and reproducer are in #4633. ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: #3916, #3917. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
On a 32-lane host the plain wave64 lowering (the default since folding is
off, 5c262d7b) reads a lane mask as a number by a ballot of the lanes'
booleans. In a group that is not a multiple of 64 threads (96: the second
console wave has lanes 0..31 only), the lanes that do not exist had no
bit, whatever the mask. On the console the SGPR pair holds all 64 bits:
those lanes are outside EXEC, a compare writes 0 there and s_not_b64 sets
them, so s_bcnt1_i32_b64 of the complement of a compare is 64 for s0 = 0
in wave 1, not 32. The structure takes EXEC on entry as every lane, so
the complement and s_andn2_b64 exec, vcc (0 there) are the same lane
boolean to it.

- outside_pair: the mask's two dwords in the lanes not in the group
  (partial console wave, or past the dispatched count), followed back
  through EXEC on entry and compare/carry masks (0), s_mov/not/and/or/
  xor/andn2/orn2/nand/nor/xnor/cselect and the saveexec forms, constants.
  A join or a load keeps the host's ballot (0 there), as before. Folded
  programs and local waves unchanged.
- mask_dword: lanes past the count take their bit from it before the
  ballot; the console lanes past the group take theirs after the exchange.
- exchange_halves: a console wave with no upper host wave reads 0 for
  that half (its LDS dword was never written).

Test: folded_tests::a_mask_complement_counts_the_lanes_outside_the_group_by_default
(emit() with default switches, 32-lane host, group of 96; also tries WARP,
which refuses WaveSize(32) here): fails before (lane 64: 32 vs 64), passes
on the card after.

Found while testing the fold default; ISA semantics from AMD RDNA2.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01PVi6XmTj4ohPL7QwUeFgV4
The second part #3916 left open (scc_some): SCC of a scalar mask
operation read as data was the host lanes' waveAnyTrue, ANDed with the
dispatch's active lanes. On the console SCC is whether any of the 64 bits
is set, and the complement of a compare holds the bits of the lanes that
are not in the group (a group of 96: the second console wave's lanes
32..63). With every lane of such a group passing the compare, s_not_b64
of it set SCC on the console and not here.

scc_some now takes those lanes' bits as mask_dword does since #3917: a
lane past the dispatched count takes its bit from outside_pair, and the
lanes past the group's end, which no host lane asks for, are ORed in
after the halves exchange (fill_outside_lanes). The mask followed is the
one the SCC-writing instruction writes (EXEC for a saveexec). A mask
outside_pair cannot follow keeps the old answer. The lane-bit selection
of mask_dword moves into outside_lane_bit, shared by both.

Built on #3917.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 19:51:44 +00:00
Author
Owner

@⁠babuakhil on GitHub · 2026-11-30 20:02 UTC · original

Ran this on NVIDIA as well: Windows 11, RTX 3060, driver 621.40, Rust 1.98.1 (pinned). The branch doesn't cherry-pick onto current main (e1251c31): both commits stop in lower.rs and folded_tests.rs, as does #3917 itself. So I tested it where it stands, the base 41adb551, #3917 alone (7161b62c), and this PR (48f55964), which isolates the last commit.

The fix does what it says on hardware. the_scc_of_a_mask_complement_counts_the_lanes_outside_the_group_by_default passes on the 3060 with this PR. With only lower.rs put back to #3917's version (test unchanged), it fails on exactly the case described:

lane 64, SCC of the complement
  left: 0
 right: 1

No regressions in the GPU test files around it:

base 41adb551 #3917 this PR
emit::folded_tests 17 passed 18 passed 19 passed
emit::wave64_tests 44 passed 44 passed 44 passed

Clippy on victory-shader reports the same findings with and without the last commit (two in lower/analysis.rs, one in lower.rs, one in native.rs, all from the base), so it adds none.

It will need rebasing onto current main together with #3917 before it can go in, and I haven't run it there.

**@⁠babuakhil** on GitHub · 2026-11-30 20:02 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4399#issuecomment-7290305024) Ran this on NVIDIA as well: Windows 11, RTX 3060, driver 621.40, Rust 1.98.1 (pinned). The branch doesn't cherry-pick onto current `main` (`e1251c31`): both commits stop in `lower.rs` and `folded_tests.rs`, as does #3917 itself. So I tested it where it stands, the base `41adb551`, #3917 alone (`7161b62c`), and this PR (`48f55964`), which isolates the last commit. **The fix does what it says on hardware.** `the_scc_of_a_mask_complement_counts_the_lanes_outside_the_group_by_default` passes on the 3060 with this PR. With only `lower.rs` put back to #3917's version (test unchanged), it fails on exactly the case described: ``` lane 64, SCC of the complement left: 0 right: 1 ``` **No regressions** in the GPU test files around it: | | base `41adb551` | #3917 | this PR | |---|---|---|---| | `emit::folded_tests` | 17 passed | 18 passed | 19 passed | | `emit::wave64_tests` | 44 passed | 44 passed | 44 passed | Clippy on `victory-shader` reports the same findings with and without the last commit (two in `lower/analysis.rs`, one in `lower.rs`, one in `native.rs`, all from the base), so it adds none. It will need rebasing onto current `main` together with #3917 before it can go in, and I haven't run it there.
outside_dword followed only the _b64 operations, so a wave32 console's
mask (s_not_b32 vcc_lo, s_and_saveexec_b32, ...) gave up and kept the
host's zeros: in a group of 48, s_bcnt1_i32_b32 of the complement of a
compare counted 16 where the console counts 32, and its SCC was 0 where
every lane of the group passed. A _b32 operation works on its dword as a
_b64 one on each of its two, so both are now followed; scc_mask takes
EXEC for a _saveexec_b32 as for a _saveexec_b64.

Tests: the wave32 group of 48, and the SCC of s_nand_saveexec_b64 in a
group of 96 (with EXEC put back before the stores). Found in a review by
GPT-6.2.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Owner

@⁠VibeCodeGuy on GitHub · 2026-11-30 23:33 UTC · original

Offline corpus check (every shader container in a v1.0.2.1 dump: 25,699 unique programs). This PR at 684da387 against its merge-base with main, 41adb551. It is stacked on #3917 and does not merge cleanly onto main e1251c31.

  • Newly failing: 0. Newly passing: 0. DXIL output changed: 6 compute programs, all validate.
  • These are the same 6 programs #3917 changes (its comment). Against #3917's head (628f25de), this PR's own two commits (48f55964, 684da387) change no program in this title at 32 lanes. In this title, the SCC and wave32-console cases they handle don't seem to come up beyond what #3917 already covers.

How: victory translate <dump> --validate --list, cross-built with cargo-xwin and run under Wine, VICTORY_HOST_WAVE=32 plus play's shader-cache-key settings (VICTORY_EARLY_DEPTH=1, VICTORY_NAN_SCRUB=1, VICTORY_BVH_MISS=1, VICTORY_SAMPLED_MARKS=1), dxil.dll from DXC v1.9.2609. No GPU on this side: nothing was run on a card.

**@⁠VibeCodeGuy** on GitHub · 2026-11-30 23:33 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4399#issuecomment-7295251643) **Offline corpus check** (every shader container in a v1.0.2.1 dump: 25,699 unique programs). This PR at 684da387 against its merge-base with `main`, 41adb551. It is stacked on #3917 and does not merge cleanly onto `main` e1251c31. - Newly failing: **0**. Newly passing: **0**. DXIL output changed: **6** compute programs, all validate. - These are the same 6 programs #3917 changes ([its comment](https://git.gtahub.st/github/trustno1-coder--VIctory-NVIDIA/pulls/3917)). Against #3917's head (628f25de), this PR's own two commits (48f55964, 684da387) change **no** program in this title at 32 lanes. In this title, the SCC and wave32-console cases they handle don't seem to come up beyond what #3917 already covers. How: `victory translate <dump> --validate --list`, cross-built with cargo-xwin and run under Wine, `VICTORY_HOST_WAVE=32` plus `play`'s shader-cache-key settings (`VICTORY_EARLY_DEPTH=1`, `VICTORY_NAN_SCRUB=1`, `VICTORY_BVH_MISS=1`, `VICTORY_SAMPLED_MARKS=1`), `dxil.dll` from DXC v1.9.2609. No GPU on this side: nothing was run on a card.
Author
Owner

@⁠tyr0nsur on GitHub · 2026-11-30 23:45 UTC · original · edited 2026-11-30 23:59 UTC

Thanks for the independent corpus and hardware checks. Claude and I prepared a combined head on current main (7d93ee07) that resolves the conflicts in lower.rs and folded_tests.rs: 28699f6e, branch codex/wave32-scc-current. It includes #3917's mask lowering, the SCC follow-up here, and the wave32 regression kept in #3917. The original author is retained on the base mask commit.

cargo test --locked -p victory-shader --lib -- emit::folded_tests mask passed all 52 selected cases on Windows, including the two SCC cases and the wave32 popcount. The corpus results above are for the previous heads. The branch is available for a matched corpus check or as a source for the upstream rebase.

**@⁠tyr0nsur** on GitHub · 2026-11-30 23:45 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4399#issuecomment-7295484084) · edited 2026-11-30 23:59 UTC Thanks for the independent corpus and hardware checks. Claude and I prepared a combined head on current `main` (`7d93ee07`) that resolves the conflicts in `lower.rs` and `folded_tests.rs`: [28699f6e](https://github.com/tyr0nsur/VIctory-NVIDIA/commit/28699f6eb10949982b8f5d35213f188906a3387e), branch `codex/wave32-scc-current`. It includes #3917's mask lowering, the SCC follow-up here, and the wave32 regression kept in #3917. The original author is retained on the base mask commit. `cargo test --locked -p victory-shader --lib -- emit::folded_tests mask` passed all 52 selected cases on Windows, including the two SCC cases and the wave32 popcount. The corpus results above are for the previous heads. The branch is available for a matched corpus check or as a source for the upstream rebase.
github-bot force-pushed github-bot/gh-4399 from 684da38785 to 28699f6eb1 2026-12-01 00:05:14 +00:00 Compare
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/4400/head:github-bot/gh-4399'
git switch 'github-bot/gh-4399'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-4399'
git switch 'github-bot/gh-4399'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-4399'
git switch 'github-bot/gh-4399'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-4399'
git switch 'main'
git merge --squash 'github-bot/gh-4399'
git switch 'main'
git merge --ff-only 'github-bot/gh-4399'
git switch 'main'
git merge 'github-bot/gh-4399'
git push origin 'main'
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/trustno1-coder--VIctory-NVIDIA!4400
No description provided.