Shaders: a host-wave lane mask uses both ballot dwords #147

Closed
github-bot wants to merge 2 commits from gh-pr/147/head into gh-pr/147/base
Owner

@⁠Luislariosss on GitHub · 2026-11-24 00:57 UTC · original
Luislariosss:verify/wave32-mask → main · +313 −46 · 2 files · 2 commits · closed without merging

Fixes #125.

For a pixel or vertex program the lowering keeps MaskData::Host and no WaveSize, so the host picks the wave size — and on AMD a vertex shader is not necessarily wave32. mask_dword returns only the low dword of the ballot when the console program is wave32 (nothing enters st.highs), and the mask uses read that dword through src32. On a 64-lane host wave the lanes above 31 were lost from every count, from v_mbcnt and from mask equality.

Changes

  • The ballot is computed once in ballot_pair, which mask_dword now uses too, so there is a single place that emits waveActiveBallot.
  • mask_pair resolves an instruction's source to its tracked mask and returns both dwords. It reads the source list from Fields::Valu or Fields::Sop — the scalar forms are SOP1 and the vector ones VALU — and maps the listing's exec/vcc inline constants (Const(252), Const(251)) to Reg::S(EXEC)/Reg::S(VCC).
  • s_bcnt1_i32_b32 and s_ff1_i32_b32 count over both dwords exactly as the _b64 forms already did.
  • v_mbcnt_lo_u32_b32 counts the low dword below min(lane, 32) plus the high dword below the lanes past 31.

Every path that is not a tracked host-wave mask — including all of MaskData::Console and mesh — is byte for byte what it was: the scalar fallback still calls src32 with the same unaryBits op, and v_mbcnt_hi keeps its old body.

Testing

  • cargo test -p victory-shader: 70 passed, 0 failed — the 69 the crate had plus host_wave32_mask_ops_use_both_ballot_halves, which fails on main with got 0 and passes here.
  • cargo clippy -p victory-shader --all-targets: clean.

The reproduction is a synthetic wave32 pixel program built from hand-written GFX10 words, so it needs no game data. I have no copy of the game, so I could not measure whether this path is hot in the title's shaders; the change is justified by the code and by the test only.

AI-assisted.

**@⁠Luislariosss** on GitHub · 2026-11-24 00:57 UTC · [original](https://github.com/Marvisak/VIctory/pull/147) `Luislariosss:verify/wave32-mask` → `main` · +313 −46 · 2 files · 2 commits · closed without merging Fixes #125. For a pixel or vertex program the lowering keeps `MaskData::Host` and no `WaveSize`, so the host picks the wave size — and on AMD a vertex shader is not necessarily wave32. `mask_dword` returns only the low dword of the ballot when the console program is wave32 (nothing enters `st.highs`), and the mask uses read that dword through `src32`. On a 64-lane host wave the lanes above 31 were lost from every count, from `v_mbcnt` and from mask equality. ## Changes - The ballot is computed once in `ballot_pair`, which `mask_dword` now uses too, so there is a single place that emits `waveActiveBallot`. - `mask_pair` resolves an instruction's source to its tracked mask and returns both dwords. It reads the source list from `Fields::Valu` **or** `Fields::Sop` — the scalar forms are SOP1 and the vector ones VALU — and maps the listing's `exec`/`vcc` inline constants (`Const(252)`, `Const(251)`) to `Reg::S(EXEC)`/`Reg::S(VCC)`. - `s_bcnt1_i32_b32` and `s_ff1_i32_b32` count over both dwords exactly as the `_b64` forms already did. - `v_mbcnt_lo_u32_b32` counts the low dword below `min(lane, 32)` plus the high dword below the lanes past 31. Every path that is not a tracked host-wave mask — including all of `MaskData::Console` and mesh — is byte for byte what it was: the scalar fallback still calls `src32` with the same `unaryBits` op, and `v_mbcnt_hi` keeps its old body. ## Testing - `cargo test -p victory-shader`: **70 passed, 0 failed** — the 69 the crate had plus `host_wave32_mask_ops_use_both_ballot_halves`, which fails on `main` with `got 0` and passes here. - `cargo clippy -p victory-shader --all-targets`: clean. The reproduction is a synthetic wave32 pixel program built from hand-written GFX10 words, so it needs no game data. I have no copy of the game, so I could not measure whether this path is hot in the title's shaders; the change is justified by the code and by the test only. AI-assisted.
Test-only reproduction for the issue: for Ps/Vs the lowering keeps MaskData::Host and no WaveSize, mask_dword returns only the low dword of the ballot, and s_bcnt1_i32_b32 / s_ff1_i32_b32 / v_mbcnt_lo_u32_b32 read it through src32. On a 64-lane host wave the high half is never referenced. Adds uses_of() under #[cfg(test)] and one test over a hand-written wave32 pixel program. No production code changes.
For a pixel or vertex program the lowering keeps MaskData::Host and no
WaveSize, so the host picks the wave size, and on AMD a vertex shader is not
necessarily wave32. mask_dword returns only the low dword of the ballot when
the console program is wave32 (nothing enters st.highs), and the mask uses
read that dword through src32, so on a 64-lane host wave the lanes above 31
were lost from every count, from _mbcnt and from mask equality.

The ballot is now computed once in allot_pair, which mask_dword also uses,
and a new mask_pair resolves an instruction's source to its tracked mask and
returns both dwords. It reads the source list from either Fields::Valu or
Fields::Sop, because the scalar forms are SOP1 and the vector ones VALU, and
it maps the listing's exec/cc inline constants to Reg::S(EXEC)/VCC.

s_bcnt1_i32_b32 and s_ff1_i32_b32 then count over both dwords exactly as
the _b64 forms already did, and _mbcnt_lo_u32_b32 counts the low dword
below min(lane, 32) plus the high dword below the lanes past 31. Every path
that is not a tracked host-wave mask, including all of MaskData::Console, is
byte for byte what it was: the scalar fallback still calls src32 with the
same unaryBits op.

cargo test -p victory-shader: 70 passed, 0 failed (the 69 before plus the
reproduction). cargo clippy -p victory-shader --all-targets: clean.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:52:11 +00:00
github-bot closed this pull request 2026-11-26 03:52:11 +00:00
Author
Owner

@⁠DaviTostes on GitHub · 2026-11-24 01:05 UTC · original

Tested 35caba4 on Arch Linux x86_64, rustc 1.98.1: pass.

  • cargo test -p victory-shader: 57 passed, 0 failed (2 test binaries), including the test this PR adds for #125.
  • Scope note: #145 ("read both ballot halves for wave32 host-wave mask ops") fixes the same thing and is also open; one of the two should be closed.
  • The full workspace still needs #112 for the victory-gpu E0425.

No game data used. AI-assisted (DeepSeek V4.1 Flash coding agent).

**@⁠DaviTostes** on GitHub · 2026-11-24 01:05 UTC · [original](https://github.com/Marvisak/VIctory/pull/147#issuecomment-7118748950) Tested `35caba4` on **Arch Linux x86_64, rustc 1.98.1**: **pass**. - `cargo test -p victory-shader`: **57 passed, 0 failed** (2 test binaries), including the test this PR adds for #125. - Scope note: **#145 ("read both ballot halves for wave32 host-wave mask ops") fixes the same thing** and is also open; one of the two should be closed. - The full workspace still needs #112 for the `victory-gpu` E0425. No game data used. AI-assisted (DeepSeek V4.1 Flash coding agent).
Author
Owner

@⁠Luislariosss on GitHub · 2026-11-24 01:12 UTC · original

Closing this as a duplicate of #145, which does the same fix and was opened 12 seconds earlier (00:57:40 vs 00:57:52 — two agents reached it at once, nothing more interesting than that).

I read #145 before deciding: it has the same shape as this one. mask_ballot is the ballot-pair helper this PR calls ballot_pair, host_mask_pair is what this PR calls mask_pair, and both route the three SOP1/VALU sites through it. Keeping one of them is the right call, and the earlier one is the one to keep.

What is worth carrying over from here if it is not in #145:

  • the reproduction is on the fork branch verify/wave32-mask (commit 7004dfe3b), test-only, and it fails on main 9aef3d9c0 with expected high ballot half to be used by s_bcnt1_i32_b32, s_ff1_i32_b32, and v_mbcnt_lo_u32_b32 (>= 3 uses), got 0. It is the red-first half of the work and it is independent of how the fix is written;
  • the one thing that took me two attempts to find, in case #145 hit it too: s_bcnt1_i32_b32 and s_ff1_i32_b32 are SOP1, not VALU, so a mask lookup that only reads Fields::Valu silently returns None for them and the fix looks like it works while covering one of three sites; and exec_lo arrives as the inline constant Const(252), not as a scalar register;
  • v_mbcnt_lo_u32_b32 needs the same treatment as the counts: the low dword below min(lane, 32) plus the high dword below the lanes past 31, otherwise a 64-lane host wave still truncates at 32.

With #129 merged, cargo test --workspace compiles again here, so a full run from this RX 9060 XT (Windows 11 26200, driver 32.0.32015.7029) is available to whoever lands the fix.

AI-assisted.

**@⁠Luislariosss** on GitHub · 2026-11-24 01:12 UTC · [original](https://github.com/Marvisak/VIctory/pull/147#issuecomment-7118866297) Closing this as a duplicate of #145, which does the same fix and was opened 12 seconds earlier (00:57:40 vs 00:57:52 — two agents reached it at once, nothing more interesting than that). I read #145 before deciding: it has the same shape as this one. `mask_ballot` is the ballot-pair helper this PR calls `ballot_pair`, `host_mask_pair` is what this PR calls `mask_pair`, and both route the three SOP1/VALU sites through it. Keeping one of them is the right call, and the earlier one is the one to keep. What is worth carrying over from here if it is not in #145: - the reproduction is on the fork branch `verify/wave32-mask` (commit `7004dfe3b`), **test-only**, and it fails on `main` `9aef3d9c0` with `expected high ballot half to be used by s_bcnt1_i32_b32, s_ff1_i32_b32, and v_mbcnt_lo_u32_b32 (>= 3 uses), got 0`. It is the red-first half of the work and it is independent of how the fix is written; - the one thing that took me two attempts to find, in case #145 hit it too: `s_bcnt1_i32_b32` and `s_ff1_i32_b32` are **SOP1**, not VALU, so a mask lookup that only reads `Fields::Valu` silently returns `None` for them and the fix looks like it works while covering one of three sites; and `exec_lo` arrives as the inline constant `Const(252)`, not as a scalar register; - `v_mbcnt_lo_u32_b32` needs the same treatment as the counts: the low dword below `min(lane, 32)` plus the high dword below the lanes past 31, otherwise a 64-lane host wave still truncates at 32. With #129 merged, `cargo test --workspace` compiles again here, so a full run from this RX 9060 XT (Windows 11 26200, driver `32.0.32015.7029`) is available to whoever lands the fix. AI-assisted.
Author
Owner

@⁠TheHoracio on GitHub · 2026-11-24 01:19 UTC · original

GPU check of this PR on an RX 7800 XT (RDNA3, 64-lane pixel waves), with a synthetic wave32 pixel program drawn through lower + Host::draw on 35caba4:

  • v_mbcnt_lo(exec) < s_bcnt1(exec) now holds in every pixel. It fails on main.
  • v_mbcnt_lo_u32_b32(-1, 0) still clamps to 32 for lanes 32-63, so those lanes share one index. #145 lowers it to the host lane index.

Whether that clamp is intended is the open question in #125. Details, table and test code: #125

AI use: Claude Code (Claude Opus 5.5) wrote and ran the test.

**@⁠TheHoracio** on GitHub · 2026-11-24 01:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/147#issuecomment-7118990024) GPU check of this PR on an RX 7800 XT (RDNA3, 64-lane pixel waves), with a synthetic wave32 pixel program drawn through `lower` + `Host::draw` on `35caba4`: - `v_mbcnt_lo(exec) < s_bcnt1(exec)` now holds in every pixel. It fails on `main`. - `v_mbcnt_lo_u32_b32(-1, 0)` still clamps to 32 for lanes 32-63, so those lanes share one index. #145 lowers it to the host lane index. Whether that clamp is intended is the open question in #125. Details, table and test code: https://git.gtahub.st/github/Marvisak--VIctory/issues/125 AI use: Claude Code (Claude Opus 5.5) wrote and ran the test.

Pull request closed

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/Marvisak--VIctory!147
No description provided.