fix(agc): accept PA_CL_CLIP_CNTL UCP_CULL_ONLY_ENA without active clip planes #26578

Merged
birdmarty merged 1 commit from upstream-pr/26578 into main 2026-11-24 14:40:43 +00:00
birdmarty commented 2026-11-24 05:54:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by birdmarty on 2026-11-24T05:54:12Z.


What

PA_CL_CLIP_CNTL (0x204 / MMIO 0x28810) bit 17 is UCP_CULL_ONLY_ENA (cull primitives against enabled user clip planes without clipping them, per AMD PAL gfx9_plus_merged_registers.h and Mesa gfx103.json). DecodeState and DrawRejection previously rejected bit 17 unconditionally through ClipControlMask, even when no user clip plane (UCP_ENA_0..5, bits 0..5, still rejected) and no vertex clip distance (PA_CL_VS_OUT_CNTL CLIP_DIST_ENA_0..7, bits 0..7) is enabled.

When neither UCP_ENA_0..5 nor PA_CL_VS_OUT_CNTL CLIP_DIST_ENA_0..7 is set, there are no active clip planes for UCP_CULL_ONLY_ENA to act on, so it leaves pipeline state unchanged. Draws that set UCP_CULL_ONLY_ENA alongside any UCP_ENA_0..5 bit or any PA_CL_VS_OUT_CNTL CLIP_DIST_ENA_0..7 bit still throw, since whether bit 17 also affects shader clip distances on the console is unverified.

Changes

  • core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp: add clipControlMask(const Registers& cx) that clears UCP_CULL_ONLY_ENA (bit 17) from ClipControlMask when PA_CL_VS_OUT_CNTL (0x207) has CLIP_DIST_ENA_0..7 (bits 0..7) clear, and use it in both DecodeState and DrawRejection.
  • core/libs/prx/libSceAgcDriver/tests/Graphics.cpp: verify bit 17 decodes cleanly without altering clip space, depth clamping or depth range when no clip distances are enabled (including with cull distances only), and still fails both DecodeState and DrawRejection when any CLIP_DIST_ENA_0..7 or UCP_ENA_0..5 bit is set.
  • docs/dev/debt/changes/fix-agc-ucp-cull-only-without-clip-planes.md: update the PA_CL_CLIP_CNTL debt entry in docs/dev/debt/libSceAgcDriver.md to record UCP_CULL_ONLY_ENA and the unverified interaction with shader clip distances.

Tested

Windows 11 Pro (build 26300), Intel Core i9-9900K, AMD Radeon RX 6800 (AMD driver 26.10.1, Windows driver 32.0.21045.16010, Vulkan 1.4.315), MinGW-w64 GCC 15.3.0, Release, main 441fa65119.

Focused set (agc_driver_graphics, agc_driver_unused_viewport_depth, agc_driver_depth_range_remap_draw, agc_driver_vertex_clip_cull_distances, agc_driver_vertex_clip_cull_draw, agc_driver_vertex_clip_cull_draw_no_key, agc_driver_viewport_index, agc_depth_range_remap, agc_driver_tessellation_depth_range_remap, agc_mesh_cull_store) with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation (1.4.363.0) and VK_LOADER_DEBUG=layer:

main 441fa65119 this change
Passed / failed 10 / 0 10 / 0
Validation layer inserted 8 8
VUID- lines 0 0

Without the fix (origin/main's State.cpp with this branch's Graphics.cpp), agc_driver_graphics fails with a PA_CL_CLIP_CNTL flag is unsupported (register 0x204 = 0x000a0000).

Kingdom Come: Deliverance II (PPSA21704, 01.052.000):

  • What the game does: submits a triangle-list draw with PA_CL_CLIP_CNTL = 0x000a0000 (DX_CLIP_SPACE_DEF | UCP_CULL_ONLY_ENA), PA_CL_VS_OUT_CNTL = 0x00000000, and all PA_CL_UCP_0..5 zero.
  • Without this change: aborts at 13.58 s (2 presents) on Main e60b2f74ad with a PA_CL_CLIP_CNTL flag is unsupported (register 0x204 = 0x000a0000) (reproduced twice).
  • With this change: clean fix applied on Main e60b2f74ad (bb0acb0514, no diagnostics) passes the stop cleanly in 5 consecutive runs with 0 errors: boots through the CryEngine/Bink/FMOD splash, EULA, Graphics Mode selection (Performance 2560x1440), Main Menu (~44–60 FPS), New Game (Standard Mode), and into the real-time 3D opening Siege of Suchdol cutscene (~6–11 FPS, verified by GPU frame dumps).

py -3 tools/check_conventions.py --base origin/main and py -3 tools/debt_fold.py --check pass. py -3 tools/pr_overlap.py --branch fix/agc-ucp-cull-only-without-clip-planes (2,595 open PRs): all 53 mergeable PRs that share files merge cleanly with no overlap; all 13 conflicting PRs touching State.cpp (#1395, #6188, #6235, #7256, #9895, #11551, #11825, #20845, #23252, #23258, #23281, #24049, #26046) were searched by hand and none touches ClipControlMask or UCP_CULL_ONLY_ENA.

Not tested: whether UCP_CULL_ONLY_ENA affects PA_CL_VS_OUT_CNTL CLIP_DIST_ENA_0..7 on console hardware (those draws still throw), other GPUs, 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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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: PPSA21704 #26577
  • GPUs tested: AMD Radeon RX 6800 (vendor=0x1002, device=0x73bf), AMD proprietary driver 26.10.1 (Windows driver 32.0.21045.16010, Vulkan 1.4.315), Windows 11 Pro (build 26300); Khronos validation layer 1.4.363.0 on main and this change, 0 VUIDs
  • AI-assisted: yes (Antigravity)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5466914447 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/26578). Originally posted by [birdmarty](https://github.com/birdmarty) on 2026-11-24T05:54:12Z. --- ### What `PA_CL_CLIP_CNTL` (`0x204` / MMIO `0x28810`) bit 17 is `UCP_CULL_ONLY_ENA` (cull primitives against enabled user clip planes without clipping them, per AMD PAL `gfx9_plus_merged_registers.h` and Mesa `gfx103.json`). `DecodeState` and `DrawRejection` previously rejected bit 17 unconditionally through `ClipControlMask`, even when no user clip plane (`UCP_ENA_0..5`, bits 0..5, still rejected) and no vertex clip distance (`PA_CL_VS_OUT_CNTL` `CLIP_DIST_ENA_0..7`, bits 0..7) is enabled. When neither `UCP_ENA_0..5` nor `PA_CL_VS_OUT_CNTL` `CLIP_DIST_ENA_0..7` is set, there are no active clip planes for `UCP_CULL_ONLY_ENA` to act on, so it leaves pipeline state unchanged. Draws that set `UCP_CULL_ONLY_ENA` alongside any `UCP_ENA_0..5` bit or any `PA_CL_VS_OUT_CNTL` `CLIP_DIST_ENA_0..7` bit still throw, since whether bit 17 also affects shader clip distances on the console is unverified. #### Changes - `core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp`: add `clipControlMask(const Registers& cx)` that clears `UCP_CULL_ONLY_ENA` (bit 17) from `ClipControlMask` when `PA_CL_VS_OUT_CNTL` (`0x207`) has `CLIP_DIST_ENA_0..7` (bits 0..7) clear, and use it in both `DecodeState` and `DrawRejection`. - `core/libs/prx/libSceAgcDriver/tests/Graphics.cpp`: verify bit 17 decodes cleanly without altering clip space, depth clamping or depth range when no clip distances are enabled (including with cull distances only), and still fails both `DecodeState` and `DrawRejection` when any `CLIP_DIST_ENA_0..7` or `UCP_ENA_0..5` bit is set. - `docs/dev/debt/changes/fix-agc-ucp-cull-only-without-clip-planes.md`: update the `PA_CL_CLIP_CNTL` debt entry in `docs/dev/debt/libSceAgcDriver.md` to record `UCP_CULL_ONLY_ENA` and the unverified interaction with shader clip distances. ### Tested Windows 11 Pro (build 26300), Intel Core i9-9900K, AMD Radeon RX 6800 (AMD driver 26.10.1, Windows driver 32.0.21045.16010, Vulkan 1.4.315), MinGW-w64 GCC 15.3.0, Release, `main` `441fa65119`. Focused set (`agc_driver_graphics`, `agc_driver_unused_viewport_depth`, `agc_driver_depth_range_remap_draw`, `agc_driver_vertex_clip_cull_distances`, `agc_driver_vertex_clip_cull_draw`, `agc_driver_vertex_clip_cull_draw_no_key`, `agc_driver_viewport_index`, `agc_depth_range_remap`, `agc_driver_tessellation_depth_range_remap`, `agc_mesh_cull_store`) with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1`, `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` (1.4.363.0) and `VK_LOADER_DEBUG=layer`: | | `main` `441fa65119` | this change | |---|---|---| | Passed / failed | 10 / 0 | 10 / 0 | | Validation layer inserted | 8 | 8 | | `VUID-` lines | 0 | 0 | Without the fix (`origin/main`'s `State.cpp` with this branch's `Graphics.cpp`), `agc_driver_graphics` fails with `a PA_CL_CLIP_CNTL flag is unsupported (register 0x204 = 0x000a0000)`. Kingdom Come: Deliverance II (`PPSA21704`, `01.052.000`): - **What the game does:** submits a triangle-list draw with `PA_CL_CLIP_CNTL = 0x000a0000` (`DX_CLIP_SPACE_DEF | UCP_CULL_ONLY_ENA`), `PA_CL_VS_OUT_CNTL = 0x00000000`, and all `PA_CL_UCP_0..5` zero. - **Without this change:** aborts at 13.58 s (2 presents) on Main `e60b2f74ad` with `a PA_CL_CLIP_CNTL flag is unsupported (register 0x204 = 0x000a0000)` (reproduced twice). - **With this change:** clean fix applied on Main `e60b2f74ad` (`bb0acb0514`, no diagnostics) passes the stop cleanly in 5 consecutive runs with 0 errors: boots through the CryEngine/Bink/FMOD splash, EULA, Graphics Mode selection (Performance 2560x1440), Main Menu (~44–60 FPS), New Game (Standard Mode), and into the real-time 3D opening Siege of Suchdol cutscene (~6–11 FPS, verified by GPU frame dumps). `py -3 tools/check_conventions.py --base origin/main` and `py -3 tools/debt_fold.py --check` pass. `py -3 tools/pr_overlap.py --branch fix/agc-ucp-cull-only-without-clip-planes` (2,595 open PRs): all 53 mergeable PRs that share files merge cleanly with no overlap; all 13 conflicting PRs touching `State.cpp` (#1395, #6188, #6235, #7256, #9895, #11551, #11825, #20845, #23252, #23258, #23281, #24049, #26046) were searched by hand and none touches `ClipControlMask` or `UCP_CULL_ONLY_ENA`. Not tested: whether `UCP_CULL_ONLY_ENA` affects `PA_CL_VS_OUT_CNTL` `CLIP_DIST_ENA_0..7` on console hardware (those draws still throw), other GPUs, Linux. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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) and the licence notice of code adapted from upstream (see AGENTS.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: PPSA21704 #26577 - [x] GPUs tested: AMD Radeon RX 6800 (vendor=0x1002, device=0x73bf), AMD proprietary driver 26.10.1 (Windows driver 32.0.21045.16010, Vulkan 1.4.315), Windows 11 Pro (build 26300); Khronos validation layer 1.4.363.0 on `main` and this change, 0 VUIDs - [x] AI-assisted: yes (Antigravity)
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!26578
No description provided.