Skip to content

rdna2spirv: --no-vertex-subgroups so VS buffer fetches build on MoltenVK (SHADER-302) - #1784

Closed
shoal-rat wants to merge 1 commit into
ProjectLeonida:mainfrom
shoal-rat:no-vertex-subgroups
Closed

shoal-rat wants to merge 1 commit into
ProjectLeonida:mainfrom
shoal-rat:no-vertex-subgroups

Conversation

@shoal-rat

Copy link
Copy Markdown
Contributor

SHADER-302. Claim: #1745 comment 7080201472. Follows up SHADER-231 (#1565).

Problem

Since #1565, every MUBUF/MTBUF access through a run-time V# adds ADD_TID_ENABLE (word3 bit 23) × the wave lane to the index. Gen.wave_lane returns SubgroupLocalInvocationId for that lane outside compute and mesh shaders. MoltenVK's subgroupSupportedStages has no vertex bit: it lists compute, fragment and tessellation control, because a Metal vertex function has no SIMD-group lane. So on a Mac the pipeline of any VS that fetches through a run-time V# fails:

[mvk-error] SPIR-V to MSL conversion error: Subgroup builtins are not available in this type of function.
PIPELINE FAIL vs_m15 (vs w32, -3)

vs_m15 is the GPU-test version of the game's fetch-without-fetch-program VS (runtime/test/shaders/vs_m15.asm). The same pattern in the corpus therefore fails at pipeline creation on every Mac.

Change

The fix follows the existing --f16-interp-fallback pattern: the device decides and a translator flag carries it.

  • tools/rdna2spirv.py: new --no-vertex-subgroups. With it, Gen.buffer_address in a VS leaves the lane out of a run-time V#'s index, just as for a literal V# without the bit, so the VS declares neither the builtin nor GroupNonUniform for it.
    • Exact while the run-time bit is clear, which is how vertex buffers are set up. With the bit set, every vertex reads lane 0's element; such a device has no vertex lane to read. This is documented as unmodelled.
    • A literal V# with ADD_TID_ENABLE in a VS is Unsupported under the flag.
    • A VS's own wave operations, and compute, mesh and pixel shaders, are unchanged. Metal fragment functions do have a SIMD-group lane.
  • tools/vk_subgroup_info.py: reports vertex_in_supported_stages, the vertex bit of subgroupSupportedStages.
  • make_game.py: turns the flag on by itself where that is false, like --f16-interp-fallback. The flag is also in FALLBACK_FLAGS, so it is recorded and forwarded.
  • scripts/run_gpu_tests.py: turns the flag on where the device answer is false. LEONIDA_NO_VERTEX_SUBGROUPS=1/0 overrides it. The device answer is read from the last JSON line of the output, so driver log lines after it don't hide it (the same fix run_gpu_tests: skip ps_ij_computed under the PerVertexKHR fallbacks, and find the device JSON past driver logs #1681 makes for per_vertex_inputs). runtime/test/shaders/build.py takes LEONIDA_NO_VERTEX_SUBGROUPS=1.
  • Docs: a new contract row "Vertex shaders without subgroups" in docs/design.md, a pointer to it from the swizzled-addressing row, and a "Macs: vertex shaders without subgroups" section in docs/testing.md.

Tested

Apple M5, macOS 27.2.1, MoltenVK 1.4.2, Khronos validation layer 1.4.363, LLVM 23.1.6, Python 3.14.

main 89b047c this PR (flag on by itself)
vk_pipeline_check over the 170 GPU-test modules, VS pipelines 8 ok, 1 failed (vs_m15) 9 ok, 0 failed
validation-layer messages in that run — same VUIDs, same counts
modules that change — only vs_m15.spv, the one VS that declared the builtin. The other 169 are byte-identical.
run_gpu_tests.py 103 pass, 62 skip, 1 fail identical per test

vs_m15 is drawn only by the Windows d3d12_translated_draw_test, so on the Mac the check is pipeline creation, not pixels. The one run_gpu_tests.py failure is ps_ij_computed, the same on main; #1680 / #1681 fix it.

Unit tests:

  • tests/semantic/test_no_vertex_subgroups.py (new) runs the VS in the one-lane interpreter:
    • the default adds lane 5 when the run-time bit is set;
    • with the flag there is no builtin and no GroupNonUniform;
    • with the bit clear, the flag reads the same record as the default; with it set, the vertex's own record;
    • a literal V# with the bit is refused under the flag;
    • a CS and a PS translate byte-identically with and without the flag.
  • Negative control: against main's translator, 3 of these fail (the builtin is still declared, and the literal is not refused).
  • tests/test_vk_subgroup_info.py: the vertex bit for all-graphics, MoltenVK-like and vertex-only stage masks.
  • tests/test_make_game_translator_flags.py: the flag follows the device, can be asked for explicitly, and composes with the f16 fallback.
  • tests/test_run_gpu_tests.py: the device answer, including a driver log line after the JSON, and the env override.
  • tests/test_make_game_argparse.py: test_custom_jobs_forwarded_to_shaders now patches the new device probe as it already did runtime_gpu_per_vertex. Without that patch it queried the real GPU, and on a Mac it got the flag.
  • python -m unittest discover -s tests/semantic: 1456 OK. I ran all 176 stdlib tests/test_*.py files and compileall is clean. The one failure, test_navmesh_index (test_differently_cased_report_path_cannot_be_scanned_input), fails the same way on main on this Mac's case-insensitive APFS, and is unrelated.

Unverified: how many of the game's VS fetch through a run-time V#, which needs a corpus count with game files, and whether any VS sets ADD_TID_ENABLE.

Validation-layer setup on the Mac: the test tools load MoltenVK directly. For the validation runs only, I used Homebrew's loader with a local copy of the MoltenVK ICD manifest marked is_portability_driver: false, since the tools don't opt in to portability enumeration. That adds an unrelated VUID-VkDeviceCreateInfo-pProperties-04451 to both runs.

Overlap

Some open PRs touch the same files:

None of them changes the same lines as far as I can see. Whichever lands second may need a trivial rebase.

No game data. AI-assisted (Claude Code).

🤖 Generated with Claude Code

…SHADER-302)

Since SHADER-231 every access through a run-time V# adds ADD_TID_ENABLE
times the wave lane, and outside compute and mesh shaders that lane is
SubgroupLocalInvocationId. MoltenVK has no subgroups in the vertex stage
(a Metal vertex function has no SIMD-group lane), so SPIRV-Cross stops
with "Subgroup builtins are not available in this type of function" and
any VS that fetches through a run-time V# (vs_m15) fails pipeline
creation on a Mac.

With --no-vertex-subgroups a VS leaves the lane out of a run-time V#'s
index (exact while the bit is clear; lane 0 when set) and refuses a
literal V# with the bit. vk_subgroup_info.py reports
vertex_in_supported_stages, and make_game.py and run_gpu_tests.py turn
the flag on where it is false (LEONIDA_NO_VERTEX_SUBGROUPS overrides the
runner; build.py takes =1), like --f16-interp-fallback.

Checked on an Apple M5 (MoltenVK 1.4.2): vk_pipeline_check creates 9 of
9 VS pipelines (8 of 9 on main), with the same validation messages; only
vs_m15.spv changes and run_gpu_tests.py gives the same result per test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sovljanskii

Copy link
Copy Markdown
Contributor

Tested 2acff9d3d1c8311961fc5148651bb56b5cff64f4 on Apple M4 (MoltenVK 1.4.2), macOS 27.2.1, LLVM 23.1.6, with my own 1.0.2.1 copy:

I translated all 2,236 VS of the corpus with --wave64-emulate --mesh-compute --f16-interp-fallback, adding --no-vertex-subgroups on the PR side. I used 4 shards and --merge, then ran vk_pipeline_check --jobs 4, built from this branch, on each side's output and stubs. The base is the merge base 89b047c.

base 89b047c this PR
translated / spirv-val valid 2,236 / 2,236 2,236 / 2,236 (nothing refused, so no VS has a literal V# with ADD_TID_ENABLE)
VS declaring GroupNonUniform* 1,568 1,207
VS declaring SubgroupLocalInvocationId 1,565 572
VS pipelines ok / failed / skipped 669 / 1,567 / 0 1,662 / 574 / 0
of those ok, wave32 / wave64 665 / 4 977 / 685

Failure classes. Each failed pipeline was re-run alone with MVK_CONFIG_LOG_LEVEL=1, because the bulk run doesn't log every failure:

  • base: 1,552 SPIR-V to MSL "Subgroup builtins are not available in this type of function"; 13 Metal compile "invalid 'threads_per_simdgroup' attribute for input declaration in a vertex function"; 2 Metal compile "no member named 'gl_CullDistance' in 'main0_out'".
  • PR: 1 SPIR-V to MSL subgroup-builtin error; 571 threads_per_simdgroup; 2 gl_CullDistance.

The PR gains 993 pipelines, and they are exactly the 993 VS whose index capabilities change:

  • 361 VS lose every subgroup capability.
  • 632 keep only GroupNonUniformVote. Metal accepts those votes in a vertex function.

The 572 VS that still fail all keep SubgroupLocalInvocationId from their own wave operations, and all 572 contain v_readfirstlane_b32. That is the row's "a VS's own wave operations" case, outside this PR. The 2 gl_CullDistance failures are the only two VS that write CullDistance. They fail the same way on both sides, and they pass on main 4eb6155.

What changes in the modules:

  • 1,552 of the 2,236 VS .spv change, all among the 1,565 that declared the lane builtin. The other 684 are byte-identical.
  • The changed modules shrink by 0.97% in total, and no module grows.
  • The opcodes removed are the lane load, the bit-23 extract, and the lane multiply and add of each access. Where an access has no idxen, the index terms of the swizzled address also go, and idx < num_records becomes num_records != 0. That is the row's rule with idx = 0, so it reads lane 0's element as the row says.
  • Without the flag, this branch's translation is byte-identical to the merge base's: all 2,236 VS and index.json.

GPU-test modules: 175 build here; I left out ps_ij_computed (#1680/#1681) and the ms_/gs_ fixtures. I built them with build.py and LEONIDA_F16_INTERP_FALLBACK=1, with and without LEONIDA_NO_VERTEX_SUBGROUPS=1. Only vs_m15.spv changes. VS pipelines go from 6 ok / 1 failed (vs_m15) to 7 / 0. CS (84 ok) and PS (83 ok, 1 skipped for no shaderFloat64) are the same on both sides.

The flag turns on by itself on this Mac:

  • vk_subgroup_info.py reports vertex_in_supported_stages: false. vulkaninfo shows subgroupSupportedStages = compute, fragment and tessellation control.
  • make_game.runtime_gpu_vertex_subgroups() returns False, and main() with no flag given passes ('--f16-interp-fallback', '--no-vertex-subgroups') to preflight() and shaders(). I mocked the stages and kept the probes real.
  • run_gpu_tests.no_vertex_subgroups() is True.
  • MoltenVK logs to stderr here. stdout is only the JSON line, even with MVK_CONFIG_LOG_LEVEL=3.

Rebasing onto main:

  • The branch no longer merges cleanly into main. The conflicts are in tools/rdna2spirv.py (next to F16_HALF_TOP, trivial), docs/design.md, tests/test_run_gpu_tests.py and tests/test_vk_subgroup_info.py.
  • I resolved the translator conflict on 4eb6155 and ran the same steps:
main 4eb6155 main + this PR
translated / valid 2,236 / 2,236 2,236 / 2,236
VS declaring SubgroupLocalInvocationId 1,569 753
VS pipelines ok / failed / skipped 667 / 1,569 / 0 1,483 / 753 / 0
  • The 181 more VS still failing on main come from Gen.mask_src (rdna2spirv: a constant used as a lane mask through an SGPR (or a b32 SOP2 on EXEC) gives each lane its bit #1792, which landed after this branch's base). An SGPR that isn't known to hold a lane mask, or an immediate other than 0 / -1, now gives each lane its bit through wave_lane(). Those VS keep SubgroupLocalInvocationId under the flag.
  • Failure classes on main + PR: 613 SPIR-V to MSL subgroup-builtin errors, 140 threads_per_simdgroup. After the rebase, the row's numbers and its "declares neither the builtin nor GroupNonUniform" wording need to cover that path too, or mask_src needs the same treatment.

Tests:

  • tests/semantic: 1456 OK. test_no_vertex_subgroups: 6 OK.
  • Negative control: against the base translator with only the NO_VERTEX_SUBGROUPS global added, 3 fail: both subtests of test_flag_declares_no_subgroup_builtin, and test_literal_add_tid_is_refused_under_the_flag.
  • Nit: test_flag_is_exact_while_the_bit_is_clear and test_flag_with_the_bit_set_reads_lane_zero also pass on base, because the interpreter's lane defaults to 0. So they don't tell the two apart.
  • test_vk_subgroup_info, test_make_game_translator_flags, test_run_gpu_tests and test_make_game_argparse pass, and fail on base.
  • 178 of the 202 tests/test_*.py exit 0. 23 need pytest, which isn't installed here. test_navmesh_index fails the same way on base (case-insensitive APFS).
  • compileall is clean.

No game data. AI-assisted.

@Jolymmiles

Copy link
Copy Markdown
Contributor

Tested under Wine on a Mac: this PR makes the Windows d3d12_translated_draw test pass there, and nothing else in the Wine list changes.

Setup: Apple M3 Max, macOS 27.3, CrossOver 26.3 (wine-11.0) with MoltenVK 1.4.3 (main 5189f8de, SPIRV-Cross 57e4efcc). Windows build cross-compiled with clang-cl 23.1.6 + xwin (runtime/cmake/clang-cl-xwin.cmake), run with scripts/run_wine_tests.py.

On main 4947579 the test fails at the PSO, the same error as in the description:

[mvk-error] SPIR-V to MSL conversion error: Subgroup builtins are not available in this type of function.
line 165: SUCCEEDED(device->CreateGraphicsPipelineState(&pso_desc, IID_PPV_ARGS(&pso.p)))

With this PR merged into 4947579 locally (conflicts resolved: F16_HALF_TOP = 29 from main, and both --max-shared-memory and --no-vertex-subgroups), and the build run as LEONIDA_NO_VERTEX_SUBGROUPS=1 cmake --build runtime/build/windows:

  • d3d12_translated_draw: 3 of 3 runs pass, "4064 of 4096 pixels exact, 32 edge pixels ... (0 its colour, 32 the clear colour)". The V# in that test has ADD_TID_ENABLE clear, so the lane-0 rule is exact there.
  • Of the shaders CMake generates for the D3D12 tests (generated/{m15,m2,m2f,m3,m4,buffer_uav,subgroup}_shaders), only vs_m15.spv/.spvasm change. The rest are byte-identical.
  • Full run_wine_tests.py list (125 tests): main 97 pass / 3 fail / 25 skip, main + this PR 98 / 2 / 25. The only per-test change is d3d12_translated_draw FAIL → PASS. The two remaining failures (d3d12_vulkan_device, d3d12_descriptor) are the same on both sides and unrelated.

One gap for the Windows/Wine path: the D3D12 tests' shaders are translated by CMake's custom command (runtime/CMakeLists.txt, test/shaders/build.py for m15), not by run_gpu_tests.py or make_game.py, so nothing probes the device there. The flag gets in only because cmake -E env inherits LEONIDA_NO_VERTEX_SUBGROUPS=1 from the cmake --build environment. Without it the test still fails on a Mac after this PR. A sentence in the new docs/testing.md section would cover it. Note also that ninja doesn't rebuild m15_shaders when the variable changes, so an existing build directory needs those outputs removed first.

No game data. AI-assisted (Claude Code).

ItsNotRexed pushed a commit that referenced this pull request Nov 22, 2026
…LSB (SHADER-413)

A native readfirstlane is a ballot of the EXEC lanes, its lowest set bit
and a shuffle from that lane. MoltenVK lowers OpGroupNonUniformBallotFindLSB,
like the SubgroupSize built-in, to Metal's threads_per_simdgroup input,
which a vertex function can't declare, so every VS with a readfirstlane
failed to compile on Apple GPUs.

In a vertex shader the lowest bit is now taken with FindILsb over the
ballot's four words, the form the --wave64-emulate path already uses on
its mask words. It gives the same lane, since a ballot has no bit at or
above the subgroup size. Other stages keep BallotFindLSB.

On an Apple M4 (MoltenVK 1.4.2), with the 1.0.2.1 corpus translated from
4eb6155: exactly the 572 VS that contain v_readfirstlane_b32 change, and
all 2,236 stay spirv-val-valid. VS pipelines go from 667 to 672 on main,
and from 1,662 to 2,233 of 2,236 with #1784's --no-vertex-subgroups.

tests/semantic/test_vs_readfirstlane.py runs it on the wave interpreter,
with the first EXEC lane in word 0 and word 1 of the ballot.

AI-assisted.
kapitche added a commit to kapitche/Leonida that referenced this pull request Nov 22, 2026
…ds use their own tool's flags

The any-flag check covers only the user-facing pages (README, CONTRIBUTING, AGENTS, i18n, docs/testing.md, the
runtime and semantic READMEs). Design and research notes such as docs/design.md cite flags of open pull requests
("ProjectLeonida#1784's --no-vertex-subgroups"), which no source has yet, so including them made the test fail on main. The
fenced-command check still runs on every page: a command block must use real flags of its script.
@bobcatchris

Copy link
Copy Markdown
Contributor

Independent MoltenVK check (claimed on #4571). Hardware correction: this machine reports Apple M2 / Mac14,3, not M1 — macOS 26.4 (25E246), MoltenVK 1.4.2 (device Vulkan 1.4.357), subgroup range 4..32, llvm-mc 23.1.6, Python 3.13.18.

Head 2acff9d3d1c8311961fc5148651bb56b5cff64f4, fetched read-only into its own worktree; clean build (cmake -S runtime -B runtime/build/vulkan -DVulkan_INCLUDE_DIR=/opt/homebrew/include + cmake --build runtime/build/vulkan --parallel) exit 0.

  • python -I scripts/run_gpu_tests.py --build runtime/build/vulkan: 170 shaders translated, 170 pass spirv-val; 102/166 passed, 62 skipped, 2 failed (ps_ij_computed missing .spv — translation failed on this older head, fixed later on main by GPU runners: ps_ij_computed SKIPs, not FAILs, without PerVertexKHR inputs (SHADER-177 follow-up) #1680/run_gpu_tests: skip ps_ij_computed under the PerVertexKHR fallbacks, and find the device JSON past driver logs #1681; ps_ssharp known MoltenVK LOD-bias case).
  • Device probe: vertex_in_supported_stages: false, and run_gpu_tests.no_vertex_subgroups() is True here, so the flag auto-enables on this Mac.
  • vs_m15 pipeline creation, via runtime/test/shaders/build.py + vk_pipeline_check <out>/spirv --stage graphics --jobs 4: without LEONIDA_NO_VERTEX_SUBGROUPS=1, VS pipelines 8 ok / 1 failed (vs_m15, -3); with the flag, 9 ok / 0 failed. So the fix itself passes on this Apple GPU.
  • check.py <out> runtime/build/vulkan with the flag: 68/150 pass, 78 skipped; the two failures are ps_ij_computed and ps_interp_f16_high (pipeline creation needs device features MoltenVK lacks here), not new to this PR.

Negative control on current upstream/main d0835dd9f9ec0a88faee510126436f2427854c2e, same commands: full suite 127/210 passed, 76 skipped, 7 failed. The fixture sets differ (166 vs 210 tests), so this is not a "same failures as base" claim; over the 166 common tests, no test that passes on main fails on this PR head (only cs_barrier_loop SKIP→PASS and ps_ij_computed SKIP→FAIL from the older tree). On main, vs_m15 is now SKIPPED (no shaderDenormPreserveFloat16 on this driver), so the pipeline A/B cannot be repeated against current main.

No code changes, no push, no game files; synthetic shaders and counts only.

AI-assisted.

@ashiikins

Copy link
Copy Markdown
Contributor

Scope on current code, for the rebase. Apple M2 Max, Homebrew MoltenVK 1.4.2, own 1.0.2.1 dump translated with --wave64-emulate --mesh-compute --f16-interp-fallback, vertex pipelines built with vk_pipeline_check. Counts only:

So on current main this PR's class is the whole VS failure set on Metal. I didn't test this PR itself (it conflicts with main); @bobcatchris's M2 result above is for its own head.

AI-assisted. No game files.

@shoal-rat

Copy link
Copy Markdown
Contributor Author

Superseded by #6160, which is rebuilt on current main and replaces this approach. Instead of dropping the lane from the ADD_TID path (lane 0), the VS computes its exact lane at entry: rank = exclusive add of 1, lane = the rank-th set bit of ballot(true). Metal compiles ballots and scans in vertex functions. This also covers the mask_src path and the VS's own wave operations that @sovljanskii found still failing after the rebase. #6160 also adds the CMake note from @Jolymmiles, fixes the test nit, and adds a GPU fixture (vs_lane_mask) that passes on an M5 with the flag and fails without it. Thanks everyone for the corpus, Wine and M2 runs here. I'll leave closing this to the maintainer, or close it once #6160 is reviewed. AI-assisted (Claude Code).

shoal-rat added a commit to shoal-rat/Leonida that referenced this pull request Nov 23, 2026
…HADER-302)

A VS reads its lane for the ADD_TID_ENABLE term of a run-time V# access
(SHADER-231), for a lane mask in an SGPR it can't prove is one
(Gen.mask_src, ProjectLeonida#1792) and for its own wave operations, and outside
compute and mesh shaders that lane is SubgroupLocalInvocationId. A Metal
vertex function has no SIMD-group lane id, so on MoltenVK SPIRV-Cross
stops with "Subgroup builtins are not available in this type of
function" and those VS fail pipeline creation.

With --no-vertex-subgroups a VS that reads its lane computes it at entry
into a Private %sg_lane: rank = exclusive add of 1, lane = position of
set bit `rank` of ballot(true). The ballot and the scan see the same
active invocations, so this is the invocation's own bit, equal to
SubgroupLocalInvocationId on any active set (subgroups up to 128).
Metal compiles ballots and scans in vertex functions. Other stages, and
everything without the flag, are unchanged.

vk_subgroup_info.py reports vertex_in_supported_stages; make_game.py and
run_gpu_tests.py turn the flag on where it is false
(LEONIDA_NO_VERTEX_SUBGROUPS overrides the runner, build.py takes =1).
The subgroup interpreter gains Inclusive/ExclusiveScan for the integer
group ops and loads through PhysicalStorageBuffer pointers (that branch
was dead code inside OpAccessChain).

New GPU fixture vs_lane_mask (a v_cndmask mask in user SGPR s2, drawn
with ps_flat): on an Apple M5 it passes with the flag and fails without
it with MoltenVK's subgroup-builtin error.

Supersedes ProjectLeonida#1784.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
shoal-rat added a commit to shoal-rat/Leonida that referenced this pull request Nov 23, 2026
…HADER-302)

A VS reads its lane for the ADD_TID_ENABLE term of a run-time V# access
(SHADER-231), for a lane mask in an SGPR it can't prove is one
(Gen.mask_src, ProjectLeonida#1792) and for its own wave operations, and outside
compute and mesh shaders that lane is SubgroupLocalInvocationId. A Metal
vertex function has no SIMD-group lane id, so on MoltenVK SPIRV-Cross
stops with "Subgroup builtins are not available in this type of
function" and those VS fail pipeline creation.

With --no-vertex-subgroups a VS that reads its lane computes it at entry
into a Private %sg_lane: rank = exclusive add of 1, lane = position of
set bit `rank` of ballot(true). The ballot and the scan see the same
active invocations, so this is the invocation's own bit, equal to
SubgroupLocalInvocationId on any active set (subgroups up to 128).
Metal compiles ballots and scans in vertex functions. Other stages, and
everything without the flag, are unchanged.

vk_subgroup_info.py reports vertex_in_supported_stages; make_game.py and
run_gpu_tests.py turn the flag on where it is false
(LEONIDA_NO_VERTEX_SUBGROUPS overrides the runner, build.py takes =1).
The subgroup interpreter gains Inclusive/ExclusiveScan for the integer
group ops and loads through PhysicalStorageBuffer pointers (that branch
was dead code inside OpAccessChain).

New GPU fixture vs_lane_mask (a v_cndmask mask in user SGPR s2, drawn
with ps_flat): on an Apple M5 it passes with the flag and fails without
it with MoltenVK's subgroup-builtin error.

Supersedes ProjectLeonida#1784.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
shoal-rat added a commit to shoal-rat/Leonida that referenced this pull request Nov 23, 2026
…HADER-302)

A VS reads its lane for the ADD_TID_ENABLE term of a run-time V# access
(SHADER-231), for a lane mask in an SGPR it can't prove is one
(Gen.mask_src, ItsNotRexed#1792) and for its own wave operations, and outside
compute and mesh shaders that lane is SubgroupLocalInvocationId. A Metal
vertex function has no SIMD-group lane id, so on MoltenVK SPIRV-Cross
stops with "Subgroup builtins are not available in this type of
function" and those VS fail pipeline creation.

With --no-vertex-subgroups a VS that reads its lane computes it at entry
into a Private %sg_lane: rank = exclusive add of 1, lane = position of
set bit `rank` of ballot(true). The ballot and the scan see the same
active invocations, so this is the invocation's own bit, equal to
SubgroupLocalInvocationId on any active set (subgroups up to 128).
Metal compiles ballots and scans in vertex functions. Other stages, and
everything without the flag, are unchanged.

vk_subgroup_info.py reports vertex_in_supported_stages; make_game.py and
run_gpu_tests.py turn the flag on where it is false
(LEONIDA_NO_VERTEX_SUBGROUPS overrides the runner, build.py takes =1).
The subgroup interpreter gains Inclusive/ExclusiveScan for the integer
group ops and loads through PhysicalStorageBuffer pointers (that branch
was dead code inside OpAccessChain).

New GPU fixture vs_lane_mask (a v_cndmask mask in user SGPR s2, drawn
with ps_flat): on an Apple M5 it passes with the flag and fails without
it with MoltenVK's subgroup-builtin error.

Supersedes ItsNotRexed#1784.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@shoal-rat

Copy link
Copy Markdown
Contributor Author

Closing as promised above: #6160 replaces this PR (same SHADER-302, exact lane instead of lane 0) and has been reviewed and approved there. AI-assisted (Claude Code).

@shoal-rat shoal-rat closed this Nov 23, 2026
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.

5 participants