rdna2spirv: the wave mask gather is stored before it is read, so every lane runs it (SHADER-WAVEMASK-EAGER) #953
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/953"
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?
Imported from ubiquitarianism/leonida. Originally posted by hugo0024 on 2026-11-24T15:39:46Z.
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
Imported from ubiquitarianism/leonida. Originally posted by shwepz on 2026-11-24T15:49:39Z.
Review: COMMENTED
Reviewed and ran locally (Windows 11, Python 3.11,
34f51abon top ofa289278). Looks correct to me.Verified
tests/semantic/test_wave_mask_eager.pypasses on this branch (5/5). The same file run againstmain's translator fails 7 checks: the vertex and compute subtests report theOpGroupNonUniformBitwiseOrin an arm ofOpSelect, andtest_the_gather_is_stored_before_v_mbcnt_selects_on_execsees the gather used by the select instead of anOpStore. So the test catches exactly this bug.mainand on this branch:test_dpp_eager_subgroup.py(7),test_salu_flbit_lane_mask.py(4),test_lane_masks_vector_bitwise.py(4),tests/test_lane_masks.py.Code
x_mcache/x_round) returns before the neweagercalls. That's fine: it exchanges through the buffer and has no subgroup op to inline.wordis enough. TheOpStoreforces the ballot to run in every lane, even though the ballot itself isn't stored.dst()withouteager: theds_append/ds_consumeresult shuffle (~L4996) and thev_readfirstlane-style shuffle (~L7719). Neither has this problem, because the source lane is the first active lane, which takes the arm. Unlike an OR-reduce or a ballot, the lanes that are off don't contribute anything there. Nothing more is needed in this PR.Questions
wave_maskcaller now gets an extra Function variable plus a store and a load. Could you add to thedesign.mdrow how many corpus.spvchange and whether they still passspirv-val(as the other rows do)?cs_wavemask/cs_wave64_ballot/cs_wm_*on a native wave64 driver (AMD RADV or AMD Windows) with this branch? It should be a no-op there, but it's the one place a regression would show.Nit
mainalready). It could be dropped while you're there.Imported from ubiquitarianism/leonida. Originally posted by hugo0024 on 2026-11-24T16:03:52Z.
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.
Imported from ubiquitarianism/leonida. Originally posted by thesubtleties on 2026-11-24T19:21:28Z.
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)
Imported from ubiquitarianism/leonida. Originally posted by tiguan26 on 2026-11-25T19:12:44Z.
Review: APPROVED
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).
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T14:49:25Z.
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
4f9199d09in GitHub Actions: no new failure.AI-assisted (Claude Code, Claude Opus 5.5)