fix(shader): forward gl_ClipDistance through the generated rect-list stages #7124

Merged
Alexius0815 merged 1 commit from upstream-pr/7124 into main 2026-10-17 23:57:16 +00:00
Alexius0815 commented 2026-10-17 12:34:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Alexius0815 on 2026-10-17T12:34:06Z.


What

Since #3878 every vertex program that exports a position also writes gl_ClipDistance (the all-zero position distance). The tessellation stages generated in RectListShaders.cpp declared only gl_Position in gl_in, so their interface no longer matched the vertex outputs. On MoltenVK the control stage then reads all-zero positions, and every rect-list draw stops with rect-list requires finite nondegenerate axis-aligned positions with equal positive W. Cloud-Multiplayer described this in #1 (https://github.com/boykopovar/AnyPS5/issues/1#issuecomment-6208433225) and worked around it by skipping the zero-position clip on Apple.

  • VertexClipDistanceCount (new header SpirvClipDistances.hpp) reads the length of the vertex program's gl_ClipDistance output from its SPIR-V.
  • The rect-list control and evaluation stages declare that array in their per-vertex blocks and forward it. The generated fourth corner gets clip distances interpolated with the same weights as its position, so the all-zero position clip from #3878 keeps working for rect lists.
  • ShaderValidation accepts gl_ClipDistance as a tessellation input and as a tessellation-control output, and the ClipDistance capability in control stages.

No platform switch is needed; the zero-position clip stays on.

Tested

Apple M4, macOS, x86_64 build under Rosetta 2, MoltenVK, on the community macOS working stack with the Apple zero-position-clip workaround removed:

without this change with this change
ccleste (PPSA59322) aborts: rect-list requires finite nondegenerate ... runs, frames presented, no rect-list faults
vkQuake (PPSA99010) over 1000 rect-list faults in 10 s no rect-list faults
DOOM shareware (PPSA99666) OK OK

agc_rect_list_position_invariant, agc_driver_pixel_ancillary_word, agc_driver_prepared_publication, agc_driver_mesh and agc_fragment_barycentric pass. The ^agc|^guest_arena|^macos_empty_tls selection (623 tests) shows no new failures against the same stack without the change; the remaining failures there are missing MoltenVK features (descriptor indexing, cull distance, MSAA storage) and f16 rounding. The changed sources also compile on current main. Not tested on Windows or Linux.

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: ccleste PPSA59322 on macOS up to its title screen (#1); vkQuake PPSA99010 no longer stops on rect-list faults
  • GPUs tested: Apple M4 (10-core GPU), MoltenVK (Vulkan 1.4), macOS 27.2 (x86_64 build under Rosetta 2)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4900078805 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7124). Originally posted by [Alexius0815](https://github.com/Alexius0815) on 2026-10-17T12:34:06Z. --- ### What Since #3878 every vertex program that exports a position also writes `gl_ClipDistance` (the all-zero position distance). The tessellation stages generated in `RectListShaders.cpp` declared only `gl_Position` in `gl_in`, so their interface no longer matched the vertex outputs. On MoltenVK the control stage then reads all-zero positions, and every rect-list draw stops with `rect-list requires finite nondegenerate axis-aligned positions with equal positive W`. Cloud-Multiplayer described this in #1 (https://github.com/boykopovar/AnyPS5/issues/1#issuecomment-6208433225) and worked around it by skipping the zero-position clip on Apple. - `VertexClipDistanceCount` (new header `SpirvClipDistances.hpp`) reads the length of the vertex program's `gl_ClipDistance` output from its SPIR-V. - The rect-list control and evaluation stages declare that array in their per-vertex blocks and forward it. The generated fourth corner gets clip distances interpolated with the same weights as its position, so the all-zero position clip from #3878 keeps working for rect lists. - `ShaderValidation` accepts `gl_ClipDistance` as a tessellation input and as a tessellation-control output, and the `ClipDistance` capability in control stages. No platform switch is needed; the zero-position clip stays on. ### Tested Apple M4, macOS, x86_64 build under Rosetta 2, MoltenVK, on the community macOS working stack with the Apple zero-position-clip workaround removed: | | without this change | with this change | | --- | --- | --- | | ccleste (PPSA59322) | aborts: `rect-list requires finite nondegenerate ...` | runs, frames presented, no rect-list faults | | vkQuake (PPSA99010) | over 1000 rect-list faults in 10 s | no rect-list faults | | DOOM shareware (PPSA99666) | OK | OK | `agc_rect_list_position_invariant`, `agc_driver_pixel_ancillary_word`, `agc_driver_prepared_publication`, `agc_driver_mesh` and `agc_fragment_barycentric` pass. The `^agc|^guest_arena|^macos_empty_tls` selection (623 tests) shows no new failures against the same stack without the change; the remaining failures there are missing MoltenVK features (descriptor indexing, cull distance, MSAA storage) and f16 rounding. The changed sources also compile on current `main`. Not tested on Windows or Linux. ### Checklist - [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: ccleste PPSA59322 on macOS up to its title screen (#1); vkQuake PPSA99010 no longer stops on rect-list faults - [x] GPUs tested: Apple M4 (10-core GPU), MoltenVK (Vulkan 1.4), macOS 27.2 (x86_64 build under Rosetta 2) - [x] AI-assisted: yes
MarcZX10 commented 2026-10-17 12:35:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T12:35:58Z.


The conventions check currently fails for nine items. I reran tools/check_conventions.py against current main and this exact head; it reports six source-comment violations (ShaderValidation.cpp:134, SpirvClipDistances.hpp:14–17, and RectListShaders.cpp:46) plus three unfilled PR-template sections. The repository rule permits code comments only for technical debt, so please remove those explanatory comments; also reformat the description with the required What, Tested, and Checklist sections, including Depends on, Unblocks, GPUs tested, and AI-assisted. This is distinct from #7118’s last-provoking-vertex refusal; I did not find an implementation overlap there.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6233948150 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7124#issuecomment-6233948150). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-17T12:35:58Z. --- The conventions check currently fails for nine items. I reran `tools/check_conventions.py` against current `main` and this exact head; it reports six source-comment violations (`ShaderValidation.cpp:134`, `SpirvClipDistances.hpp:14–17`, and `RectListShaders.cpp:46`) plus three unfilled PR-template sections. The repository rule permits code comments only for technical debt, so please remove those explanatory comments; also reformat the description with the required `What`, `Tested`, and `Checklist` sections, including Depends on, Unblocks, GPUs tested, and AI-assisted. This is distinct from #7118’s last-provoking-vertex refusal; I did not find an implementation overlap there.
github-actions[bot] commented 2026-10-17 13:08:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-17T13:08:24Z.


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 4072 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cpp
PR 6222 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cpp
core/shader/recompiler/SpirvBackend/src/RectListShaders.cpp
PR 6235 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cpp
PR 6947 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cpp
PR 7201 core/shader/recompiler/SpirvBackend/src/RectListShaders.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6234253479 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7124#issuecomment-6234253479). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-17T13:08:24Z. --- <!-- 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 4072](https://www.github.com/boykopovar/AnyPS5/pull/4072) | `core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cpp` | | [PR 6222](https://www.github.com/boykopovar/AnyPS5/pull/6222) | `core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cpp`<br>`core/shader/recompiler/SpirvBackend/src/RectListShaders.cpp` | | [PR 6235](https://www.github.com/boykopovar/AnyPS5/pull/6235) | `core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cpp` | | [PR 6947](https://www.github.com/boykopovar/AnyPS5/pull/6947) | `core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cpp` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `core/shader/recompiler/SpirvBackend/src/RectListShaders.cpp` |
akkadbakkad89 commented 2026-10-17 13:13:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by akkadbakkad89 on 2026-10-17T13:13:43Z.


First datapoint outside MoltenVK: head 2b9c131e0, Windows 11, MinGW (WinLibs GCC 15.2.0), Release, serial fresh processes.

  • NVIDIA RTX 3070 (driver 617.42): agc_rect_list_position_invariant, agc_fragment_barycentric, agc_driver_mesh, agc_driver_pixel_ancillary_word, agc_driver_prepared_publication — 5/5 pass.
  • Intel UHD 630 (ANYPS5_GPU=UHD, igvk64): same five, 5/5 pass.

No rect-list faults on either mainstream driver.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6234302665 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7124#issuecomment-6234302665). Originally posted by [akkadbakkad89](https://github.com/akkadbakkad89) on 2026-10-17T13:13:43Z. --- First datapoint outside MoltenVK: head `2b9c131e0`, Windows 11, MinGW (WinLibs GCC 15.2.0), Release, serial fresh processes. - NVIDIA RTX 3070 (driver 617.42): `agc_rect_list_position_invariant`, `agc_fragment_barycentric`, `agc_driver_mesh`, `agc_driver_pixel_ancillary_word`, `agc_driver_prepared_publication` — 5/5 pass. - Intel UHD 630 (`ANYPS5_GPU=UHD`, igvk64): same five, 5/5 pass. No rect-list faults on either mainstream driver.
Alexius0815 commented 2026-10-17 13:34:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Alexius0815 on 2026-10-17T13:34:20Z.


@MarcZX100 thanks, both points are fixed: the comments are removed (head 2b9c131e0) and the description follows the template. The conventions check is green now.

@akkadbakkad89 thanks for the NVIDIA and Intel runs. That covers the non-MoltenVK side I could not test.

Prior art, which I missed: @yripper fixed the same mismatch on 13.10 in feat/macos-runtime (3fbf9aef3, "forward clip distance through rect-list tessellation"). It is also part of #6222, which is why the overlap bot lists that PR. My search went through PR titles and #1 and did not find it inside the larger branch. Sorry about that.

The approach is the same. The difference: 3fbf9aef3 assumes exactly one clip distance (f32[1] in the rect-list blocks and in validation). This PR reads the length of the vertex program's gl_ClipDistance array from its SPIR-V (VertexClipDistanceCount), so it also matches when the guest writes its own clip distances in addition to the all-zero position one.

@yripper, you said the rest of your macOS work goes upstream as small PRs. Would you rather submit your version yourself? In that case I will close this one and add the clip-count handling to yours if it helps. Or, if you prefer, keep this one and I will add you as co-author of the commit. Either is fine with me.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6234498575 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7124#issuecomment-6234498575). Originally posted by [Alexius0815](https://github.com/Alexius0815) on 2026-10-17T13:34:20Z. --- @MarcZX100 thanks, both points are fixed: the comments are removed (head `2b9c131e0`) and the description follows the template. The conventions check is green now. @akkadbakkad89 thanks for the NVIDIA and Intel runs. That covers the non-MoltenVK side I could not test. **Prior art, which I missed:** @yripper fixed the same mismatch on 13.10 in `feat/macos-runtime` (3fbf9aef3, "forward clip distance through rect-list tessellation"). It is also part of #6222, which is why the overlap bot lists that PR. My search went through PR titles and #1 and did not find it inside the larger branch. Sorry about that. The approach is the same. The difference: 3fbf9aef3 assumes exactly one clip distance (`f32[1]` in the rect-list blocks and in validation). This PR reads the length of the vertex program's `gl_ClipDistance` array from its SPIR-V (`VertexClipDistanceCount`), so it also matches when the guest writes its own clip distances in addition to the all-zero position one. @yripper, you said the rest of your macOS work goes upstream as small PRs. Would you rather submit your version yourself? In that case I will close this one and add the clip-count handling to yours if it helps. Or, if you prefer, keep this one and I will add you as co-author of the commit. Either is fine with me. AI-assisted: yes
oneandonlydean commented 2026-10-17 21:40:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T21:40:28Z.


#7251 has merged, and it adds a RectListEmitter lastVertexControl(...) call that passes four arguments. This PR adds a fifth constructor parameter, clipDistances, with no default, so the two together don't compile. Could you rebase onto current main and pass clipDistances at that call too? We'll run full CI on the new head and merge it from there.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6241582333 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7124#issuecomment-6241582333). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-17T21:40:28Z. --- #7251 has merged, and it adds a `RectListEmitter lastVertexControl(...)` call that passes four arguments. This PR adds a fifth constructor parameter, `clipDistances`, with no default, so the two together don't compile. Could you rebase onto current main and pass `clipDistances` at that call too? We'll run full CI on the new head and merge it from there.
DavidSamir commented 2026-10-17 22:32:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-17T22:32:01Z.


@Alexius0815 heads-up: since #7251 merged, main builds a second rect-list control stage (lastVertexControl) with the old four-argument RectListEmitter constructor. Merged with this branch, RectListShaders.cpp then fails to compile (no matching constructor for initialization of 'RectListEmitter', at the lastVertexControl line). Passing clipDistances there as well fixes it, and the merged control code (clip forwarding plus the flat-vertex choice) is consistent:

RectListEmitter lastVertexControl(parameters, spv::ExecutionModelTessellationControl, target.spirvVersion, faultBinding, clipDistances);

#7308 builds on this PR for the barycentric tessellation stages on MoltenVK (it reuses VertexClipDistanceCount), and carries that one-line fix in its merge of main. On an M2, forwarding the clip distances was exactly what made MoltenVK's control-stage input match the vertex output.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6242326697 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7124#issuecomment-6242326697). Originally posted by [DavidSamir](https://github.com/DavidSamir) on 2026-10-17T22:32:01Z. --- @Alexius0815 heads-up: since #7251 merged, `main` builds a second rect-list control stage (`lastVertexControl`) with the old four-argument `RectListEmitter` constructor. Merged with this branch, `RectListShaders.cpp` then fails to compile (`no matching constructor for initialization of 'RectListEmitter'`, at the `lastVertexControl` line). Passing `clipDistances` there as well fixes it, and the merged control code (clip forwarding plus the flat-vertex choice) is consistent: ```cpp RectListEmitter lastVertexControl(parameters, spv::ExecutionModelTessellationControl, target.spirvVersion, faultBinding, clipDistances); ``` #7308 builds on this PR for the barycentric tessellation stages on MoltenVK (it reuses `VertexClipDistanceCount`), and carries that one-line fix in its merge of `main`. On an M2, forwarding the clip distances was exactly what made MoltenVK's control-stage input match the vertex output. AI-assisted: yes
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!7124
No description provided.