MaskData::Host: the high half of a ballot is dropped, and nothing forces the host wave to 32 #131

Open
opened 2026-11-26 03:51:26 +00:00 by github-bot · 4 comments
Owner

@⁠Luislariosss on GitHub · 2026-11-24 00:48 UTC · original

In MaskData::Host (lower.rs:226-232) a ballot is taken over the host wave, "whatever its size", and the high half of that ballot pair is dropped by the four uses that read a mask as a number. Nothing forces the host wave to be 32 lanes for a pixel or vertex shader: s.wave_size is only set on the compute path (lower.rs:382-386), so wave_size stays None and the driver picks the wave size at PSO creation.

If a driver runs one of those shaders 64-wide, the upper 32 lanes are invisible to:

  • s_bcnt1_i32_b32 (lower.rs:2549-2557) - WaveActiveCountBits over a 64-lane wave counts at most 32.
  • s_ff1_i32_b32 (same block) - a first active lane of 32 or above reports 0.
  • s_cmp_eq_u32 / s_cmp_lg_u32 (lower.rs:2322-2353) - a mask compared against another mask only compares the low halves.
  • v_mbcnt_lo_u32_b32 (lower.rs:4879-4927) - WavePrefixCountBits over a 64-lane wave stops at 32.

On my machine this does not bite: an AMD Radeon RX 9060 XT (RDNA4) on Windows 11 runs the pixel shaders wave32, so the high half is zero anyway. That is a property of the current driver's default, not of the code, which is why I am reporting it rather than sending a fix.

What I can show

A unit test on main (4926f72) that lowers a synthetic wave32 pixel program through Lower and inspects the emitted module. The program is hand-written GFX10, no game data:

0xBE80_0F7E              // s_bcnt1_i32_b32 s0, exec_lo
0xBE81_137E              // s_ff1_i32_b32 s1, exec_lo
0xD765_0002, 0x0001_007E // v_mbcnt_lo_u32_b32 v2, exec_lo, 0
0xD765_0003, 0x0001_00C1 // v_mbcnt_lo_u32_b32 v3, -1, 0
0x7E00_0200              // v_mov_b32 v0, s0
0x7E02_0201              // v_mov_b32 v1, s1
0xF800_180F, 0x0302_0100 // exp mrt0, v0, v1, v2, v3 done vm
S_ENDPGM

After ir::build(&code, false, 8) -> resource::track -> io::raise -> structure::structure -> Lower, with a #[cfg(test)] helper that counts the operands referring to a value:

assert_eq!(l.mask_data, MaskData::Host);
assert_eq!(l.s.wave_size, None);
let &(lo, hi) = l.ballots.values().next().unwrap();
assert!(l.s.m.uses_of(hi) >= 3);   // fails on main: uses_of(hi) == 0

cargo test -p victory-shader gives 61 passed; 1 failed, and the failure is that last assertion. The low half is used three times as expected.

The question

Is dropping the high half deliberate, on the grounds that a MaskData::Host ballot only has to be exact for the uses the comment lists and the driver's default is 32 lanes? If it is deliberate, the four sites may deserve a comment saying the upper half is unreachable, and I will keep the test out. If it is not, the fix looks small: share the 64-bit countbits/firstbitlow logic that s_bcnt1_i32_b64 (2363-2378) and s_ff1_i32_b64 (2379-2397) already have, and take both halves of the ballot in those four places.

I have not opened a PR because I could not measure a wrong result on this GPU with only the tools here (no game package, so no title run). The test is ready and I can send it as a draft PR if you want it.

AI-assisted.

**@⁠Luislariosss** on GitHub · 2026-11-24 00:48 UTC · [original](https://github.com/Marvisak/VIctory/issues/131) In `MaskData::Host` (`lower.rs:226-232`) a ballot is taken over the **host** wave, "whatever its size", and the high half of that ballot pair is dropped by the four uses that read a mask as a number. Nothing forces the host wave to be 32 lanes for a pixel or vertex shader: `s.wave_size` is only set on the compute path (`lower.rs:382-386`), so `wave_size` stays `None` and the driver picks the wave size at PSO creation. If a driver runs one of those shaders 64-wide, the upper 32 lanes are invisible to: - `s_bcnt1_i32_b32` (`lower.rs:2549-2557`) - `WaveActiveCountBits` over a 64-lane wave counts at most 32. - `s_ff1_i32_b32` (same block) - a first active lane of 32 or above reports 0. - `s_cmp_eq_u32` / `s_cmp_lg_u32` (`lower.rs:2322-2353`) - a mask compared against another mask only compares the low halves. - `v_mbcnt_lo_u32_b32` (`lower.rs:4879-4927`) - `WavePrefixCountBits` over a 64-lane wave stops at 32. On my machine this does not bite: an AMD Radeon RX 9060 XT (RDNA4) on Windows 11 runs the pixel shaders wave32, so the high half is zero anyway. That is a property of the current driver's default, not of the code, which is why I am reporting it rather than sending a fix. ## What I can show A unit test on `main` (`4926f72`) that lowers a synthetic wave32 pixel program through `Lower` and inspects the emitted module. The program is hand-written GFX10, no game data: ``` 0xBE80_0F7E // s_bcnt1_i32_b32 s0, exec_lo 0xBE81_137E // s_ff1_i32_b32 s1, exec_lo 0xD765_0002, 0x0001_007E // v_mbcnt_lo_u32_b32 v2, exec_lo, 0 0xD765_0003, 0x0001_00C1 // v_mbcnt_lo_u32_b32 v3, -1, 0 0x7E00_0200 // v_mov_b32 v0, s0 0x7E02_0201 // v_mov_b32 v1, s1 0xF800_180F, 0x0302_0100 // exp mrt0, v0, v1, v2, v3 done vm S_ENDPGM ``` After `ir::build(&code, false, 8)` -> `resource::track` -> `io::raise` -> `structure::structure` -> `Lower`, with a `#[cfg(test)]` helper that counts the operands referring to a value: ``` assert_eq!(l.mask_data, MaskData::Host); assert_eq!(l.s.wave_size, None); let &(lo, hi) = l.ballots.values().next().unwrap(); assert!(l.s.m.uses_of(hi) >= 3); // fails on main: uses_of(hi) == 0 ``` `cargo test -p victory-shader` gives `61 passed; 1 failed`, and the failure is that last assertion. The low half is used three times as expected. ## The question Is dropping the high half deliberate, on the grounds that a `MaskData::Host` ballot only has to be exact for the uses the comment lists and the driver's default is 32 lanes? If it is deliberate, the four sites may deserve a comment saying the upper half is unreachable, and I will keep the test out. If it is not, the fix looks small: share the 64-bit `countbits`/`firstbitlow` logic that `s_bcnt1_i32_b64` (`2363-2378`) and `s_ff1_i32_b64` (`2379-2397`) already have, and take both halves of the ballot in those four places. I have not opened a PR because I could not measure a wrong result on this GPU with only the tools here (no game package, so no title run). The test is ready and I can send it as a draft PR if you want it. AI-assisted.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:51:26 +00:00
Author
Owner

@⁠NolanCotter on GitHub · 2026-11-24 03:10 UTC · original

Claiming this (renderer-path, no overlapping claim or PR found — #320's console flow covers wave64 compute on wave32 hosts and documents mask reads there; the PS/VS MaskData::Host path is untouched).

The defect: for MaskData::Host (Ps/Vs — no WaveSize attribute, host wave size is driver-chosen), mask_dword returns the ballot's first dword for every lane mask read as a number (s_bcnt1_i32_*, s_ff1_i32_*, v_mbcnt_*, s_cmp_eq/lg_u32/u64). On a 64-lane host wave the upper 32 lanes are a second console wave whose bits land in the ballot's second dword — they get the first console wave's mask values instead of their own.

Fix plan, all in crates/victory-shader/src/emit/lower.rs:

  1. mask_dword: for MaskData::Host on a wave32 program, pick the ballot half by host lane (lane >= 32 ? y : x). No-op on 32-lane host waves.
  2. v_mbcnt_lo in that mode: count bits of the lane's own half below lane & 31.
  3. v_mbcnt_hi in that mode: a wave32 mask has no high half, so the count is src1.

Verification: synthetic wave32 pixel-program test in emit::lower's test module (mask from v_cmp, read by s_bcnt1, exported via exp) asserting the emitted DXIL takes the lane index; cargo test -p victory-shader on Linux. No game data.

Out of scope: the host-lane-vs-console-lane space for v_readlane/v_writelane computed lanes — that's the lane-space problem #225/#320 handle in the console flow, not a mask read.

**@⁠NolanCotter** on GitHub · 2026-11-24 03:10 UTC · [original](https://github.com/Marvisak/VIctory/issues/131#issuecomment-7120835664) Claiming this (renderer-path, no overlapping claim or PR found — #320's console flow covers wave64 compute on wave32 hosts and documents mask reads there; the PS/VS `MaskData::Host` path is untouched). The defect: for `MaskData::Host` (Ps/Vs — no `WaveSize` attribute, host wave size is driver-chosen), `mask_dword` returns the ballot's first dword for every lane mask read as a number (`s_bcnt1_i32_*`, `s_ff1_i32_*`, `v_mbcnt_*`, `s_cmp_eq/lg_u32/u64`). On a 64-lane host wave the upper 32 lanes are a second console wave whose bits land in the ballot's second dword — they get the first console wave's mask values instead of their own. Fix plan, all in `crates/victory-shader/src/emit/lower.rs`: 1. `mask_dword`: for `MaskData::Host` on a wave32 program, pick the ballot half by host lane (`lane >= 32 ? y : x`). No-op on 32-lane host waves. 2. `v_mbcnt_lo` in that mode: count bits of the lane's own half below `lane & 31`. 3. `v_mbcnt_hi` in that mode: a wave32 mask has no high half, so the count is `src1`. Verification: synthetic wave32 pixel-program test in `emit::lower`'s test module (mask from `v_cmp`, read by `s_bcnt1`, exported via `exp`) asserting the emitted DXIL takes the lane index; `cargo test -p victory-shader` on Linux. No game data. Out of scope: the host-lane-vs-console-lane space for `v_readlane`/`v_writelane` computed lanes — that's the lane-space problem #225/#320 handle in the console flow, not a mask read.
Author
Owner

@⁠NolanCotter on GitHub · 2026-11-24 03:20 UTC · original

Done: #434 (branch agent/host-wave-mask-halves, head 588a0e2).

  • mask_dword selects the ballot half by host lane for MaskData::Host wave32 programs; v_mbcnt_lo counts within the lane's own 32-lane half; v_mbcnt_hi is src1 alone on wave32 (no high mask half). No behavior change on 32-lane host waves.
  • Verification: cargo test -p victory-shader 57/57 on Linux; new synthetic wave32-PS test fails on the unfixed lowering; cargo build + cargo fmt --check clean. victory-gpu not built (pre-existing Linux E0425, #90). No GPU/dxil.dll run available.
**@⁠NolanCotter** on GitHub · 2026-11-24 03:20 UTC · [original](https://github.com/Marvisak/VIctory/issues/131#issuecomment-7120995204) Done: https://git.gtahub.st/github/Marvisak--VIctory/pulls/434 (branch `agent/host-wave-mask-halves`, head 588a0e2). - `mask_dword` selects the ballot half by host lane for `MaskData::Host` wave32 programs; `v_mbcnt_lo` counts within the lane's own 32-lane half; `v_mbcnt_hi` is src1 alone on wave32 (no high mask half). No behavior change on 32-lane host waves. - Verification: `cargo test -p victory-shader` 57/57 on Linux; new synthetic wave32-PS test fails on the unfixed lowering; `cargo build` + `cargo fmt --check` clean. victory-gpu not built (pre-existing Linux E0425, #90). No GPU/dxil.dll run available.
Author
Owner

@⁠Sunkiller-qc on GitHub · 2026-11-24 12:54 UTC · original

This looks like the same bug as #125 (same author, same MaskData::Host path that drops the high ballot half). #145 lists both #125 and #131 as fixed, and #434 also fixes #131, so we have two PRs for one bug. I'd keep #125, since it has the repro branch and the RDNA3 GPU test, and close this one. Whichever of #145 or #434 gets merged should say "Fixes #125".

**@⁠Sunkiller-qc** on GitHub · 2026-11-24 12:54 UTC · [original](https://github.com/Marvisak/VIctory/issues/131#issuecomment-7132072979) This looks like the same bug as #125 (same author, same `MaskData::Host` path that drops the high ballot half). #145 lists both #125 and #131 as fixed, and #434 also fixes #131, so we have two PRs for one bug. I'd keep #125, since it has the repro branch and the RDNA3 GPU test, and close this one. Whichever of #145 or #434 gets merged should say "Fixes #125".
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 01:44 UTC · original

Automated triage for the maintainers.

This is the same defect as #125, opened six minutes earlier by the same reporter: in crates/victory-shader/src/emit/lower.rs, Lower::mask_dword returns only the low ballot dword for a wave32 MaskData::Host program, so s_bcnt1_i32_b32, s_ff1_i32_b32, s_cmp_eq/lg_u32 and v_mbcnt_lo_u32_b32 drop lanes 32-63 of a 64-lane host wave. It names the same four sites and asks the same semantics question. I confirmed the defect on current main in #125, which also has the reproduction branch and the RDNA3 measurements. Both open fixes, #145 and #434, are linked there.

Proposed close as a duplicate of #125. This issue will be closed in 48 hours unless the reporter replies or a maintainer removes the triage: proposed close label.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 01:44 UTC · [original](https://github.com/Marvisak/VIctory/issues/131#issuecomment-7149908629) <!-- victory-issue-triage v1 verdict=proposed-close seen=2026-11-24T12:54:04Z at=2026-11-25T01:45:00Z --> Automated triage for the maintainers. This is the same defect as #125, opened six minutes earlier by the same reporter: in `crates/victory-shader/src/emit/lower.rs`, `Lower::mask_dword` returns only the low ballot dword for a wave32 `MaskData::Host` program, so `s_bcnt1_i32_b32`, `s_ff1_i32_b32`, `s_cmp_eq/lg_u32` and `v_mbcnt_lo_u32_b32` drop lanes 32-63 of a 64-lane host wave. It names the same four sites and asks the same semantics question. I confirmed the defect on current `main` in #125, which also has the reproduction branch and the RDNA3 measurements. Both open fixes, #145 and #434, are linked there. Proposed close as a duplicate of #125. This issue will be closed in 48 hours unless the reporter replies or a maintainer removes the `triage: proposed close` label. --- _Generated by [Claude Code](https://claude.ai/code)_
This discussion has been locked. Commenting is limited to contributors.
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/Marvisak--VIctory#131
No description provided.