perf(agc): create compute pipelines before taking the GPU lock #5989
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5989"
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 oneandonlydean on 2026-10-14T18:34:16Z.
Carries @karanvora2599's #4897 (authorship kept) with MarcZX100's review point, plus the address-table shaders that #4897 still compiled under the lock; supersedes #4897; fixes #4977.
What
Compute pipelines are created before the dispatch takes
GuestMemory::GpuMutex, instead of inVulkanDevice::dispatchunder it.Background. On
main, the first dispatch of a compiled variant creates its pipeline indispatch(), whichDriver::dispatchcalls underGpuMutex. While the driver compiles, everything else that takes the mutex waits: other queues' dispatches and draws,Driver::Present, label writes, memory waits and the guest'smunmap. Large compute modules take seconds on NVIDIA (#2292, #2013) and minutes on ANV (#4977).#4897 (karanvora2599), rebased onto
main:VulkanDevice::computePipeline: module, layout, specialization, subgroup size, #3717's capture and the statistics.computePipelinereturns the pipeline fromcomputePipelines, or creates and inserts it. A pipeline another thread is creating is waited for through ashared_futureper key incomputePipelinesBuilding, so two queues that need the same new variant create it once; if creation fails, every waiter gets the error.PrepareDispatchcalls it once the descriptor set layout is known (stage A or the cachedShaderResources); the result travels inPreparedDispatch::objects.dispatch()still creates it under the lock withAPS5_LOCKED_BUILD=1.CreateComputePipelinegetscontext.pipelineCacheSynchronization(#4795), so the moved creation is guarded against the cache snapshot (MarcZX100's review).APS5_LOCKED_PIPELINEis dropped; comparisons are against amainbuild.PreparedDispatch::cachedkeeps alive,workgroupMemoryLayoutand the pipeline cache, which is created withoutVK_PIPELINE_CACHE_CREATE_EXTERNALLY_SYNCHRONIZED_BIT(graphics library prebuilds already use it outside the lock).Address-table shaders:
ShaderResourcesdefers its whole build toComplete(), under the mutex), so with #4897 alone its layout is null inPrepareDispatchand it is still created under the mutex. These are the largest modules, and the ones in #4977.Graphics::DescribeSetLayoutsmakes it from the shader alone, as the draw path and the graphics library prebuild already do. For an address-table shader,PrepareDispatchcreates the pipeline with that layout.dispatch()checks afterComplete()that the build's layout key equals the described one, and throws if not.computePipelinetakes the set layout and its key instead of aShaderResources; the compute capture (APS5_DUMP_COMPUTE_PIPELINES) reads the bindings from the key.VulkanDevice::ComputePipelineCounts()counts compute pipelines created, and those created while the creating thread held the mutex; the[vk]line ofAPS5_PROFILE_DRAWprints both.Results don't change: module, specialization, subgroup size, flags, per-variant key and the descriptor-cache set layout object are the same.
Tested
ANYPS5_ENABLE_SPIRV_TOOLS=ON, onmainatea30c9274:ctest -R "agc_|dispatch|bda|pipeline"withANYPS5_REQUIRE_VULKAN=1, 556 tests, all pass (agc_driver_stencil_ref_exportskipped).agc_driver_compute_pipeline_outside_gpu_mutex(new): the test thread holds the mutex and submits a new program on queue 0x20. Its pipeline has to be created while the lock is still held, none under the lock, and the dispatch stores the right value after release. Fails onmain.agc_driver_global_loadsnow goes throughPrepareDispatchandDispatchunder the mutex, as the driver does, and requires the address-table program's pipeline to be created inPrepareDispatch. It fails with #4897's change alone.APS5_PROFILE_DRAW=1, each build with its own empty shader and pipeline caches, then a second run on the same caches. Time invkCreate*Pipelinescalls of 2 ms or more while the creating thread heldGpuMutex(local timing patch, not part of this PR; measured on the same change rebased onto78f1aea70):With #4897's change alone (first run, first 152 s), 43 creates held the mutex for 54.3 s: queue 0's four largest programs (406K to 504K words, all address-table shaders) were still created under it. With this PR no compute pipeline is created under the mutex; what remains are graphics pipelines in
Draw(the 8.5 s one is aDRAW_INDEX_AUTO), which is a separate change.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)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-14T20:18:37Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppL4494-4547