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
compaccount1-coder wants to merge 1 commit from upstream-pr/308 into main
compaccount1-coder commented 2026-11-26 15:20:22 +00:00 (Migrated from github.com)

Imported from avatarmanz/VIctory-7900XTX. Originally posted by compaccount1-coder on 2026-11-26T15:20:22Z.


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

<!-- greyfinch-sync:avatarmanz/VIctory-7900XTX:issue:6629771106 --> Imported from [avatarmanz/VIctory-7900XTX](https://github.com/avatarmanz/VIctory-7900XTX/pull/308). Originally posted by [compaccount1-coder](https://github.com/compaccount1-coder) on 2026-11-26T15:20:22Z. --- ### 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)
illuminatedfellow commented 2026-11-26 16:48:12 +00:00 (Migrated from github.com)

Imported from avatarmanz/VIctory-7900XTX. Originally posted by illuminatedfellow on 2026-11-26T16:48:12Z.


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

<!-- greyfinch-sync:avatarmanz/VIctory-7900XTX:comment:7198114461 --> Imported from [avatarmanz/VIctory-7900XTX](https://github.com/avatarmanz/VIctory-7900XTX/pull/308#issuecomment-7198114461). Originally posted by [illuminatedfellow](https://github.com/illuminatedfellow) on 2026-11-26T16:48:12Z. --- 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 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/308:upstream-pr/308'
git switch 'upstream-pr/308'

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/308'
git switch 'upstream-pr/308'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/308'
git switch 'upstream-pr/308'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/308'
git switch 'main'
git merge --squash 'upstream-pr/308'
git switch 'main'
git merge --ff-only 'upstream-pr/308'
git switch 'main'
git merge 'upstream-pr/308'
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
avatarmanz/VIctory-7900XTX!308
No description provided.