[HOLD] perf(agc): pre-warm graphics pipelines outside GpuMutex during draw preparation #5441
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5441"
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 Kikoarl on 2026-10-13T19:54:32Z.
What
Pre-warms Vulkan graphics pipelines outside the driver's global GPU mutex during draw preparation.
In
Driver::draw,lockForDrawacquiresGuestMemory::GpuMutex. Previously, if an indirect or direct draw encountered an unseen pipeline configuration or cold shaders,CachedPipelinebuilt and compiled the Vulkan graphics pipeline (vkCreateGraphicsPipelines) while holdingGpuMutex. In titles such as Astro Bot (PPSA21567), compiling monolithic graphics pipelines underGpuMutexinduces 5,000–9,500 ms stalls that starve concurrent compute queues (Queue 0x40 and Queue 0x48).PrewarmPipelineresolves the vertex input layout, masked fragment output states, and descriptor set layouts prior tolockForDraw, caching the pipeline inPipelines()which is independently protected by its own granular mutex. Subsequent execution inDrawinsidelockForDrawhits the warm pipeline cache in < 1 µs without stalling the global GPU mutex during compilation.Tested
prewarmPipelineTestsincore/libs/prx/libSceAgcDriver/tests/Graphics.cppverifying that cold misses create the pipeline, while subsequent calls hit the cached entry without creating new pipelines (mock.graphicsPipelineCreateCount).tests/agc_driver_graphics_tests(Graphics validation tests passed).python3 tools/check_conventions.py.Standard #218 Multi-Sample Telemetry (Astro Bot -
PPSA21567):Measured across alternating runs on Astro Bot intro/world loading scene against base
0aa4cb1c2(APS5_PROFILE_DRAW=1):origin/main(0aa4cb1c2)GpuMutexmain + #5441GpuMutex(pre-warmed ahead)origin/main(0aa4cb1c2)GpuMutexmain + #5441GpuMutexorigin/main(0aa4cb1c2)GpuMutexmain + #5441GpuMutexPipelines()outsideGpuMutexallows monolithic Vulkan PSO compilation (vkCreateGraphicsPipelines) to execute concurrently with compute queues, eliminating up to 9,000 ms of mutex lock hold time per new shader configuration.Checklist
Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-14T00:51:33Z.
Review: COMMENTED
This needs changes before it can help. As written it is more likely to add pipeline compiles and per-draw CPU time than to remove stalls.
1. The prewarm key doesn't match the draw's key, so some draws compile twice.
PrewarmPipelinerebuilds the inputs ofCachedPipelinefrom the pre-lock state.Drawchanges some of them after resolving its targets (Graphics/src/Draw.cpp, aroundCachedPipelineinDraw):leanisrecorded && !drawTransitions, andrecordeddepends on residency, completion work and leases. The prewarm assumesrecordDraws && !drawTransitions, so every draw that isn't recorded gets aGENERAL-layout pipeline built ahead and aCOLOR_ATTACHMENT_OPTIMALone built inDraw.Drawreplaces the attachment format withAttachmentProxyFormatand masks the write mask. The prewarm builds with the original format, which is the format the device can't render to (that is why it is proxied). That is a second pipeline at best, and a creation failure outside the draw's error handling at worst.Each mismatch is a full extra
vkCreateGraphicsPipelines. The extra entries also count against the store's 1024-entry bound and can evict pipelines that live draws use.2. The compile doesn't actually leave the critical section.
CachedPipelineholdsPipelines().mutexfor the wholestd::make_shared<Pipeline>(...)(Graphics/src/Pipeline.cpp), and every draw on every queue takes that mutex for its lookup. Moving the call from underGpuMutexto beforelockForDrawstill blocks every other draw for the duration of the compile. Only work that takesGpuMutexand never looks up a graphics pipeline gains.3. Every draw pays for it. For the more than 99% of draws that hit, this adds a second
CachedFragmentOutputs(which builds astd::set),BuildVertexInputLayout,DescribeSetLayouts, a key build and a hash lookup under the store mutex. That is CPU time on the hottest path in the driver, spent to warm a cache that is already warm.4. GPL devices already avoid the long compile. With
VK_EXT_graphics_pipeline_library, the stage libraries are prebuilt onPrebuildStageLibrary's pool and the draw only fast-links. The multi-second monolithic compile described here applies only to the whole-pipeline paths (no GPL, or the cases listed in ARCHITECTURE.md). Please name the device and driver and say which path the measured pipelines took.5. The numbers. A 5–9 s stall per new pipeline doesn't fit a mean frame time of 54 ms. One such stall in a capture would dominate the mean. The runs also used
APS5_PROFILE_DRAW=1, which the Performance report form rules out. Please attach theaps5-summary.jsonllines and traces as CONTRIBUTING asks forperf(changes.#4897 takes the same approach for compute: the pipeline is created from the exact resources the dispatch will use, and builds of the same key are deduplicated with a
shared_future. A graphics version would need to compute the key from the resolved targets (afterlean, proxies andmaskedare known) and release the store mutex during the build, which means the same in-flight dedup.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T01:06:14Z.
CachedPipelinebuilds the pipeline while holdingPipelines().mutex(Pipeline.cpp:903), so another draw that looks up any pipeline under the GPU lock still waits out the whole compile. Please create it outside that lock and share one in-flight creation per key, as #4897 does for compute pipelines.PrewarmPipelinealso guesses the draw's key: the attachment layout fromAPS5_SYNC_DRAWSalone (Draw takes it fromrecorded), and no proxied-target formats. When the guess is wrong, the pipeline is compiled twice. Please get the inputs from the codeDrawuses rather than a copy.The test should cover that: a draw after the prewarm creates nothing, and a lookup during a creation doesn't wait for it.
Please use the current PR template (Based on main, Unblocks, GPUs tested) and replace the table with the summary lines of main and of this PR from the same scene, with the traces.
Imported from boykopovar/AnyPS5. Originally posted by Kikoarl on 2026-10-14T11:58:37Z.
putting this pr on hold while i re-evaluate telemetry and profiling on full in-engine scenes.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T00:41:27Z.
Understood, on hold. The 10-14 points stand for when you pick it up: create the pipeline outside
Pipelines().mutex, and share one in-flight creation per key. It conflicts with main now, so rebase first.Pull request closed