fix(shader): keep clip distances in the blocks between the barycentric tessellation stages #7487

Merged
DavidSamir merged 3 commits from upstream-pr/7487 into main 2026-10-18 11:13:34 +00:00
DavidSamir commented 2026-10-18 09:12:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-18T09:12:01Z.


What

#7330 fixed #7328: our generated tessellation stages declared ClipDistance inside their gl_PerVertex input block, while the vertex shader writes it as a separate built-in array, so the validation layer reported VUID-RuntimeSpirv-OpVariable-08746. Its fix passes ClipDistance as separate built-in arrays through both generated stages.

That broke the route these stages exist for: Apple GPUs under MoltenVK, which have no geometry shaders. SPIRV-Cross, which MoltenVK uses to translate SPIR-V to Metal, cannot handle a separate ClipDistance array in a tessellation evaluation stage:

program_source:134:39: error: no member named 'gl_ClipDistance' in 'main0_out'
    spvArrayCopyFromDeviceToStack(out.gl_ClipDistance, gl_in[_50].elements);
[mvk-error] VK_ERROR_INITIALIZATION_FAILED: Tessellation evaluation shader function could not be compiled into pipeline.

As a result, every pipeline on the barycentric tessellation route fails with vkCreateGraphicsPipelines: Vulkan result -3 on macOS.

This PR keeps #7330's fix where it applies and goes back to the block where it doesn't. VUID-08746 concerns the vertex-to-control interface, so:

  • Control stage input: it still reads {Position} plus the separate ClipDistance array, exactly what the vertex shader writes.
  • Control stage output and evaluation stage: these interfaces exist only between the two generated stages. Here ClipDistance goes back inside the per-vertex block {Position, ClipDistance}, which SPIRV-Cross translates. That's the layout MoltenVK ran with in #7308.

Without vertex clip distances, the stages are unchanged. The unit test now checks both: the separate array on the control stage's input, the block member on its output, and only the block member on the evaluation stage. The shader.md entry explains why.

Tested

Apple M2, macOS 26.7.2, MoltenVK 1.4.2 (no geometryShader), x86-64 under Rosetta. The test stack is current main (e5c2b3c32) plus mugurc's macOS port branches (ci/macos-series-2), with our open macOS PRs including #7426, and with #6535 so the titles below get past the depth-range check first. Release build, ANYPS5_NO_SHADER_CACHE=1. The changed files also compile on this Mac against plain main, and the conventions check passes.

  • agc_driver_pixel_barycentric_emulation: fails on main at the first tessellation pipeline (MoltenVK's errors above). With this PR it passes the tessellation route: 932 perspective and 932 linear I/J pixels, raw vertex values, host interpolation, face culling, and flat inputs in first and last provoking vertex mode.
  • Validation layer (VK_LAYER_KHRONOS_validation 1.4.363) with this PR: no VUID-RuntimeSpirv-OpVariable-08746. The only message is the unrelated VUID-VkImageCreateInfo-usage-00968, which main also reports. So #7328 stays fixed.
  • agc_driver_graphics_tests: passes, including the updated clip-interface checks.

Titles (homebrew catalog, checksum-checked, relinked for macOS, 45 s each, same build with and without this PR):

Title main This PR
EVO Player (PPSA99039) aborts at 37 s, vkCreateGraphicsPipelines: Vulkan result -3 (evaluation stage) runs 45 s
Nuvio PS5 (PPSA99997) aborts at 15 s, same error runs 45 s
Jelly5 (PPSA99505) aborts at 14 s, same error runs 45 s
Twispero (PPSA99474) aborts at 6 s, same error runs 45 s
CD Player (PPSA98427) aborts at 4 s, same error runs 45 s
ProsperoStore (PPSA99000) aborts at 16 s, same error runs 45 s

Without #6535, these titles stop earlier on current main at viewport depth outside [0, 1] requires VK_EXT_depth_range_unrestricted. CD Player and ProsperoStore also need #7426 (last provoking vertex), which is in the stack.

Device limits of the M2 that stop titles here, not tested past them: no geometryShader, shaderFloat64, VK_EXT_provoking_vertex or VK_EXT_depth_range_unrestricted.

Not tested: Windows and Linux. There, devices with geometry shaders don't use this route; the validation result above covers the interface rule #7328 is about.

@MarcZX100 @Amoenus FYI, since this adjusts #7330 / #7328.

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 (the titles also need #6535 to reach this draw on current main)
  • Fixes: none
  • Unblocks: PPSA99039, PPSA99997, PPSA99505, PPSA99474, PPSA98427, PPSA99000 on macOS (#1)
  • GPUs tested: Apple M2, MoltenVK 1.4.2, macOS 26.7.2 (x86-64 under Rosetta)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4907850045 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7487). Originally posted by [DavidSamir](https://github.com/DavidSamir) on 2026-10-18T09:12:01Z. --- ### What #7330 fixed #7328: our generated tessellation stages declared `ClipDistance` inside their `gl_PerVertex` input block, while the vertex shader writes it as a separate built-in array, so the validation layer reported VUID-RuntimeSpirv-OpVariable-08746. Its fix passes `ClipDistance` as separate built-in arrays through both generated stages. That broke the route these stages exist for: Apple GPUs under MoltenVK, which have no geometry shaders. SPIRV-Cross, which MoltenVK uses to translate SPIR-V to Metal, cannot handle a separate `ClipDistance` array in a tessellation evaluation stage: ``` program_source:134:39: error: no member named 'gl_ClipDistance' in 'main0_out' spvArrayCopyFromDeviceToStack(out.gl_ClipDistance, gl_in[_50].elements); [mvk-error] VK_ERROR_INITIALIZATION_FAILED: Tessellation evaluation shader function could not be compiled into pipeline. ``` As a result, every pipeline on the barycentric tessellation route fails with `vkCreateGraphicsPipelines: Vulkan result -3` on macOS. This PR keeps #7330's fix where it applies and goes back to the block where it doesn't. VUID-08746 concerns the vertex-to-control interface, so: - **Control stage input:** it still reads `{Position}` plus the separate `ClipDistance` array, exactly what the vertex shader writes. - **Control stage output and evaluation stage:** these interfaces exist only between the two generated stages. Here `ClipDistance` goes back inside the per-vertex block `{Position, ClipDistance}`, which SPIRV-Cross translates. That's the layout MoltenVK ran with in #7308. Without vertex clip distances, the stages are unchanged. The unit test now checks both: the separate array on the control stage's input, the block member on its output, and only the block member on the evaluation stage. The `shader.md` entry explains why. ### Tested Apple M2, macOS 26.7.2, MoltenVK 1.4.2 (no `geometryShader`), x86-64 under Rosetta. The test stack is current `main` (e5c2b3c32) plus mugurc's macOS port branches (`ci/macos-series-2`), with our open macOS PRs including #7426, and with #6535 so the titles below get past the depth-range check first. Release build, `ANYPS5_NO_SHADER_CACHE=1`. The changed files also compile on this Mac against plain `main`, and the conventions check passes. - **`agc_driver_pixel_barycentric_emulation`:** fails on `main` at the first tessellation pipeline (MoltenVK's errors above). With this PR it passes the tessellation route: 932 perspective and 932 linear I/J pixels, raw vertex values, host interpolation, face culling, and flat inputs in first and last provoking vertex mode. - **Validation layer (`VK_LAYER_KHRONOS_validation` 1.4.363) with this PR:** no VUID-RuntimeSpirv-OpVariable-08746. The only message is the unrelated `VUID-VkImageCreateInfo-usage-00968`, which `main` also reports. So #7328 stays fixed. - **`agc_driver_graphics_tests`:** passes, including the updated clip-interface checks. **Titles** (homebrew catalog, checksum-checked, relinked for macOS, 45 s each, same build with and without this PR): | Title | `main` | This PR | | --- | --- | --- | | EVO Player (PPSA99039) | aborts at 37 s, `vkCreateGraphicsPipelines: Vulkan result -3` (evaluation stage) | runs 45 s | | Nuvio PS5 (PPSA99997) | aborts at 15 s, same error | runs 45 s | | Jelly5 (PPSA99505) | aborts at 14 s, same error | runs 45 s | | Twispero (PPSA99474) | aborts at 6 s, same error | runs 45 s | | CD Player (PPSA98427) | aborts at 4 s, same error | runs 45 s | | ProsperoStore (PPSA99000) | aborts at 16 s, same error | runs 45 s | Without #6535, these titles stop earlier on current `main` at `viewport depth outside [0, 1] requires VK_EXT_depth_range_unrestricted`. CD Player and ProsperoStore also need #7426 (last provoking vertex), which is in the stack. **Device limits of the M2 that stop titles here, not tested past them:** no `geometryShader`, `shaderFloat64`, `VK_EXT_provoking_vertex` or `VK_EXT_depth_range_unrestricted`. **Not tested:** Windows and Linux. There, devices with geometry shaders don't use this route; the validation result above covers the interface rule #7328 is about. @MarcZX100 @Amoenus FYI, since this adjusts #7330 / #7328. ### 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 (the titles also need #6535 to reach this draw on current `main`) - [x] Fixes: none - [x] Unblocks: PPSA99039, PPSA99997, PPSA99505, PPSA99474, PPSA98427, PPSA99000 on macOS (#1) - [x] GPUs tested: Apple M2, MoltenVK 1.4.2, macOS 26.7.2 (x86-64 under Rosetta) - [x] AI-assisted: yes
DavidSamir commented 2026-10-18 09:12:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-18T09:12:44Z.


Overlap note: this PR and #7426 (last provoking vertex through the same stages) edit adjacent lines of BarycentricGeometryShader.cpp and the same shader.md entry, so whichever merges second needs a small merge. The combination, with #7426's flat-value line next to this PR's clip line, is what ran the titles above. I'll push that merge as soon as the first one lands.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6248093542 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7487#issuecomment-6248093542). Originally posted by [DavidSamir](https://github.com/DavidSamir) on 2026-10-18T09:12:44Z. --- Overlap note: this PR and #7426 (last provoking vertex through the same stages) edit adjacent lines of `BarycentricGeometryShader.cpp` and the same `shader.md` entry, so whichever merges second needs a small merge. The combination, with #7426's flat-value line next to this PR's clip line, is what ran the titles above. I'll push that merge as soon as the first one lands. AI-assisted: yes
github-actions[bot] commented 2026-10-18 09:20:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-18T09:20:03Z.


Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 1395 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 4040 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 4650 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 5021 docs/dev/debt/shader.md
PR 5371 docs/dev/debt/shader.md
PR 5426 docs/dev/debt/shader.md
PR 5441 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 5499 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 5500 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/shader.md
PR 5925 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 5941 docs/dev/debt/shader.md
PR 5958 docs/dev/debt/shader.md
PR 5999 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6009 docs/dev/debt/shader.md
PR 6054 docs/dev/debt/shader.md
PR 6094 docs/dev/debt/shader.md
PR 6188 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6194 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6222 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/shader.md
PR 6235 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/shader.md
PR 6297 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6320 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6412 docs/dev/debt/shader.md
PR 6472 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6481 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6488 docs/dev/debt/shader.md
PR 6529 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6535 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6548 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6563 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6674 docs/dev/debt/shader.md
PR 6783 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6808 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6972 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6977 docs/dev/debt/shader.md
PR 7223 docs/dev/debt/shader.md
PR 7332 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/shader.md
PR 7395 docs/dev/debt/shader.md
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6248168203 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7487#issuecomment-6248168203). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-18T09:20:03Z. --- <!-- pr-overlap --> Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 1395](https://www.github.com/boykopovar/AnyPS5/pull/1395) | `core/libs/prx/libSceAgcDriver/tests/Graphics.cpp` | | [PR 4040](https://www.github.com/boykopovar/AnyPS5/pull/4040) | `core/libs/prx/libSceAgcDriver/tests/Graphics.cpp` | | [PR 4650](https://www.github.com/boykopovar/AnyPS5/pull/4650) | `core/libs/prx/libSceAgcDriver/tests/Graphics.cpp` | | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `docs/dev/debt/shader.md` | | [PR 5371](https://www.github.com/boykopovar/AnyPS5/pull/5371) | `docs/dev/debt/shader.md` | | [PR 5426](https://www.github.com/boykopovar/AnyPS5/pull/5426) | `docs/dev/debt/shader.md` | | [PR 5441](https://www.github.com/boykopovar/AnyPS5/pull/5441) | `core/libs/prx/libSceAgcDriver/tests/Graphics.cpp` | | [PR 5499](https://www.github.com/boykopovar/AnyPS5/pull/5499) | `core/libs/prx/libSceAgcDriver/tests/Graphics.cpp` | | [PR 5500](https://www.github.com/boykopovar/AnyPS5/pull/5500) | `core/libs/prx/libSceAgcDriver/tests/Graphics.cpp`<br>`docs/dev/debt/shader.md` | | [PR 5925](https://www.github.com/boykopovar/AnyPS5/pull/5925) | `core/libs/prx/libSceAgcDriver/tests/Graphics.cpp` | | [PR 5941](https://www.github.com/boykopovar/AnyPS5/pull/5941) | `docs/dev/debt/shader.md` | | [PR 5958](https://www.github.com/boykopovar/AnyPS5/pull/5958) | `docs/dev/debt/shader.md` | | [PR 5999](https://www.github.com/boykopovar/AnyPS5/pull/5999) | `core/libs/prx/libSceAgcDriver/tests/Graphics.cpp` | | [PR 6009](https://www.github.com/boykopovar/AnyPS5/pull/6009) | `docs/dev/debt/shader.md` | | [PR 6054](https://www.github.com/boykopovar/AnyPS5/pull/6054) | `docs/dev/debt/shader.md` | | [PR 6094](https://www.github.com/boykopovar/AnyPS5/pull/6094) | `docs/dev/debt/shader.md` | | [PR 6188](https://www.github.com/boykopovar/AnyPS5/pull/6188) | `core/libs/prx/libSceAgcDriver/tests/Graphics.cpp` | | [PR 6194](https://www.github.com/boykopovar/AnyPS5/pull/6194) | `core/libs/prx/libSceAgcDriver/tests/Graphics.cpp` | | [PR 6222](https://www.github.com/boykopovar/AnyPS5/pull/6222) | `core/libs/prx/libSceAgcDriver/tests/Graphics.cpp`<br>`docs/dev/debt/shader.md` | | [PR 6235](https://www.github.com/boykopovar/AnyPS5/pull/6235) | `core/libs/prx/libSceAgcDriver/tests/Graphics.cpp`<br>`docs/dev/debt/shader.md` | | [PR 6297](https://www.github.com/boykopovar/AnyPS5/pull/6297) | `core/libs/prx/libSceAgcDriver/tests/Graphics.cpp` | | [PR 6320](https://www.github.com/boykopovar/AnyPS5/pull/6320) | `core/libs/prx/libSceAgcDriver/tests/Graphics.cpp` | | [PR 6412](https://www.github.com/boykopovar/AnyPS5/pull/6412) | `docs/dev/debt/shader.md` | | [PR 6472](https://www.github.com/boykopovar/AnyPS5/pull/6472) | `core/libs/prx/libSceAgcDriver/tests/Graphics.cpp` | | [PR 6481](https://www.github.com/boykopovar/AnyPS5/pull/6481) | `core/libs/prx/libSceAgcDriver/tests/Graphics.cpp` | | [PR 6488](https://www.github.com/boykopovar/AnyPS5/pull/6488) | `docs/dev/debt/shader.md` | | [PR 6529](https://www.github.com/boykopovar/AnyPS5/pull/6529) | `core/libs/prx/libSceAgcDriver/tests/Graphics.cpp` | | [PR 6535](https://www.github.com/boykopovar/AnyPS5/pull/6535) | `core/libs/prx/libSceAgcDriver/tests/Graphics.cpp` | | [PR 6548](https://www.github.com/boykopovar/AnyPS5/pull/6548) | `core/libs/prx/libSceAgcDriver/tests/Graphics.cpp` | | [PR 6563](https://www.github.com/boykopovar/AnyPS5/pull/6563) | `core/libs/prx/libSceAgcDriver/tests/Graphics.cpp` | | [PR 6674](https://www.github.com/boykopovar/AnyPS5/pull/6674) | `docs/dev/debt/shader.md` | | [PR 6783](https://www.github.com/boykopovar/AnyPS5/pull/6783) | `core/libs/prx/libSceAgcDriver/tests/Graphics.cpp` | | [PR 6808](https://www.github.com/boykopovar/AnyPS5/pull/6808) | `core/libs/prx/libSceAgcDriver/tests/Graphics.cpp` | | [PR 6972](https://www.github.com/boykopovar/AnyPS5/pull/6972) | `core/libs/prx/libSceAgcDriver/tests/Graphics.cpp` | | [PR 6977](https://www.github.com/boykopovar/AnyPS5/pull/6977) | `docs/dev/debt/shader.md` | | [PR 7223](https://www.github.com/boykopovar/AnyPS5/pull/7223) | `docs/dev/debt/shader.md` | | [PR 7332](https://www.github.com/boykopovar/AnyPS5/pull/7332) | `core/libs/prx/libSceAgcDriver/tests/Graphics.cpp`<br>`docs/dev/debt/shader.md` | | [PR 7395](https://www.github.com/boykopovar/AnyPS5/pull/7395) | `docs/dev/debt/shader.md` |
oneandonlydean commented 2026-10-18 09:51:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-18T09:51:57Z.


The change looks right to me: separate array only at VS→TCS, block from the TCS output on. One gap: agc_driver_pixel_barycentric_emulation draws without clip distances, so its validation-layer run covers the unchanged unclipped path, and nothing creates a pipeline for the clipped tessellation route under the layer. Could the emulation test add a case whose vertex shader writes clip distances (e.g. one plane that cuts the triangle, checked in the readback), run through both routes? That would pin the MoltenVK translation and the VUID-08746 rule on the exact layout this PR changes, on lavapipe in CI as well.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6248445589 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7487#issuecomment-6248445589). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-18T09:51:57Z. --- The change looks right to me: separate array only at VS→TCS, block from the TCS output on. One gap: `agc_driver_pixel_barycentric_emulation` draws without clip distances, so its validation-layer run covers the unchanged unclipped path, and nothing creates a pipeline for the clipped tessellation route under the layer. Could the emulation test add a case whose vertex shader writes clip distances (e.g. one plane that cuts the triangle, checked in the readback), run through both routes? That would pin the MoltenVK translation and the VUID-08746 rule on the exact layout this PR changes, on lavapipe in CI as well.
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!7487
No description provided.