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

Closed
Luislariosss wants to merge 2 commits from upstream-pr/147 into main
Luislariosss commented 2026-11-24 00:57:52 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Luislariosss on 2026-11-24T00:57:52Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6572142439 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/147). Originally posted by [Luislariosss](https://github.com/Luislariosss) on 2026-11-24T00:57:52Z. --- 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.
upstream-sync closed this pull request 2026-11-24 06:51:31 +00:00
DaviTostes commented 2026-11-24 06:54:49 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DaviTostes on 2026-11-24T01:05:43Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7118748950 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/147#issuecomment-7118748950). Originally posted by [DaviTostes](https://github.com/DaviTostes) on 2026-11-24T01:05:43Z. --- 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).
Luislariosss commented 2026-11-24 06:54:52 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Luislariosss on 2026-11-24T01:12:23Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7118866297 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/147#issuecomment-7118866297). Originally posted by [Luislariosss](https://github.com/Luislariosss) on 2026-11-24T01:12:23Z. --- 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.
TheHoracio commented 2026-11-24 06:54:54 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by TheHoracio on 2026-11-24T01:19:40Z.


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://github.com/Marvisak/VIctory/issues/125

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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7118990024 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/147#issuecomment-7118990024). Originally posted by [TheHoracio](https://github.com/TheHoracio) on 2026-11-24T01:19:40Z. --- 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://github.com/Marvisak/VIctory/issues/125 AI use: Claude Code (Claude Opus 5.5) wrote and ran the test.

Pull request closed

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