Repository navigation
Shaders: a host-wave lane mask uses both ballot dwords - #147
Luislariosss wants to merge 2 commits into
Conversation
…el/vertex mask ops 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.
…k#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, 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.
|
Tested
No game data used. AI-assisted (DeepSeek V4.1 Flash coding agent). |
|
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. What is worth carrying over from here if it is not in #145:
With #129 merged, AI-assisted. |
|
GPU check of this PR on an RX 7800 XT (RDNA3, 64-lane pixel waves), with a synthetic wave32 pixel program drawn through
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. |
Fixes #125.
For a pixel or vertex program the lowering keeps
MaskData::Hostand noWaveSize, so the host picks the wave size — and on AMD a vertex shader is not necessarily wave32.mask_dwordreturns only the low dword of the ballot when the console program is wave32 (nothing entersst.highs), and the mask uses read that dword throughsrc32. On a 64-lane host wave the lanes above 31 were lost from every count, fromv_mbcntand from mask equality.Changes
ballot_pair, whichmask_dwordnow uses too, so there is a single place that emitswaveActiveBallot.mask_pairresolves an instruction's source to its tracked mask and returns both dwords. It reads the source list fromFields::ValuorFields::Sop— the scalar forms are SOP1 and the vector ones VALU — and maps the listing'sexec/vccinline constants (Const(252),Const(251)) toReg::S(EXEC)/Reg::S(VCC).s_bcnt1_i32_b32ands_ff1_i32_b32count over both dwords exactly as the_b64forms already did.v_mbcnt_lo_u32_b32counts the low dword belowmin(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::Consoleand mesh — is byte for byte what it was: the scalar fallback still callssrc32with the sameunaryBitsop, andv_mbcnt_hikeeps its old body.Testing
cargo test -p victory-shader: 70 passed, 0 failed — the 69 the crate had plushost_wave32_mask_ops_use_both_ballot_halves, which fails onmainwithgot 0and 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.