feat(agc): emulate barycentrics in rect-list draws #8339

Merged
DavidSamir merged 6 commits from upstream-pr/8339 into main 2026-10-23 17:01:48 +00:00
DavidSamir commented 2026-10-20 10:23:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-20T10:23:47Z.


What

On a device without VK_KHR_fragment_shader_barycentric, a pixel shader that reads barycentrics takes them from generated stages. A rect-list draw is itself built from generated tessellation stages and the barycentric path refused it: a pixel shader that reads barycentrics without VK_KHR_fragment_shader_barycentric needs a vertex shader before it.

The rect-list control and evaluation stages now carry what the pixel shader needs. The evaluation stage writes the barycentric weights for each interpolated point of the rectangle (the three corner weights, with the fourth corner of the rectangle weighted the way the rect-list stage already derives it), and it passes the three raw vertex values of each pixel input that reads them per vertex (v_interp_mov of P10/P20). Draw.cpp stops refusing a rect list with an active barycentric emulation and the recompiler's RectListShaders.cpp builds the extra interface locations. A plain v_interp_p1/p2 pixel shader is unchanged and needs no generated outputs.

The debt entry for barycentric emulation now says that a rect-list draw takes them from its generated tessellation stages and that this was checked on MoltenVK only.

Tested

macOS 26 (Darwin 25.6), Apple M2, MoltenVK and the Khronos validation layer from Vulkan SDK 1.4.363.0, x86-64 build under Rosetta, Ninja Release. The tree is main 35fa2bdd82 plus the macOS port series and my other open macOS and barycentric PRs (not a clean main); the baseline below is the same tree with this change's two production files restored to their previous contents.

  • pixel_barycentric_emulation, rect-list case, run as ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ctest -R pixel_barycentric_emulation -V:
    • Baseline: fails with AGC graphics: graphics interfaces disagree at location 0 (stage 2 output missing, stage 3 input vertex:f32x3 ...).
    • This change: passes. barycentric emulation through the rect-list stages passed: 1518 perspective and 1518 linear I/J pixels, raw vertex values, host interpolation. The tessellation-stage cases of the same test still pass.
    • Neither log contains was not found but was requested by env var VK_INSTANCE_LAYERS, and neither contains a VUID- line.
  • Ruffle Flash PPSA68091 v1.2.0, relinked with --macos --to-rosetta --macos-fixed-base 0x400000 (without a low fixed base it faults before drawing):
    • Before: aborts after a few seconds with [gpu] driver failure: AGC driver: a pixel shader that reads barycentrics without VK_KHR_fragment_shader_barycentric needs a vertex shader before it, on a rect-list draw.
    • After: still running at 60 s, no driver failure, no terminating. The frames were not inspected, so correct rendering is not claimed.
  • After merging main (087c1f40a4, which also adapts the test to main's flat and provoking-vertex cases): Windows 11, AMD Radeon 680M (driver 32.0.21030.2001), WinLibs GCC 15.2.0, Release, the same three variables: agc_driver_graphics, agc_driver_pixel_barycentric_emulation and agc_driver_provoking_vertex pass, the layer loaded and the log has no VUID- line.
  • After merging main with #8083 (triangle strips now share the test's Draw() with the rect-list case; a81f89fa6b): Windows 11, NVIDIA RTX 3070 (driver 610.60), WinLibs GCC 15.2.0, Release, ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1: agc_driver_graphics, agc_driver_pixel_barycentric_emulation and agc_driver_provoking_vertex pass. That run had no validation layer installed, so it has no VUID- check.
  • Not tested: Linux on this head. The 680M has VK_KHR_fragment_shader_barycentric, so on it the test runs the rect-list stages but titles do not take this path. Titles that stop later on the M2 for lack of mesh shaders or geometry-stage barycentrics are not affected by this change.
  • tools/check_conventions.py --base origin/main passes with one warning on the existing barycentric debt entry, which was over 1000 characters before this change.

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
  • Fixes: none
  • Unblocks: PPSA68091 (Ruffle Flash); no bring-up discussion
  • GPUs tested: Apple M2, MoltenVK and Khronos validation layer from Vulkan SDK 1.4.363.0, macOS 26 (AGC and shader recompiler change; no other GPU run)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4934382968 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8339). Originally posted by [DavidSamir](https://github.com/DavidSamir) on 2026-10-20T10:23:47Z. --- ### What On a device without `VK_KHR_fragment_shader_barycentric`, a pixel shader that reads barycentrics takes them from generated stages. A rect-list draw is itself built from generated tessellation stages and the barycentric path refused it: `a pixel shader that reads barycentrics without VK_KHR_fragment_shader_barycentric needs a vertex shader before it`. The rect-list control and evaluation stages now carry what the pixel shader needs. The evaluation stage writes the barycentric weights for each interpolated point of the rectangle (the three corner weights, with the fourth corner of the rectangle weighted the way the rect-list stage already derives it), and it passes the three raw vertex values of each pixel input that reads them per vertex (`v_interp_mov` of P10/P20). `Draw.cpp` stops refusing a rect list with an active barycentric emulation and the recompiler's `RectListShaders.cpp` builds the extra interface locations. A plain `v_interp_p1/p2` pixel shader is unchanged and needs no generated outputs. The debt entry for barycentric emulation now says that a rect-list draw takes them from its generated tessellation stages and that this was checked on MoltenVK only. ### Tested macOS 26 (Darwin 25.6), Apple M2, MoltenVK and the Khronos validation layer from Vulkan SDK 1.4.363.0, x86-64 build under Rosetta, Ninja Release. The tree is main `35fa2bdd82` plus the macOS port series and my other open macOS and barycentric PRs (not a clean main); the baseline below is the same tree with this change's two production files restored to their previous contents. - `pixel_barycentric_emulation`, rect-list case, run as `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ctest -R pixel_barycentric_emulation -V`: - Baseline: fails with `AGC graphics: graphics interfaces disagree at location 0 (stage 2 output missing, stage 3 input vertex:f32x3 ...)`. - This change: passes. `barycentric emulation through the rect-list stages passed: 1518 perspective and 1518 linear I/J pixels, raw vertex values, host interpolation`. The tessellation-stage cases of the same test still pass. - Neither log contains `was not found but was requested by env var VK_INSTANCE_LAYERS`, and neither contains a `VUID-` line. - Ruffle Flash PPSA68091 v1.2.0, relinked with `--macos --to-rosetta --macos-fixed-base 0x400000` (without a low fixed base it faults before drawing): - Before: aborts after a few seconds with `[gpu] driver failure: AGC driver: a pixel shader that reads barycentrics without VK_KHR_fragment_shader_barycentric needs a vertex shader before it`, on a rect-list draw. - After: still running at 60 s, no `driver failure`, no `terminating`. The frames were not inspected, so correct rendering is not claimed. - After merging main (`087c1f40a4`, which also adapts the test to main's flat and provoking-vertex cases): Windows 11, AMD Radeon 680M (driver 32.0.21030.2001), WinLibs GCC 15.2.0, Release, the same three variables: `agc_driver_graphics`, `agc_driver_pixel_barycentric_emulation` and `agc_driver_provoking_vertex` pass, the layer loaded and the log has no `VUID-` line. - After merging main with #8083 (triangle strips now share the test's `Draw()` with the rect-list case; `a81f89fa6b`): Windows 11, NVIDIA RTX 3070 (driver 610.60), WinLibs GCC 15.2.0, Release, `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1`: `agc_driver_graphics`, `agc_driver_pixel_barycentric_emulation` and `agc_driver_provoking_vertex` pass. That run had no validation layer installed, so it has no `VUID-` check. - Not tested: Linux on this head. The 680M has `VK_KHR_fragment_shader_barycentric`, so on it the test runs the rect-list stages but titles do not take this path. Titles that stop later on the M2 for lack of mesh shaders or geometry-stage barycentrics are not affected by this change. - `tools/check_conventions.py --base origin/main` passes with one warning on the existing barycentric debt entry, which was over 1000 characters before this change. ### 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 - [x] Fixes: none - [x] Unblocks: PPSA68091 (Ruffle Flash); no bring-up discussion - [x] GPUs tested: Apple M2, MoltenVK and Khronos validation layer from Vulkan SDK 1.4.363.0, macOS 26 (AGC and shader recompiler change; no other GPU run) - [x] AI-assisted: yes
TheSovietWaffle commented 2026-10-20 11:09:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by TheSovietWaffle on 2026-10-20T11:09:11Z.


Windows data point on NVIDIA and AMD: RTX 3080 (NVIDIA 617.42) and AMD Radeon RDNA 2 iGPU (1002:164e, 32.0.21045.5002), Windows 10 Pro 22H2, WinLibs GCC 15.2.0, Release, head 1713855fb: agc_driver_pixel_barycentric_emulation passes 3 of 3 on both GPUs.

AI-assisted: yes (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6289503676 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8339#issuecomment-6289503676). Originally posted by [TheSovietWaffle](https://github.com/TheSovietWaffle) on 2026-10-20T11:09:11Z. --- Windows data point on NVIDIA and AMD: RTX 3080 (NVIDIA 617.42) and AMD Radeon RDNA 2 iGPU (`1002:164e`, 32.0.21045.5002), Windows 10 Pro 22H2, WinLibs GCC 15.2.0, Release, head `1713855fb`: `agc_driver_pixel_barycentric_emulation` passes 3 of 3 on both GPUs. AI-assisted: yes (Claude Code).
DavidSamir commented 2026-10-20 11:11:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-20T11:11:48Z.


Ran the focused test on lavapipe with validation, clean main vs this branch, same machine (WSL Ubuntu 24.04, Mesa lavapipe ICD, Khronos validation layer 1.3.275). Env: ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, ctest -R pixel_barycentric_emulation -V. lavapipe has no fragment-shader-barycentric support, so the emulated paths ran; nothing skipped.

  • main 6bd02dd91 with this PR's PixelBarycentricEmulation.cpp copied in: Failed. Geometry stage passed (932/932 I/J pixels), tessellation stages passed (932/932). Then the test exits non-zero without a rect-list line.
  • This branch 1713855fb: Passed. Geometry 932/932, tessellation 932/932, and "barycentric emulation through the rect-list stages passed: 1518 perspective and 1518 linear I/J pixels, raw vertex values, host interpolation".
  • Neither log contains was not found but was requested by env var VK_INSTANCE_LAYERS.
  • VUIDs: identical on both, 3 x VUID-VkDeviceCreateInfo-pNext-pNext. This is the 1.3.275 layer not knowing VkStructureType 1000574000 in the device create chain, which is unrelated to this PR. No new VUID- from the change.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6289545456 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8339#issuecomment-6289545456). Originally posted by [DavidSamir](https://github.com/DavidSamir) on 2026-10-20T11:11:48Z. --- Ran the focused test on lavapipe with validation, clean `main` vs this branch, same machine (WSL Ubuntu 24.04, Mesa lavapipe ICD, Khronos validation layer 1.3.275). Env: `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, `ctest -R pixel_barycentric_emulation -V`. lavapipe has no fragment-shader-barycentric support, so the emulated paths ran; nothing skipped. - `main` 6bd02dd91 with this PR's `PixelBarycentricEmulation.cpp` copied in: **Failed**. Geometry stage passed (932/932 I/J pixels), tessellation stages passed (932/932). Then the test exits non-zero without a rect-list line. - This branch 1713855fb: **Passed**. Geometry 932/932, tessellation 932/932, and "barycentric emulation through the rect-list stages passed: 1518 perspective and 1518 linear I/J pixels, raw vertex values, host interpolation". - Neither log contains `was not found but was requested by env var VK_INSTANCE_LAYERS`. - VUIDs: identical on both, `3 x VUID-VkDeviceCreateInfo-pNext-pNext`. This is the 1.3.275 layer not knowing VkStructureType 1000574000 in the device create chain, which is unrelated to this PR. No new `VUID-` from the change. AI-assisted: yes
DavidAmsellem commented 2026-10-20 19:00:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DavidAmsellem on 2026-10-20T19:00:43Z.


First Linux run of this PR on a hardware GPU: AMD with RADV. Head 1713855fb merged onto main 2fee39f1b (clean merge), built in full and compared with the same main, on the same machine.

AMD Radeon RX 7900 XT (RADV NAVI31, gfx1100), Mesa 25.2.8, Linux Mint 22.3 (Ubuntu 24.04 base), kernel 7.0.0-38, GCC 13.3, Release.

Full suite (ANYPS5_REQUIRE_VULKAN=1 ctest -j8) at 7e95dafc3: 1715/1716 with this PR, against 1715/1716 on main. The one failure is the same on both, so this PR adds none: agc_driver_guest_memory_lifetime (#7784, which #7849 addresses).

Comparing the JUnit output with main: this PR adds no ctest entry, and none is skipped or removed. The test it changes, agc_driver_pixel_barycentric_emulation, runs and passes. It sets fragmentShaderBarycentricEnabled = false, so the emulation is used even though RADV has native barycentrics, and RADV exposes geometryShader and tessellationShader, so none of the test's stage skips apply.

GPUs tested: AMD Radeon RX 7900 XT (RADV NAVI31, gfx1100), Mesa 25.2.8, Linux Mint 22.3 / kernel 7.0.0-38

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6298823871 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8339#issuecomment-6298823871). Originally posted by [DavidAmsellem](https://github.com/DavidAmsellem) on 2026-10-20T19:00:43Z. --- First Linux run of this PR on a hardware GPU: AMD with RADV. Head `1713855fb` merged onto `main` `2fee39f1b` (clean merge), built in full and compared with the same `main`, on the same machine. AMD Radeon RX 7900 XT (RADV NAVI31, gfx1100), Mesa 25.2.8, Linux Mint 22.3 (Ubuntu 24.04 base), kernel 7.0.0-38, GCC 13.3, Release. Full suite (`ANYPS5_REQUIRE_VULKAN=1 ctest -j8`) at `7e95dafc3`: **1715/1716 with this PR**, against 1715/1716 on `main`. The one failure is the same on both, so this PR adds none: `agc_driver_guest_memory_lifetime` (#7784, which #7849 addresses). Comparing the JUnit output with `main`: this PR adds no ctest entry, and none is skipped or removed. The test it changes, `agc_driver_pixel_barycentric_emulation`, runs and passes. It sets `fragmentShaderBarycentricEnabled = false`, so the emulation is used even though RADV has native barycentrics, and RADV exposes `geometryShader` and `tessellationShader`, so none of the test's stage skips apply. GPUs tested: AMD Radeon RX 7900 XT (RADV NAVI31, gfx1100), Mesa 25.2.8, Linux Mint 22.3 / kernel 7.0.0-38 AI-assisted: yes
adriadam10 commented 2026-10-21 11:14:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-21T11:14:21Z.

Review: CHANGES_REQUESTED


The change reads correctly: the rect-list control/evaluation stages emit the barycentric weights (fourth corner with the -1/1 weights the stage already derives) and the three raw vertex values, and the interface sizes are checked against the tessellation limits. One thing blocks it:

  • The PR conflicts with main in core/libs/prx/libSceAgcDriver/tests/execution/PixelBarycentricEmulation.cpp and docs/dev/debt/shader.md. main now has the flat-input check (FlatBarycentricPixelCode, CheckFlat, provoking vertex, 44b13e650) inside RunEmulation. After the rebase the rect-list case also runs it, and CheckFlat expects the triangle corners and Barycentrics() without the emulation argument. Please rebase and either make the flat check use Corners(emulation) for the rect list (what the first/last vertex values must be there) or skip it for Emulation::RectList with a reason.
  • Debt line in shader.md: after rebasing, keep main's new lines and update the barycentric entry; the RADV (7900 XT) and Windows NVIDIA/AMD runs in this thread can be cited next to the MoltenVK one.

Thanks to @TheSovietWaffle and @DavidAmsellem for the hardware runs.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5598804144 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8339#pullrequestreview-5598804144). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-21T11:14:21Z. **Review:** CHANGES_REQUESTED --- The change reads correctly: the rect-list control/evaluation stages emit the barycentric weights (fourth corner with the -1/1 weights the stage already derives) and the three raw vertex values, and the interface sizes are checked against the tessellation limits. One thing blocks it: - The PR conflicts with `main` in `core/libs/prx/libSceAgcDriver/tests/execution/PixelBarycentricEmulation.cpp` and `docs/dev/debt/shader.md`. `main` now has the flat-input check (`FlatBarycentricPixelCode`, `CheckFlat`, provoking vertex, 44b13e650) inside `RunEmulation`. After the rebase the rect-list case also runs it, and `CheckFlat` expects the triangle corners and `Barycentrics()` without the `emulation` argument. Please rebase and either make the flat check use `Corners(emulation)` for the rect list (what the first/last vertex values must be there) or skip it for `Emulation::RectList` with a reason. - Debt line in `shader.md`: after rebasing, keep main's new lines and update the barycentric entry; the RADV (7900 XT) and Windows NVIDIA/AMD runs in this thread can be cited next to the MoltenVK one. Thanks to @TheSovietWaffle and @DavidAmsellem for the hardware runs.
DavidSamir commented 2026-10-21 20:33:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-21T20:33:22Z.


@adriadam10 thanks for the review. Both points are addressed on the current head:

  • Rebased on main (merge, no force-push). The rect-list case skips the flat-input check: CheckFlat compares against the first and last vertex of each triangle, and a rect list's provoking vertex has no triangle order to check against, so the check runs only for the triangle emulations. CheckFlat now passes Emulation::Geometry explicitly to ClipPositions and BarycentricsUnsnapped/Snapped, so main's flat cases run as before. Merged with main again today; no main commit since the tested merge touches this PR's files.
  • docs/dev/debt/shader.md: kept main's lines and updated the barycentric entry to list where the rect-list test passed: MoltenVK 1.4.2 (Apple M2), RADV on a Radeon RX 7900 XT (Mesa 25.2.8, @DavidAmsellem), lavapipe, and Windows on an RTX 3080 and a Radeon RDNA 2 iGPU (@TheSovietWaffle) and a Radeon 680M.

After the rebase, the Radeon 680M run (Windows 11, AMD 32.0.21030.2001, WinLibs GCC 15.2.0) under VK_LAYER_KHRONOS_validation with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 passes agc_driver_graphics, agc_driver_pixel_barycentric_emulation and agc_driver_provoking_vertex, with no VUID- line.

Could you take another look?

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6325925814 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8339#issuecomment-6325925814). Originally posted by [DavidSamir](https://github.com/DavidSamir) on 2026-10-21T20:33:22Z. --- @adriadam10 thanks for the review. Both points are addressed on the current head: - Rebased on `main` (merge, no force-push). The rect-list case skips the flat-input check: `CheckFlat` compares against the first and last vertex of each triangle, and a rect list's provoking vertex has no triangle order to check against, so the check runs only for the triangle emulations. `CheckFlat` now passes `Emulation::Geometry` explicitly to `ClipPositions` and `BarycentricsUnsnapped`/`Snapped`, so main's flat cases run as before. Merged with `main` again today; no `main` commit since the tested merge touches this PR's files. - `docs/dev/debt/shader.md`: kept main's lines and updated the barycentric entry to list where the rect-list test passed: MoltenVK 1.4.2 (Apple M2), RADV on a Radeon RX 7900 XT (Mesa 25.2.8, @DavidAmsellem), lavapipe, and Windows on an RTX 3080 and a Radeon RDNA 2 iGPU (@TheSovietWaffle) and a Radeon 680M. After the rebase, the Radeon 680M run (Windows 11, AMD 32.0.21030.2001, WinLibs GCC 15.2.0) under `VK_LAYER_KHRONOS_validation` with `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1` passes `agc_driver_graphics`, `agc_driver_pixel_barycentric_emulation` and `agc_driver_provoking_vertex`, with no `VUID-` line. Could you take another look?
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!8339
No description provided.