Shaders: a host-wave lane mask uses both ballot dwords #147
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!147
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/147/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Luislariosss on GitHub · 2026-11-24 00:57 UTC · original
Luislariosss:verify/wave32-mask→main· +313 −46 · 2 files · 2 commits · closed without mergingFixes #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.
@DaviTostes on GitHub · 2026-11-24 01:05 UTC · original
Tested
35caba4on 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.victory-gpuE0425.No game data used. AI-assisted (DeepSeek V4.1 Flash coding agent).
@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_ballotis the ballot-pair helper this PR callsballot_pair,host_mask_pairis what this PR callsmask_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:
verify/wave32-mask(commit7004dfe3b), test-only, and it fails onmain9aef3d9c0withexpected 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;s_bcnt1_i32_b32ands_ff1_i32_b32are SOP1, not VALU, so a mask lookup that only readsFields::Valusilently returnsNonefor them and the fix looks like it works while covering one of three sites; andexec_loarrives as the inline constantConst(252), not as a scalar register;v_mbcnt_lo_u32_b32needs the same treatment as the counts: the low dword belowmin(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 --workspacecompiles again here, so a full run from this RX 9060 XT (Windows 11 26200, driver32.0.32015.7029) is available to whoever lands the fix.AI-assisted.
@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::drawon35caba4:v_mbcnt_lo(exec) < s_bcnt1(exec)now holds in every pixel. It fails onmain.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.
Pull request closed