Repository navigation
rdna2spirv: run DPP's ballot and shuffle in every lane under SPIRV-Cross (SHADER-529) - #3227
Conversation
|
The Mac run requested in the PR body, done on Apple M2 (Mac14,3), macOS 26.4 (25E246), MoltenVK 1.4.2 (Homebrew, direct), subgroup 4..32, llvm-mc 23.1.6, Python 3.13.18. PR head a750e60 alone: To actually run them I locally merged open PR #2886 (the exact-32-lane harness fix) into a throwaway worktree of this head — no push, no change to your branch — and re-ran: 9 shaders translated, 9 pass spirv-val; 8/9 passed, 1 skipped (cs_dpp_w64 still skips). The passed words: cs_dpp A/B: I also ran the same filter on #2886's head alone (without this PR) on this M2 — the eight fixtures give identical words both times. So this M2/MoltenVK 1.4.2 machine does not reproduce the lane-conditional DPP bug your static analysis found, and the change causes no regression here. It remains a Mac data point, not a refutation of the M3 Max/SPIRV-Cross finding. Full builds at these heads fail on AppleClang 17 at vk_pipeline_check.cpp:567 (BUILD-822, fixed by open PR #2927); GPU binaries built, so all runs above are valid. Synthetic shaders and counts only; no game files. AI-assisted. |
|
Tested a750e60 on an RTX 5090 (driver 616.92), Windows 11, Vulkan SDK 1.4.363. The GPU test programs were built from the same tree:
AI-assisted (Claude Code). |
|
Tested Linux runtime built from the branch (CMake + Ninja, GCC, RelWithDebInfo);
AI-assisted (Claude Code). Synthetic test shaders only, no game files. |
…oss (SHADER-529) SPIRV-Cross (MoltenVK) inlines a single-use result into the expression that uses it. The DPP lowering put the source-EXEC ballot on the right of an OpLogicalAnd (a short-circuiting && in MSL) and the shuffle in the arm of a scalar OpSelect (a ternary), so lanes out of their row skipped the ballot and the shuffle read from lanes that never ran it: row_shr:1's lane 1 found lane 0 inactive and kept its old value (cs_dpp_ops on MoltenVK). Both results are now stored to a Function variable of their own (Gen.eager) and loaded back; a store is a statement every lane runs. Only the DPP path changes: of the 217 GPU test shaders that assemble here, exactly the nine cs_dpp* ones translate differently, all still pass spirv-val, and SPIRV-Cross 1.3.239's MSL now computes the ballot and the shuffle as their own statements. tests/semantic/test_dpp_eager_subgroup.py models SPIRV-Cross's single-use forwarding and fails on the old lowering for all 11 DPP16/DPP8 forms tested; it also checks the values in spirv_wave_interp.py against a DPP reference. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GN11jbD4AeqgwR5C5Z5Xs9
a750e60 to
4d65bae
Compare
|
Re-tested |
|
Tested 4d65bae on NVIDIA GeForce GTX 1660 (Turing, TU116, subgroup 32..32), driver 620.73.04 (proprietary, Vulkan 1.4.357), Arch Linux (kernel 6.18): pass, no regression. Native build of runtime/ from this head (Ninja, RelWithDebInfo, clang 23.1.5), llvm-mc 23.1.5, SPIRV-Tools v2026.4.
AI-assisted run (Claude). Synthetic programs only, no game files involved. |
Claimed in the coordination issue as: SHADER-529
What and why
SPIRV-Cross (MoltenVK) inlines a result that is used once into the expression that uses it. The DPP lowering in
Gen.dpp_insnleft two subgroup ops where that inlining makes them conditional:OpLogicalAnd, which becomes a short-circuiting&&in MSL:bool _255 = _246 && spvSubgroupBallotBitExtract(spvSubgroupBallot(_99), _251);OpSelect, which becomes a ternary:(_255 ? spvSubgroupShuffle(_93[0u], _251) : 0u), itself inside theactive && enabled && src_ok ? … : oldwrite.So lanes outside their row skip the ballot, and the shuffle reads from lanes that never ran it. With
row_shr:1, lane 1 finds lane 0 inactive and keeps its old value (cs_dpp_ops).The fix stores both results to a Function variable of their own and loads them back (
Gen.eager). A store is a statement, so every lane runs it. In SPIRV-Cross's MSL each op is now its own statement:Only the non-emulated DPP path changes. The
--wave64-emulatepath uses no subgroup ops.Tested
No GPU or Mac here, so this is not yet run on MoltenVK. Someone with a Mac should run
cs_dpp*withcheck.pybefore this is called fixed on hardware.runtime/test/shaders/build.pywith LLVM 18'sllvm-mc: 217 of the 218 GPU test shaders assemble (ps_sdwa_f16_constneeds a newerllvm-mc). Before and after, all 217 translate and passspirv-val. Exactly the ninecs_dpp*shaders translate differently.--msl --msl-version 30000oncs_dpp_ops: the before and after excerpts above.tests/semantic/test_dpp_eager_subgroup.py, 7 tests:mainand passes with this change. Its own tests cover what it flags and what it leaves alone.spirv_wave_interp.pyagainst a plain-Python DPP reference (values unchanged).python -m unittest discover -s tests/semantic, re-run after rebasing ontomainat1628210: 4,149 tests. The only failure istest_fma_khr.test_spirv_tools_accept_it, because the distro's olderspirv-asdoesn't knowFMAKHR. It fails the same way onmain.tests/test_*.pyloop, split as CI splits it: all 225 pass.ps_sdwa_f16_const, which LLVM 18'sllvm-mccan't assemble; CI uses LLVM 21.Follow-ups (not in this PR)
The same static check over all 217 test shaders also flags subgroup ops in ternary arms outside DPP. Many look harmless: either the condition is wave-uniform (
simd_any(x) ? FindLSB(Ballot(x)) : 0), or it's a reduction where the lanes that skip it would contribute 0 anyway. Some may not be. The ones to look at first are the swizzle/permlane shuffles behind the EXEC select indst()(ps_w64_a_swizzle,ps_w64_a_permlane,cs_w32_permute,cs_w64x_permute), which give_87 ? spvSubgroupShuffle(...) : old. I can post them as afinding:if that's useful.Checklist
docs/design.md, with how it was confirmed. It's added to the DPP row, and says it's not run on a Mac yet.