fix(shader): leave out the all-zero position distance when guest distances fill all eight #6317

Merged
SleglJan merged 1 commit from upstream-pr/6317 into main 2026-10-18 22:12:58 +00:00
SleglJan commented 2026-10-15 11:13:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by SleglJan on 2026-10-15T11:13:15Z.


What

A vertex or tessellation evaluation program whose PA_CL_VS_OUT_CNTL enables all eight guest clip distances (CLIP_DIST_ENA 0xff with both distance vectors) does not compile on main:

guest clip distances plus the all-zero clip position distance exceed 8 clip distances

A program whose guest clip and cull distances together take eight (four of each, say) compiles, but its draw fails in the pipeline validator with more than eight clip and cull distances in one shader. The guest distances (#423) and the distance that removes primitives with a vertex at clip position (0,0,0,0) (#3878) share one gl_ClipDistance array, and eight guest distances leave no slot for the second.

The all-zero position distance is now added only while the guest clip and cull distances leave one of the eight slots free. Otherwise the program keeps its guest distances, and a primitive with a vertex at clip position (0,0,0,0) is not removed. The EmitSetAttribute debt entry records this.

It is left out rather than folded into a guest distance. The extra distance (-1 at an all-zero vertex, 0 at the others) removes every primitive with such a vertex, matching the Radeon 610M and llvmpipe results in the EmitSetAttribute debt entry. Writing -1 into a guest clip distance at that vertex keeps the parts of the primitive where the other vertices' distances are positive, and the minimum with the extra distance turns every positive guest distance into 0. A very large negative value there would remove the primitive and keep the guest plane, but it is not measured and has no equivalent when all eight are cull distances.

Related: #4650 (open) adds two clip distances for a depth range remap in the same function. Whichever lands second counts them in the same limit.

Tested

  • Tested on main 1db84d574, then rebased without conflicts onto main 8276a1d05, where tools/check_conventions.py --base upstream/main and git diff --check pass.
  • agc_position_invariance: one vertex program exporting two distance vectors, compiled with seven and eight clip distances (0x007f, 0x00ff) and with three and four clip distances beside four cull distances (0xf007, 0xf00f). The clip distance arrays are 8, 8, 4 and 4, so the all-zero position distance is in the first and third only. On main the second case throws and the fourth gives 5.
  • ctest agc|shader|recompiler|position on lavapipe (Mesa 26.2.4, LLVM 23.1.1; Arch Linux container, GCC 16.2.1): 577 of 582 pass. The five failures (agc_storage_kept_unit_settle, agc_driver_bc_block_copy, agc_driver_depth_compare_copy, agc_driver_native_multisample_depth, agc_driver_storage_write_back_overhang) also fail on main built the same way, which with only the test applied fails agc_position_invariance too, with the error above.
  • RTX 3080 (NVIDIA 615.78.08), CachyOS (Linux 7.2.10), GCC 16.2.1, Release: ctest agc|shader|recompiler|position, 582 of 582 pass, two of them skipped as on main (agc_import_watch_other_family, agc_driver_stencil_ref_export).
  • PPSA11386 (007 First Light), on a branch with #5799 and other local fixes: on that stack 137 vertex programs are refused at registration with this error in the first 110 frames of a boot and 459 by the time the level loads, and the run stops at frame 1025, in the level load, when one of them is drawn. With this change none are refused and the run continues to frame 1093, where it stops on a different error (registered program refers to an incompatible shader binary type).

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
  • Unblocks: PPSA11386 #5714
  • GPUs tested: NVIDIA RTX 3080, driver 615.78.08, CachyOS (Linux 7.2.10); lavapipe (Mesa 26.2.4, LLVM 23.1.1), Arch Linux container
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4872336727 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6317). Originally posted by [SleglJan](https://github.com/SleglJan) on 2026-10-15T11:13:15Z. --- ### What A vertex or tessellation evaluation program whose `PA_CL_VS_OUT_CNTL` enables all eight guest clip distances (`CLIP_DIST_ENA` 0xff with both distance vectors) does not compile on `main`: `guest clip distances plus the all-zero clip position distance exceed 8 clip distances` A program whose guest clip and cull distances together take eight (four of each, say) compiles, but its draw fails in the pipeline validator with `more than eight clip and cull distances in one shader`. The guest distances (#423) and the distance that removes primitives with a vertex at clip position (0,0,0,0) (#3878) share one `gl_ClipDistance` array, and eight guest distances leave no slot for the second. The all-zero position distance is now added only while the guest clip and cull distances leave one of the eight slots free. Otherwise the program keeps its guest distances, and a primitive with a vertex at clip position (0,0,0,0) is not removed. The `EmitSetAttribute` debt entry records this. It is left out rather than folded into a guest distance. The extra distance (-1 at an all-zero vertex, 0 at the others) removes every primitive with such a vertex, matching the Radeon 610M and llvmpipe results in the `EmitSetAttribute` debt entry. Writing -1 into a guest clip distance at that vertex keeps the parts of the primitive where the other vertices' distances are positive, and the minimum with the extra distance turns every positive guest distance into 0. A very large negative value there would remove the primitive and keep the guest plane, but it is not measured and has no equivalent when all eight are cull distances. Related: #4650 (open) adds two clip distances for a depth range remap in the same function. Whichever lands second counts them in the same limit. ### Tested - Tested on `main` 1db84d574, then rebased without conflicts onto `main` 8276a1d05, where `tools/check_conventions.py --base upstream/main` and `git diff --check` pass. - `agc_position_invariance`: one vertex program exporting two distance vectors, compiled with seven and eight clip distances (0x007f, 0x00ff) and with three and four clip distances beside four cull distances (0xf007, 0xf00f). The clip distance arrays are 8, 8, 4 and 4, so the all-zero position distance is in the first and third only. On `main` the second case throws and the fourth gives 5. - ctest `agc|shader|recompiler|position` on lavapipe (Mesa 26.2.4, LLVM 23.1.1; Arch Linux container, GCC 16.2.1): 577 of 582 pass. The five failures (`agc_storage_kept_unit_settle`, `agc_driver_bc_block_copy`, `agc_driver_depth_compare_copy`, `agc_driver_native_multisample_depth`, `agc_driver_storage_write_back_overhang`) also fail on `main` built the same way, which with only the test applied fails `agc_position_invariance` too, with the error above. - RTX 3080 (NVIDIA 615.78.08), CachyOS (Linux 7.2.10), GCC 16.2.1, Release: ctest `agc|shader|recompiler|position`, 582 of 582 pass, two of them skipped as on `main` (`agc_import_watch_other_family`, `agc_driver_stencil_ref_export`). - PPSA11386 (007 First Light), on a branch with #5799 and other local fixes: on that stack 137 vertex programs are refused at registration with this error in the first 110 frames of a boot and 459 by the time the level loads, and the run stops at frame 1025, in the level load, when one of them is drawn. With this change none are refused and the run continues to frame 1093, where it stops on a different error (`registered program refers to an incompatible shader binary type`). ### 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] Unblocks: PPSA11386 #5714 - [x] GPUs tested: NVIDIA RTX 3080, driver 615.78.08, CachyOS (Linux 7.2.10); lavapipe (Mesa 26.2.4, LLVM 23.1.1), Arch Linux container - [x] AI-assisted: yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-15 12:18:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T12:18:35Z.


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
PR 6470 docs/dev/debt/shader.md L148-149
PR 6613 docs/dev/debt/shader.md L19-20

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 4650 core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvEmitterHelpers.cpp
PR 5021 docs/dev/debt/shader.md
PR 5371 docs/dev/debt/shader.md
PR 5426 docs/dev/debt/shader.md
PR 5500 docs/dev/debt/shader.md
PR 5941 docs/dev/debt/shader.md
PR 6009 docs/dev/debt/shader.md
PR 6235 core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvEmitterHelpers.cpp
docs/dev/debt/shader.md
PR 6280 docs/dev/debt/shader.md
PR 6412 docs/dev/debt/shader.md
PR 6488 docs/dev/debt/shader.md
PR 6941 core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvEmitterHelpers.cpp
PR 6947 core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvEmitterHelpers.cpp
PR 6977 docs/dev/debt/shader.md
PR 7201 core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvEmitterHelpers.cpp
PR 7223 docs/dev/debt/shader.md
PR 7388 docs/dev/debt/shader.md
PR 7429 docs/dev/debt/shader.md
PR 7642 core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvEmitterHelpers.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6191867379 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6317#issuecomment-6191867379). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-15T12:18:35Z. --- <!-- 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 | |---|---|---|---| | [PR 6470](https://www.github.com/boykopovar/AnyPS5/pull/6470) | `docs/dev/debt/shader.md` [L148-149](https://github.com/boykopovar/AnyPS5/blob/8a456334f62fb961cb32f049ee5e389d8864306a/docs/dev/debt/shader.md#L148-L149) | | | | [PR 6613](https://www.github.com/boykopovar/AnyPS5/pull/6613) | `docs/dev/debt/shader.md` [L19-20](https://github.com/boykopovar/AnyPS5/blob/8a456334f62fb961cb32f049ee5e389d8864306a/docs/dev/debt/shader.md#L19-L20) | | | 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 4650](https://www.github.com/boykopovar/AnyPS5/pull/4650) | `core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvEmitterHelpers.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 5500](https://www.github.com/boykopovar/AnyPS5/pull/5500) | `docs/dev/debt/shader.md` | | [PR 5941](https://www.github.com/boykopovar/AnyPS5/pull/5941) | `docs/dev/debt/shader.md` | | [PR 6009](https://www.github.com/boykopovar/AnyPS5/pull/6009) | `docs/dev/debt/shader.md` | | [PR 6235](https://www.github.com/boykopovar/AnyPS5/pull/6235) | `core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvEmitterHelpers.cpp`<br>`docs/dev/debt/shader.md` | | [PR 6280](https://www.github.com/boykopovar/AnyPS5/pull/6280) | `docs/dev/debt/shader.md` | | [PR 6412](https://www.github.com/boykopovar/AnyPS5/pull/6412) | `docs/dev/debt/shader.md` | | [PR 6488](https://www.github.com/boykopovar/AnyPS5/pull/6488) | `docs/dev/debt/shader.md` | | [PR 6941](https://www.github.com/boykopovar/AnyPS5/pull/6941) | `core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvEmitterHelpers.cpp` | | [PR 6947](https://www.github.com/boykopovar/AnyPS5/pull/6947) | `core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvEmitterHelpers.cpp` | | [PR 6977](https://www.github.com/boykopovar/AnyPS5/pull/6977) | `docs/dev/debt/shader.md` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvEmitterHelpers.cpp` | | [PR 7223](https://www.github.com/boykopovar/AnyPS5/pull/7223) | `docs/dev/debt/shader.md` | | [PR 7388](https://www.github.com/boykopovar/AnyPS5/pull/7388) | `docs/dev/debt/shader.md` | | [PR 7429](https://www.github.com/boykopovar/AnyPS5/pull/7429) | `docs/dev/debt/shader.md` | | [PR 7642](https://www.github.com/boykopovar/AnyPS5/pull/7642) | `core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvEmitterHelpers.cpp` |
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!6317
No description provided.