perf(agc): prebuild graphics pipeline shader libraries off the GpuMutex on first visit #25434
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/25434"
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 tablefrogpillow on 2026-11-22T03:07:57Z.
What
First-visit graphics draws built their pipeline shader libraries while holding
GuestMemory::GpuMutex().Driver::commitDrawtakes the mutex and holds it acrossVulkanDevice::Draw, so the pre-rasterization and fragment-shaderGraphicsPipelineLibrarycompiles for a never-seen pipeline ran with the mutex held and blocked the queue worker atfill— the first-visit freezes of #25352.This prebuilds those libraries before
commitDrawtakes the mutex, and only on a pipeline's first visit, so the warm path adds no per-draw build work:VulkanDevice::PrebuildGraphicsLibrariesOnFirstVisitfolds the draw's shadervariantIds into a key and checks a per-device set. On the common (warm) path it returns after one mutex-guarded hash-set lookup and calls novkCreateGraphicsPipelines. On a first visit it calls the existing, already off-lockPrebuildGraphicsLibrariesand records the key.commitDrawcalls it once, beforeTagGpuLockSiteand thestd::lock_guard.How the off-lock build is published, and who races.
PrebuildGraphicsLibrariesbuilds the library parts through the same code a mutex-held link uses (LinkPipelineFromLibraries,partsOnly), which already drops the pipeline-library store's own mutex around eachvkCreateGraphicsPipelinesand inserts the finishedVkPipelineback into the per-device store under that store mutex. That store is the single publication point: the later mutex-held link reads the same keyed cache and hits it. Because the build runs with the store mutex dropped, the journal replay, the registration prepare pool and several draw-commit threads can already build the same part at once; the store resolves that by keeping the first inserted part and destroying the duplicate (theracedbranch inLinkPipelineFromLibraries). The new first-visit set adds only a best-effort filter under its own mutex — if two threads race the very first visit of one pipeline they both prebuild once (the store drops one) and one of them may still compile under the lock that single time. It never changes which pipeline a draw binds, only whether the compile happened before or under the mutex.A per-part
builtLocked/linkedLockedcounter onPipelineLibraryCounters, incremented at thevkCreateGraphicsPipelinessites whenGpuMutex().HeldByThisThread(), backs the test and the measurement below; it mirrors the existingcomputePipelinesCreatedLocked.Tested
AMD Radeon RX Vega 56 (RADV VEGA10), Mesa 26.2.6, Linux 6.8,
VK_LAYER_KHRONOS_validation1.4.x inserted,ANYPS5_NO_SHADER_CACHE=1(cold pipeline cache):agc_driver_graphics_pipeline_outside_gpu_mutex_testspasses with the change and fails without it (without the prebuild a first-visit draw builds its pre-rasterization and fragment libraries under the mutex). No newVUID-validation errors.I cannot reproduce the multi-second stall on the pipeline-light titles I have (Cat Quest 3's whole library set is ~2 ms), so the above is the counter evidence that the shader compiles move off the mutex, not a wall-clock number on a title that actually freezes. The PPSA06207 Molly's-story cold rerun is the wall-clock check.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T06:13:08Z.
Review: COMMENTED
Reviewed — no blocking findings
The inspected change moves first visit shader library construction before the GPU mutex; I did not run the new test or read every changed file, so the evidence is insufficient for approval.
What I ran
No commands or tests were run. I inspected the prepared diff and targeted source ranges with
repo_read.py; exact head:2cb997da06754c69194fc3543a2756c135ffe835.Results
Findings
Blocking
None verified in the inspected code.
Non-blocking
None.
Not verified
The full text for
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppwas excluded from the review folder because it was too large; I read only lines 5140–5200 through the pinned reader. I did not read all lines of the included changed files or inspect the full new test. The prepared bundle included five changed files:VulkanDevice.hpp,Draw.cpp,VulkanDevice.cpp,PipelineLibrary.hpp,PipelineLibrary.cpp, andGraphicsPipelineOutsideGpuMutex.cpp(six files total); I read targeted ranges fromDraw.cpp,VulkanDevice.cpp,PipelineLibrary.cpp, and the diff, but not the full text of every included file. Author-reported test and measurement results were not independently verified.To get this to a good state
Nothing is required. Optional: run
agc_driver_graphics_pipeline_outside_gpu_mutex_testson this head and complete review of the remaining changed-file text before treating the review as complete.