rdna2spirv: the wave mask gather is stored before it is read, so every lane runs it (SHADER-WAVEMASK-EAGER) #953
No reviewers
No assignees
Labels
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
No project
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
No due date set.
Reference
leonida/mandy!953
Loading…
Reference in a new issue
No description provided.
Delete branch "shader-wavemask-eager"
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?
Pull request successfully merged and closed
Claimed in the coordination issue as: SHADER-WAVEMASK-EAGER (claim)
What and why
On MoltenVK,
v_mbcntof a lane mask counts too few lanes when it runs with EXEC narrowed.tools/crosslane_fuzz.pyfinds it on an Apple M5: 4 of 100 wave32 programs of the default seed mismatch, the same four with the same words every run. The smallest one:A register holds only this lane's bit of a mask, and
Gen.wave_maskgathers the other lanes' bits with a subgroup operation.v_mbcntwrites a VGPR, so its result is anOpSelecton the lane's EXEC. SPIRV-Cross inlines a result that is used once, and the MSL MoltenVK 1.4.2 generates for that line is:simd_oris in the taken arm of the ternary on EXEC. A lane that is off never runs it, so its bit is missing from what every other lane counts. This is the mechanism SHADER-529 fixed for DPP's ballot and shuffle, in a place that fix did not cover.tools/rdna2spirv.py:Gen.wave_maskstores the gathered mask to a variable of its own withGen.eager(both words of theOpGroupNonUniformBitwiseOrpath, and the ballot word of the wave32 fragment path). A store is a statement every lane runs. The emulated path has no subgroup operation and is unchanged.tests/semantic/test_wave_mask_eager.py:v_mbcnt,s_bcnt1ands_ff1of a compare mask, of VCC and of EXEC, read under a narrowed EXEC in a vertex, a compute and a pixel shader, checked with the model of SPIRV-Cross's forwarding fromtest_dpp_eager_subgroup.py, and the values against a plain-Python reference inspirv_wave_interp.py.docs/design.md("Whole-wave masks" row) andtests/semantic/README.md: the rule and how it was confirmed.No new instruction is translated; the contract row that changes is the existing one.
Tested
Apple M5, MoltenVK 1.4.2,
maina28927849.crosslane_fuzz.pywith the samevk_compute_testand the translator ofmain(before) or of this branch (after); match / mismatch / hypothesis-only:--wave 32 --modes native --no-maskdata, 100 programs--dpp --seed 7, 200 programs--wave 32 --modes native, 100 programs--wave 64 --modes emulate --no-maskdata, 100 programs--no-maskdataleaves out (docs/shader_validation.md). Not touched here.tests/semantic/test_wave_mask_eager.py: 5 tests pass. With the translator ofmainit fails 7 ways:v_mbcntin the vertex and the compute shader for each of the three masks, and the shape test.main.build.py: 281 of 281 fixtures translate and pass spirv-val before and after; 33 of the 281 modules change.run_gpu_tests.py: 257 of 258 translated and valid before and after.run_gpu_tests.py, native and withLEONIDA_W64_EMULATE=1: every test has the same verdict before and after (184/249 and 215/249 passed; failedcs_fma_fused,cs_imgload_tfe,cs_imgload_d16_tfeand the intermittentps_imgatomic, #543).ctest: 72/72.lds_fuzz.pyandvalu_fuzz.py --family mem: 40/40 each.tests/test_tool_stdout_encoding.py, which fails the same way onmain.tests/test_docs_*.pypass.Not measured: the translated and
spirv-val-valid counts over the game's shaders (no game files here), and any GPU other than this one. On a driver that already ran the gather in every lane the change is a store and a load of the same value.GPUs tested: Apple M5 (8-core GPU), MoltenVK 1.4.2, macOS 27.2.1 (26B131)
AI-assisted: yes
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed.🤖 Generated with Claude Code
Thanks for running it both ways.
The repeated sentence in that row is on main already; I left it so this pull request stays one topic.
Tested
15185922cmerged onto main3aa97542, including the RADV run you asked for. NVIDIA RTX 3080 (620.73.04) and AMD Raphael RDNA2 iGPU gfx1036 (RADV, Mesa 26.3.1), CachyOS.cs_wavemask,cs_wave64_ballot,cs_wm_bfm64,cs_wm_half_cmp,cs_wm_half_opsandcs_wm_scc_rflpass on gfx1036, native and withLEONIDA_W64_EMULATE=1.crosslane_fuzz.pygives the same output as main (4 runs of 250 programs).run_semantic_tests.py tests/semantic: 471 files / 6,173 tests, 0 failed.Not tested: MoltenVK, game corpus, performance. AI-assisted (Claude Code)
Approving. Merged into current main (9f9a7c5) with no conflicts.
test_wave_mask_eager.pypasses, and the full translator suite gives 491 files / 6,297 tests with onlytest_int32_to_f64failing, the same baseline failure as main here (Linux, Python 3.13).It's a small, safe change: the wave-mask gather words go through
eager()on both the wave32 and wave64 returns. The ballot is then stored at the point it is computed, so a downstream compiler (SPIRV-Cross for MoltenVK here) can't sink it into an EXEC-guarded select arm where inactive lanes would skip the subgroup op. On drivers that don't sink it, the values are unchanged.AI-assisted (Claude).
Red/green: tests/semantic/test_wave_mask_eager.py fails on main (7 failures) and passes with this PR.
Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main 4f9199d09 in GitHub Actions: no new failure.
AI-assisted (Claude Code, Claude Opus 5.5)