fix(shader): run tessellation evaluation stages one lane per invocation on devices without subgroups there #13807

Merged
frankea merged 2 commits from upstream-pr/13807 into main 2026-11-01 01:35:27 +00:00
frankea commented 2026-10-31 07:30:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by frankea on 2026-10-31T07:30:20Z.


What

MoltenVK and lavapipe leave the tessellation evaluation stage out of subgroupSupportedStages. MoltenVK 1.4.2 on an Apple M5 Max reports TESSELLATION_CONTROL | FRAGMENT | COMPUTE (vulkaninfo; MVKDevice.mm adds only the control stage to fragment and compute), and lavapipe reports FRAGMENT | COMPUTE | TASK | MESH (lvp_device.c). The recompiler lays every tessellation evaluation program out for the device's subgroup width, so a domain program with lane operations declares GroupNonUniform and ValidateShaders refuses the draw: AGC graphics: subgroup capability 61 is unsupported for shader stage 4. #4470 handled the same refusal for the vertex stage.

  • Change. SpirvTarget::tessellationEvaluationSubgroups (default true) records whether the device has subgroups in that stage; VulkanDevice::buildTarget sets it from subgroupSupportedStages, next to vertexSubgroups. When it is false, HostSubgroupSize gives tessellation evaluation programs a host subgroup width of 1, so they take the one-lane rules #4470 added for vertex programs: the lane id is 0, a ballot is the invocation's own bit, a shuffle returns the invocation's own value and an elect is true. A v_readlane_b32 of another lane named by a constant throws; a lane selector held in a register is not checked and reads the invocation's own value, as on the vertex path (recorded in the debt entry; a check for it, on both paths, is left for a follow-up). Devices with subgroups in the stage emit the same SPIR-V as before.
  • Tessellation followed by a geometry program. A domain program compiled with graphics->mesh set (tessellation followed by a guest geometry program: the domain program feeds the generated capture geometry stage and the geometry half runs on the mesh path) keeps the device width. That path needs geometry and mesh shaders, which MoltenVK does not have, and it is not exercised here.
  • Cache and replay. The flag joins RecompileCacheKey, and the request serialization moves to version 51 with the flag as its last byte; older requests read it as true, and version 50 is rejected. I skipped 50 because 12 open pull requests already write it (#7410, #9020, #9335, #9748, #10359, #10547, #10846, #11351, #11483, #11551, #12662, #12980), and they are the only open pull requests whose changes conflict with this one (the version lines and the serialization tests). The shader disk cache format is unchanged: its key already holds the RecompileCacheKey words and the host subgroup width, and no encoded field changes.
  • Debt. One new entry in docs/dev/debt/shader.md for the one-lane tessellation evaluation waves.

Title: Gran Turismo 7 (PPSA01317) on an Apple M5 Max through MoltenVK stops with this error at the Used Car dealership's car showcase, about 870 s into a run, on its own domain programs. The new Tessellation.cpp draw reproduces that refusal on MoltenVK without this change and passes with it (see Tested); I have no GT7 run with this change that has reached the dealership yet.

Tested

Windows 11 on an RTX 4090 (driver 616.92, Vulkan 1.4.341), winlibs GCC 15.2.0, Release with BUILD_TESTING=ON. The 4090 has subgroups in the tessellation evaluation stage, so its draws keep the subgroup path; the one-lane path runs there only in verifySingleLaneDomainWave, which compiles for explicit targets.

  • 33 ctest entries pass 3 times in a row on this branch (53e4e8e796, and again at 32a6bdb6d3) and on main 833be4af8d: request_serializer, the 21 entries of agc_shader_memory_tests, agc_driver_tessellation, agc_driver_tessellation_depth_range_remap, agc_tessellation_pipeline_cache, agc_tessellation_factor_ring, agc_tessellation_lowering, agc_depth_range_remap, agc_driver_pixel_barycentric_emulation, agc_driver_mesh_barycentric_emulation, agc_driver_rect_list_corner, agc_driver_provoking_vertex and agc_driver_vertex_elected_atomic_max (skipped: the 4090 has vertex subgroups). They pass once more under VK_LAYER_KHRONOS_validation with ANYPS5_NO_SHADER_CACHE=1 and ANYPS5_REQUIRE_VULKAN=1 (ctest -V) on both, with no VUID- lines and no was not found but was requested by env var VK_INSTANCE_LAYERS; the loader log for agc_driver_tessellation in that environment shows the layer inserted.

Apple M5 Max, macOS 27.0.1, MoltenVK 1.4.2 (Vulkan SDK 1.4.363.0), x86-64 under Rosetta 2:

  • request_serializer and the 21 agc_shader_memory_tests entries pass 3 times in a row on this branch, built natively. Two local build aids that are not part of this pull request were needed for that: the duplicate write_watch test registration removed as in #13220, and the GuestMemory.cpp part of #11447.
  • main does not build the AGC driver on macOS by itself, so the GPU check runs on my macOS tree (main 102b7a5cf with the open macOS host pull requests and my open GT7 pull requests) at 48539c856b, which carries the same change (serialization version 52 there), with this pull request's Tessellation.cpp change applied. The new draw passes, and agc_driver_tessellation then stops at a later check, did not take its blue channel from the hull's relative patch index across instances, which fails the same way on that tree with neither the change nor the new draw. With only the HostSubgroupSize line removed, the new draw stops with AGC graphics: subgroup capability 61 is unsupported for shader stage 4, the error GT7 hits. Under VK_LAYER_KHRONOS_validation (inserted, per VK_LOADER_DEBUG=layer) the run with the change has no VUID- lines.

New checks:

  • verifySingleLaneDomainWave (tests/ShaderMemory.cpp): domain programs with lane operations and with a v_readlane_b32 waterfall loop declare no subgroup capability, built-in or instruction without tessellation evaluation subgroups, whatever the device's subgroup width, and still use subgroup operations with them; turning off vertex subgroups leaves a domain program on subgroups and turning off tessellation evaluation subgroups leaves a vertex program on them; a read of lane 31 throws; the flag survives serialization and changes the cache key. With the HostSubgroupSize line removed it fails with a domain program without tessellation evaluation subgroups declared a subgroup capability, built-in or instruction.
  • RequestSerializerTests.cpp: both values round-trip at version 51 as its last byte, a version 51 request without it is rejected as truncated, a version 49 request reads true and is written back as version 51 with the flag set, and a version 50 request is rejected in either layout (as is NVNQQTIAAAA= in ShaderMemory.cpp's unsupported-version list); both rejection checks fail with the version 50 check removed. The existing layout checks move by the one trailing byte.
  • DomainFirstLaneCount (tests/execution/Tessellation.cpp): DomainCode with its depth taken from v_cvt_f32_u32 of v_readfirstlane_b32 of v_mbcnt (0 at any wave width), drawn through RequirePatches. It runs on subgroups on the 4090 and one lane per invocation on MoltenVK; lavapipe in CI takes the one-lane path too, which I could not run here.
  • tools/check_conventions.py --base origin/main passes, and the branch merges cleanly with main 828ac0b2ae, whose 19 new commits touch none of its files. tools/pr_overlap.py --branch fix/tes-single-lane-without-subgroups against main de83e8f270 finds only the 12 version 50 pull requests above; 51 pull requests that conflict with main themselves share files with this branch and could not be compared.

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 under Silent stubs in their library's technical debt file
  • 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
  • Fixes: none
  • Unblocks: PPSA01317 #4697 (Gran Turismo 7), domain programs with lane operations at the Used Car dealership on Apple GPUs through MoltenVK
  • GPUs tested: NVIDIA RTX 4090 (Windows 11, driver 616.92, Vulkan 1.4.341); Apple M5 Max (macOS 27.0.1, MoltenVK 1.4.2)
  • AI-assisted: yes (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5095579657 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13807). Originally posted by [frankea](https://github.com/frankea) on 2026-10-31T07:30:20Z. --- ### What MoltenVK and lavapipe leave the tessellation evaluation stage out of `subgroupSupportedStages`. MoltenVK 1.4.2 on an Apple M5 Max reports `TESSELLATION_CONTROL | FRAGMENT | COMPUTE` (`vulkaninfo`; [MVKDevice.mm](https://github.com/KhronosGroup/MoltenVK/blob/5189f8de86ec365860f63bf1da736815cfaea5cd/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm#L1486-L1489) adds only the control stage to fragment and compute), and lavapipe reports `FRAGMENT | COMPUTE | TASK | MESH` ([lvp_device.c](https://gitlab.freedesktop.org/mesa/mesa/-/blob/fd8ef2befafd01190e33f12dbfd109b924c8ebc3/src/gallium/frontends/lavapipe/lvp_device.c#L1108)). The recompiler lays every tessellation evaluation program out for the device's subgroup width, so a domain program with lane operations declares `GroupNonUniform` and `ValidateShaders` refuses the draw: `AGC graphics: subgroup capability 61 is unsupported for shader stage 4`. #4470 handled the same refusal for the vertex stage. - **Change.** `SpirvTarget::tessellationEvaluationSubgroups` (default `true`) records whether the device has subgroups in that stage; `VulkanDevice::buildTarget` sets it from `subgroupSupportedStages`, next to `vertexSubgroups`. When it is `false`, `HostSubgroupSize` gives tessellation evaluation programs a host subgroup width of 1, so they take the one-lane rules #4470 added for vertex programs: the lane id is 0, a ballot is the invocation's own bit, a shuffle returns the invocation's own value and an elect is true. A `v_readlane_b32` of another lane named by a constant throws; a lane selector held in a register is not checked and reads the invocation's own value, as on the vertex path (recorded in the debt entry; a check for it, on both paths, is left for a follow-up). Devices with subgroups in the stage emit the same SPIR-V as before. - **Tessellation followed by a geometry program.** A domain program compiled with `graphics->mesh` set (tessellation followed by a guest geometry program: the domain program feeds the generated capture geometry stage and the geometry half runs on the mesh path) keeps the device width. That path needs geometry and mesh shaders, which MoltenVK does not have, and it is not exercised here. - **Cache and replay.** The flag joins `RecompileCacheKey`, and the request serialization moves to version 51 with the flag as its last byte; older requests read it as `true`, and version 50 is rejected. I skipped 50 because 12 open pull requests already write it (#7410, #9020, #9335, #9748, #10359, #10547, #10846, #11351, #11483, #11551, #12662, #12980), and they are the only open pull requests whose changes conflict with this one (the version lines and the serialization tests). The shader disk cache format is unchanged: its key already holds the `RecompileCacheKey` words and the host subgroup width, and no encoded field changes. - **Debt.** One new entry in `docs/dev/debt/shader.md` for the one-lane tessellation evaluation waves. Title: Gran Turismo 7 (PPSA01317) on an Apple M5 Max through MoltenVK stops with this error at the Used Car dealership's car showcase, about 870 s into a run, on its own domain programs. The new `Tessellation.cpp` draw reproduces that refusal on MoltenVK without this change and passes with it (see Tested); I have no GT7 run with this change that has reached the dealership yet. ### Tested Windows 11 on an RTX 4090 (driver 616.92, Vulkan 1.4.341), winlibs GCC 15.2.0, Release with `BUILD_TESTING=ON`. The 4090 has subgroups in the tessellation evaluation stage, so its draws keep the subgroup path; the one-lane path runs there only in `verifySingleLaneDomainWave`, which compiles for explicit targets. - 33 ctest entries pass 3 times in a row on this branch (`53e4e8e796`, and again at `32a6bdb6d3`) and on `main` 833be4af8d: `request_serializer`, the 21 entries of `agc_shader_memory_tests`, `agc_driver_tessellation`, `agc_driver_tessellation_depth_range_remap`, `agc_tessellation_pipeline_cache`, `agc_tessellation_factor_ring`, `agc_tessellation_lowering`, `agc_depth_range_remap`, `agc_driver_pixel_barycentric_emulation`, `agc_driver_mesh_barycentric_emulation`, `agc_driver_rect_list_corner`, `agc_driver_provoking_vertex` and `agc_driver_vertex_elected_atomic_max` (skipped: the 4090 has vertex subgroups). They pass once more under `VK_LAYER_KHRONOS_validation` with `ANYPS5_NO_SHADER_CACHE=1` and `ANYPS5_REQUIRE_VULKAN=1` (`ctest -V`) on both, with no `VUID-` lines and no `was not found but was requested by env var VK_INSTANCE_LAYERS`; the loader log for `agc_driver_tessellation` in that environment shows the layer inserted. Apple M5 Max, macOS 27.0.1, MoltenVK 1.4.2 (Vulkan SDK 1.4.363.0), x86-64 under Rosetta 2: - `request_serializer` and the 21 `agc_shader_memory_tests` entries pass 3 times in a row on this branch, built natively. Two local build aids that are not part of this pull request were needed for that: the duplicate `write_watch` test registration removed as in #13220, and the `GuestMemory.cpp` part of #11447. - `main` does not build the AGC driver on macOS by itself, so the GPU check runs on my macOS tree (`main` 102b7a5cf with the open macOS host pull requests and my open GT7 pull requests) at `48539c856b`, which carries the same change (serialization version 52 there), with this pull request's `Tessellation.cpp` change applied. The new draw passes, and `agc_driver_tessellation` then stops at a later check, `did not take its blue channel from the hull's relative patch index across instances`, which fails the same way on that tree with neither the change nor the new draw. With only the `HostSubgroupSize` line removed, the new draw stops with `AGC graphics: subgroup capability 61 is unsupported for shader stage 4`, the error GT7 hits. Under `VK_LAYER_KHRONOS_validation` (inserted, per `VK_LOADER_DEBUG=layer`) the run with the change has no `VUID-` lines. New checks: - `verifySingleLaneDomainWave` (`tests/ShaderMemory.cpp`): domain programs with lane operations and with a `v_readlane_b32` waterfall loop declare no subgroup capability, built-in or instruction without tessellation evaluation subgroups, whatever the device's subgroup width, and still use subgroup operations with them; turning off vertex subgroups leaves a domain program on subgroups and turning off tessellation evaluation subgroups leaves a vertex program on them; a read of lane 31 throws; the flag survives serialization and changes the cache key. With the `HostSubgroupSize` line removed it fails with `a domain program without tessellation evaluation subgroups declared a subgroup capability, built-in or instruction`. - `RequestSerializerTests.cpp`: both values round-trip at version 51 as its last byte, a version 51 request without it is rejected as truncated, a version 49 request reads `true` and is written back as version 51 with the flag set, and a version 50 request is rejected in either layout (as is `NVNQQTIAAAA=` in `ShaderMemory.cpp`'s unsupported-version list); both rejection checks fail with the version 50 check removed. The existing layout checks move by the one trailing byte. - `DomainFirstLaneCount` (`tests/execution/Tessellation.cpp`): `DomainCode` with its depth taken from `v_cvt_f32_u32` of `v_readfirstlane_b32` of `v_mbcnt` (0 at any wave width), drawn through `RequirePatches`. It runs on subgroups on the 4090 and one lane per invocation on MoltenVK; lavapipe in CI takes the one-lane path too, which I could not run here. - `tools/check_conventions.py --base origin/main` passes, and the branch merges cleanly with `main` 828ac0b2ae, whose 19 new commits touch none of its files. `tools/pr_overlap.py --branch fix/tes-single-lane-without-subgroups` against `main` de83e8f270 finds only the 12 version 50 pull requests above; 51 pull requests that conflict with `main` themselves share files with this branch and could not be compared. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: PPSA01317 #4697 (Gran Turismo 7), domain programs with lane operations at the Used Car dealership on Apple GPUs through MoltenVK - [x] GPUs tested: NVIDIA RTX 4090 (Windows 11, driver 616.92, Vulkan 1.4.341); Apple M5 Max (macOS 27.0.1, MoltenVK 1.4.2) - [x] AI-assisted: yes (Claude Code)
jotitadev commented 2026-10-31 15:08:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-31T15:08:40Z.

Review: COMMENTED


The lavapipe run the description says it couldn't get, of head 32a6bdb6d3. Lavapipe has no subgroups in the tessellation evaluation stage, so it takes the new one-lane path. That path works, and the new draw catches the refusal without the change.

Setup: Ubuntu 26.04, GCC 15.2, Release. Lavapipe from Mesa 26.0.3; its subgroupSupportedStages here is FRAGMENT | COMPUTE | TASK | MESH. An RTX 3070 with NVIDIA 595.99.02 serves as a control, since it has subgroups in that stage. The head is merged --no-ff onto main 809c7fa2df with no conflicts. ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1, ctest -j1.

  • Green, lavapipe: the 24 entries of agc_driver_tessellation_tests, agc_shader_memory_tests and request_serializer_tests pass 3/3 with VVL 1.4.341, with no VUID- lines. agc_driver_tessellation runs all the way to Tessellation tests passed, with no skip of the new draw. The only skips are the two unmapped hull-read checks that llvmpipe always skips.
  • Green, 3070: the same 24 pass with VVL 1.3.275 and with no layer.
  • Red, lavapipe: main plus only this PR's Tessellation.cpp fails agc_driver_tessellation with AGC graphics: subgroup capability 61 is unsupported for shader stage 4. That's the GT7 error. On the 3070, the same red passes, as expected.
  • ^agc on lavapipe (minus dcc/flip/lds_atomics64): 1132/1132 with the PR.

GPUs tested: Mesa 26.0.3 lavapipe, Ubuntu 26.04 (one-lane path); NVIDIA GeForce RTX 3070, 595.99.02, Ubuntu 26.04 (subgroup path)

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5723466556 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13807#pullrequestreview-5723466556). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-31T15:08:40Z. **Review:** COMMENTED --- The lavapipe run the description says it couldn't get, of head `32a6bdb6d3`. Lavapipe has no subgroups in the tessellation evaluation stage, so it takes the new one-lane path. That path works, and the new draw catches the refusal without the change. Setup: Ubuntu 26.04, GCC 15.2, Release. Lavapipe from Mesa 26.0.3; its `subgroupSupportedStages` here is `FRAGMENT | COMPUTE | TASK | MESH`. An RTX 3070 with NVIDIA 595.99.02 serves as a control, since it has subgroups in that stage. The head is merged `--no-ff` onto `main` `809c7fa2df` with no conflicts. `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1`, `ctest -j1`. - **Green, lavapipe:** the 24 entries of `agc_driver_tessellation_tests`, `agc_shader_memory_tests` and `request_serializer_tests` pass 3/3 with VVL 1.4.341, with no `VUID-` lines. `agc_driver_tessellation` runs all the way to `Tessellation tests passed`, with no skip of the new draw. The only skips are the two unmapped hull-read checks that llvmpipe always skips. - **Green, 3070:** the same 24 pass with VVL 1.3.275 and with no layer. - **Red, lavapipe:** `main` plus only this PR's `Tessellation.cpp` fails `agc_driver_tessellation` with `AGC graphics: subgroup capability 61 is unsupported for shader stage 4`. That's the GT7 error. On the 3070, the same red passes, as expected. - **`^agc` on lavapipe** (minus dcc/flip/lds_atomics64): 1132/1132 with the PR. GPUs tested: Mesa 26.0.3 lavapipe, Ubuntu 26.04 (one-lane path); NVIDIA GeForce RTX 3070, 595.99.02, Ubuntu 26.04 (subgroup path) Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!13807
No description provided.