Skip to content

feat(agc): emulate mesh-fallback barycentrics through tessellation - #103

Open
Thimo188 wants to merge 4 commits into
mainfrom
upstream-pr/9387
Open

Thimo188 wants to merge 4 commits into
mainfrom
upstream-pr/9387

Conversation

@Thimo188

@Thimo188 Thimo188 commented Dec 2, 2026

Copy link
Copy Markdown
Owner

Imported from boykopovar/AnyPS5#9387, originally opened by Alexius0815.

Source commit: 73641399d35dafa6576e1c974bff65e207f1bd20. The import branch preserves this fetched upstream PR snapshot. The description and validation below are copied from upstream; no new code changes or test runs were made for this import. Original reviews, discussions, and attachments remain at the linked upstream PR.


What

Builds on boykopovar#9356. On a device without fragmentShaderBarycentric, a mesh-path draw that runs through the compute fallback and whose pixel shader reads barycentrics had no route. The barycentric tessellation emulation from boykopovar#7308 was limited to the vertex path. This PR feeds the mesh readback vertex shader from boykopovar#9356 into BuildBarycentricTessellationShaders. The draw then runs as compute pass → readback VS → TCS → TES → fragment, drawn as a 3-control-point patch list.

  • Execution/.../Draw.cpp: a compute-fallback mesh program takes the emulation branch. It requires triangle output, tessellation support and no clip, cull or layer exports, and passes the provoking vertex mode as in feat(agc): draw the last provoking vertex through the barycentric tessellation stages boykopovar/AnyPS5#7426.
  • Graphics/src/Draw.cpp: MeshComputeStages accepts the two emulation stages after the mesh stage.
  • Pipeline.cpp: patch-list topology and patchControlPoints = 3 for the emulation patches on the mesh path. Like the vertex path's patches, they need no VK_EXT_provoking_vertex for the last provoking vertex, because the generated evaluation stage writes the provoking vertex's flat values itself (feat(agc): draw the last provoking vertex through the barycentric tessellation stages boykopovar/AnyPS5#7426).
  • ShaderValidation.cpp: validates the five-stage mesh layout. The failure text stays "require a triangle list".
  • Recompiler.cpp: a pixel shader whose request runs the mesh program as compute is no longer compiled in mesh mode. Its flat inputs then stay per vertex, as the tessellation evaluation stage in front of it provides them (from root-over, co-author).
  • MeshReadbackVertexShader.cpp: copies parameterExports so the control stage sees the mesh outputs.
  • core/shader/recompiler/CMakeLists.txt: MeshRecordClipDistances, MeshRecordCullDistances and MeshRecordLayer are recorded in shaderCacheReviewedNames. They are inline decoders of RecompileResult::meshRecordLayout, which is part of the cached result, and Draw.cpp only uses them to refuse draws. They do not reach a RecompileRequest.
  • tests/Mesh.cpp: agc_driver_mesh draws through the compute fallback with fragmentShaderBarycentric disabled, non-indexed and indexed, and compares front/back culling with the ordinary readback draw. A flat-input case with a different value per vertex checks the provoking vertex's value on every triangle, with the first and with the last provoking vertex. The emulated draws give the pixel request the mesh GraphicsCompileContext, as DrawCapture does.
  • docs/dev/debt/libSceAgcDriver.md:
    • lists the mesh-fallback cases that still refuse: clip, cull and layer exports;
    • lists the layered-draw case on devices with mesh shaders, whose pixel request still carries no meshAsCompute.

Overlap: boykopovar#8083 (now merged) and boykopovar#8339 each change a condition line in Execution/.../Draw.cpp, and boykopovar#8083 also changes the triangle-list check in ShaderValidation.cpp. This branch sits on boykopovar#9356's current head f49a25a, which itself conflicts with main again. Once boykopovar#9356 is rebased, I will rebase this commit onto it and keep the triangle-strip condition and its message next to the mesh stage count.

Tested

Apple M4 (10-core GPU), macOS 27.2, MoltenVK (no mesh shaders, no fragment barycentrics, no VK_EXT_provoking_vertex), x86_64 build under Rosetta 2. Current main does not build its libc on macOS, so the runtime tests ran on the community macOS stack with boykopovar#9356 and the same changes applied:

  • agc_driver_graphics, agc_driver_mesh (including the flat-input cases with the first and the last provoking vertex) and agc_driver_pixel_barycentric_emulation pass. The stack lacked feat(agc): draw the last provoking vertex through the barycentric tessellation stages boykopovar/AnyPS5#7426, so its three code commits were cherry-picked there.
  • The two GPU tests, agc_driver_mesh and agc_driver_pixel_barycentric_emulation, pass with and without VK_LAYER_KHRONOS_validation 1.4.357.0, with no validation errors. agc_driver_graphics is CPU-side. MoltenVK has no VK_EXT_provoking_vertex.
  • Negative controls fail as intended:
    • without the Recompiler.cpp line: the interface mismatch root-over's titles hit;
    • without the Pipeline.cpp exemption: the VK_EXT_provoking_vertex requirement;
    • with provoking vertex 0 passed to the evaluation stage: vertex 0's value instead of vertex 2's.
  • On this branch, all changed sources and tests/Graphics.cpp compile.
  • The shader-cache key check (ShaderCacheVersion.cmake) passes. Without the three reviewed names it reports the six uses that wachi35676 and MarcZX10 hit.
  • tools/check_conventions.py --base origin/main passes.

Independent runs on the previous head (thanks):

  • wachi35676: Windows, NVIDIA RTX 5070 Ti and an AMD RDNA2 iGPU with APS5_NO_MESH_SHADER=1.
    • agc_driver_mesh passes there, and the negative control fails without the change.
    • Their run found the two issues fixed here.
  • root-over: Linux, RADV Vega (no mesh shaders, no fragment barycentrics), RADV and lavapipe, with no VUID-.
    • The five catalog titles below run with the Recompiler.cpp change that is now part of this PR. ccleste reaches its title screen.
    • On 75fb6a509, 17 more catalog titles get past main's missing-mesh-shader abort and are still running at 40 s. Four still stop: FMASK in two titles, and Ruffle Flash and Dusklight on this PR's "needs a vertex shader before it" condition (under investigation).

Not tested on titles on macOS (the macOS stack needs further work for ccleste).

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: feat(agc): run mesh-path draws through a compute pass on devices without mesh shaders boykopovar/AnyPS5#9356
  • Fixes: none
  • Unblocks: on devices without mesh shaders and fragment barycentrics, per root-over's Linux runs (RADV Vega): ccleste (PPSA59322), PSXS5 (PPSA97510), SwanStationPS5 (PPSA98510), PSFlyCast (PPSA99247), Mario 64 (PPSA99310); and past main's "device does not support mesh shaders" abort, still running at 40 s: VLC (PPSA85300), XPSemu (PPSA97358), ReKHCoM (PPSA98511), Mortalfin (PPSA99141), DevilutionX (PPSA99308), Ship of Harkinian (PPSA99320), Wind Waker HD (PPSA99641), Link's Awakening (PPSA99670), RommPS (PPSA76677), PSP5 (PPSA99131), Seedee5 (PPSA99142), PS5SX2 (PPSA99203), PSSwanStation (PPSA99248), Eternal Darkness (PPSA99314), Art Swap (PPSA99318), Porpoise (PPSA99764), vkQuake (PPSA99010). Several of these only reach their own missing-data screen or ran without a dumped frame.
  • GPUs tested: Apple M4 (10-core GPU), MoltenVK (Vulkan 1.4), macOS 27.2 (x86_64 build under Rosetta 2)
  • AI-assisted: yes

billythemenace2 and others added 4 commits October 23, 2026 18:05
…out mesh shaders

A mesh-path draw (the NGG primitive shader path) needed VK_EXT_mesh_shader.
On a device without it, or for a draw whose targets have more layers than
the device's maxMeshOutputLayers, the mesh program is now compiled as a
GLCompute shader (SpirvTarget::meshAsCompute) that writes the draw's
primitives and vertex records to a device buffer behind a
VkDrawIndirectCommand header. A generated readback vertex shader
(BuildMeshReadbackVertexShader) reads the records back for a triangle or
line list drawn with vkCmdDrawIndirect, carrying position, parameters,
clip and cull distances and the provoking vertex's layer.

- The compute pass has its own pipeline layout with a compute push range;
  the draw's independent-sets layout lost the device on RDNA1.
- The pass pins the program's subgroup size where the device allows it and
  refuses compute subgroups narrower than the wave, except the 32-lane
  subgroups that run a wave-64 program in paired lanes.
- MeshDrawRunsAsCompute decides per draw: always without mesh shaders, and
  on a device with them when MeshDrawLayers exceeds maxMeshOutputLayers.
- APS5_NO_MESH_SHADER=1 leaves VK_EXT_mesh_shader off.
- Serialization version 43 stores meshAsCompute; the shader disk cache
  format is 45 for the record layout field.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…nd it

From review of the mesh compute fallback:
- An indirect mesh draw run as compute sized its output buffer for four
  instances, and a record with more drew nothing. Its record is now read
  on the CPU (IndirectDrawPath::MeshCompute, which waits for the producer
  like the other CPU-read paths), and the buffer is sized from the groups
  and instances it resolves to. Mesh.cpp draws an indirect record with six
  instances.
- The output buffer is bounded: a draw that needs more than 256 MiB
  (MeshComputeOutputLimitBytes) or maxStorageBufferRange throws.
- docs/dev/ARCHITECTURE.md describes the compute pass and the readback
  vertex stage.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
main gained mesh-path point output with register and exported point
sizes. The compute fallback's vertex record carries no point size and its
readback draws triangle or line lists, so a mesh program with point output
run as compute now throws instead of failing to emit; agc_driver_mesh runs
its point cases on the native mesh stage only, and the debt file lists it.
Rebased onto main: serialization version 45 after main's point and fused
arithmetic fields, shader disk cache format 46.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Route mesh shaders that run through the compute fallback into the
barycentric tessellation emulation when the device lacks
fragmentShaderBarycentric, reusing the readback vertex shader.

The pixel shader of such a draw follows the tessellation evaluation
stage, so it is no longer compiled in mesh mode when the request runs
the mesh program as compute: its flat inputs stay per vertex instead
of per primitive.

These patches need no VK_EXT_provoking_vertex for the last provoking
vertex: the generated evaluation stage writes the provoking vertex's
flat values itself, as on the vertex path.

AI-assisted: yes

Co-authored-by: root-over <91559694+root-over@users.noreply.github.com>
@github-actions github-actions Bot added the unblocks title Names a title ID on the Unblocks line label Dec 2, 2026
@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

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 100 core/shader/recompiler/SpirvBackend/src/MeshReadbackVertexShader.cpp
PR 311 core/shader/recompiler/SpirvBackend/src/MeshReadbackVertexShader.cpp
PR 425 core/shader/recompiler/SpirvBackend/src/MeshReadbackVertexShader.cpp
PR 1959 core/shader/recompiler/SpirvBackend/src/MeshReadbackVertexShader.cpp

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Dec 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs rebase Conflicts with main, rebase needed unblocks title Names a title ID on the Unblocks line

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants