Skip to content

feat(shader): lower vertex-stage subgroup use to lane-local code on devices without it - #6

Merged
giljakoki merged 1 commit into
mainfrom
claude/vertex-subgroups
Oct 12, 2026
Merged

giljakoki merged 1 commit into
mainfrom
claude/vertex-subgroups

Conversation

@giljakoki

Copy link
Copy Markdown
Owner

What

Handover 1 of #5, phases 1 and 2: MoltenVK has no subgroup operations in vertex and tessellation-evaluation shaders (subgroupSupportedStages = 0x32), so every vertex program whose SPIR-V declared GroupNonUniform stopped PvZ and Hades II at their first draws with subgroup capability 61 is unsupported for shader stage 1, without saying which construct needed it.

  • Plumbing. SpirvTarget::subgroupStages carries the device's stage mask into every cache key and the request serializer (version 17). APS5_SUBGROUP_STAGES=<hex> removes stages from any device (the Selected GPU line now shows stages= and operations=), and agc_shader_replay --subgroup-stages=<hex> replays a dumped request as MoltenVK.
  • Exact lane-local lowering (LaneLocalLowering, after the static interface is applied) for vertex, local and tessellation-evaluation programs on a target that lacks the stage: lane-index values that are the same for every lane of the wave s3 describes (the NGG v_mbcnt prologue), own-lane bit tests of ballot words (VOPC into VCC/SGPRs, v_cndmask, carry chains, s_*_saveexec, EXEC restores, s_cselect of masks), first-lane reads of wave-uniform values, and execz/execnz/vccz/vccnz regions proven EXEC-masked with merge phis unchanged for the lanes that skip them. Wave-uniform and constant branch conditions become plain branches.
  • Diagnostics. What is left stops the program with vertex program 0x… (wave64, s3 counts 32) needs subgroup operations, which the device does not support in vertex shaders (subgroup stages 0x32); exact lowering left: <construct> at 0x…-0x…, replayable through the appended request. The SPIR-V emitter refuses any leftover subgroup use for such a stage, and the driver's validator names the program, stage, wave and device masks. APS5_DUMP_IR now prints block terminators.

Rank 3 of the design (APS5_ONE_LANE_WAVES) is not included; neither title needed it.

Tested

macOS 27.0.1, M5 Pro, MoltenVK from the LunarG SDK:

  • agc_shader_memory_tests (new verifyStagesWithoutSubgroups: lowered modules carry no subgroup capability, instruction or built-in; the same programs keep them on a device with vertex subgroups; s_bcnt1 of EXEC, an SGPR written in an execz region and read after the join, a waterfall loop and DPP are refused with the construct named; serializer round trip; separate sources per stage mask), agc_shader_disk_cache_tests, agc_driver_graphics_tests.
  • agc_driver_vertex_lane_local_tests (new): 189 vertices through a wave32 and a wave64 program with v_cmp/v_cndmask, a VCC carry chain, an s_cbranch_execz region and v_mbcnt against the s3 count write the CPU-expected values on MoltenVK. agc_driver_exec_host_lanes_tests: the waterfall vertex program is refused with a wave-mask branch controls a loop. Both are also registered with APS5_SUBGROUP_STAGES=0x32 for Linux and Windows.
  • PvZ (PPSA29802, APS5_MSAA_SINGLE_SAMPLE=1): no longer stops; runs at 60 fps with sound. Its next stop was a rect-list draw rejected every frame (black screen), fixed in the follow-up PR.
  • Hades II (PPSA36082): no longer stops at the draw; it now dies with a null dereference in its own code on a guest thread right after opening Content/Packages/1080p/GUI.pkg (log line ~1070, crash report eboot-2026-10-11-215305.ips). With main's driver it still stops at the subgroup error at line 834, so this is its next stop, not a regression of the lowering; all 117 of its registered programs replay cleanly with --subgroup-stages=0x32.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

🤖 Generated with Claude Code

…evices without it

MoltenVK has no subgroup operations in vertex and tessellation-evaluation
shaders, so every vertex program whose SPIR-V declared GroupNonUniform
stopped the title at validation, without saying which construct needed it.

The device's subgroupSupportedStages now reaches the recompiler target,
every cache key and the request serializer (version 17). For a vertex,
local or tessellation-evaluation program on a target that lacks the stage,
LaneLocalLowering rewrites what is exact for each invocation on its own:
lane-index values equal in every lane of the wave s3 describes, own-lane
bit tests of ballot words, first-lane reads of wave-uniform values, and
execz/vccz regions proven EXEC-masked with unchanged merge phis. What is
left stops the program with its guest addresses; the SPIR-V emitter and
the driver's validator refuse any leftover use with the program named.
APS5_SUBGROUP_STAGES=<hex> and agc_shader_replay --subgroup-stages test
this on any GPU.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@giljakoki
giljakoki merged commit 4507aed into main Oct 12, 2026
17 checks passed
@giljakoki
giljakoki deleted the claude/vertex-subgroups branch October 12, 2026 04:06
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.

2 participants