Skip to content

perf(shader): read a pass-through input that the pixel shader reads only at P0 as a flat input - #19530

Merged
oneandonlydean merged 3 commits into
boykopovar:mainfrom
imellag:perf/shader-custom-p0-flat
Nov 14, 2026
Merged

oneandonlydean merged 3 commits into
boykopovar:mainfrom
imellag:perf/shader-custom-p0-flat

Conversation

@imellag

@imellag imellag commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

What

On a device without VK_KHR_fragment_shader_barycentric per-vertex inputs (MoltenVK), a pixel shader that reads a pass-through input (SPI_PS_INPUT_CNTL flat shading with bit 5 of the offset set, InputIsCustom) with v_interp_mov_f32 P0 is rejected by HostInterpolationChecker (GetInterpolationParameter is accepted only for default or flat inputs). The whole pixel shader then goes through the generated barycentric stages: on MoltenVK every triangle becomes a three-point patch through two generated tessellation stages.

When P0 is the only read of the input, those stages give it one value: the per-vertex array's element 0 (EmitInterpolationParameterValue picks vertex (2 + 1) % 3 = 0, raw for a pass-through input), the triangle's first vertex in Vulkan's order. A Flat input under the first provoking vertex gives the same vertex, for lists (3i) and for strips (i, also for odd triangles, whose Vulkan order is (i, i+2, i+1)), so the shader can stay on the host path.

#12619 (flat aliases in barycentric emulation) changes the same files for another case, a flat input that shares an export slot with an interpolated one, and also moves the provoking-vertex checks before the pipeline cache lookup. Neither depends on the other; whichever lands second takes the other's lines.

Scope: the change applies only where a rejected pixel shader goes through the generated stages, i.e. devices without usable VK_KHR_fragment_shader_barycentric per-vertex inputs (MoltenVK, and devices without the extension). On RADV (HostInterpolationPreferred) the checker runs first and a rejected shader falls back to native PerVertexKHR inputs; there the first-vertex acceptance is off, so such a shader keeps its native per-vertex input and last provoking mode works as before. Devices that use native per-vertex inputs without trying host interpolation first never run the checker.

Newly accepted, with the console's P0 unmeasured (the same assumption as the generated stages): on the tessellation path, draws those stages refused now draw with the host's first provoking vertex: triangle fans, lines, points, an indexed triangle strip with primitive restart, and a triangle list with primitive restart on a device with VK_EXT_primitive_topology_list_restart. On a device with geometry shaders and without the barycentric extension, a draw in last provoking mode that the generated geometry stage drew now throws. Rect lists are unchanged: BuildRectListShaders refuses a custom input before and after (checked on this device: custom per-vertex interpolation is unsupported).

Why it matters: on Astro's Playroom (PPSA21564) on macOS, the barycentric patch emulation ran for ~180k draws in the first 200 s, almost all triangle lists in first provoking mode. Logging the first instruction the checker rejected in each pixel shader gave 96 of 120 rejected shaders on exactly this case ("P0 of a pass-through input, no other read"), including the three most-drawn ones (44.7k draws for the top one). The log's per-shader tally at 180k patch draws attributes 167k of them to listed shaders; the shaders of this case account for 119k of those (72%). The rest: 18.7k (11%) for the five shaders that read a pass-through input at P10, which needs real per-vertex values, and 28.7k (17%) for shaders the checker did not log a reason for. Each of those draws goes through MoltenVK's tessellation emulation, which allocates temporary vertex and control-point buffers per draw (this was most of MoltenVK's ~2-4 GB of temporary buffers in that title). That measurement was made on a local tree before this change; the game is not available to me now, so no run of a title with this PR is claimed.

Tested

macOS 27.2, Apple M4 Pro, x86-64 build under Rosetta 2, MoltenVK 1.4.2 and the validation layer of Vulkan SDK 1.4.363.0 (ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer), main d4556df.

agc_driver_pixel_barycentric_emulation gains CheckFirstVertex:

  • a pixel shader that reads a pass-through input only at P0 (three vertices with different values) must compile without generated stages, pass the input as flat, custom and not per-vertex, write the first vertex's value to every channel of every interior pixel, and refuse the last provoking vertex;

  • a triangle strip whose shader reads x and y at P0 (all four vertices differ in the pair) must give each pixel the first vertex in Vulkan's order: vertex 0 for the even triangle and vertex 1 for the odd one, whose order is (1, 3, 2);

  • an input read at P10, P20 and P0, and an input read only at P10, must still be per-vertex through the generated stages;

  • compiled with fragmentShaderBarycentricEnabled and hostInterpolationFirst (RADV's setup; compile only, since MoltenVK cannot run PerVertexKHR), the P0-only shader must keep a per-vertex, non-flat input without generated stages.

  • this PR: passes (932 interior pixels at the first vertex's value, 864 and 864 pixels of the strip's even and odd triangle; the existing tessellation, strip, restart and rect-list cases pass as before). Log shows Insert instance layer "VK_LAYER_KHRONOS_validation", no VUID-.

  • negative control (the test change on main): fails with a pass-through input read only at P0 needed generated stages.

  • negative control for the RADV scope (the first-vertex acceptance forced on with hostInterpolationFirst, as in the first version of this PR): fails with with native per-vertex inputs preferred after host interpolation, a pass-through input read only at P0 stopped being read per vertex.

The 116 tests matching (rerun on the current head, same result) ^(agc_[a-z0-9_]*(barycentric|interp|flat|provoking|mesh|rect|pixel|fragment)[a-z0-9_]*|shader_[a-z0-9_]*|request_serializer)$, on main and on this PR, each after a full build of its tree, with the environment above:

main this PR
passed 112 (14 skipped: no mesh shaders, interlock or f16 interpolation here) 112 (same 14 skipped)
failed agc_driver_pixel_sample_coverage (vkCreateGraphicsPipelines -3), agc_driver_pixel_sample_iteration (sample shading rate), agc_driver_provoking_vertex (provokingVertexLast is not supported), agc_driver_queued_indirect_read_order (timeout) the same four, same messages
validation layer inserted in 133 tests, VUID-VkDeviceCreateInfo-sType-unique 2 times the same

So the change adds no failure and no validation error on this device.

Not run on Linux or Windows.

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.2 (x86-64 under Rosetta 2)
  • AI-assisted: yes

@github-actions github-actions Bot added shader core/shader docs agc libSceAgc* labels Nov 13, 2026
@oneandonlydean

Copy link
Copy Markdown
Collaborator

The reasoning for the generated stages holds: they pick vertex (mode+1)%3, so P0 is vertex 0 and raw for a custom input, and a Flat input under the first provoking vertex reads the same one. One scope point needs to change, and it is about RADV rather than MoltenVK.

The PR body says devices with VK_KHR_fragment_shader_barycentric never run the checker. On RADV they do: Recompiler.cpp:273-274 sets fragmentShaderBarycentricEnabled = ext && !hostInterpolationFirst, HostInterpolationPreferred is true for RADV (FragmentBarycentric.hpp:12, applied at VulkanDevice.cpp:1635), and the checker call at line 354 is gated only on that value. Before this change a pass-through input read only at P0 was rejected and the shader went to native per-vertex inputs; now it stays on the host path as Flat. The test forces fragmentShaderBarycentricEnabled=false, so RADV's native path is never compared. There is a visible regression too: the last-provoking-vertex check at Pipeline.cpp:246-249 throws for flat && custom, while the native per-vertex form passed it, so a shader that worked on RADV in last mode would now throw.

Please either keep RADV unchanged (pass a flag into Lower so the first-vertex acceptance applies only when the device has no native per-vertex inputs) or keep it in scope and show on a RADV run that native PerVertexKHR[0] equals the provoking vertex in first and last mode, for strips and odd triangles, and that the last-mode check no longer throws for shaders that worked. Either way, please correct the scope sentence in the body.

Smaller points: firstVertexInputs accepts any custom input read only at P0, not only flat-bit ones, and topology is not gated, so fans, lines, points and strips with restart (which threw in the generated stages) are newly accepted as Flat, with the console's P0 for those unmeasured; please list them. A strip draw with an odd triangle and a P10-only negative control would pin the cases the body argues from. FormatVersion 69 is also set by #6924, #9852, #10049, #14032, #14871, #15343, #17056 and #18185, so the later ones to land renumber.

…-through input

HostInterpolationChecker accepts a pass-through input read only at P0 as
flat only when the shader would otherwise go through the generated
stages, not when native per-vertex inputs follow host interpolation
(RADV), and only for pass-through inputs. The test adds a triangle strip
whose odd triangle reads its first vertex in Vulkan's order, an input
read only at P10 that stays per-vertex, and a compile with native
per-vertex inputs preferred after host interpolation.
@imellag
imellag force-pushed the perf/shader-custom-p0-flat branch from 6d74bd6 to b06cb3e Compare November 13, 2026 14:15
@imellag

imellag commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, you are right about RADV: with hostInterpolationFirst a rejected shader falls back to native PerVertexKHR, not to the generated stages, so the first version changed RADV and made last mode throw there. Fixed in b06cb3e:

  • RADV unchanged. HostInterpolationChecker::Lower takes a firstVertexFlat flag, and Recompile passes !hostInterpolationFirst, so the first-vertex acceptance applies only where a rejected shader would go through the generated stages. The new compile-only case sets fragmentShaderBarycentricEnabled and hostInterpolationFirst (RADV's setup) and requires the P0-only input to stay per-vertex and non-flat, without generated stages. With the acceptance forced on, as in the first version, it fails with with native per-vertex inputs preferred after host interpolation, a pass-through input read only at P0 stopped being read per vertex. The scope sentence in the body is corrected.
  • Only pass-through inputs. firstVertexInputs now uses InputIsPassthrough (0x420) instead of InputIsCustom. Nothing sets customInterpolationMask today, so no current input changes, but the check no longer depends on that.
  • Odd strip triangle and P10 only. The test draws a triangle strip whose shader reads x and y at P0, so all four vertices differ. Every pixel of the even triangle gets vertex 0, and every pixel of the odd triangle gets vertex 1, its first vertex in Vulkan's (1, 3, 2) order (864 and 864 pixels on MoltenVK). An input read only at P10 must stay per-vertex through the generated stages.
  • Topologies listed in the body and in the debt entry. Fans, lines, points, indexed strips with restart, and lists with restart on a device with list restart now draw with the host's first provoking vertex, where the tessellation stages refused them; the console's P0 there is unmeasured. On a device with geometry shaders and no barycentric extension, last mode now throws where the generated geometry stage drew it. Rect lists are unchanged: BuildRectListShaders refuses a custom input before and after; I checked that it throws custom per-vertex interpolation is unsupported on this device.
  • FormatVersion 69 is listed in the body with the other PRs that set it.

Rerun on the new head (macOS 27.2, Apple M4 Pro, MoltenVK 1.4.2, validation layer 1.4.363.0, ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer):

  • agc_driver_pixel_barycentric_emulation passes, with the layer inserted and no VUID-.
  • The same 116 focused tests give the same result as main: the same 4 failures, the same 14 skips, and 2 VUID-VkDeviceCreateInfo-sType-unique on both.

I have no RADV device, so the RADV side is covered only by the compile-only case.

@github-actions

github-actions Bot commented Nov 13, 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 6416 core/shader/recompiler/ShaderDiskCache.hpp L16
PR 6924 core/shader/recompiler/ShaderDiskCache.hpp L16
PR 7395 core/shader/recompiler/ShaderDiskCache.hpp L16
PR 8939 core/shader/recompiler/ShaderDiskCache.hpp L16
PR 9457 core/shader/recompiler/ShaderDiskCache.hpp L16
PR 9508 core/libs/prx/libSceAgcDriver/tests/execution/PixelBarycentricEmulation.cpp L90, L129
core/shader/recompiler/ShaderDiskCache.hpp L16
PR 9633 core/shader/recompiler/ShaderDiskCache.hpp L16
PR 9749 core/shader/recompiler/ShaderDiskCache.hpp L16
PR 9790 core/shader/recompiler/ShaderDiskCache.hpp L16
PR 9969 core/shader/recompiler/ShaderDiskCache.hpp L16
PR 14853 core/shader/recompiler/ShaderDiskCache.hpp L16
PR 15555 core/shader/recompiler/ShaderDiskCache.hpp L16
PR 16472 core/shader/recompiler/ShaderDiskCache.hpp L16
PR 16631 core/shader/recompiler/ShaderDiskCache.hpp L16
PR 16812 core/shader/recompiler/ShaderDiskCache.hpp L16
PR 16814 core/shader/recompiler/ShaderDiskCache.hpp L16
PR 18106 core/shader/recompiler/ShaderDiskCache.hpp L16
PR 18107 core/shader/recompiler/ShaderDiskCache.hpp L16
PR 18455 core/shader/recompiler/ShaderDiskCache.hpp L16
PR 19852 core/shader/recompiler/ShaderDiskCache.hpp L16

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 5371 docs/dev/debt/shader.md
PR 5609 core/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cpp
core/shader/recompiler/Recompiler.cpp
PR 5925 core/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cpp
core/shader/recompiler/ShaderDiskCache.hpp
PR 6235 docs/dev/debt/shader.md
PR 6280 core/shader/recompiler/ShaderDiskCache.hpp
docs/dev/debt/shader.md
PR 6412 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.hpp
docs/dev/debt/shader.md
PR 6488 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.hpp
docs/dev/debt/shader.md
PR 7085 core/shader/recompiler/ShaderDiskCache.hpp
docs/dev/debt/shader.md
PR 7275 core/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cpp
PR 7642 core/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cpp
core/libs/prx/libSceAgcDriver/tests/execution/PixelBarycentricEmulation.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.hpp
PR 7684 core/shader/recompiler/ShaderDiskCache.hpp
docs/dev/debt/shader.md
PR 8004 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvInputOutput.cpp
docs/dev/debt/shader.md
PR 9335 docs/dev/debt/shader.md
PR 9356 core/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.hpp
PR 9387 core/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.hpp
docs/dev/debt/shader.md
PR 9852 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.hpp
PR 9897 core/shader/recompiler/Recompiler.cpp
PR 10049 core/shader/recompiler/ShaderDiskCache.hpp
PR 10193 core/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cpp
core/libs/prx/libSceAgcDriver/tests/execution/PixelBarycentricEmulation.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.hpp
PR 10351 core/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.hpp
PR 10359 core/shader/recompiler/Recompiler.cpp
PR 10652 core/shader/recompiler/Recompiler.cpp
docs/dev/debt/shader.md
PR 10757 core/shader/recompiler/Recompiler.cpp
PR 11483 core/shader/recompiler/Recompiler.cpp
docs/dev/debt/shader.md
PR 12324 core/shader/recompiler/IntermediateRepresentation/include/IntermediateRepresentation/IrMetadata/ProgramMetadata.hpp
core/shader/recompiler/Recompiler.cpp
PR 12619 core/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cpp
core/libs/prx/libSceAgcDriver/tests/execution/PixelBarycentricEmulation.cpp
core/shader/recompiler/Optimization/src/ShaderInfoCollector.cpp
core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvInputOutput.cpp
PR 12790 core/shader/recompiler/Optimization/src/ShaderInfoCollector.cpp
core/shader/recompiler/Recompiler.cpp
docs/dev/debt/shader.md
PR 12828 core/shader/recompiler/Recompiler.cpp
PR 12944 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.hpp
docs/dev/debt/shader.md
PR 13928 core/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cpp
core/libs/prx/libSceAgcDriver/tests/execution/PixelBarycentricEmulation.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.hpp
PR 13929 core/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cpp
core/libs/prx/libSceAgcDriver/tests/execution/PixelBarycentricEmulation.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.hpp
PR 14032 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.hpp
PR 14217 core/shader/recompiler/Recompiler.cpp
docs/dev/debt/shader.md
PR 14218 core/shader/recompiler/Recompiler.cpp
docs/dev/debt/shader.md
PR 14944 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.hpp
PR 15548 core/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.hpp
docs/dev/debt/shader.md
PR 15719 core/shader/recompiler/Recompiler.cpp
docs/dev/debt/shader.md
PR 17056 core/shader/recompiler/Optimization/src/ShaderInfoCollector.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.hpp
PR 17611 core/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.hpp
docs/dev/debt/shader.md
PR 17899 core/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cpp
PR 19119 core/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cpp
PR 19373 core/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cpp
PR 19697 core/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cpp

@github-actions github-actions Bot added perf Performance change perf numbers missing perf pull request without a before and after summary line labels Nov 13, 2026
@JJenkx

JJenkx commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Windows check of head b06cb3e763, merged onto main 19ba356e59. Setup: Windows 11 Enterprise 22621, AMD RX 6700 XT, AMD driver 26.10.1, MinGW-w64 GCC 15.2 UCRT, Release.

agc_driver_pixel_barycentric_emulation:

  • GPU, through the shared Windows GPU FIFO with ANYPS5_REQUIRE_VULKAN=1 (merge e10ac15346): passed in 3 of 3 runs. The binary matched the hash recorded at preparation, and the receipt shows exit 0 and app_count=0.
  • CPU, Vulkan hidden (merge 2a4a3d5620): skipped (it needs a device), 0 failed.

This is a correctness check only; I did not measure the performance effect.

AI-assisted: yes.

@github-actions

Copy link
Copy Markdown

This pull request is labeled perf, so it needs the summary line of a capture on main and one with the change, from the same title, scene and machine, as the Performance report form asks. Please paste both aps5-summary.jsonl lines, attach the two traces and add the output of tools/trace_digest.py.

@Doorriiaann

Copy link
Copy Markdown
Contributor

An NVIDIA run, next to the MoltenVK and AMD runs: RTX 3070 (8 GB), NVIDIA 610.57.04, Ryzen 5 5600X, Debian 13, kernel 6.12.115, GCC 13.3.0 Release, validation layer 1.4.335, ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, ctest -R 'barycentric' -V, 3 runs each.

merge-base d4556df this PR b06cb3e
agc_driver_pixel_barycentric_emulation, agc_driver_mesh_barycentric_emulation, agc_driver_barycentric_patch_vertex_layer, agc_fragment_barycentric all 4 passed 3/3 all 4 passed 3/3, with this PR's PixelBarycentricEmulation.cpp cases
VUID- lines / layer not found 0 / 0 0 / 0

Negative control: this PR's PixelBarycentricEmulation.cpp on the merge-base, 3 runs: agc_driver_pixel_barycentric_emulation fails 3/3 with AGC graphics: a pass-through input read only at P0 needed generated stages, and the other three pass.

This device logs Pixel interpolation driver=4 hostInterpolationFirst=0, so unlike RADV it takes the generated-stage path this PR changes.

AI-assisted: yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* docs perf numbers missing perf pull request without a before and after summary line perf Performance change shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants