feat(agc): emulate barycentrics of mesh draws run as compute in the readback vertex shader #28142

Open
yuriy1337 wants to merge 16 commits from upstream-pr/28142 into main
yuriy1337 commented 2026-11-28 18:21:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by yuriy1337 on 2026-11-28T18:21:10Z.


What

Depends on #17611. Until it merges, this diff also shows #17611's commits; only the top commit is this PR.

Problem. On a GPU with neither VK_EXT_mesh_shader nor fragmentShaderBarycentric, #17611 runs mesh draws as compute, but a pixel shader that reads barycentrics still stops the draw:

  • Recompiler.cpp compiles that pixel shader for the mesh stage, which puts SPV_EXT_mesh_shader in a SPIR-V 1.3 module, and the validator refuses it. This is the stage-5 stop in the GTX 1050 Ti run on #17611 (25 of 47 titles, Lantern Miner PPSA58001 in the log).
  • MeshComputeStages refuses barycentric emulation without native mesh shaders. This is the refusal that stops ccleste and PSteroid5 in #17611's reports.

Fix.

  • A draw run as compute compiles its pixel shader as on the vertex path.
  • The readback vertex shader writes the emulated barycentric inputs (BuildMeshBarycentricReadbackVertexShader). Each corner writes its one-hot weights, the 1/w-scaled weights for offset reads, all three corners' per-vertex values and the provoking corner's flat values.
  • The readback cache is also keyed by the pixel shader's SPIR-V hash when it emulates barycentrics.
  • Provoking-vertex validation applies the barycentric-patch rule: line output, and a flat per-vertex input with the last provoking vertex, throw.

This is an alternative to #9387 (the tessellation route) for draws run as compute. The native mesh path and main's native barycentric pairing are untouched. Debt: edits to #17611's fragment agc-mesh-fallback-compute.md.

Overlap with other PRs

tools/pr_overlap.py measures from main, so it reports #17611's footprint too, and it fails closed. Counting only this PR's commit:

Tested

Linux, A/B against #17611's head 59203ed861 on the same machine, with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1.

Full ctest (6844 tests), RTX 3070: native and APS5_NO_MESH_SHADER=1 have 0 failures on both heads. APS5_FORCE_MESH_COMPUTE=1 fails the same 2 tests on both heads (agc_driver_tessellation_geometry, agc_driver_viewport_index).

Focused set, 26 tests, under the validation layer:

Device #17611 this PR
RTX 3070, native mesh 26 passed 26 passed
RTX 3070, APS5_NO_MESH_SHADER=1 26 passed, mesh_barycentric_emulation skipped 26 passed, it runs
RTX 3070, APS5_FORCE_MESH_COMPUTE=1 26 passed, mesh_barycentric_emulation skipped 26 passed, it runs
Intel UHD TGL GT1 (no mesh, no barycentrics) 26 passed, mesh_barycentric_emulation skipped 26 passed, it runs
llvmpipe 26 passed, mesh tests skip 26 passed, mesh tests skip

The PR adds no VUID- lines: there are 0 on each device except Intel, which logs the same 48 maxCombinedClipAndCullDistances-00710 on both heads.

The new tests catch the bug. Applied to #17611 without the fix, all three fail in every compute-path config: Intel and no-mesh with the SPIR-V 1.4 error from the GTX 1050 Ti logs, forced compute with graphics interfaces disagree at location 0.

Not tested: titles, AMD. Windows: build only.

Test details
  • Build: Ubuntu 26.04.1, kernel 7.0.0-31, GCC, Release, -DANYPS5_ENABLE_SPIRV_TOOLS=ON.
  • Focused set: ctest -V -R 'agc_driver_mesh|barycentric|layered_volume|mesh_output|request_serializer|agc_driver_graphics' with VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer, using the layer from LunarG SDK 1.4.363.0. Every log shows Insert instance layer "VK_LAYER_KHRONOS_validation", and none shows was not found but was requested.
  • New coverage on the compute path:
    • agc_driver_mesh_barycentric_emulation used to skip there. It now checks perspective, linear and iterated (offset) I/J pixels and raw per-vertex values against the reference: 932 pixels each on RTX 3070 (no mesh, forced) and Intel.
    • agc_driver_mesh adds non-indexed and indexed draws, front and back culling compared with the ordinary readback draw, and a flat input with the first and last provoking vertex.
    • agc_driver_layered_volume_draw adds a layered mesh draw run as compute.
  • Titles: the failures above come from reports in #17611's thread; I did not rerun those titles.
  • Windows 10, WinLibs GCC 15.2.0 r7 (the release CI uses): every file this PR changes compiles and links. 36 executables fail at the post-link objcopy --rename-section step ("Invalid argument"), the same 36 on #17611's head. Tests can't run on this machine: its CPU (i7-3770K) lacks AVX2/BMI, and the host-CPU check stops them on both heads.

Checklist

  • Based on current main; no other open PR implements the same functions (stacked on #17611, which is on current main; #9387 covers the same draws through tessellation)
  • 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: #17611
  • Fixes: none
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 3070 Laptop (595.91.07, Linux), Intel UHD Graphics TGL GT1 (Mesa 26.0.8 ANV, Linux), llvmpipe (Mesa, LLVM 21.1.8, Linux)
  • AI-assisted: yes

🤖 Generated with Claude Code

https://claude.ai/code/session_01Kn5E2jBvwSg6P3XXp7MUJt

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5543253210 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/28142). Originally posted by [yuriy1337](https://github.com/yuriy1337) on 2026-11-28T18:21:10Z. --- ### What Depends on #17611. Until it merges, this diff also shows #17611's commits; only the top commit is this PR. **Problem.** On a GPU with neither `VK_EXT_mesh_shader` nor `fragmentShaderBarycentric`, #17611 runs mesh draws as compute, but a pixel shader that reads barycentrics still stops the draw: - `Recompiler.cpp` compiles that pixel shader for the mesh stage, which puts `SPV_EXT_mesh_shader` in a SPIR-V 1.3 module, and the validator refuses it. This is the stage-5 stop in the GTX 1050 Ti run on #17611 (25 of 47 titles, Lantern Miner PPSA58001 in the log). - `MeshComputeStages` refuses barycentric emulation without native mesh shaders. This is the refusal that stops ccleste and PSteroid5 in #17611's reports. **Fix.** - A draw run as compute compiles its pixel shader as on the vertex path. - The readback vertex shader writes the emulated barycentric inputs (`BuildMeshBarycentricReadbackVertexShader`). Each corner writes its one-hot weights, the 1/w-scaled weights for offset reads, all three corners' per-vertex values and the provoking corner's flat values. - The readback cache is also keyed by the pixel shader's SPIR-V hash when it emulates barycentrics. - Provoking-vertex validation applies the barycentric-patch rule: line output, and a flat per-vertex input with the last provoking vertex, throw. This is an alternative to #9387 (the tessellation route) for draws run as compute. The native mesh path and `main`'s native barycentric pairing are untouched. Debt: edits to #17611's fragment `agc-mesh-fallback-compute.md`. <details><summary>Overlap with other PRs</summary> `tools/pr_overlap.py` measures from `main`, so it reports #17611's footprint too, and it fails closed. Counting only this PR's commit: - It shares lines with #9356, which #17611 supersedes. - It shares only `tests/Mesh.cpp` with #7642, #9508 and #10193, which already conflict with `main`. - A three-way merge with each PR the tool lists (#27849, #27887, #27979, #28067, #28070, #28077), each merged onto #17611, finds no conflict. - `tests/execution/LayeredVolumeDraw.cpp` conflicts with `main`'s 3867c1e89c. I will resolve it when I rebase onto #17611 after #17611 itself is rebased. </details> ### Tested Linux, A/B against #17611's head `59203ed861` on the same machine, with `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1`. Full ctest (6844 tests), RTX 3070: native and `APS5_NO_MESH_SHADER=1` have 0 failures on both heads. `APS5_FORCE_MESH_COMPUTE=1` fails the same 2 tests on both heads (`agc_driver_tessellation_geometry`, `agc_driver_viewport_index`). Focused set, 26 tests, under the validation layer: | Device | #17611 | this PR | |---|---|---| | RTX 3070, native mesh | 26 passed | 26 passed | | RTX 3070, `APS5_NO_MESH_SHADER=1` | 26 passed, `mesh_barycentric_emulation` skipped | 26 passed, it runs | | RTX 3070, `APS5_FORCE_MESH_COMPUTE=1` | 26 passed, `mesh_barycentric_emulation` skipped | 26 passed, it runs | | Intel UHD TGL GT1 (no mesh, no barycentrics) | 26 passed, `mesh_barycentric_emulation` skipped | 26 passed, it runs | | llvmpipe | 26 passed, mesh tests skip | 26 passed, mesh tests skip | The PR adds no `VUID-` lines: there are 0 on each device except Intel, which logs the same 48 `maxCombinedClipAndCullDistances-00710` on both heads. The new tests catch the bug. Applied to #17611 without the fix, all three fail in every compute-path config: Intel and no-mesh with the SPIR-V 1.4 error from the GTX 1050 Ti logs, forced compute with `graphics interfaces disagree at location 0`. Not tested: titles, AMD. Windows: build only. <details><summary>Test details</summary> - Build: Ubuntu 26.04.1, kernel 7.0.0-31, GCC, Release, `-DANYPS5_ENABLE_SPIRV_TOOLS=ON`. - Focused set: `ctest -V -R 'agc_driver_mesh|barycentric|layered_volume|mesh_output|request_serializer|agc_driver_graphics'` with `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer`, using the layer from LunarG SDK 1.4.363.0. Every log shows `Insert instance layer "VK_LAYER_KHRONOS_validation"`, and none shows `was not found but was requested`. - New coverage on the compute path: - `agc_driver_mesh_barycentric_emulation` used to skip there. It now checks perspective, linear and iterated (offset) I/J pixels and raw per-vertex values against the reference: 932 pixels each on RTX 3070 (no mesh, forced) and Intel. - `agc_driver_mesh` adds non-indexed and indexed draws, front and back culling compared with the ordinary readback draw, and a flat input with the first and last provoking vertex. - `agc_driver_layered_volume_draw` adds a layered mesh draw run as compute. - Titles: the failures above come from reports in #17611's thread; I did not rerun those titles. - Windows 10, WinLibs GCC 15.2.0 r7 (the release CI uses): every file this PR changes compiles and links. 36 executables fail at the post-link `objcopy --rename-section` step ("Invalid argument"), the same 36 on #17611's head. Tests can't run on this machine: its CPU (i7-3770K) lacks AVX2/BMI, and the host-CPU check stops them on both heads. </details> ### Checklist - [x] Based on current `main`; no other open PR implements the same functions (stacked on #17611, which is on current `main`; #9387 covers the same draws through tessellation) - [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: #17611 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: NVIDIA GeForce RTX 3070 Laptop (595.91.07, Linux), Intel UHD Graphics TGL GT1 (Mesa 26.0.8 ANV, Linux), llvmpipe (Mesa, LLVM 21.1.8, Linux) - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01Kn5E2jBvwSg6P3XXp7MUJt
MarcZX10 commented 2026-11-28 18:44:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-28T18:44:23Z.

Review: COMMENTED


Reviewed — no blocking findings

The mesh compute fallback and barycentric readback changes were inspected at head b496c74cc5726bf928a75f33d5c00864f0743cbe; I did not run tests, and the review is incomplete because several changed files were not fully read.

What I ran

No commands or tests were run. Author-reported test results in the PR description were not independently verified.

Results

Check Result Note
Code inspection not run Partial inspection only
Tests not run Author reports Linux test runs

Findings

Blocking

None verified in the code inspected.

Non-blocking

None.

Not verified

The full text of core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp, core/libs/prx/libSceAgcDriver/tests/Graphics.cpp, and core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp was excluded from the review folder; I did not read those files through the pinned reader. Other included changed files were not all fully read. I did not independently verify the reported test results, title behavior, or Windows build.

To get this to a good state

Nothing is required. The optional next step is to complete inspection of the excluded and unread changed files and run the relevant checks on this head.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6099606636 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/28142#pullrequestreview-6099606636). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-28T18:44:23Z. **Review:** COMMENTED --- # Reviewed — no blocking findings The mesh compute fallback and barycentric readback changes were inspected at head `b496c74cc5726bf928a75f33d5c00864f0743cbe`; I did not run tests, and the review is incomplete because several changed files were not fully read. ## What I ran No commands or tests were run. Author-reported test results in the PR description were not independently verified. ## Results | Check | Result | Note | |---|---|---| | Code inspection | not run | Partial inspection only | | Tests | not run | Author reports Linux test runs | ## Findings ### Blocking None verified in the code inspected. ### Non-blocking None. ## Not verified The full text of `core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp`, `core/libs/prx/libSceAgcDriver/tests/Graphics.cpp`, and `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` was excluded from the review folder; I did not read those files through the pinned reader. Other included changed files were not all fully read. I did not independently verify the reported test results, title behavior, or Windows build. ## To get this to a good state Nothing is required. The optional next step is to complete inspection of the excluded and unread changed files and run the relevant checks on this head.
ligmaSec commented 2026-12-03 20:38:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T20:38:01Z.

Review: COMMENTED


The new fixture explicitly skips llvmpipe before inspecting which mesh path it will use. Could the skip be limited to native mesh compilation if the compute fallback works there? That would let the software Vulkan job exercise the readback vertex shader, while the existing pixel-count checks identify which native and iterated cases ran.

Source review at b496c74cc5. The trial merge conflicts in the device and graphics draw code. Native GPU execution remains unverified here.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6178080937 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/28142#pullrequestreview-6178080937). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T20:38:01Z. **Review:** COMMENTED --- The new fixture explicitly skips llvmpipe before inspecting which mesh path it will use. Could the skip be limited to native mesh compilation if the compute fallback works there? That would let the software Vulkan job exercise the readback vertex shader, while the existing pixel-count checks identify which native and iterated cases ran. Source review at `b496c74cc5`. The trial merge conflicts in the device and graphics draw code. Native GPU execution remains unverified here. AI-assisted: yes.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/28142:upstream-pr/28142'
git switch 'upstream-pr/28142'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/28142'
git switch 'upstream-pr/28142'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/28142'
git switch 'upstream-pr/28142'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/28142'
git switch 'main'
git merge --squash 'upstream-pr/28142'
git switch 'main'
git merge --ff-only 'upstream-pr/28142'
git switch 'main'
git merge 'upstream-pr/28142'
git push origin 'main'
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!28142
No description provided.