fix(shader): clip primitives with an all-zero clip position #3878
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3878"
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 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_ClipDistanceelement: -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 advertisesClipDistancewhenshaderClipDistanceis enabled, and the pipeline validator accepts exactly this one-element output.Limits, also in TechnicalDebt:
shaderClipDistancecan no longer compile vertex shaders (the compile throws).Tested
Arch Linux, GCC 16.2.1, Release,
ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1,maina11c8f7f(the "this branch" row was run again after the rebase ontomaine013f8c9con 2026-10-12, same results on the RTX 5080, RADV and lavapipe). New testagc_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).Full ctest on this branch on
maine013f8c9c, RTX 5080: 927 pass, none fail (fourvideo_out_flip_*skipped). Existing recompiler tests that recompile a vertex shader gotClipDistanceadded to their hand-built capability lists; that now includes both target lists ofverifyNarrowVertexWaveintests/ShaderMemory.cpp, which arrived onmainafter this PR was opened and madeagc_shader_memoryfail with it until9db923e90.tools/check_conventions.py --base origin/mainpasses.Astro's Playroom on the RTX 5080 with #3669, #425, #3750 and this branch merged onto
maina11c8f7f: 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
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T18:39:01Z.
Built and ran the focused
agc_driver_zero_position_vertex_testsexecutable on Linux with GCC 12.2, Release, using Ninja 1.11.1. The run completed successfully withANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1on 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.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T22:12:31Z.
Thanks, the approach (one extra
gl_ClipDistanceelement, -1 when all four components are zero) reads correctly,agc_driver_zero_position_vertexand the 412 tests of libSceAgc/libSceAgcDriver pass here on RADV with the PR merged ontomain.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_vertexon your RTX 4090 withANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1, onmain(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 theClipDistancecapability to every vertex/tessellation-evaluation shader, and a device withoutshaderClipDistancecan no longer compile vertex shaders (TechnicalDebt line included).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.
main)core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppL264, L1350core/libs/prx/libSceAgcDriver/Graphics/include/Pipeline.hppL113core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppL735core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cppL139, L550, L571core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cppL570-571Imported 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: onmain22cecd5awith only the test file added,agc_driver_zero_position_vertexfails 5 of 5 witha 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.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
a11c8f7fwith 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:
With it:
Main menu after one Cross press, without and with:
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.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-12T04:38:04Z.
agc_shader_memorystill fails with this merged onto currentmain, on Linux and Windows (run 38201405444), withclipping a primitive with an all-zero clip position needs shaderClipDistance on the target device.verifyNarrowVertexWave()intests/ShaderMemory.cpp(added by #3546) compiles vertex shaders with two target lists,capabilitiesandnoArithmetic; addingspv::CapabilityClipDistanceto both made it pass here. The two titles I ran with the previous head showed no difference in frames or GPU time.Imported from boykopovar/AnyPS5. Originally posted by fma-rc on 2026-10-12T04:46:59Z.
Thanks, reproduced and fixed in
9db923e90. Onmaine013f8c9cwith the previous head,agc_shader_memoryfailed here with the same message. Both lists inverifyNarrowVertexWavenow carryspv::CapabilityClipDistance, as you did.With that, the full suite on the RTX 5080 has 927 passing and none failing, and
agc_shader_memoryandagc_driver_zero_position_vertexpass on the RTX 5080, RADV and lavapipe. The branch is rebased ontoe013f8c9cand the description is updated.