fix(shader): forward gl_ClipDistance through the generated rect-list stages #7124
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7124"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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 inRectListShaders.cppdeclared onlygl_Positioningl_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 withrect-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 headerSpirvClipDistances.hpp) reads the length of the vertex program'sgl_ClipDistanceoutput from its SPIR-V.ShaderValidationacceptsgl_ClipDistanceas a tessellation input and as a tessellation-control output, and theClipDistancecapability 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:
rect-list requires finite nondegenerate ...agc_rect_list_position_invariant,agc_driver_pixel_ancillary_word,agc_driver_prepared_publication,agc_driver_meshandagc_fragment_barycentricpass. The^agc|^guest_arena|^macos_empty_tlsselection (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 currentmain. Not tested on Windows or Linux.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)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.pyagainst currentmainand this exact head; it reports six source-comment violations (ShaderValidation.cpp:134,SpirvClipDistances.hpp:14–17, andRectListShaders.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 requiredWhat,Tested, andChecklistsections, 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.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.
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cppcore/shader/recompiler/SpirvBackend/src/RectListShaders.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cppcore/shader/recompiler/SpirvBackend/src/RectListShaders.cppImported 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.agc_rect_list_position_invariant,agc_fragment_barycentric,agc_driver_mesh,agc_driver_pixel_ancillary_word,agc_driver_prepared_publication— 5/5 pass.ANYPS5_GPU=UHD, igvk64): same five, 5/5 pass.No rect-list faults on either mainstream driver.
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:
3fbf9aef3assumes exactly one clip distance (f32[1]in the rect-list blocks and in validation). This PR reads the length of the vertex program'sgl_ClipDistancearray 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
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 passclipDistancesat that call too? We'll run full CI on the new head and merge it from there.Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-17T22:32:01Z.
@Alexius0815 heads-up: since #7251 merged,
mainbuilds a second rect-list control stage (lastVertexControl) with the old four-argumentRectListEmitterconstructor. Merged with this branch,RectListShaders.cppthen fails to compile (no matching constructor for initialization of 'RectListEmitter', at thelastVertexControlline). PassingclipDistancesthere as well fixes it, and the merged control code (clip forwarding plus the flat-vertex choice) is consistent:#7308 builds on this PR for the barycentric tessellation stages on MoltenVK (it reuses
VertexClipDistanceCount), and carries that one-line fix in its merge ofmain. On an M2, forwarding the clip distances was exactly what made MoltenVK's control-stage input match the vertex output.AI-assisted: yes