fix(shader): clip primitives with an all-zero clip position #3878

Merged
fma-rc merged 1 commit from upstream-pr/3878 into main 2026-10-12 05:18:41 +00:00
fma-rc commented 2026-10-11 18:25:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fma-rc on 2026-10-11T18:25:44Z.


What

A primitive with a vertex whose clip position is exactly (0,0,0,0) comes out differently per host. The RTX 5080 rasterises it as if that vertex were at the viewport centre; a Radeon 610M (RDNA2, RADV) and llvmpipe draw nothing for a triangle.

Titles produce such vertices by reading past a vertex buffer's num_records, which the driver zero-fills (#2573). Astro's Playroom (PPSA01325) draws its full-screen passes as 4-vertex strips over 3-record buffers, so on NVIDIA the second triangle (3,-1), (-1,3), (0,0,0,0) paints a wedge from the screen centre over every scene.

Vertex and tessellation evaluation shaders now write one extra gl_ClipDistance element: -1 when all four position components are zero, 0 otherwise. A primitive with such a vertex is then negative everywhere and clips to nothing on every host; other primitives are untouched. The device advertises ClipDistance when shaderClipDistance is enabled, and the pipeline validator accepts exactly this one-element output.

Limits, also in TechnicalDebt:

  • Mesh and geometry stages and the generated rect-list and barycentric stages do not write the element.
  • Guest clip distances stay refused by the validator as before. That is #423's topic, and this change touches the same validator lines.
  • A device without shaderClipDistance can no longer compile vertex shaders (the compile throws).
  • Lines are clipped by the same element and were not measured. The PS5 rasteriser was not measured.

Tested

Arch Linux, GCC 16.2.1, Release, ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1, main a11c8f7f (the "this branch" row was run again after the rebase onto main e013f8c9c on 2026-10-12, same results on the RTX 5080, RADV and lavapipe). New test agc_driver_zero_position_vertex: a strip whose first triangle is the lower-left corner of the target, with the fourth vertex out of range, stored as zeros, stored as negative zeros, as a list, and with two zero vertices. It counts pixels written outside the first triangle (a stored (0,0,0,1) gives 496 everywhere). It also draws a point at (0,0,0,0).

RTX 5080 (615.78.08) RADV (Radeon 610M) lavapipe (Mesa 26.2.4)
triangle with a (0,0,0,0) vertex, without the change 496 pixels, test fails 0 0
point at (0,0,0,0), without the change drawn at the centre not drawn drawn at the top-left corner
this branch pass pass pass

Full ctest on this branch on main e013f8c9c, RTX 5080: 927 pass, none fail (four video_out_flip_* skipped). Existing recompiler tests that recompile a vertex shader got ClipDistance added to their hand-built capability lists; that now includes both target lists of verifyNarrowVertexWave in tests/ShaderMemory.cpp, which arrived on main after this PR was opened and made agc_shader_memory fail with it until 9db923e90. tools/check_conventions.py --base origin/main passes.

Astro's Playroom on the RTX 5080 with #3669, #425, #3750 and this branch merged onto main a11c8f7f: the wedge is gone on the title screen and the main menu; without this branch it covers the upper right of both. PRs 3669 and 3750 have merged since; the title was not run again on the new base.

Not tested on Windows.

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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4821304827 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3878). Originally posted by [fma-rc](https://github.com/fma-rc) on 2026-10-11T18:25:44Z. --- ### What A primitive with a vertex whose clip position is exactly (0,0,0,0) comes out differently per host. The RTX 5080 rasterises it as if that vertex were at the viewport centre; a Radeon 610M (RDNA2, RADV) and llvmpipe draw nothing for a triangle. Titles produce such vertices by reading past a vertex buffer's `num_records`, which the driver zero-fills (#2573). Astro's Playroom (PPSA01325) draws its full-screen passes as 4-vertex strips over 3-record buffers, so on NVIDIA the second triangle (3,-1), (-1,3), (0,0,0,0) paints a wedge from the screen centre over every scene. Vertex and tessellation evaluation shaders now write one extra `gl_ClipDistance` element: -1 when all four position components are zero, 0 otherwise. A primitive with such a vertex is then negative everywhere and clips to nothing on every host; other primitives are untouched. The device advertises `ClipDistance` when `shaderClipDistance` is enabled, and the pipeline validator accepts exactly this one-element output. Limits, also in TechnicalDebt: - Mesh and geometry stages and the generated rect-list and barycentric stages do not write the element. - Guest clip distances stay refused by the validator as before. That is #423's topic, and this change touches the same validator lines. - A device without `shaderClipDistance` can no longer compile vertex shaders (the compile throws). - Lines are clipped by the same element and were not measured. The PS5 rasteriser was not measured. ### Tested Arch Linux, GCC 16.2.1, Release, `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1`, `main` a11c8f7f (the "this branch" row was run again after the rebase onto `main` e013f8c9c on 2026-10-12, same results on the RTX 5080, RADV and lavapipe). New test `agc_driver_zero_position_vertex`: a strip whose first triangle is the lower-left corner of the target, with the fourth vertex out of range, stored as zeros, stored as negative zeros, as a list, and with two zero vertices. It counts pixels written outside the first triangle (a stored (0,0,0,1) gives 496 everywhere). It also draws a point at (0,0,0,0). | | RTX 5080 (615.78.08) | RADV (Radeon 610M) | lavapipe (Mesa 26.2.4) | |---|---|---|---| | triangle with a (0,0,0,0) vertex, without the change | 496 pixels, test fails | 0 | 0 | | point at (0,0,0,0), without the change | drawn at the centre | not drawn | drawn at the top-left corner | | this branch | pass | pass | pass | Full ctest on this branch on `main` e013f8c9c, RTX 5080: 927 pass, none fail (four `video_out_flip_*` skipped). Existing recompiler tests that recompile a vertex shader got `ClipDistance` added to their hand-built capability lists; that now includes both target lists of `verifyNarrowVertexWave` in `tests/ShaderMemory.cpp`, which arrived on `main` after this PR was opened and made `agc_shader_memory` fail with it until 9db923e90. `tools/check_conventions.py --base origin/main` passes. Astro's Playroom on the RTX 5080 with #3669, #425, #3750 and this branch merged onto `main` a11c8f7f: the wedge is gone on the title screen and the main menu; without this branch it covers the upper right of both. PRs 3669 and 3750 have merged since; the title was not run again on the new base. Not tested on Windows. ### 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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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] AI-assisted: yes
MarcZX10 commented 2026-10-11 18:39:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T18:39:01Z.


Built and ran the focused agc_driver_zero_position_vertex_tests executable on Linux with GCC 12.2, Release, using Ninja 1.11.1. The run completed successfully with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 on Mesa llvmpipe (LLVM 15.0.6). All cases passed, including out-of-range and stored all-zero vertices, negative zero, triangle lists/strips, and the point-list case. This verifies the focused test on llvmpipe; it does not cover the full test suite or NVIDIA/RADV hardware.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6112353482 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3878#issuecomment-6112353482). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-11T18:39:01Z. --- Built and ran the focused `agc_driver_zero_position_vertex_tests` executable on Linux with GCC 12.2, Release, using Ninja 1.11.1. The run completed successfully with `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1` on Mesa llvmpipe (LLVM 15.0.6). All cases passed, including out-of-range and stored all-zero vertices, negative zero, triangle lists/strips, and the point-list case. This verifies the focused test on llvmpipe; it does not cover the full test suite or NVIDIA/RADV hardware.
adriadam10 commented 2026-10-11 22:12:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T22:12:31Z.


Thanks, the approach (one extra gl_ClipDistance element, -1 when all four components are zero) reads correctly, agc_driver_zero_position_vertex and the 412 tests of libSceAgc/libSceAgcDriver pass here on RADV with the PR merged onto main.

The test cannot fail on Linux CI or on our hosts, though: with the source changes reverted it still passes on RADV, because RADV already clips such a primitive. That matches the PR body (only NVIDIA draws the wedge), so the fix is proven only by the RTX 5080 table in the description.

@oneandonlydean could you run agc_driver_zero_position_vertex on your RTX 4090 with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1, on main (expected: fails, ~496 pixels) and on this branch (expected: passes), and check the Astro's Playroom title screen? @boykopovar FYI: this adds one clip distance and the ClipDistance capability to every vertex/tessellation-evaluation shader, and a device without shaderClipDistance can no longer compile vertex shaders (TechnicalDebt line included).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6114433067 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3878#issuecomment-6114433067). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T22:12:31Z. --- Thanks, the approach (one extra `gl_ClipDistance` element, -1 when all four components are zero) reads correctly, `agc_driver_zero_position_vertex` and the 412 tests of libSceAgc/libSceAgcDriver pass here on RADV with the PR merged onto `main`. The test cannot fail on Linux CI or on our hosts, though: with the source changes reverted it still passes on RADV, because RADV already clips such a primitive. That matches the PR body (only NVIDIA draws the wedge), so the fix is proven only by the RTX 5080 table in the description. @oneandonlydean could you run `agc_driver_zero_position_vertex` on your RTX 4090 with `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1`, on `main` (expected: fails, ~496 pixels) and on this branch (expected: passes), and check the Astro's Playroom title screen? @boykopovar FYI: this adds one clip distance and the `ClipDistance` capability to every vertex/tessellation-evaluation shader, and a device without `shaderClipDistance` can no longer compile vertex shaders (TechnicalDebt line included).
github-actions[bot] commented 2026-10-11 22:55:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T22:55:42Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#3763 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp L264, L1350
core/libs/prx/libSceAgcDriver/Graphics/include/Pipeline.hpp L113
core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp L735
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cpp L139, L550, L571
#4152 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cpp L570-571
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6114826874 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3878#issuecomment-6114826874). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-11T22:55:42Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #3763 | `core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp` [L264](https://github.com/boykopovar/AnyPS5/blob/e013f8c9c565e4a28be16268c93ec36c64baa34b/core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp#L264), [L1350](https://github.com/boykopovar/AnyPS5/blob/e013f8c9c565e4a28be16268c93ec36c64baa34b/core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp#L1350)<br>`core/libs/prx/libSceAgcDriver/Graphics/include/Pipeline.hpp` [L113](https://github.com/boykopovar/AnyPS5/blob/e013f8c9c565e4a28be16268c93ec36c64baa34b/core/libs/prx/libSceAgcDriver/Graphics/include/Pipeline.hpp#L113)<br>`core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp` [L735](https://github.com/boykopovar/AnyPS5/blob/e013f8c9c565e4a28be16268c93ec36c64baa34b/core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp#L735)<br>`core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cpp` [L139](https://github.com/boykopovar/AnyPS5/blob/e013f8c9c565e4a28be16268c93ec36c64baa34b/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cpp#L139), [L550](https://github.com/boykopovar/AnyPS5/blob/e013f8c9c565e4a28be16268c93ec36c64baa34b/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cpp#L550), [L571](https://github.com/boykopovar/AnyPS5/blob/e013f8c9c565e4a28be16268c93ec36c64baa34b/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cpp#L571) | | | | #4152 | `core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cpp` [L570-571](https://github.com/boykopovar/AnyPS5/blob/e013f8c9c565e4a28be16268c93ec36c64baa34b/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cpp#L570-L571) | | |
oneandonlydean commented 2026-10-11 23:12:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-11T23:12:26Z.


RTX 4090 (NVIDIA 610.57.04, Linux), ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1: on main 22cecd5a with only the test file added, agc_driver_zero_position_vertex fails 5 of 5 with a vertex fetched past num_records must clip the primitive away (496 pixels outside the first triangle in cases A, B, F, G and H); with 79efcd07 merged onto it, it passes 5 of 5. I haven't checked the PPSA01325 title screen.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6114964253 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3878#issuecomment-6114964253). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-11T23:12:26Z. --- RTX 4090 (NVIDIA 610.57.04, Linux), `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1`: on `main` 22cecd5a with only the test file added, `agc_driver_zero_position_vertex` fails 5 of 5 with `a vertex fetched past num_records must clip the primitive away` (496 pixels outside the first triangle in cases A, B, F, G and H); with 79efcd07 merged onto it, it passes 5 of 5. I haven't checked the PPSA01325 title screen.
fma-rc commented 2026-10-11 23:25:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fma-rc on 2026-10-11T23:25:55Z.


PPSA01325 before and after screenshots, RTX 5080 (NVIDIA 615.78.08, Linux). Both builds are main a11c8f7f with PRs 3669, 425 and 3750 merged, which the title needs to get this far; the second build adds this PR and nothing else.

Title screen about 60 s in. Without the PR a flat dark-blue triangle covers the upper right of the frame and half the logo:

title screen without the PR

With it:

title screen with the PR

Main menu after one Cross press, without and with:

main menu without the PR
main menu with the PR

The triangle is the second one of the title's 4-vertex full-screen strips over a 3-record vertex buffer, the case the test covers.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6115088220 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3878#issuecomment-6115088220). Originally posted by [fma-rc](https://github.com/fma-rc) on 2026-10-11T23:25:55Z. --- PPSA01325 before and after screenshots, RTX 5080 (NVIDIA 615.78.08, Linux). Both builds are main a11c8f7f with PRs 3669, 425 and 3750 merged, which the title needs to get this far; the second build adds this PR and nothing else. Title screen about 60 s in. Without the PR a flat dark-blue triangle covers the upper right of the frame and half the logo: ![title screen without the PR](https://raw.githubusercontent.com/fma-rc/AnyPS5/0b1f8a259f75d3b31b338eb3a13ba134e4f9b87c/title-without.png) With it: ![title screen with the PR](https://raw.githubusercontent.com/fma-rc/AnyPS5/0b1f8a259f75d3b31b338eb3a13ba134e4f9b87c/title-with.png) Main menu after one Cross press, without and with: ![main menu without the PR](https://raw.githubusercontent.com/fma-rc/AnyPS5/0b1f8a259f75d3b31b338eb3a13ba134e4f9b87c/menu-without.png) ![main menu with the PR](https://raw.githubusercontent.com/fma-rc/AnyPS5/0b1f8a259f75d3b31b338eb3a13ba134e4f9b87c/menu-with.png) The triangle is the second one of the title's 4-vertex full-screen strips over a 3-record vertex buffer, the case the test covers.
oneandonlydean commented 2026-10-12 04:38:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-12T04:38:04Z.


agc_shader_memory still fails with this merged onto current main, on Linux and Windows (run 38201405444), with clipping a primitive with an all-zero clip position needs shaderClipDistance on the target device. verifyNarrowVertexWave() in tests/ShaderMemory.cpp (added by #3546) compiles vertex shaders with two target lists, capabilities and noArithmetic; adding spv::CapabilityClipDistance to both made it pass here. The two titles I ran with the previous head showed no difference in frames or GPU time.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6117845681 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3878#issuecomment-6117845681). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-12T04:38:04Z. --- `agc_shader_memory` still fails with this merged onto current `main`, on Linux and Windows ([run 38201405444](https://github.com/boykopovar/AnyPS5/actions/runs/38201405444)), with `clipping a primitive with an all-zero clip position needs shaderClipDistance on the target device`. `verifyNarrowVertexWave()` in `tests/ShaderMemory.cpp` (added by #3546) compiles vertex shaders with two target lists, `capabilities` and `noArithmetic`; adding `spv::CapabilityClipDistance` to both made it pass here. The two titles I ran with the previous head showed no difference in frames or GPU time.
fma-rc commented 2026-10-12 04:46:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fma-rc on 2026-10-12T04:46:59Z.


Thanks, reproduced and fixed in 9db923e90. On main e013f8c9c with the previous head, agc_shader_memory failed here with the same message. Both lists in verifyNarrowVertexWave now carry spv::CapabilityClipDistance, as you did.

With that, the full suite on the RTX 5080 has 927 passing and none failing, and agc_shader_memory and agc_driver_zero_position_vertex pass on the RTX 5080, RADV and lavapipe. The branch is rebased onto e013f8c9c and the description is updated.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6117928495 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3878#issuecomment-6117928495). Originally posted by [fma-rc](https://github.com/fma-rc) on 2026-10-12T04:46:59Z. --- Thanks, reproduced and fixed in 9db923e90. On `main` e013f8c9c with the previous head, `agc_shader_memory` failed here with the same message. Both lists in `verifyNarrowVertexWave` now carry `spv::CapabilityClipDistance`, as you did. With that, the full suite on the RTX 5080 has 927 passing and none failing, and `agc_shader_memory` and `agc_driver_zero_position_vertex` pass on the RTX 5080, RADV and lavapipe. The branch is rebased onto e013f8c9c and the description is updated.
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!3878
No description provided.