feat(recompiler): read I/J from barycentric built-ins on MoltenVK #9193

Merged
imellag merged 3 commits from upstream-pr/9193 into main 2026-10-27 15:21:06 +00:00
imellag commented 2026-10-21 14:50:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by imellag on 2026-10-21T14:50:13Z.


What

On MoltenVK a pixel shader whose I/J VGPRs outlive their v_interp_p1_f32/v_interp_p2_f32 pairs now reads them from BaryCoordKHR or BaryCoordNoPerspKHR instead of taking the generated barycentric stages.

MoltenVK exposes VK_KHR_fragment_shader_barycentric, but its MSL step rejects PerVertexKHR, so FragmentShaderBarycentricUsable turns the extension off there and every such shader takes the generated stages. Without geometry shaders those accept only a triangle list without primitive restart, so other draws stop with a pixel shader that reads barycentrics without VK_KHR_fragment_shader_barycentric or geometry shaders needs a triangle list without primitive restart. Planet of Lana (PPSA19450) stops at its first such draw on main + #8658.

  • A new SpirvTarget flag, fragmentBarycentricBuiltins, enables the extension for its built-ins only. It is set wherever the device offers the extension, so devices where FragmentShaderBarycentricUsable keeps it on behave as before.
  • With the flag, HostInterpolationChecker also accepts I/J reads left after the pairs are lowered, as long as they are all perspective or all linear (Metal takes one barycentric built-in per shader) and read at the fragment's default position. Raw vertex parameters and I/J at an offset or a sample position still take the generated stages. The interpolated attributes stay hardware varyings.
  • Apple GPUs return the perspective weights unnormalized unless the compiled fragment function reads [[position]], so gl_FragCoord is declared with the BaryCoordKHR built-in and each perspective read returns gl_FragCoord.w > 0 ? b : 0. w is positive for every rasterized fragment, so the weight is unchanged, and unlike min(b, b + |gl_FragCoord.w|) a compiler cannot fold the read away. gl_FragCoord.w is loaded through EmitBuiltinU32, a float load, instead of a uint pointer into the float input, which adriadam10 pointed out on #7332.
  • The flag is part of the shader cache key and of the request serialization (version 48).

This is yripper's 376079ada4 from the closed #7332 (originally 508a8947b), ported to current main, with him as co-author. Changes from the original: the I/J check uses BarycentricInputOf and falls back for the offset and sample kinds main added since, the gl_FragCoord.w load above, the code comment moved into docs/dev/debt/shader.md, and the execution test follows main's Draw/RunEmulation structure.

Overlap: the serialization version and its checks share lines with #10359, which also needs a new version and goes first as agreed there; this PR then takes the next number. main is at version 47 (#10515), so this PR uses 48 until then. #11551 also raises the request format and lands after this PR; PixelBarycentricEmulation.cpp and the shader.md entry share lines with #8083 and #8339, the shader.md entry with #8281, and Recompiler.hpp one line with #8489.

Tested

Current head 03f7c1134f, rebased onto main fe2b52c7e4. main took request format 47 in #10515, so this PR now uses 48; the commit that only moved fixtures to 47 became empty and was dropped. On macOS (same machine, current main with the open macOS boot PRs and a local patch that loads libvulkan.1.dylib), with the same variables and the validation layer loaded, agc_driver_pixel_barycentric_emulation passes 3 of 3 and reads I/J from the built-ins (932 perspective and 932 linear I/J pixels), and request_serializer, agc_shader_memory, agc_fragment_barycentric and agc_driver_interpolation_modes pass 3 of 3, with no VUID- lines.

Previous head, rebased onto main 8a85a5c848, with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1 and VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation (ctest -V, layer loaded, no missing-layer line in any log):

  • Linux x86-64 (Ubuntu 24.04 amd64 container on the same Mac, GCC 14.2, Release, lavapipe from Mesa 25.2.8, validation layer 1.3.275), paired with main 8a85a5c848 in the same container: request_serializer, agc_driver_graphics, agc_driver_depth_bounds_state, agc_driver_pixel_barycentric_emulation, agc_shader_memory and the three agc_shader_control_flow tests pass on both. The only validation message on both sides is VUID-VkDeviceCreateInfo-pNext-pNext at device creation. lavapipe has no barycentric extension, so the built-in case does not run there.
  • macOS, Apple M4 Pro, macOS 27.0.1, MoltenVK 1.4.2 (Vulkan SDK 1.4.363.0), x86-64 Release under Rosetta 2. main does not build on macOS, so both arms are #8658's feat/macos-port 564e005acb, without and with this change (its serializer hunks left out, since that branch is on an older format), 3 runs each: agc_driver_pixel_barycentric_emulation passes on both, and with the change also its built-in case (932 perspective and 932 linear I/J pixels from BaryCoordKHR/BaryCoordNoPerspKHR); agc_driver_graphics, agc_driver_depth_bounds_state, agc_shader_memory, agc_driver_interpolation_modes and agc_fragment_barycentric pass on both; agc_driver_mesh_barycentric_emulation is skipped on both. Validation: VUID-VkDeviceCreateInfo-pProperties-04451, 6 lines on each side.
  • Controls on that base: the previous head fails the built-in case 3 of 3 (pixel (16, 6) channel 0 is 0.009037, expected 0.004731 or 0.004730, as on @iamthehimansh's M2 Pro), because gl_FragCoord was declared only for the offset kinds and its w was read as the constant 0; declaring it alone makes it pass; the select without the declaration fails (... is 0.000000).

Earlier runs, before the gl_FragCoord fix and the last rebase:

Apple M4 Pro, macOS 27.0.1, x86-64 under Rosetta 2, MoltenVK 1.4.2 (Vulkan SDK 1.4.363.0), Apple clang 21.0.0. main does not build on macOS, so both arms are main 27bcd6a29 merged with #8658 at 4a7efd236, without and with this change, same build directory.

Focused tests with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1 and VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation (ctest -V, layer loaded, no missing-layer line in either log):

test base change
request_serializer pass pass
agc_shader_memory pass pass
agc_driver_graphics pass pass
agc_driver_pixel_barycentric_emulation pass (tessellation stages: 932 perspective and 932 linear I/J pixels) pass, plus the new built-in case: 932 perspective and 932 linear I/J pixels from BaryCoordKHR/BaryCoordNoPerspKHR
agc_driver_interpolation_modes pass pass
agc_fragment_barycentric pass pass
agc_driver_interpolation_f16, agc_driver_mesh_barycentric_emulation skipped skipped

Validation: the same single identifier in both logs, VUID-VkDeviceCreateInfo-pProperties-04451 (8 lines each), so no new VUID- errors.

Negative controls on the change:

  • Without the gl_FragCoord.w use, the built-in case fails: PERSP_CENTER I/J from BaryCoordKHR: pixel (16, 6) channel 0 is 0.009037, expected 0.004731 or 0.004730.
  • With the built-ins refused in HostInterpolationChecker, agc_driver_graphics fails: reading the I/J VGPRs with barycentric built-ins did not use BaryCoordKHR.

Titles: with this change on main + #8658, Planet of Lana gets past the draw above; both it and God of War Sons of Sparta (PPSA28997) then stop at scene load with an uncaught Il2CppExceptionWrapper, reported on #8658, so there is no gameplay run on main yet. On the closed #7332 branch, which carries the original commit, both titles reach gameplay on this machine.

Linux x86-64 (Ubuntu 24.04 amd64 container on the same Mac, GCC 14.2, lavapipe/llvmpipe from LLVM 20.1.2, ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1): request_serializer, agc_shader_memory, agc_driver_graphics and agc_driver_pixel_barycentric_emulation pass; lavapipe has no barycentric extension, so the last one runs the geometry and the tessellation emulation (932 perspective and 932 linear I/J pixels each) and not the new built-in case.

Not tested: Windows. On a device that lacks the extension the flag is off; on one where FragmentShaderBarycentricUsable keeps it, the shader takes the full extension path as before and the flag only enters the cache key.

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: none
  • GPUs tested: Apple M4 Pro, MoltenVK 1.4.2 (Vulkan SDK 1.4.363.0), macOS 27.0.1; lavapipe (llvmpipe, LLVM 20.1.2), Ubuntu 24.04 container
  • AI-assisted: yes

cc @yripper

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4953552039 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9193). Originally posted by [imellag](https://github.com/imellag) on 2026-10-21T14:50:13Z. --- ### What On MoltenVK a pixel shader whose I/J VGPRs outlive their `v_interp_p1_f32`/`v_interp_p2_f32` pairs now reads them from `BaryCoordKHR` or `BaryCoordNoPerspKHR` instead of taking the generated barycentric stages. MoltenVK exposes `VK_KHR_fragment_shader_barycentric`, but its MSL step rejects `PerVertexKHR`, so `FragmentShaderBarycentricUsable` turns the extension off there and every such shader takes the generated stages. Without geometry shaders those accept only a triangle list without primitive restart, so other draws stop with `a pixel shader that reads barycentrics without VK_KHR_fragment_shader_barycentric or geometry shaders needs a triangle list without primitive restart`. Planet of Lana (PPSA19450) stops at its first such draw on `main` + #8658. - A new `SpirvTarget` flag, `fragmentBarycentricBuiltins`, enables the extension for its built-ins only. It is set wherever the device offers the extension, so devices where `FragmentShaderBarycentricUsable` keeps it on behave as before. - With the flag, `HostInterpolationChecker` also accepts I/J reads left after the pairs are lowered, as long as they are all perspective or all linear (Metal takes one barycentric built-in per shader) and read at the fragment's default position. Raw vertex parameters and I/J at an offset or a sample position still take the generated stages. The interpolated attributes stay hardware varyings. - Apple GPUs return the perspective weights unnormalized unless the compiled fragment function reads `[[position]]`, so `gl_FragCoord` is declared with the `BaryCoordKHR` built-in and each perspective read returns `gl_FragCoord.w > 0 ? b : 0`. `w` is positive for every rasterized fragment, so the weight is unchanged, and unlike `min(b, b + |gl_FragCoord.w|)` a compiler cannot fold the read away. `gl_FragCoord.w` is loaded through `EmitBuiltinU32`, a float load, instead of a `uint` pointer into the float input, which adriadam10 pointed out on #7332. - The flag is part of the shader cache key and of the request serialization (version 48). This is yripper's 376079ada4 from the closed #7332 (originally 508a8947b), ported to current `main`, with him as co-author. Changes from the original: the I/J check uses `BarycentricInputOf` and falls back for the offset and sample kinds `main` added since, the `gl_FragCoord.w` load above, the code comment moved into `docs/dev/debt/shader.md`, and the execution test follows `main`'s `Draw`/`RunEmulation` structure. Overlap: the serialization version and its checks share lines with #10359, which also needs a new version and goes first as agreed there; this PR then takes the next number. `main` is at version 47 (#10515), so this PR uses 48 until then. #11551 also raises the request format and lands after this PR; `PixelBarycentricEmulation.cpp` and the `shader.md` entry share lines with #8083 and #8339, the `shader.md` entry with #8281, and `Recompiler.hpp` one line with #8489. ### Tested **Current head `03f7c1134f`, rebased onto `main` `fe2b52c7e4`.** `main` took request format 47 in #10515, so this PR now uses 48; the commit that only moved fixtures to 47 became empty and was dropped. On macOS (same machine, current `main` with the open macOS boot PRs and a local patch that loads `libvulkan.1.dylib`), with the same variables and the validation layer loaded, `agc_driver_pixel_barycentric_emulation` passes 3 of 3 and reads I/J from the built-ins (`932 perspective and 932 linear I/J pixels`), and `request_serializer`, `agc_shader_memory`, `agc_fragment_barycentric` and `agc_driver_interpolation_modes` pass 3 of 3, with no `VUID-` lines. Previous head, rebased onto `main` `8a85a5c848`, with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1` and `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` (`ctest -V`, layer loaded, no missing-layer line in any log): - **Linux** x86-64 (Ubuntu 24.04 amd64 container on the same Mac, GCC 14.2, Release, lavapipe from Mesa 25.2.8, validation layer 1.3.275), paired with `main` `8a85a5c848` in the same container: `request_serializer`, `agc_driver_graphics`, `agc_driver_depth_bounds_state`, `agc_driver_pixel_barycentric_emulation`, `agc_shader_memory` and the three `agc_shader_control_flow` tests pass on both. The only validation message on both sides is `VUID-VkDeviceCreateInfo-pNext-pNext` at device creation. lavapipe has no barycentric extension, so the built-in case does not run there. - **macOS**, Apple M4 Pro, macOS 27.0.1, MoltenVK 1.4.2 (Vulkan SDK 1.4.363.0), x86-64 Release under Rosetta 2. `main` does not build on macOS, so both arms are #8658's `feat/macos-port` `564e005acb`, without and with this change (its serializer hunks left out, since that branch is on an older format), 3 runs each: `agc_driver_pixel_barycentric_emulation` passes on both, and with the change also its built-in case (932 perspective and 932 linear I/J pixels from `BaryCoordKHR`/`BaryCoordNoPerspKHR`); `agc_driver_graphics`, `agc_driver_depth_bounds_state`, `agc_shader_memory`, `agc_driver_interpolation_modes` and `agc_fragment_barycentric` pass on both; `agc_driver_mesh_barycentric_emulation` is skipped on both. Validation: `VUID-VkDeviceCreateInfo-pProperties-04451`, 6 lines on each side. - Controls on that base: the previous head fails the built-in case 3 of 3 (`pixel (16, 6) channel 0 is 0.009037, expected 0.004731 or 0.004730`, as on @iamthehimansh's M2 Pro), because `gl_FragCoord` was declared only for the offset kinds and its `w` was read as the constant 0; declaring it alone makes it pass; the select without the declaration fails (`... is 0.000000`). Earlier runs, before the `gl_FragCoord` fix and the last rebase: Apple M4 Pro, macOS 27.0.1, x86-64 under Rosetta 2, MoltenVK 1.4.2 (Vulkan SDK 1.4.363.0), Apple clang 21.0.0. `main` does not build on macOS, so both arms are `main` 27bcd6a29 merged with #8658 at 4a7efd236, without and with this change, same build directory. Focused tests with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1` and `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` (`ctest -V`, layer loaded, no missing-layer line in either log): | test | base | change | |---|---|---| | `request_serializer` | pass | pass | | `agc_shader_memory` | pass | pass | | `agc_driver_graphics` | pass | pass | | `agc_driver_pixel_barycentric_emulation` | pass (tessellation stages: 932 perspective and 932 linear I/J pixels) | pass, plus the new built-in case: 932 perspective and 932 linear I/J pixels from `BaryCoordKHR`/`BaryCoordNoPerspKHR` | | `agc_driver_interpolation_modes` | pass | pass | | `agc_fragment_barycentric` | pass | pass | | `agc_driver_interpolation_f16`, `agc_driver_mesh_barycentric_emulation` | skipped | skipped | Validation: the same single identifier in both logs, `VUID-VkDeviceCreateInfo-pProperties-04451` (8 lines each), so no new `VUID-` errors. Negative controls on the change: - Without the `gl_FragCoord.w` use, the built-in case fails: `PERSP_CENTER I/J from BaryCoordKHR: pixel (16, 6) channel 0 is 0.009037, expected 0.004731 or 0.004730`. - With the built-ins refused in `HostInterpolationChecker`, `agc_driver_graphics` fails: `reading the I/J VGPRs with barycentric built-ins did not use BaryCoordKHR`. Titles: with this change on `main` + #8658, Planet of Lana gets past the draw above; both it and God of War Sons of Sparta (PPSA28997) then stop at scene load with an uncaught `Il2CppExceptionWrapper`, reported on #8658, so there is no gameplay run on `main` yet. On the closed #7332 branch, which carries the original commit, both titles reach gameplay on this machine. Linux x86-64 (Ubuntu 24.04 amd64 container on the same Mac, GCC 14.2, lavapipe/llvmpipe from LLVM 20.1.2, `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1`): `request_serializer`, `agc_shader_memory`, `agc_driver_graphics` and `agc_driver_pixel_barycentric_emulation` pass; lavapipe has no barycentric extension, so the last one runs the geometry and the tessellation emulation (932 perspective and 932 linear I/J pixels each) and not the new built-in case. Not tested: Windows. On a device that lacks the extension the flag is off; on one where `FragmentShaderBarycentricUsable` keeps it, the shader takes the full extension path as before and the flag only enters the cache key. ### 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) - [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: none - [x] GPUs tested: Apple M4 Pro, MoltenVK 1.4.2 (Vulkan SDK 1.4.363.0), macOS 27.0.1; lavapipe (llvmpipe, LLVM 20.1.2), Ubuntu 24.04 container - [x] AI-assisted: yes cc @yripper
jotitadev commented 2026-10-21 22:45:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-21T22:45:33Z.

Review: COMMENTED


Apple GPU / MoltenVK run of this PR, which is exactly the host it targets.

Machine: Apple M2 Max (vendor=0x106b device=0x1b020208), macOS 27.2, x86_64 under Rosetta 2. Vulkan loader + MoltenVK 1.4.2 (Vulkan SDK 1.4.363.0); also re-run against MoltenVK main + SPIRV-Cross #2704. Release, BUILD_TESTING=ON.

Base/method: PR #8658 feat/macos-port @ 4ebe71f2e5 (current main 0c6a5bd593 plus the macOS port), not main — main does not build on macOS. This PR's diff (git diff merge-base..e0d54227c -- . ':!docs') applied on top, clean. Device reports pipelineLibrary=0, tessellationAvailable=1, mesh=0.

Result (agc_driver_pixel_barycentric_emulation, --repeat until-fail:3, both drivers): passes 3/3 on each. The new built-in block runs:

barycentric built-in tests passed: 932 perspective and 932 linear I/J pixels

Both Require(!builtin.barycentricEmulation.active, ...) checks hold, so on MoltenVK the I/J VGPRs are read from BaryCoordKHR / BaryCoordNoPerspKHR and no generated barycentric stage is produced. agc_driver_graphics and agc_shader_memory still pass 3/3, and request_serializer passes with the serialization flag moved.

Negative control (SDK and #2704): with only HostInterpolationChecker.cpp reverted to this PR's base (the built-in acceptance removed, signature kept), agc_driver_pixel_barycentric_emulation fails:

AGC graphics: reading PERSP_CENTER I/J with barycentric built-ins needed generated stages

So the lowering in HostInterpolationChecker::Lower is what lets MoltenVK take the built-in path; without it the draw falls back to generated stages, which is the case the PR describes (Planet of Lana stops at its first such draw on main + #8658).

Full ^agc suite (SDK, with #9125 also stacked in the same build): 16 failures vs 18 at base; the only delta is the two tests those PRs address, no new failure. So the shader changes add nothing to the failing set on Apple.

GPUs tested: Apple M2 Max (MoltenVK 1.4.2; and MoltenVK main + SPIRV-Cross #2704).

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5607143546 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9193#pullrequestreview-5607143546). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-21T22:45:33Z. **Review:** COMMENTED --- Apple GPU / MoltenVK run of this PR, which is exactly the host it targets. **Machine:** Apple M2 Max (`vendor=0x106b device=0x1b020208`), macOS 27.2, x86_64 under Rosetta 2. Vulkan loader + MoltenVK 1.4.2 (Vulkan SDK 1.4.363.0); also re-run against MoltenVK main + SPIRV-Cross #2704. Release, `BUILD_TESTING=ON`. **Base/method:** PR #8658 `feat/macos-port` @ `4ebe71f2e5` (current `main` `0c6a5bd593` plus the macOS port), not `main` — `main` does not build on macOS. This PR's diff (`git diff merge-base..e0d54227c -- . ':!docs'`) applied on top, clean. Device reports `pipelineLibrary=0`, `tessellationAvailable=1`, `mesh=0`. **Result** (`agc_driver_pixel_barycentric_emulation`, `--repeat until-fail:3`, both drivers): passes 3/3 on each. The new built-in block runs: ``` barycentric built-in tests passed: 932 perspective and 932 linear I/J pixels ``` Both `Require(!builtin.barycentricEmulation.active, ...)` checks hold, so on MoltenVK the I/J VGPRs are read from `BaryCoordKHR` / `BaryCoordNoPerspKHR` and no generated barycentric stage is produced. `agc_driver_graphics` and `agc_shader_memory` still pass 3/3, and `request_serializer` passes with the serialization flag moved. **Negative control** (SDK and #2704): with only `HostInterpolationChecker.cpp` reverted to this PR's base (the built-in acceptance removed, signature kept), `agc_driver_pixel_barycentric_emulation` fails: ``` AGC graphics: reading PERSP_CENTER I/J with barycentric built-ins needed generated stages ``` So the lowering in `HostInterpolationChecker::Lower` is what lets MoltenVK take the built-in path; without it the draw falls back to generated stages, which is the case the PR describes (Planet of Lana stops at its first such draw on `main` + #8658). Full `^agc` suite (SDK, with #9125 also stacked in the same build): 16 failures vs 18 at base; the only delta is the two tests those PRs address, no new failure. So the shader changes add nothing to the failing set on Apple. GPUs tested: Apple M2 Max (MoltenVK 1.4.2; and MoltenVK main + SPIRV-Cross #2704). Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
krishalivaibhav commented 2026-10-22 06:30:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by krishalivaibhav on 2026-10-22T06:30:45Z.


Tested this on a fanless Apple M2 with Balatro (PPSA21402), where the same fallback is the main cost of the shop and booster-pack screens. It removes it.

Setup: MacBook Air M2, macOS 27.2, MoltenVK 1.4.2, x86-64 under Rosetta 2, 1920x1080. main does not build on macOS, so all three arms are the same macOS series build (42c3fd09a2b6 plus local macOS changes, hence dirty). The #9193 arm adds this PR's runtime files at e0d54227c8; on that older base the conflicts were only fields it does not have (waveLdsMemoryBarriers, float32DenormPreserve), and the request serialization takes local version 39 instead of 43. Scene: Continue into a saved run's shop/pack screen, untouched. Warm caches, APS5_TRACE_SECONDS=60:20, no other trace or profile switch.

What the fallback costs there: the title's sprite/text pixel shader keeps I/J live after its v_interp pairs, only as the value lanes outside the export mask keep (a select on a WQM of the export mask). On MoltenVK every such draw goes through the generated tessellation stages, which restarts the Metal render encoder per draw; the pack screen issues about 730 of them per frame. Clipping those draws to a 1x1 scissor changed nothing, and skipping only their vkCmdDraw took the screen from about 11 to about 34 FPS, so the cost is per draw, not per pixel.

Same scene, 60–80 s base narrower local fix this PR
presents / FPS 908 / 45.4 1192 / 59.6 1199 / 60.0
frame p50 / p90 / p99 / max 21.7 / 23.8 / 25.4 / 79.4 ms 16.7 / 17.9 / 23.9 / 55.1 ms 16.7 / 17.8 / 18.4 / 18.6 ms
GPU busy per present 21.3 ms 13.7 ms 12.4 ms

The "narrower local fix" is something I had written before finding this PR: it proves the leftover I/J only reaches lanes that never export and replaces it with 0. It covers 4 of the title's pixel programs; this PR also covers the two it cannot prove (a CRT post-process and one more), and after it only the title's rect-list draws still use tessellation. I'm not opening mine, since this PR handles the case more generally.

Base:

{"commit":"42c3fd09a2b6","dirty":true,"env":{"APS5_SYNC_COMMAND_ALLOCATIONS":"1","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"60:20"},"gpu":"Apple M2","driver":"MoltenVK 1.4.2","os":"Darwin 27.2.0","resolution":"1920x1080","window":{"spec":"seconds 60:20","first_present":2945,"ms":20005.583},"presents":908,"frame_ms":{"p50":21.730,"p90":23.802,"p99":25.384,"max":79.376},"gpu_busy_ms_per_present":21.344,"worker_busy_pct":{"queue worker 0x0":98.854},"top_phases_ms_per_frame":{"Driver.Packet":21.777,"VideoOut.Flip":20.737,"Driver.Present":20.017,"VideoOut.Flip.present":19.996,"Driver.Present.render_fence_wait":18.713,"Vulkan.Retire":18.711,"Vulkan.Retire.wait":18.696,"Driver.Packet.rendering_wait":13.372},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":17.007,"events_lost":45073,"totals_full":false}},"trace":"aps5-trace-42c3fd09a2b6-21429.json.gz"}

This PR:

{"commit":"42c3fd09a2b6","dirty":true,"env":{"APS5_SYNC_COMMAND_ALLOCATIONS":"1","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"60:20"},"gpu":"Apple M2","driver":"MoltenVK 1.4.2","os":"Darwin 27.2.0","resolution":"1920x1080","window":{"spec":"seconds 60:20","first_present":3573,"ms":20003.296},"presents":1199,"frame_ms":{"p50":16.687,"p90":17.790,"p99":18.403,"max":18.578},"gpu_busy_ms_per_present":12.400,"worker_busy_pct":{"queue worker 0x0":98.477},"top_phases_ms_per_frame":{"Driver.Packet":16.425,"VideoOut.Flip":16.250,"VideoOut.Flip.vblank_wait":12.344,"Driver.Packet.rendering_wait":12.056,"Driver.Packet.draw":3.349,"Driver.Draw":3.307,"VideoOut.Flip.present":3.263,"Driver.Present":3.261},"trace_dropped":false,"trace":"aps5-trace-42c3fd09a2b6-44665.json.gz"}

Traces: aps5-trace-42c3fd09a2b6-21429.json.gz (base; its event buffer filled after 17 of 20 s, the summary line covers the window) and aps5-trace-42c3fd09a2b6-44665.json.gz (this PR); I can attach both if useful.

Rendering looked correct in the scene (text, cards, CRT effect). Clip of this PR's build in normal play, FPS in the title bar:

https://github.com/user-attachments/assets/58f8da7a-3971-492c-9f15-5de422a3bcf2

AI-assisted: yes (Claude Code); the measurements and observations are mine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6334358420 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9193#issuecomment-6334358420). Originally posted by [krishalivaibhav](https://github.com/krishalivaibhav) on 2026-10-22T06:30:45Z. --- Tested this on a fanless Apple M2 with Balatro (PPSA21402), where the same fallback is the main cost of the shop and booster-pack screens. It removes it. **Setup:** MacBook Air M2, macOS 27.2, MoltenVK 1.4.2, x86-64 under Rosetta 2, 1920x1080. `main` does not build on macOS, so all three arms are the same macOS series build (42c3fd09a2b6 plus local macOS changes, hence `dirty`). The #9193 arm adds this PR's runtime files at e0d54227c8; on that older base the conflicts were only fields it does not have (`waveLdsMemoryBarriers`, `float32DenormPreserve`), and the request serialization takes local version 39 instead of 43. Scene: Continue into a saved run's shop/pack screen, untouched. Warm caches, `APS5_TRACE_SECONDS=60:20`, no other trace or profile switch. **What the fallback costs there:** the title's sprite/text pixel shader keeps I/J live after its `v_interp` pairs, only as the value lanes outside the export mask keep (a select on a WQM of the export mask). On MoltenVK every such draw goes through the generated tessellation stages, which restarts the Metal render encoder per draw; the pack screen issues about 730 of them per frame. Clipping those draws to a 1x1 scissor changed nothing, and skipping only their `vkCmdDraw` took the screen from about 11 to about 34 FPS, so the cost is per draw, not per pixel. | Same scene, 60–80 s | base | narrower local fix | this PR | |---|---|---|---| | presents / FPS | 908 / 45.4 | 1192 / 59.6 | 1199 / 60.0 | | frame p50 / p90 / p99 / max | 21.7 / 23.8 / 25.4 / 79.4 ms | 16.7 / 17.9 / 23.9 / 55.1 ms | 16.7 / 17.8 / 18.4 / 18.6 ms | | GPU busy per present | 21.3 ms | 13.7 ms | 12.4 ms | The "narrower local fix" is something I had written before finding this PR: it proves the leftover I/J only reaches lanes that never export and replaces it with 0. It covers 4 of the title's pixel programs; this PR also covers the two it cannot prove (a CRT post-process and one more), and after it only the title's rect-list draws still use tessellation. I'm not opening mine, since this PR handles the case more generally. Base: ```json {"commit":"42c3fd09a2b6","dirty":true,"env":{"APS5_SYNC_COMMAND_ALLOCATIONS":"1","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"60:20"},"gpu":"Apple M2","driver":"MoltenVK 1.4.2","os":"Darwin 27.2.0","resolution":"1920x1080","window":{"spec":"seconds 60:20","first_present":2945,"ms":20005.583},"presents":908,"frame_ms":{"p50":21.730,"p90":23.802,"p99":25.384,"max":79.376},"gpu_busy_ms_per_present":21.344,"worker_busy_pct":{"queue worker 0x0":98.854},"top_phases_ms_per_frame":{"Driver.Packet":21.777,"VideoOut.Flip":20.737,"Driver.Present":20.017,"VideoOut.Flip.present":19.996,"Driver.Present.render_fence_wait":18.713,"Vulkan.Retire":18.711,"Vulkan.Retire.wait":18.696,"Driver.Packet.rendering_wait":13.372},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":17.007,"events_lost":45073,"totals_full":false}},"trace":"aps5-trace-42c3fd09a2b6-21429.json.gz"} ``` This PR: ```json {"commit":"42c3fd09a2b6","dirty":true,"env":{"APS5_SYNC_COMMAND_ALLOCATIONS":"1","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"60:20"},"gpu":"Apple M2","driver":"MoltenVK 1.4.2","os":"Darwin 27.2.0","resolution":"1920x1080","window":{"spec":"seconds 60:20","first_present":3573,"ms":20003.296},"presents":1199,"frame_ms":{"p50":16.687,"p90":17.790,"p99":18.403,"max":18.578},"gpu_busy_ms_per_present":12.400,"worker_busy_pct":{"queue worker 0x0":98.477},"top_phases_ms_per_frame":{"Driver.Packet":16.425,"VideoOut.Flip":16.250,"VideoOut.Flip.vblank_wait":12.344,"Driver.Packet.rendering_wait":12.056,"Driver.Packet.draw":3.349,"Driver.Draw":3.307,"VideoOut.Flip.present":3.263,"Driver.Present":3.261},"trace_dropped":false,"trace":"aps5-trace-42c3fd09a2b6-44665.json.gz"} ``` Traces: `aps5-trace-42c3fd09a2b6-21429.json.gz` (base; its event buffer filled after 17 of 20 s, the summary line covers the window) and `aps5-trace-42c3fd09a2b6-44665.json.gz` (this PR); I can attach both if useful. Rendering looked correct in the scene (text, cards, CRT effect). Clip of this PR's build in normal play, FPS in the title bar: https://github.com/user-attachments/assets/58f8da7a-3971-492c-9f15-5de422a3bcf2 AI-assisted: yes (Claude Code); the measurements and observations are mine.
adriadam10 commented 2026-10-24 03:54:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-24T03:54:24Z.

Review: CHANGES_REQUESTED


The head is rebased onto current main (serialization version 47, fixtures adjusted) and merges cleanly, and the I/J check, cache key and serialization read correctly. One open problem blocks the merge:

  • @iamthehimansh reported above that agc_driver_pixel_barycentric_emulation fails 3/3 on an Apple M2 Pro (MoltenVK 1.4.2) with this PR and passes without it: PERSP_CENTER I/J from BaryCoordKHR: pixel (16, 6) channel 0 is 0.009037, expected 0.004731 or 0.004730. That is the same message as your negative control without the gl_FragCoord.w use, so on that machine the normalization is not taking effect, while it does on the M4 Pro, M2 Max and M2 runs. Please reproduce or explain the difference (MoltenVK/SPIRV-Cross build, macOS version, fast-math setting).
  • min(b, b + |gl_FragCoord.w|) equals b in exact arithmetic, so a compiler that folds it (Metal with fast math) drops the [[position]] read, and the weights come back unnormalized. The fix needs a dependence on w that cannot be folded, or a way to detect that it was; as written the result depends on the Metal compiler not optimizing it.

Once the test passes on that M2 Pro as well, this is ready. Note also that #10359 takes serialization version 47; whichever merges second moves to 48.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5636721086 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9193#pullrequestreview-5636721086). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-24T03:54:24Z. **Review:** CHANGES_REQUESTED --- The head is rebased onto current `main` (serialization version 47, fixtures adjusted) and merges cleanly, and the I/J check, cache key and serialization read correctly. One open problem blocks the merge: - @iamthehimansh reported above that `agc_driver_pixel_barycentric_emulation` fails 3/3 on an Apple M2 Pro (MoltenVK 1.4.2) with this PR and passes without it: `PERSP_CENTER I/J from BaryCoordKHR: pixel (16, 6) channel 0 is 0.009037, expected 0.004731 or 0.004730`. That is the same message as your negative control without the `gl_FragCoord.w` use, so on that machine the normalization is not taking effect, while it does on the M4 Pro, M2 Max and M2 runs. Please reproduce or explain the difference (MoltenVK/SPIRV-Cross build, macOS version, fast-math setting). - `min(b, b + |gl_FragCoord.w|)` equals `b` in exact arithmetic, so a compiler that folds it (Metal with fast math) drops the `[[position]]` read, and the weights come back unnormalized. The fix needs a dependence on `w` that cannot be folded, or a way to detect that it was; as written the result depends on the Metal compiler not optimizing it. Once the test passes on that M2 Pro as well, this is ready. Note also that #10359 takes serialization version 47; whichever merges second moves to 48.
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!9193
No description provided.