Shaders: a select on a lane mask held as a number keeps the console's lanes (release lowered it without them; debug hit the cross_lane assertion) #308

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

@⁠compaccount1-coder on GitHub · 2026-11-26 15:20 UTC · original
compaccount1-coder:fix/select-on-numeric-mask → main · +33 −0 · 2 files · 1 commits · open

What and why

v_cndmask_b32 on a lane mask the code holds as a number (not one structure tracks as lanes: a constant bit pattern, or one loaded from memory) is lowered to the lane's own bit of that number (lane_bit, lower.rs ~9279). That bit is the console's only where host lanes are the console's, which is what console_lanes is for.

The check that sets console_lanes looks for the cross-lane instructions, masks read as data (reads_mask_as_data, which skips v_cndmask_b32 on purpose), guards on constant masks (lane_constant_masks, whose comment says masks only selects read are not followed) and wave-wide branches. A select on a numeric mask is in none of them, so a compute program whose only cross-lane code is such a select was lowered without console lanes:

  • release builds (what play.ps1 runs; diag inherits release): no WaveSize and no relabelling, so each lane took the bit of whatever host lane it landed in;
  • debug builds: debug_assert!(self.s.threads.is_none() || self.console_lanes) in cross_lane fires. The assertion states exactly the invariant that was missed.

The change

selects_on_mask_data(st, i) (a v_cndmask_b32 whose mask operand reads a value that is not in st.masks, the same lookup the lowering does) now counts for console_lanes, beside reads_mask_as_data. About 15 lines. The other two numeric-mask paths (Atom::Opaque/Atom::Constant in boolean) were already guarded by if self.console_lanes, and carry-ins refuse untracked masks, so this select was the only gap.

Tested

  • New wave64_tests::a_select_on_a_mask_held_as_a_number_keeps_the_consoles_lanes: an every-other-lane select (s_mov_b32 vcc_lo, 0x55555555; v_cndmask_b32) in a wave32 program of 64 threads.
    • main, debug: the assertion in cross_lane fires.
    • main, --release: wave_size is None.
    • this branch: Some(32), in both.
  • cargo test -p victory-shader: everything else passes as before. The only failures are the three validator tests that need a newer Windows SDK's dxil.dll than this PC has (10.0.22621), the same as without this change. Clippy is clean, and rustfmt reports nothing new.
  • How it was found: random GFX10 programs (test-program words with bits flipped) through spill::build → structure → resource::track → io::raise → emit::emit. 500,000 programs, about 54,000 emitted; this was the one panic, found from a load into s[103:106] (VCC) followed by a select on VCC.

Not run: the title's own shaders, since I have no game files. I have not seen a title shader with only this kind of select. The change can only turn console_lanes on for compute programs that contain one, so a shader census before and after (victory shaders) would show whether any title program changes.

AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

**@⁠compaccount1-coder** on GitHub · 2026-11-26 15:20 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/308) `compaccount1-coder:fix/select-on-numeric-mask` → `main` · +33 −0 · 2 files · 1 commits · open ### What and why `v_cndmask_b32` on a lane mask the code holds as a number (not one `structure` tracks as lanes: a constant bit pattern, or one loaded from memory) is lowered to the lane's own bit of that number (`lane_bit`, `lower.rs` ~9279). That bit is the console's only where host lanes are the console's, which is what `console_lanes` is for. The check that sets `console_lanes` looks for the cross-lane instructions, masks read as data (`reads_mask_as_data`, which skips `v_cndmask_b32` on purpose), guards on constant masks (`lane_constant_masks`, whose comment says masks only selects read are not followed) and wave-wide branches. A select on a numeric mask is in none of them, so a compute program whose only cross-lane code is such a select was lowered without console lanes: - **release builds** (what `play.ps1` runs; `diag` inherits `release`): no `WaveSize` and no relabelling, so each lane took the bit of whatever host lane it landed in; - **debug builds**: `debug_assert!(self.s.threads.is_none() || self.console_lanes)` in `cross_lane` fires. The assertion states exactly the invariant that was missed. ### The change `selects_on_mask_data(st, i)` (a `v_cndmask_b32` whose mask operand reads a value that is not in `st.masks`, the same lookup the lowering does) now counts for `console_lanes`, beside `reads_mask_as_data`. About 15 lines. The other two numeric-mask paths (`Atom::Opaque`/`Atom::Constant` in `boolean`) were already guarded by `if self.console_lanes`, and carry-ins refuse untracked masks, so this select was the only gap. ### Tested - New `wave64_tests::a_select_on_a_mask_held_as_a_number_keeps_the_consoles_lanes`: an every-other-lane select (`s_mov_b32 vcc_lo, 0x55555555`; `v_cndmask_b32`) in a wave32 program of 64 threads. - main, debug: the assertion in `cross_lane` fires. - main, `--release`: `wave_size` is `None`. - this branch: `Some(32)`, in both. - `cargo test -p victory-shader`: everything else passes as before. The only failures are the three validator tests that need a newer Windows SDK's `dxil.dll` than this PC has (10.0.22621), the same as without this change. Clippy is clean, and rustfmt reports nothing new. - How it was found: random GFX10 programs (test-program words with bits flipped) through `spill::build` → `structure` → `resource::track` → `io::raise` → `emit::emit`. 500,000 programs, about 54,000 emitted; this was the one panic, found from a load into s[103:106] (VCC) followed by a select on VCC. **Not run:** the title's own shaders, since I have no game files. I have not seen a title shader with only this kind of select. The change can only turn `console_lanes` on for compute programs that contain one, so a shader census before and after (`victory shaders`) would show whether any title program changes. AI-assisted: yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
`v_cndmask_b32` on a mask the code holds as a number (not one it tracks as
lanes: a constant bit pattern, one loaded from memory) is lowered to the
lane's own bit of it (`lane_bit`), which is the console's bit only with the
console's lanes. The check that decides `console_lanes` looked for masks read
as data, guards on constant masks and the cross-lane instructions, but not
for such a select, so a compute program whose only cross-lane code is one was
lowered without them:

- release builds: no wave size and no relabelling, so each lane took the bit
  of whatever host lane it landed in;
- debug builds: `debug_assert!(self.s.threads.is_none() || self.console_lanes)`
  in `cross_lane` fired.

`selects_on_mask_data` now counts for `console_lanes`, beside
`reads_mask_as_data`. Found by feeding random GFX10 programs through the
whole translator; the new test is the smallest form of it (an every-other-
lane select in a wave32 program of 64 threads): `wave_size` None before,
Some(32) now.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 15:20:46 +00:00
Author
Owner

@⁠illuminatedfellow on GitHub · 2026-11-26 16:48 UTC · original

Independent confirmation: fuzzing the translator on Linux (mutated test programs and random words through ir::build → structure → resource::track → io::raise → lower, debug assertions on) hit debug_assert!(self.s.threads.is_none() || self.console_lanes) in cross_lane from the v_cndmask_b32 numeric-mask path (lower.rs ~9278) 18 times in 800,000 programs. With this PR's lower.rs change applied to c9c932c, all five cases I replayed lower without hitting it.

(Written with Claude Opus 5.5.)

**@⁠illuminatedfellow** on GitHub · 2026-11-26 16:48 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/308#issuecomment-7198114461) Independent confirmation: fuzzing the translator on Linux (mutated test programs and random words through `ir::build` → `structure` → `resource::track` → `io::raise` → `lower`, debug assertions on) hit `debug_assert!(self.s.threads.is_none() || self.console_lanes)` in `cross_lane` from the `v_cndmask_b32` numeric-mask path (`lower.rs` ~9278) 18 times in 800,000 programs. With this PR's `lower.rs` change applied to c9c932c, all five cases I replayed lower without hitting it. (Written with Claude Opus 5.5.)
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/308/head:github-bot/gh-308'
git switch 'github-bot/gh-308'

Merge

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