mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 21:55:52 +01:00
[PR #953] rdna2spirv: the wave mask gather is stored before it is read, so every lane runs it (SHADER-WAVEMASK-EAGER) #992
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#992
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/953
Author: @hugo0024
Created: 11/24/2026
Status: 🔄 Open
Base:
main← Head:shader-wavemask-eager📝 Commits (1)
eb2b1b4rdna2spirv: the wave mask gather is stored before it is read, so every lane runs it (SHADER-WAVEMASK-EAGER)📊 Changes
4 files changed (+150 additions, -3 deletions)
View changed files
📝
docs/design.md(+1 -1)📝
tests/semantic/README.md(+3 -0)➕
tests/semantic/test_wave_mask_eager.py(+140 -0)📝
tools/rdna2spirv.py(+6 -2)📄 Description
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
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.