Skip to content

vk_compute_test: run the 32-lane compute tests on MoltenVK, checked by a subgroup probe - #2886

Merged
ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
Jolymmiles:moltenvk-32-lane-subgroup-tests
Nov 23, 2026
Merged

ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
Jolymmiles:moltenvk-32-lane-subgroup-tests

Conversation

@Jolymmiles

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: new TEST item, run the exact-32-lane compute tests on MoltenVK. This implements what BUILD-437 diagnosed (claimed by @DomasUrbonas as diagnosis only; @bobcatchris's M2 diagnosis found that these tests give the right words at MoltenVK's default size).

What and why

MoltenVK reports compute subgroups 4..32 and requiredSubgroupSizeStages 0. So VKC_SUBGROUP_SIZE=32 printed compute subgroup size: 32 not available, and every 32-lane compute test was a SKIP on a Mac: 16 in run_gpu_tests.py (17 on today's main, with cs_mask_vgpr_exec) and 46 in check.py.

The size is fixed anyway. The translator emits SPIR-V 1.5, where varying subgroup sizes are not allowed, and Vulkan ("Varying Subgroup Size") then makes SubgroupSize always equal subgroupSize, which is 32 on MoltenVK. Measured with a plain-Vulkan probe on an Apple M3 Max (MoltenVK 1.4.2, MoltenVK main 1.4.3, KosmicKrisp):

  • 17 workgroup shapes: 1, 7, 33, 40, 100, 32 to 1024 in 1D, 32x2, 32x4x8, 64x4x4, 8x8, 4x8x2 and 16x16.
  • Each with and without REQUIRE_FULL_SUBGROUPS, and with and without register and threadgroup-memory pressure, 64 groups per run.
  • Every invocation had 32 lanes in linear order, and every ballot was 32 lanes wide (or the partial tail).

vk_compute_test now handles a size the device can't require but that equals its default subgroupSize, in a module below SPIR-V 1.6. Before the test it runs an embedded probe (runtime/test/glsl/cs_wave_probe.comp → cs_wave_probe_spv.h) with the test's local size and flags, one group. The probe checks each invocation's SubgroupInvocationID, SubgroupID and the lane count of subgroupBallot(true). The ballot is the real width: MoltenVK's MSL declares gl_SubgroupSize as the constant 32.

  • All match: it prints compute subgroup size: 32 (observed: all N invocations of a XxYxZ group[, full subgroups]) and the test is judged as usual.
  • Otherwise: compute subgroup size: 32 observed wrong in ... with the first wrong invocation, and exit 1. Both runners report that as a FAIL, not a skip (checked by forcing a mismatch).
  • Full subgroups are requested where local size X is a multiple of maxSubgroupSize (VUID-02759).
  • Devices whose default isn't the requested size keep printing not available and skip as before.

Clean under the Khronos validation layer (1.4.357). A deliberate violation shows the layer was really active. No translator change.

The tests now show two MoltenVK 1.4.2 bugs, which the skips used to hide. Both pass with MoltenVK main and on KosmicKrisp, and both are documented in docs/testing.md "Known problems":

  • cs_dpp_ops: SPIRV-Cross puts the DPP lowering's ballot and shuffle inside a short-circuiting && / ?:, so only some lanes run them. SPIRV-Cross 5c372ffb keeps them out of ?:, but a ballot on the right of OpLogicalAnd is still put inside && by SPIRV-Cross head (57e4efcc). I have a native repro and will post a finding: for a translator-side guard.
  • check.py's cs_fma_fused (f16 word): the MSL differs between 1.4.2 and main only in SPIRV-Cross's precise-arithmetic helpers (the SHADER-182 / SHADER-234 change).

Tested

Apple M3 Max, macOS 27.3, on ec8ec4c9 (base) against this branch, same commit:

Config run_gpu_tests.py base branch changes
MoltenVK 1.4.2 (Homebrew) 116/189, 72 skip 132/189, 55 skip 16 SKIP→PASS, cs_dpp_ops SKIP→FAIL (1.4.2 bug above)
MoltenVK 1.4.2 + LEONIDA_W64_EMULATE=1 LEONIDA_MESH_COMPUTE=1 152/189, 36 skip 168/189, 19 skip same
MoltenVK main 1.4.3 (SPIRV-Cross 57e4efcc) 116/189, 72 skip 133/189, 55 skip 17 SKIP→PASS
KosmicKrisp (Mesa 26.3.1), plain and emulated 132 / 168 132 / 168 none
llvmpipe (LLVM 23.1.6, 4-wide), plain and emulated 120 / 151 120 / 151 none

ps_ssharp fails on MoltenVK before and after (unrelated).

  • check.py (before → after): MoltenVK 1.4.2 78 → 122 of 163 pass (46 SKIP→ok, except cs_dpp_ops and cs_fma_fused, which became FAIL); MoltenVK main 78 → 124 (all 46 ok); KosmicKrisp 122 → 122; llvmpipe 77 → 77.
  • Stability: each of the 17 tests run 20 times directly on 1.4.2 and 1.4.3 gave the same output every time; the cs_ subset of run_gpu_tests.py gave the same result in 3 runs on each version.
  • crosslane_fuzz.py --wave 32 --modes native --seed 1 (60 programs), which now runs on MoltenVK instead of skipping: identical counts on 1.4.2, 1.4.3 and KosmicKrisp. With --no-maskdata: 0 mismatches on 1.4.3 and KosmicKrisp, 2 on 1.4.2 (the same SPIRV-Cross bug).
  • Translator untouched: runtime/test/shaders/build.py output is byte-identical to the base in four modes (433/433/432/437 files).
  • vk_compute_test.exe cross-built with clang-cl + xwin; under Wine (CrossOver 26.3, MoltenVK 1.4.3) it prints the observed line and passes cs_dpp, cs_w32_partial_scmp, cs_bpermute32, cs_wqm_w32.
  • python -m unittest discover -s tests/semantic, tests/test_shader_checks.py, tests/test_run_gpu_tests.py and the new tests/test_cs_wave_probe_spv.py (the header matches glslang 16.6.0's output) pass. Native ctest: 36/37, with xdxr_build_check failing the same way on the base (MoltenVK 1.4.2, xdxr_build: radix scan writes offsets apart from the counts, correct on MoltenVK 1.4.2 #2423).

AI-assisted (Claude Code).

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (No translator change.)

🤖 Generated with Claude Code

@tupacfan04

Copy link
Copy Markdown
Contributor

Code read of 092c5883 (I didn't run it; I have no MoltenVK device). The gating looks careful. It only applies when the size can't be required, isn't fixed, equals the device's default subgroupSize, and the module is below SPIR-V 1.6, where Vulkan's "varying subgroup size" rule says SubgroupSize must equal subgroupSize. The probe checks the ballot width as well as gl_SubgroupSize, which is the right call given MoltenVK reports the constant 32. Full subgroups are requested only where computeFullSubgroups is available and local X is a multiple of maxSubgroupSize.

One limitation worth a line in the comment: on Metal, threadExecutionWidth is a property of each compute pipeline state, so the probe checks the probe pipeline's width, not the test pipeline's. They share local size and flags, and current Apple GPUs always report 32 for compute, so this holds in practice. But it's an inference, not a measurement of the test shader itself. Reading threadExecutionWidth back for the real pipeline isn't possible through Vulkan, so saying so would keep the "observed" label honest.

AI-assisted review (Claude Code).

@padhossein

Copy link
Copy Markdown
Contributor

Independent subgroup probe entry-point check (092c5883). Linux llvmpipe 26.1.6: the unmodified harness correctly reports size 8 with an 8-wide request and “32 not available” at the 32-wide request. To exercise observed mode on Linux I built a temporary harness that masks off required-size support and reports an adjustable minimum while leaving actual GPU execution at its real default (8). A single-entry 8x1x1 shader passes the real dispatch probe. I found one parser edge with a valid two-entry SPIR-V 1.5 module: main has LocalSize 8x1x1 and other 4x1x1. The harness probes 4 invocations if the other entry's OpExecutionMode is listed last, yet runs main. Swapping only the two mode declarations makes it probe 8 invocations. Could spirv_local_size select LocalSize by the chosen entry-point ID? This is an external-module edge case; the normal generated shaders use one entry point. The test is on software Vulkan, not a MoltenVK retest.

Synthetic inputs only. AI-assisted (Codex).

@UNYTIX

UNYTIX commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Independent Windows validation with synthetic inputs. AI-assisted.

Tested 092c58832. On Windows 11 with Python 3.15.2, python -B tests/test_shader_checks.py -v -k judged_when_32_lanes_are_observed -k failed_when_the_observed_size_is_wrong passed 2/2 (exit 0). Those two mocked-output tests also passed against the base parser. On the PR head, python -B tests/test_run_gpu_tests.py -v Wave32LaneDumps passed 3/3 (exit 0). These checks cover how the runners classify mocked harness output. The actual subgroup probe and MoltenVK behavior still need hardware validation.

@Marukooh

Copy link
Copy Markdown
Contributor

Tested 092c5883 on CachyOS Linux, Python 3.14. tests/test_cs_wave_probe_spv.py, tests/test_run_gpu_tests.py, tests/test_shader_checks.py: 109 passed, 283 subtests passed.

The embedded subgroup-probe SPIR-V, GPU-runner and shader-check unit files passed on Linux. Both embedded probe header checks fail against the base without the change. MoltenVK itself was outside this run.

AI-assisted, synthetic inputs only.

@bobcatchris

Copy link
Copy Markdown
Contributor

Apple M2 validation of the exact-32-lane fix (the machine behind the M2 diagnosis linked in the PR body). Tested head 092c588 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.

python -I scripts/run_gpu_tests.py --build runtime/build/linux: 193 shaders translated, 193 pass spirv-val; 133/189 passed, 55 skipped, 1 failed. On the same M2 with unpatched main 673d3d1 and the identical command: 116/189 passed, 72 skipped, 1 failed. The delta is exactly 17 newly passing tests and 17 fewer skips, with no new failures or skips: cs_bpermute32, cs_dpp, cs_dpp8, cs_dpp_bank, cs_dpp_bound, cs_dpp_fi, cs_dpp_mask, cs_dpp_ops, cs_dpp_row, cs_exec_const, cs_lds_b64_cmpst, cs_mask_vgpr_exec, cs_w32_lane_wrap, cs_w32_mask_imm, cs_w32_partial_scmp, cs_w32_permute, cs_wqm_w32. This confirms on M2 that the previously skipped wave32 tests run and produce the correct words when the harness verifies the fixed subgroup size.

The one remaining failure, ps_ssharp, is unchanged by this PR and is separately reported.

Build note: the full build fails on AppleClang 17 at vk_pipeline_check.cpp:567 (BUILD-822, fixed by open PR #2927); all GPU binaries built, so the suite above is valid. Head fetched unchanged into a separate worktree; no rebase/edit/push. Synthetic shaders and counts only; no game files.

AI-assisted.

@JRamos1993

Copy link
Copy Markdown
Contributor

Tested 092c588 merged onto main 1628210 on an RTX 5090 (driver 616.92), Windows 11, MSVC 19.44, Vulkan SDK 1.4.363, RelWithDebInfo:

  • Full ctest: 130/130.
  • scripts/run_gpu_tests.py (which drives vk_compute_test, the program this PR changes): 143/189 passed, 46 skipped, 0 failed, the same as main 1628210. All 194 test shaders translate and pass spirv-val.
  • tests/test_run_gpu_tests.py: 34 OK.

AI-assisted (Claude Code).

Jolymmiles added a commit to Jolymmiles/Leonida that referenced this pull request Nov 22, 2026
…idth apart from lane order

Review of ItsNotRexed#2886: the probe needs subgroup operations in compute (supportedStages) with basic and ballot
(supportedOperations), or the size stays "not available". LocalSize is the one of the GLCompute entry point "main"
the pipeline is made from, not the last in the module. The width is checked from each subgroup's own lane numbers
and ballot (a wrong width fails the test); 32-lane subgroups that aren't in invocation order, which Vulkan doesn't
promise and the translator assumes, print "not available" and the runners skip.
@Jolymmiles

Copy link
Copy Markdown
Contributor Author

Review fixes in 368511e8 (blind review of #2886 / #3086):

  • The probe needs compute ballots. It runs only where supportedStages has compute and supportedOperations has BASIC and BALLOT. Otherwise the size stays not available, as before.
  • LocalSize of main. It is read from the GLCompute OpEntryPoint named main, the one the pipeline is made from, not from the last LocalSize in the module. With no such entry point the size is unknown, so there is no probe and no full subgroups. Checked on a hand-written module with two entry points (main 64, other 20): the probe and the flag used 64.
  • Width apart from lane order. The width comes from what each subgroup reports: its lane numbers (each lane once, every subgroup N wide except at most one partial tail) and a ballot of its lanes. A wrong width is a FAIL (observed wrong). If the subgroups are 32 lanes wide but not in invocation order, which Vulkan doesn't promise and the translator assumes, the test prints compute subgroup size: 32 not available and runs, so the runners skip it. I checked both outcomes by forcing them in a scratch build.

Re-run on an Apple M3 Max, on 16282101 with #3086 on top: the full run_gpu_tests.py matrix (MoltenVK 1.4.2 plain and emulated, MoltenVK main, KosmicKrisp plain and emulated, llvmpipe plain and emulated) gives the same result for every test as before the fix. AI-assisted.

…quirable (MoltenVK)

MoltenVK reports subgroups 4..32 and requiredSubgroupSizeStages 0, so VKC_SUBGROUP_SIZE=32 printed "not available"
and the 32-lane compute tests skipped. The translator emits SPIR-V 1.5, where varying subgroup sizes are not allowed,
so Vulkan fixes SubgroupSize at the device's subgroupSize (32 there). vk_compute_test now runs a probe shader
(cs_wave_probe.comp, embedded) with the test's local size and flags first, checks every invocation's lane, subgroup
number and ballot width, and runs the test if they match. If they don't, the test fails (exit 1) instead of being
skipped. Full subgroups are requested where local size X is a multiple of maxSubgroupSize. Devices whose default
isn't the requested size keep printing "not available".
…idth apart from lane order

Review of ItsNotRexed#2886: the probe needs subgroup operations in compute (supportedStages) with basic and ballot
(supportedOperations), or the size stays "not available". LocalSize is the one of the GLCompute entry point "main"
the pipeline is made from, not the last in the module. The width is checked from each subgroup's own lane numbers
and ballot (a wrong width fails the test); 32-lane subgroups that aren't in invocation order, which Vulkan doesn't
promise and the translator assumes, print "not available" and the runners skip.
@Jolymmiles

Copy link
Copy Markdown
Contributor Author

Rebased on main f847748c (the conflict was main's --pc-tail-ubo and Float64 changes in vk_compute_test.cpp); head a13d9551.

  • The probe fits the 128-byte layout. cs_wave_probe now takes its buffer address from push-constant words 0 and 1 instead of offset 128, so it works with LEONIDA_PC_TAIL_UBO=1. The embedded SPIR-V is regenerated and tests/test_cs_wave_probe_spv.py checks it. run_gpu_tests.py --filter cs_ on MoltenVK 1.4.2 gives the same result with and without LEONIDA_PC_TAIL_UBO=1: 61/97, and no 32-lane skips.
  • The module is read once. main's Float64 check uses the code that is now read at the start.

Apple M3 Max, full run_gpu_tests.py matrix, main f847748c against this branch on the same commit:

Config main this PR
MoltenVK 1.4.2, plain / LEONIDA_W64_EMULATE=1 LEONIDA_MESH_COMPUTE=1 120 / 156 of 199 137 / 173: 18 SKIP→PASS (now including cs_barrier_loop), cs_dpp_ops SKIP→FAIL (the 1.4.2 SPIRV-Cross bug, fixed by #3086)
MoltenVK main 1.4.3 120/199 138/199: 18 SKIP→PASS
KosmicKrisp, plain / emulated 141 / 177 same per test
llvmpipe, plain / emulated 129 / 160 same per test

ps_ssharp and the four ps_vcmp*_f16 tests fail on main as well. AI-assisted.

@ItsNotRexed
ItsNotRexed merged commit efa9dc1 into ItsNotRexed:main Nov 23, 2026
2 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants