perf(agc): give each graphics stage a fixed push constant slot with pipeline libraries #2661
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2661"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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
maxPushConstantsSize256, and library mode now requires it.Changes:
IrBindingLayout::PushSlotDword), and a read indexes from that slot. A push range may not cross a slot (BindingAllocator).NativePushConstantSizeis two slots.StagePushOffsetputs the pixel shader at byte 128 when the target hasfixedPushSlots. 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 requiresmaxPushConstantsSize >= 256.Pipelinethrows when, with pipeline libraries, a stage's push constants are outside its slot.AssemblePushConstantsthrows 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 reportedVUID-VkGraphicsPipelineCreateInfo-layout-10069for six execution tests that placed the pixel shader by hand before these checks existed.PixelPushOffset/PixelPushLayout(VulkanTestDevice.hpp, built onStagePushOffset), as the driver's draw does.Tested
Linux, AMD Radeon 660M (RADV, Mesa 26.2.4), and CI's lavapipe (Mesa 25.2.8).
ctest -R '^agc_|^shader', GPL on (default)APS5_NO_GPL=1(today's path)^agc_on CI's lavapipe (GPL on), without the 4-minutebuffer_formatVK_LAYER_KHRONOS_validation, GPL on and offVUID-vkCmdPipelineBarrier-dstAccessMask-02816,VUID-vkCmdPipelineBarrier-srcAccessMask-02815,VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605)agc_pipeline_librarynow 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
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)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. WithAPS5_NO_GPL=1it'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.
lookupDrawstill 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.