Skip to content

perf(agc): create compute pipelines before taking the GPU lock - #5989

Merged
oneandonlydean merged 3 commits into
boykopovar:mainfrom
oneandonlydean:carry4897/compute-pipeline-unlocked
Oct 14, 2026
Merged

oneandonlydean merged 3 commits into
boykopovar:mainfrom
oneandonlydean:carry4897/compute-pipeline-unlocked

Conversation

@oneandonlydean

Copy link
Copy Markdown
Collaborator

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 in VulkanDevice::dispatch under it.

Background. On main, the first dispatch of a compiled variant creates its pipeline in dispatch(), which Driver::dispatch calls under GpuMutex. 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's munmap. Large compute modules take seconds on NVIDIA (#2292, #2013) and minutes on ANV (#4977).

#4897 (karanvora2599), rebased onto main:

  • The creation code moves unchanged into VulkanDevice::computePipeline: module, layout, specialization, subgroup size, feat(agc): capture and replay compute pipeline compilation #3717's capture and the statistics.
  • computePipeline returns the pipeline from computePipelines, or creates and inserts it. A pipeline another thread is creating is waited for through a shared_future per key in computePipelinesBuilding, so two queues that need the same new variant create it once; if creation fails, every waiter gets the error.
  • PrepareDispatch calls it once the descriptor set layout is known (stage A or the cached ShaderResources); the result travels in PreparedDispatch::objects. dispatch() still creates it under the lock with APS5_LOCKED_BUILD=1.
  • Changes from perf(agc): create compute pipelines before taking the GPU lock #4897: CreateComputePipeline gets context.pipelineCacheSynchronization (fix(agc): serialize pipeline cache snapshots #4795), so the moved creation is guarded against the cache snapshot (MarcZX100's review). APS5_LOCKED_PIPELINE is dropped; comparisons are against a main build.
  • Safety, from perf(agc): create compute pipelines before taking the GPU lock #4897: the creation reads only the compiled shader, a set layout that the dispatch owns or PreparedDispatch::cached keeps alive, workgroupMemoryLayout and the pipeline cache, which is created without VK_PIPELINE_CACHE_CREATE_EXTERNALLY_SYNCHRONIZED_BIT (graphics library prebuilds already use it outside the lock).

Address-table shaders:

  • A shader that maps guest memory through BDA tables builds nothing in stage A (ShaderResources defers its whole build to Complete(), under the mutex), so with perf(agc): create compute pipelines before taking the GPU lock #4897 alone its layout is null in PrepareDispatch and it is still created under the mutex. These are the largest modules, and the ones in AGC: vkQuake's ray-traced shadow compute shader becomes 519,500 SPIR-V words; Intel ANV compiles it for minutes under GpuMutex and crashes (PPSA99010, Linux) #4977.
  • The set layout of a compute dispatch depends only on the shader's bindings (binding, type, count, stage, plus update-after-bind from the device limits). Graphics::DescribeSetLayouts makes it from the shader alone, as the draw path and the graphics library prebuild already do. For an address-table shader, PrepareDispatch creates the pipeline with that layout.
  • dispatch() checks after Complete() that the build's layout key equals the described one, and throws if not.
  • computePipeline takes the set layout and its key instead of a ShaderResources; 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 of APS5_PROFILE_DRAW prints both.

Results don't change: module, specialization, subgroup size, flags, per-variant key and the descriptor-cache set layout object are the same.

Tested

  • Linux (CachyOS), RTX 4090 (NVIDIA 610.57.04), GCC 16.2.1, Release, ANYPS5_ENABLE_SPIRV_TOOLS=ON, on main at ea30c92: ctest -R "agc_|dispatch|bda|pipeline" with ANYPS5_REQUIRE_VULKAN=1, 556 tests, all pass (agc_driver_stencil_ref_export skipped).
  • 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 on main.
  • agc_driver_global_loads now goes through PrepareDispatch and Dispatch under the mutex, as the driver does, and requires the address-table program's pipeline to be created in PrepareDispatch. It fails with perf(agc): create compute pipelines before taking the GPU lock #4897's change alone.
  • perf(agc): create compute pipelines before taking the GPU lock #4897's own runs (RTX 4060 Laptop, Intel UHD, lavapipe 25.2.8 on Windows; dispatch-path tests and 352 shader/driver tests) and its synthetic measurement: two 771K-word programs on queues 0x20 and 0x28 done after 20.7 → 14.4 s; worst wait of a cached dispatch on 0x28 while 0x20 compiles 7.6 s → 3 ms.
  • PPSA21564, RTX 4090, start through title, menu and first level (270 s), APS5_PROFILE_DRAW=1, each build with its own empty shader and pipeline caches, then a second run on the same caches. Time in vkCreate*Pipelines calls of 2 ms or more while the creating thread held GpuMutex (local timing patch, not part of this PR; measured on the same change rebased onto 78f1aea):
main this PR
first run (empty caches) 104 creates, 160.7 s, longest 14.3 s 51 creates, 19.9 s, longest 8.5 s
second run 70 creates, 101.0 s, longest 21.0 s 25 creates, 19.1 s, longest 2.7 s

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 a DRAW_INDEX_AUTO), which is a separate change.

  • Gate phases, second run (fps; other builds ran on the host during both runs): intro 29.6 → 35.0, title 10.1 → 14.1, menu 6.7 → 8.3, level 7.1 → 7.6. Video check passed on both. PPSA02929: no regression (menu 29.6, gameplay 30.4 fps).

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • GPUs tested: NVIDIA RTX 4090, 610.57.04, Linux; from perf(agc): create compute pipelines before taking the GPU lock #4897: RTX 4060 Laptop 591.86, Intel UHD (Raptor Lake) 101.6790, lavapipe 25.2.8, Windows 11
  • AI-assisted: yes

karanvora2599 and others added 3 commits October 15, 2026 07:27
PrepareDispatch now creates a missing compute pipeline once the
descriptor set layout is known, so the driver's compile no longer runs
under GuestMemory::GpuMutex. Other queues, presentation and label
writes go on during it, and compiles from different queues overlap.
Two queues that need the same new variant create it once.

The pipeline is still created in dispatch() when the layout is only
built under the lock, or with APS5_LOCKED_BUILD=1. The creation passes
the context's PipelineCacheSynchronization to CreateComputePipeline.
@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

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.

Pull request Conflicting files (lines on main) Same exports Same new files
#6012 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp L4494-4547

@oneandonlydean
oneandonlydean merged commit e6ef803 into boykopovar:main Oct 14, 2026
9 checks passed
TheBlenDed pushed a commit to TheBlenDed/AnyPS5 that referenced this pull request Oct 25, 2026
Main now carries boykopovar#4450, boykopovar#4475 and Pipodi's pointer-in-record table columns (c794273), which replace our copies and our record-pointer columns; boykopovar#5181, boykopovar#5989, boykopovar#5906, boykopovar#5484 (live snapshot mismatches serve live bytes; our retry is dropped), boykopovar#5483, boykopovar#5522, boykopovar#4732, boykopovar#5792. Kept local: the two-lane wave64 hang fixes, boykopovar#5815, option 1 substitutes, image-table stores and set 0 tables, stencil remap, 10_11_11 blending, the VRAM share/spill, block-hash snapshots, diagnostics. Versions: disk FormatVersion 42, RuntimeAbi 17, request serializer v30, BdaAbi UnnormalizedWrap 11 / DirectImage 12. Notes in work/sync-20261013/*-3.md.

AI-assisted: yes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc*

Projects

None yet

2 participants