perf(agc): give each graphics stage a fixed push constant slot with pipeline libraries #2661

Merged
adriadam10 merged 1 commit from upstream-pr/2661 into main 2026-10-10 11:50:19 +00:00
adriadam10 commented 2026-10-10 10:22:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T10:22:12Z.


What

On devices that link graphics pipelines from libraries (#2636, #2645), each side of the pipeline gets a fixed push constant slot. The pre-rasterization stages use bytes 0-127 and the pixel shader bytes 128-255 of a 256-byte block. Today the pixel shader starts where its vertex shader's push data ends.

Today a pixel shader's push offset (in its specialization key and its fragment shader library key) depends on which vertex shader it is drawn with. The same pixel shader paired with vertex shaders that push different amounts gets another specialized module and another fragment shader library, which compiles it again. With a fixed slot it gets one. Building the shader libraries at registration (Discussion #2242) needs this too, since the partner stage isn't known there.

Why 128 bytes per side, measured on Astro's Playroom's 780 prepared modules: vertex shaders push a median of 22 and at most 30 dwords, and 82% push more than 16. So a 64 + 64 split would spill most of them, while every vertex shader and every pixel shader up to 32 dwords fits in 128 bytes. RADV, NVIDIA and lavapipe report maxPushConstantsSize 256, and library mode now requires it.

Changes:

  • Recompiler: the push block's member starts at its stage slot (IrBindingLayout::PushSlotDword), and a read indexes from that slot. A push range may not cross a slot (BindingAllocator). NativePushConstantSize is two slots.
  • Driver: StagePushOffset puts the pixel shader at byte 128 when the target has fixedPushSlots. It is used at registration, for prepared graphics stages and at the draw; pre-rasterization stages still stack from 0. In library mode the pipeline layout has two push ranges (pre-rasterization stages [0,128), fragment [128,256)) and the block is pushed per range. Compute keeps its 128-byte range (ComputePushConstantBytes). Library mode also requires maxPushConstantsSize >= 256.
  • Pipeline throws when, with pipeline libraries, a stage's push constants are outside its slot. AssemblePushConstants throws when a stage's range crosses a slot. Both are the rules the recompiler already enforces, so a misplaced stage fails with a message instead of producing an invalid pipeline. The validation layer reported VUID-VkGraphicsPipelineCreateInfo-layout-10069 for six execution tests that placed the pixel shader by hand before these checks existed.
  • The execution tests that build a vertex + pixel pair by hand get the pixel shader's offset from PixelPushOffset / PixelPushLayout (VulkanTestDevice.hpp, built on StagePushOffset), as the driver's draw does.
  • Devices without pipeline libraries keep the single 128-byte block and the stacked offsets.

Tested

Linux, AMD Radeon 660M (RADV, Mesa 26.2.4), and CI's lavapipe (Mesa 25.2.8).

result
ctest -R '^agc_|^shader', GPL on (default) 319/319
same with APS5_NO_GPL=1 (today's path) 319/319
^agc_ on CI's lavapipe (GPL on), without the 4-minute buffer_format 317/317
same under VK_LAYER_KHRONOS_validation, GPL on and off no VUID only with GPL (both report the same 3 already on main: VUID-vkCmdPipelineBarrier-dstAccessMask-02816, VUID-vkCmdPipelineBarrier-srcAccessMask-02815, VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605)

agc_pipeline_library now also checks two things: StagePushOffset (pixel shader at 128 with fixed slots, its cursor without them, tessellation stages stacked), and that a pixel shader in its slot, drawn with two vertex shaders, builds its fragment shader library once.

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 in TechnicalDebt
  • 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
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4810490463 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2661). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T10:22:12Z. --- ### What On devices that link graphics pipelines from libraries (#2636, #2645), each side of the pipeline gets a fixed push constant slot. The pre-rasterization stages use bytes 0-127 and the pixel shader bytes 128-255 of a 256-byte block. Today the pixel shader starts where its vertex shader's push data ends. Today a pixel shader's push offset (in its specialization key and its fragment shader library key) depends on which vertex shader it is drawn with. The same pixel shader paired with vertex shaders that push different amounts gets another specialized module and another fragment shader library, which compiles it again. With a fixed slot it gets one. Building the shader libraries at registration (Discussion #2242) needs this too, since the partner stage isn't known there. Why 128 bytes per side, measured on Astro's Playroom's 780 prepared modules: vertex shaders push a median of 22 and at most 30 dwords, and 82% push more than 16. So a 64 + 64 split would spill most of them, while every vertex shader and every pixel shader up to 32 dwords fits in 128 bytes. RADV, NVIDIA and lavapipe report `maxPushConstantsSize` 256, and library mode now requires it. Changes: - Recompiler: the push block's member starts at its stage slot (`IrBindingLayout::PushSlotDword`), and a read indexes from that slot. A push range may not cross a slot (`BindingAllocator`). `NativePushConstantSize` is two slots. - Driver: `StagePushOffset` puts the pixel shader at byte 128 when the target has `fixedPushSlots`. It is used at registration, for prepared graphics stages and at the draw; pre-rasterization stages still stack from 0. In library mode the pipeline layout has two push ranges (pre-rasterization stages [0,128), fragment [128,256)) and the block is pushed per range. Compute keeps its 128-byte range (`ComputePushConstantBytes`). Library mode also requires `maxPushConstantsSize >= 256`. - `Pipeline` throws when, with pipeline libraries, a stage's push constants are outside its slot. `AssemblePushConstants` throws when a stage's range crosses a slot. Both are the rules the recompiler already enforces, so a misplaced stage fails with a message instead of producing an invalid pipeline. The validation layer reported `VUID-VkGraphicsPipelineCreateInfo-layout-10069` for six execution tests that placed the pixel shader by hand before these checks existed. - The execution tests that build a vertex + pixel pair by hand get the pixel shader's offset from `PixelPushOffset` / `PixelPushLayout` (`VulkanTestDevice.hpp`, built on `StagePushOffset`), as the driver's draw does. - Devices without pipeline libraries keep the single 128-byte block and the stacked offsets. ### Tested Linux, AMD Radeon 660M (RADV, Mesa 26.2.4), and CI's lavapipe (Mesa 25.2.8). | | result | |---|---| | `ctest -R '^agc_\|^shader'`, GPL on (default) | 319/319 | | same with `APS5_NO_GPL=1` (today's path) | 319/319 | | `^agc_` on CI's lavapipe (GPL on), without the 4-minute `buffer_format` | 317/317 | | same under `VK_LAYER_KHRONOS_validation`, GPL on and off | no VUID only with GPL (both report the same 3 already on main: `VUID-vkCmdPipelineBarrier-dstAccessMask-02816`, `VUID-vkCmdPipelineBarrier-srcAccessMask-02815`, `VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605`) | `agc_pipeline_library` now also checks two things: `StagePushOffset` (pixel shader at 128 with fixed slots, its cursor without them, tessellation stages stacked), and that a pixel shader in its slot, drawn with two vertex shaders, builds its fragment shader library once. ### 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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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] AI-assisted: yes
JAB-dev commented 2026-10-10 17:47:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JAB-dev on 2026-10-10T17:47:50Z.


Heads up: on Windows (RTX 4070 SUPER) this costs Animal Well (PPSA22520) about 7-8 FPS with pipeline libraries on. I bisected today's merges down to this PR, and reverting only it on current main (57f96fd2b) brings it back: 52.3 vs 44.7 FPS average over two runs each, same 50 s scene. With APS5_NO_GPL=1 it's back near the old speed too.

I'm looking into why now and will report back, hopefully with a fix that keeps the one-fragment-library win.

Update: found it. lookupDraw still compared the cached pixel stage's push offset to the stacked cursor, while draws now record the fixed slot (128), so with libraries every draw-cache lookup missed as "layout (push offset)" and no recipes were used. One-line fix in my PR #2900, which gets Animal Well back (52.8 / 51.0 vs 42.5 / 41.8 FPS) and keeps the single fragment library.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6100425149 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2661#issuecomment-6100425149). Originally posted by [JAB-dev](https://github.com/JAB-dev) on 2026-10-10T17:47:50Z. --- Heads up: on Windows (RTX 4070 SUPER) this costs Animal Well (PPSA22520) about 7-8 FPS with pipeline libraries on. I bisected today's merges down to this PR, and reverting only it on current `main` (57f96fd2b) brings it back: 52.3 vs 44.7 FPS average over two runs each, same 50 s scene. With `APS5_NO_GPL=1` it's back near the old speed too. I'm looking into why now and will report back, hopefully with a fix that keeps the one-fragment-library win. **Update:** found it. `lookupDraw` still compared the cached pixel stage's push offset to the stacked cursor, while draws now record the fixed slot (128), so with libraries every draw-cache lookup missed as "layout (push offset)" and no recipes were used. One-line fix in my PR #2900, which gets Animal Well back (52.8 / 51.0 vs 42.5 / 41.8 FPS) and keeps the single fragment library.
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!2661
No description provided.