perf(agc): link graphics pipelines from per-stage libraries #2636
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2636"
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-10T09:31:10Z.
What
Graphics pipelines are linked from
VK_EXT_graphics_pipeline_libraryparts that are cached per device and reused across pipelines, instead of being created whole.Today a draw with a new state combination calls
vkCreateGraphicsPipelines, even when its shaders were already compiled for another pipeline. That happens with another blend, cull mode or vertex layout, for example. Drivers don't reuse the stages: on RADV, a second pipeline with the same shaders and only cull + blend changed costs as much as the first (median 10.4 vs 10.9 ms over 60 Astro's Playroom modules, 34 vs 32 ms with RADV's cache off).With this change,
Pipelinebuilds four libraries (vertex input, pre-rasterization shaders, fragment shader, fragment output), each keyed by exactly the state it is built from, and fast-links them. Cull mode, front face, depth and stencil state become dynamic (VK_EXT_extended_dynamic_state), so changing them only links. Another blend builds only the fragment output library, and another vertex layout only the vertex input one. The newPipelineLibrary.cppkeeps the libraries per device, with their own identical render pass and pipeline layout, since they outlive the pipeline that first needed them.ClearCachedPipelinesdestroys them with the pipelines.When it's used: the device must report
graphicsPipelineLibrary,graphicsPipelineLibraryFastLinkingandextendedDynamicState(VulkanDeviceenables the three extensions only then). Pipelines with per-face depth bias, rect lists, geometry shaders or a stage without a variant id, andAPS5_NO_GPL=1, keep today's whole-pipeline path.This is phase A of the plan in Discussion #2242: GPL at the draw, independent of steps 1-3. Creating the shader libraries at registration (phase B) needs stable per-stage layouts and comes later.
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)buffer_formatVK_LAYER_KHRONOS_validation, GPL on and offVUID-vkCmdPipelineBarrier-dstAccessMask-02816,VUID-vkCmdPipelineBarrier-srcAccessMask-02815,VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605)New tests:
agc_pipeline_library(with the libraries) andagc_pipeline_library_off(APS5_NO_GPL=1). The first checks with the per-device counters that, for the same shaders:It fails with "a cull mode change rebuilt a library instead of setting dynamic state" if the cull mode is put back in the pre-rasterization key. The test device in
Recorder.cppnow enables GPL the same wayVulkanDevicedoes, so the recorder tests also draw through libraries.Second pipeline cost, same shaders, cull and blend changed (offline bench on the 60 Astro's Playroom modules, RADV):
On NVIDIA (RTX 4090, 615.71, Raghav314's run on PPSA36082's modules in #2242), the fast link costs 0.003 ms and the vertex input / fragment output libraries under 0.01 ms each. The fast-linked code is identical to the whole pipeline's (pipeline executable statistics), except for a vertex stage whose outputs the pixel stage doesn't read: that keeps them (up to 68 registers instead of 38). Recorded in TechnicalDebt, together with the render-pass compatibility limit (targets of other formats build the libraries again).
Cost per bind: 13 more dynamic-state commands, measured at 62 ns per bind on RADV (80 ns instead of 18 ns, 100 000 binds, median of 7).
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)