fix(agc): draw compacted restart lists and restart-free strips through the barycentric patches #12706

Merged
Gonic0 merged 1 commit from upstream-pr/12706 into main 2026-10-29 10:56:53 +00:00
Gonic0 commented 2026-10-29 03:57:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Gonic0 on 2026-10-29T03:57:05Z.


What

On a device with neither fragmentShaderBarycentric nor geometry shaders (MoltenVK), a pixel shader that reads barycentrics is emulated through generated tessellation stages. Until now, Driver::draw and Pipeline refused every such draw with the primitive restart bit set, but two of those draws never restart on the host:

  • A non-indexed triangle strip. The restart bit has no index to match, the same reasoning as #60. #8083 already expands strips into patch lists on the CPU.
  • A triangle list on a device without VK_EXT_primitive_topology_list_restart. Since #12180, its indices are compacted on the CPU before the draw, so no restart index reaches the host.

Both now take the patches. These still throw:

  • an indexed strip with restart;
  • a list with restart on a device that has the extension, where the host would restart and a patch list cannot.

Pipeline does not know whether a draw is indexed, so it accepts any strip. Graphics::Draw, which does know, now refuses an indexed strip with restart next to its existing indirect-strip check. Driver::draw refuses it too.

The pipeline keeps primitiveRestartEnable off for patch lists. Vulkan requires that without primitiveTopologyPatchListRestart (VUID-VkPipelineInputAssemblyStateCreateInfo-topology-06253).

The docs/dev/debt/shader.md and libSceAgcDriver.md entries for this path now say what is accepted and what throws. check_conventions.py warns about the length of the shader entry. That entry was already over 1000 characters on main; this PR only rewrites two of its clauses.

Overlap

  • #9387 (mesh-fallback barycentrics) rewrites the same require in Driver::draw and adds a mesh block right after the primitiveRestartEnable line in Pipeline.cpp. Neither PR needs the other. Whichever lands second keeps both changes: the meshCompute || prefix from #9387 in front of this PR's topology condition, and #9387's mesh block after the patch-aware primitiveRestartEnable line.
  • #9875 adds APS5_NO_LIST_RESTART. Once it lands, a CTest entry with that variable can run this PR's list cases on devices that have the extension (NVIDIA, AMD, lavapipe). For now they run only on devices without it. I did not add the same switch here, to avoid duplicating #9875.

Tested

Apple M5 Pro, macOS 27.2, MoltenVK from Vulkan SDK 1.4.363 (no geometry shaders, no primitiveTopologyListRestart), x86-64 Release under Rosetta 2, ANYPS5_NO_SHADER_CACHE=1.

main alone does not build libkernel or the driver on macOS, so I ran the tests in a tree with the open macOS port PRs. In that tree the changed functions match this branch exactly, and main has not touched the three source files between that tree's base and b433c40f2f.

agc_driver_pixel_barycentric_emulation_tests passes 3 of 3 with VK_LAYER_KHRONOS_validation loaded and no VUID- messages. It now draws through the tessellation stages, with the restart bit set:

  • a triangle strip;
  • a non-indexed triangle list;
  • the indexed list 2 R 0 1 2 0 1, where R is the restart index and only 0 1 2 is a complete triangle;
  • an indexed strip with restart, which must be refused.

It checks the I/J of every interior pixel as for the draws without restart: 864 and 864 pixels for the strip's two triangles, and 932 for each list. The list cases run only on a device without the extension. The strip cases run wherever tessellation does.

Negative controls (each fails, or reports, as expected):

  • The old Pipeline check fails at that check.
  • Skipping #12180's compaction for patch draws fails: "pixel (16, 6) channel 0 is 0.967349, expected 0.004731". This one ran on the previous base; the others ran on the current one.
  • Without the new Graphics::Draw check, the run fails with "an indexed triangle strip with primitive restart was not refused".
  • Without !patches in primitiveRestartEnable, the run passes but the validation layer reports VUID-...-06253 4 times.

agc_driver_list_restart_tests passes. agc_driver_graphics_tests passed 7 of 9 runs; both failures were "two ranges under a budget for two were not imported" from the host-import budget check in BdaResources.cpp. This PR does not touch that code, and the test then passed 5 runs in a row. agc_driver_mesh_barycentric_emulation_tests skips because there is no VK_EXT_mesh_shader.

Not covered by a test: the changed require in Driver::draw. The tests call VulkanDevice::Draw directly, and no execution test sends a barycentric draw through Driver::draw.

ASTRO BOT (PPSA21564 01.007.000): in a local tree that also emulates mesh shaders, the title aborted about 10 s in, while loading the UI, at this require without this change. With it, it ran for 300 s. Which of the three cases its draws use was not logged.

Not tested on Linux or Windows. Devices with geometry shaders do not take the patches.

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 (overlaps #9387 on the same lines, see Overlap)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: Apple M5 Pro, MoltenVK (Vulkan SDK 1.4.363), macOS 27.2
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5061862136 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12706). Originally posted by [Gonic0](https://github.com/Gonic0) on 2026-10-29T03:57:05Z. --- ### What On a device with neither `fragmentShaderBarycentric` nor geometry shaders (MoltenVK), a pixel shader that reads barycentrics is emulated through generated tessellation stages. Until now, `Driver::draw` and `Pipeline` refused every such draw with the primitive restart bit set, but two of those draws never restart on the host: - **A non-indexed triangle strip.** The restart bit has no index to match, the same reasoning as #60. #8083 already expands strips into patch lists on the CPU. - **A triangle list on a device without `VK_EXT_primitive_topology_list_restart`.** Since #12180, its indices are compacted on the CPU before the draw, so no restart index reaches the host. Both now take the patches. These still throw: - an indexed strip with restart; - a list with restart on a device that has the extension, where the host would restart and a patch list cannot. `Pipeline` does not know whether a draw is indexed, so it accepts any strip. `Graphics::Draw`, which does know, now refuses an indexed strip with restart next to its existing indirect-strip check. `Driver::draw` refuses it too. The pipeline keeps `primitiveRestartEnable` off for patch lists. Vulkan requires that without `primitiveTopologyPatchListRestart` (VUID-VkPipelineInputAssemblyStateCreateInfo-topology-06253). The `docs/dev/debt/shader.md` and `libSceAgcDriver.md` entries for this path now say what is accepted and what throws. `check_conventions.py` warns about the length of the shader entry. That entry was already over 1000 characters on `main`; this PR only rewrites two of its clauses. ### Overlap - **#9387** (mesh-fallback barycentrics) rewrites the same `require` in `Driver::draw` and adds a mesh block right after the `primitiveRestartEnable` line in `Pipeline.cpp`. Neither PR needs the other. Whichever lands second keeps both changes: the `meshCompute ||` prefix from #9387 in front of this PR's topology condition, and #9387's mesh block after the patch-aware `primitiveRestartEnable` line. - **#9875** adds `APS5_NO_LIST_RESTART`. Once it lands, a CTest entry with that variable can run this PR's list cases on devices that have the extension (NVIDIA, AMD, lavapipe). For now they run only on devices without it. I did not add the same switch here, to avoid duplicating #9875. ### Tested Apple M5 Pro, macOS 27.2, MoltenVK from Vulkan SDK 1.4.363 (no geometry shaders, no `primitiveTopologyListRestart`), x86-64 Release under Rosetta 2, `ANYPS5_NO_SHADER_CACHE=1`. `main` alone does not build libkernel or the driver on macOS, so I ran the tests in a tree with the open macOS port PRs. In that tree the changed functions match this branch exactly, and `main` has not touched the three source files between that tree's base and `b433c40f2f`. `agc_driver_pixel_barycentric_emulation_tests` passes 3 of 3 with `VK_LAYER_KHRONOS_validation` loaded and no `VUID-` messages. It now draws through the tessellation stages, with the restart bit set: - a triangle strip; - a non-indexed triangle list; - the indexed list `2 R 0 1 2 0 1`, where R is the restart index and only `0 1 2` is a complete triangle; - an indexed strip with restart, which must be refused. It checks the I/J of every interior pixel as for the draws without restart: 864 and 864 pixels for the strip's two triangles, and 932 for each list. The list cases run only on a device without the extension. The strip cases run wherever tessellation does. Negative controls (each fails, or reports, as expected): - The old `Pipeline` check fails at that check. - Skipping #12180's compaction for patch draws fails: "pixel (16, 6) channel 0 is 0.967349, expected 0.004731". This one ran on the previous base; the others ran on the current one. - Without the new `Graphics::Draw` check, the run fails with "an indexed triangle strip with primitive restart was not refused". - Without `!patches` in `primitiveRestartEnable`, the run passes but the validation layer reports VUID-...-06253 4 times. `agc_driver_list_restart_tests` passes. `agc_driver_graphics_tests` passed 7 of 9 runs; both failures were "two ranges under a budget for two were not imported" from the host-import budget check in `BdaResources.cpp`. This PR does not touch that code, and the test then passed 5 runs in a row. `agc_driver_mesh_barycentric_emulation_tests` skips because there is no `VK_EXT_mesh_shader`. Not covered by a test: the changed `require` in `Driver::draw`. The tests call `VulkanDevice::Draw` directly, and no execution test sends a barycentric draw through `Driver::draw`. ASTRO BOT (PPSA21564 01.007.000): in a local tree that also emulates mesh shaders, the title aborted about 10 s in, while loading the UI, at this `require` without this change. With it, it ran for 300 s. Which of the three cases its draws use was not logged. Not tested on Linux or Windows. Devices with geometry shaders do not take the patches. ### 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 (overlaps #9387 on the same lines, see Overlap) - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: Apple M5 Pro, MoltenVK (Vulkan SDK 1.4.363), macOS 27.2 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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!12706
No description provided.