fix(agc): draw a last provoking vertex through the barycentric tessellation stages without VK_EXT_provoking_vertex #21938

Merged
kurexw merged 1 commit from upstream-pr/21938 into main 2026-11-20 09:56:50 +00:00
kurexw commented 2026-11-16 22:29:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by kurexw on 2026-11-16T22:29:58Z.


What

On a device without VK_EXT_provoking_vertex provokingVertexLast (MoltenVK on Apple GPUs), a draw in last-provoking-vertex mode whose pixel shader shows the provoking vertex fails at ValidateProvokingVertex (Graphics/src/Pipeline.cpp) with last provoking vertex requires VK_EXT_provoking_vertex with provokingVertexLast enabled. The barycentric tessellation stages already give each corner the last vertex's flat values (#7426, #8083), but a draw used them only when its pixel shader had been recompiled with emulated barycentrics, which happens only on devices without native fragment barycentrics. The Apple M4 has native barycentrics, so these draws took the native path and threw.

This PR sends such draws through the existing tessellation stages:

  • LastVertexPatches (Pipeline.cpp) decides it. The device lacks provokingVertexLast and has tessellation shaders, the draw is in last mode on the vertex path (not a rect list, mesh or tessellation draw), and its pixel shader shows the provoking vertex (the same test ValidateProvokingVertex already applies, moved to file scope). Its vertex shader writes no Layer or ViewportIndex, and the topology is one the stages draw: a triangle list (primitive restart only without VK_EXT_primitive_topology_list_restart) or a triangle strip (primitive restart only in a non-indexed draw).
  • The driver (Execution/src/Driver/Draw/Draw.cpp) then recompiles the pixel shader with a new GraphicsCompileContext::emulateBarycentrics flag and builds the tessellation stages with the last vertex, as it already does for emulated barycentrics. Re-materialised stages of an indirect draw keep the flag.
  • The recompiler (Recompiler.cpp) translates a pixel shader with that flag the way it already does when lowering to host interpolation fails.
  • The flag only enters the cache key of a pixel shader that sets it; every other request keeps its exact key. Request serialization moves to version 63 and writes the flag as one trailing byte only when it is set. A request without it serializes to the same bytes as before apart from the version number. Version 62 requests still load.
  • Points, lines, fans, mesh and tessellation paths, and draws whose vertex shader writes the layer or viewport still throw, as before. A debt fragment records that, and that the cost of the two extra stages per draw is not measured.

Note for merging: #20153 also moves request serialization to version 63. Whichever merges second needs version 64.

Tested

macOS 27.2 on an Apple M4 (MoltenVK 1.4.2 from the LunarG Vulkan SDK 1.4.363.1, x86-64 build under Rosetta). This is the only GPU I tested. I could not run RADV, NVIDIA or Windows here. Devices with provokingVertexLast don't reach the new path, which LastVertexPatchTests checks on the CPU.

New tests

  • agc_driver_vertex_provoking_vertex (new) submits real DCB draws through the driver: a guest vertex program with a flat v_interp_mov P0 pixel shader, as a triangle list and a triangle strip, alternating first, last and first mode. It checks that each triangle takes its first or its last vertex's color.
    • Main at 3b17977ba6 fails it with the throw above.
    • With the Draw.cpp routing disabled, it also fails with that message.
    • This branch passes.
  • agc_driver_provoking_vertex: on a device without provokingVertexLast and with tessellation, it now also draws the guest P0 shader through the emulated barycentric stages, as a list and a strip, first/last/first, and checks the last-vertex colors.
    • Building the last-mode stages with vertex 0 instead of 2 makes it fail.
    • Main fails this test on the M4 under ANYPS5_REQUIRE_VULKAN; this branch passes it.
  • agc_driver_unobserved_provoking_vertex gains LastVertexPatchTests, which covers every condition of the decision.
  • agc_shader_memory gains verifyEmulatedBarycentricRequests. It checks that:
    • a pixel request without the flag has the same cache key and context hash as one without a graphics context;
    • the flag adds exactly one key element, and only for the pixel stage;
    • the flag round-trips through serialization;
    • a version 62 request is upgraded byte-identically;
    • malformed trailing flags are refused.
  • request_serializer and agc_shader_memory were updated for version 63.

GPU tests, main vs. this branch

  • Main was 3b17977ba6; this branch was first tested on that commit, then rebased onto 459f4f8c22 and tested again.
  • Command: ctest --test-dir build -R '^agc_driver_.*(barycentric|tessellation|provoking|patch_vertex|interpolation|rect_list).*' -V, three runs per side.
  • Environment: ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation and VK_LOADER_DEBUG=layer.
  • Every test process logged Insert instance layer "VK_LAYER_KHRONOS_validation" (layer 1.4.363). None logged was not found but was requested by env var VK_INSTANCE_LAYERS.
main (3 runs) this branch (3 runs, before and after rebase)
agc_driver_provoking_vertex Failed Passed
agc_driver_vertex_provoking_vertex (absent) Passed
agc_driver_tessellation Failed Failed (same message: instanced patch relative index, unrelated)
other 14 Passed or skipped Passed or skipped, identical
VUID- lines 0 0

Full ctest -j8

  • Main: 50 failures out of 5650 tests. This branch: 51 out of 5651.
  • By name, three tests fail only on the branch: guest_audio_propagation, guest_main_stack_move and guest_system_service_open_url. None of them links the AGC driver or the recompiler. Run alone, each passes on some runs and fails on others on this branch.
  • Two tests time out only on main: guest_pthread_mutex_contention and write_watch_backing_shared.

Not tested

  • PPSA98001 and PPSA99993 themselves, which I don't have.
  • On the GPU, the new driver test submits only non-indexed, non-indirect DRAW_INDEX_AUTO draws without primitive restart. These run only in the CPU tests (LastVertexPatchTests), not on a GPU:
    • indexed draws;
    • primitive restart: a list on a device without VK_EXT_primitive_topology_list_restart, or a non-indexed strip;
    • re-materialising the pixel stage of an indirect draw, which passes the flag again (Draw.cpp, the patched-program loop).

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: PPSA98001 (PokeMMO) and PPSA99993 (Pulse), which stop at this throw on macOS in #1 (comment). Not run with the titles.
  • GPUs tested: Apple M4, MoltenVK 1.4.2 (LunarG Vulkan SDK 1.4.363.1), macOS 27.2
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5346372144 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21938). Originally posted by [kurexw](https://github.com/kurexw) on 2026-11-16T22:29:58Z. --- ### What On a device without `VK_EXT_provoking_vertex` `provokingVertexLast` (MoltenVK on Apple GPUs), a draw in last-provoking-vertex mode whose pixel shader shows the provoking vertex fails at `ValidateProvokingVertex` (`Graphics/src/Pipeline.cpp`) with `last provoking vertex requires VK_EXT_provoking_vertex with provokingVertexLast enabled`. The barycentric tessellation stages already give each corner the last vertex's flat values (#7426, #8083), but a draw used them only when its pixel shader had been recompiled with emulated barycentrics, which happens only on devices without native fragment barycentrics. The Apple M4 has native barycentrics, so these draws took the native path and threw. This PR sends such draws through the existing tessellation stages: - `LastVertexPatches` (`Pipeline.cpp`) decides it. The device lacks `provokingVertexLast` and has tessellation shaders, the draw is in last mode on the vertex path (not a rect list, mesh or tessellation draw), and its pixel shader shows the provoking vertex (the same test `ValidateProvokingVertex` already applies, moved to file scope). Its vertex shader writes no `Layer` or `ViewportIndex`, and the topology is one the stages draw: a triangle list (primitive restart only without `VK_EXT_primitive_topology_list_restart`) or a triangle strip (primitive restart only in a non-indexed draw). - The driver (`Execution/src/Driver/Draw/Draw.cpp`) then recompiles the pixel shader with a new `GraphicsCompileContext::emulateBarycentrics` flag and builds the tessellation stages with the last vertex, as it already does for emulated barycentrics. Re-materialised stages of an indirect draw keep the flag. - The recompiler (`Recompiler.cpp`) translates a pixel shader with that flag the way it already does when lowering to host interpolation fails. - The flag only enters the cache key of a pixel shader that sets it; every other request keeps its exact key. Request serialization moves to version 63 and writes the flag as one trailing byte only when it is set. A request without it serializes to the same bytes as before apart from the version number. Version 62 requests still load. - Points, lines, fans, mesh and tessellation paths, and draws whose vertex shader writes the layer or viewport still throw, as before. A debt fragment records that, and that the cost of the two extra stages per draw is not measured. Note for merging: #20153 also moves request serialization to version 63. Whichever merges second needs version 64. ### Tested macOS 27.2 on an Apple M4 (MoltenVK 1.4.2 from the LunarG Vulkan SDK 1.4.363.1, x86-64 build under Rosetta). This is the only GPU I tested. I could not run RADV, NVIDIA or Windows here. Devices with `provokingVertexLast` don't reach the new path, which `LastVertexPatchTests` checks on the CPU. **New tests** - `agc_driver_vertex_provoking_vertex` (new) submits real DCB draws through the driver: a guest vertex program with a flat `v_interp_mov` P0 pixel shader, as a triangle list and a triangle strip, alternating first, last and first mode. It checks that each triangle takes its first or its last vertex's color. - Main at 3b17977ba6 fails it with the throw above. - With the `Draw.cpp` routing disabled, it also fails with that message. - This branch passes. - `agc_driver_provoking_vertex`: on a device without `provokingVertexLast` and with tessellation, it now also draws the guest P0 shader through the emulated barycentric stages, as a list and a strip, first/last/first, and checks the last-vertex colors. - Building the last-mode stages with vertex 0 instead of 2 makes it fail. - Main fails this test on the M4 under `ANYPS5_REQUIRE_VULKAN`; this branch passes it. - `agc_driver_unobserved_provoking_vertex` gains `LastVertexPatchTests`, which covers every condition of the decision. - `agc_shader_memory` gains `verifyEmulatedBarycentricRequests`. It checks that: - a pixel request without the flag has the same cache key and context hash as one without a graphics context; - the flag adds exactly one key element, and only for the pixel stage; - the flag round-trips through serialization; - a version 62 request is upgraded byte-identically; - malformed trailing flags are refused. - `request_serializer` and `agc_shader_memory` were updated for version 63. **GPU tests, main vs. this branch** - Main was 3b17977ba6; this branch was first tested on that commit, then rebased onto 459f4f8c22 and tested again. - Command: `ctest --test-dir build -R '^agc_driver_.*(barycentric|tessellation|provoking|patch_vertex|interpolation|rect_list).*' -V`, three runs per side. - Environment: `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1`, `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` and `VK_LOADER_DEBUG=layer`. - Every test process logged `Insert instance layer "VK_LAYER_KHRONOS_validation"` (layer 1.4.363). None logged `was not found but was requested by env var VK_INSTANCE_LAYERS`. | | main (3 runs) | this branch (3 runs, before and after rebase) | | --- | --- | --- | | `agc_driver_provoking_vertex` | Failed | Passed | | `agc_driver_vertex_provoking_vertex` | (absent) | Passed | | `agc_driver_tessellation` | Failed | Failed (same message: instanced patch relative index, unrelated) | | other 14 | Passed or skipped | Passed or skipped, identical | | `VUID-` lines | 0 | 0 | **Full `ctest -j8`** - Main: 50 failures out of 5650 tests. This branch: 51 out of 5651. - By name, three tests fail only on the branch: `guest_audio_propagation`, `guest_main_stack_move` and `guest_system_service_open_url`. None of them links the AGC driver or the recompiler. Run alone, each passes on some runs and fails on others on this branch. - Two tests time out only on main: `guest_pthread_mutex_contention` and `write_watch_backing_shared`. **Not tested** - PPSA98001 and PPSA99993 themselves, which I don't have. - On the GPU, the new driver test submits only non-indexed, non-indirect `DRAW_INDEX_AUTO` draws without primitive restart. These run only in the CPU tests (`LastVertexPatchTests`), not on a GPU: - indexed draws; - primitive restart: a list on a device without `VK_EXT_primitive_topology_list_restart`, or a non-indexed strip; - re-materialising the pixel stage of an indirect draw, which passes the flag again (`Draw.cpp`, the patched-program loop). ### 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: PPSA98001 (PokeMMO) and PPSA99993 (Pulse), which stop at this throw on macOS in #1 ([comment](https://github.com/boykopovar/AnyPS5/issues/1#issuecomment-6343620098)). Not run with the titles. - [x] GPUs tested: Apple M4, MoltenVK 1.4.2 (LunarG Vulkan SDK 1.4.363.1), macOS 27.2 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-11-17 00:35:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-17T00:35:05Z.

Review: COMMENTED


Reviewed — no blocking findings

The inspected implementation supports the described last-vertex fallback; a complete review and local checks were not possible because several changed files were not read and no tests were run.

What I ran

Reviewed head 942ec64f2f798b0a8adbc5990c6cb9c6c3590685 using the prepared review bundle and repo_read.py reader. No test commands were run. I read description.md, commits.md, manifest.json, and the relevant portions of diff.patch; repository code read included Draw.cpp, DrawCapture.cpp, Pipeline.hpp, Pipeline.cpp, CacheKey.hpp, RequestSerializer.cpp, Recompiler.cpp, and tests/execution/VertexProvokingVertex.cpp.

Results

Check Result Note
Targeted code review passed No concrete defect found in the inspected changes.
Tests not run Author-reported results were not independently verified.
Full review coverage not run Some changed files were not read.

Findings

Blocking

None in the inspected code.

Non-blocking

  • The description notes that another PR also moves request serialization to version 63. Coordinate merge order so the second change advances the version to 64; otherwise both changes can assign different payload meanings to the same version.

Not verified

I did not read the changed files tests/Graphics.cpp and tests/ShaderMemory.cpp, which were excluded from the review folder as too large, or the remaining changed files and hunks not listed above. I did not run tests or verify the author-reported GPU results. The PR description says indexed draws, primitive-restart cases, and indirect draw re-materialization were not GPU-tested.

To get this to a good state

Nothing is required. Optional: coordinate the serialization version with the other PR before merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5930533873 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21938#pullrequestreview-5930533873). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-17T00:35:05Z. **Review:** COMMENTED --- # Reviewed — no blocking findings The inspected implementation supports the described last-vertex fallback; a complete review and local checks were not possible because several changed files were not read and no tests were run. ## What I ran Reviewed head `942ec64f2f798b0a8adbc5990c6cb9c6c3590685` using the prepared review bundle and `repo_read.py` reader. No test commands were run. I read `description.md`, `commits.md`, `manifest.json`, and the relevant portions of `diff.patch`; repository code read included `Draw.cpp`, `DrawCapture.cpp`, `Pipeline.hpp`, `Pipeline.cpp`, `CacheKey.hpp`, `RequestSerializer.cpp`, `Recompiler.cpp`, and `tests/execution/VertexProvokingVertex.cpp`. ## Results | Check | Result | Note | | --- | --- | --- | | Targeted code review | passed | No concrete defect found in the inspected changes. | | Tests | not run | Author-reported results were not independently verified. | | Full review coverage | not run | Some changed files were not read. | ## Findings ### Blocking None in the inspected code. ### Non-blocking - The description notes that another PR also moves request serialization to version 63. Coordinate merge order so the second change advances the version to 64; otherwise both changes can assign different payload meanings to the same version. ## Not verified I did not read the changed files `tests/Graphics.cpp` and `tests/ShaderMemory.cpp`, which were excluded from the review folder as too large, or the remaining changed files and hunks not listed above. I did not run tests or verify the author-reported GPU results. The PR description says indexed draws, primitive-restart cases, and indirect draw re-materialization were not GPU-tested. ## To get this to a good state Nothing is required. Optional: coordinate the serialization version with the other PR before merging.
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!21938
No description provided.