perf(agc): build the pipelines of a submission ahead on a compile pool #5925
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5925"
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-14T16:05:51Z.
What
On the first run of a title, the queue worker finds the pipelines of a submission already built instead of creating them under
GuestMemory::GpuMutexat each draw and dispatch.Driver::resolveGroupAhead(DispatchAhead.cpp), which resolved only the dispatch groups of the compute queues, now also walks the graphics queue and the draws. At the start of every submission the worker walks the packets with a scratchQueueState, decodes every draw and dispatch whose draw-cache or dispatch-cache key is new (the materialized stage results go to the recompile cache, which serves the worker again at the packet) and hands their pipeline builds to a pool ofhardware_concurrency() / 2threads theVulkanDeviceowns (PipelineLookaheadPool).Driver::drawgets the same resolve modeDriver::dispatchhas: it stops beforelockForDrawand hands the state and the stage results over.Graphics::BuildDrawPipelineAhead, the derivationGraphics::Drawmakes (masked blend states and proxied targets, now shared withDrawaspipelineStateOf, the vertex input layout, the described set layouts and the attachment layout a recorded draw uses) ending inCachedPipeline; a compute pipeline throughVulkanDevice::ReplayComputePipeline, the journal replay's hook. Both find-or-insert: a worker that reaches the packet first builds the pipeline itself and the pool's copy is dropped. Nothing waits for the pool.APS5_GROUP_CAPTURE_ALL_QUEUES=1adopts on the graphics queue too, as before). The walk now also executesSET_*_REG_INDIRECTpackets from their submit-time register lists instead of stopping at them.PrepareForReplacement) and at its teardown, before the journal replay, following the replay'sCancel/Waitpattern.APS5_NO_SUBMIT_LOOKAHEAD=1disables it;APS5_SUBMIT_LOOKAHEAD_THREADSsets the pool's threads (0disables it too);APS5_PROFILE_DRAW=1prints a[lookahead]line for the walk (per queue, with the[groupcap]line) and one for the pool at teardown.Depends on #5875: the stable identities (
RecompileResult::Identity), the find-or-insert stores, the builds outside the store mutexes inCachedPipeline/LinkPipelineFromLibrariesandVulkanDevice::createComputePipeline/ReplayComputePipelineare what the pool builds through. The diff on top of #5875 is 18 files; review the last commit only.Open pull requests near this change, checked before writing it: #4897 (compute pipelines created in
PrepareDispatchbefore the GPU lock, with a futures map that waits on a concurrent build) and #5526 (PrewarmComputePipeline, the same idea) build the compute pipeline on the worker thread at the dispatch's own preparation; #5441 (PrewarmPipeline, draft) builds the graphics pipeline on the worker thread right beforelockForDraw; #5115 (draft) prepares deferred shaders atSET_SH_REG. This pull request implements none of their functions: the builds run on a pool ahead of the packets, from a decode of the whole submission, through the #5875 entry points; the one shared step, deriving the pipeline inputs of a draw from its state and stages, is extracted fromGraphics::Drawitself (pipelineStateOf) and used byDraw. If #5441 lands first, the pool task can call itsPrewarmPipelineinstead. #5747, #5481 and #5477 touchresolveGroupAheadby a few lines each (the indirect-argument stop, NOP skipping, COPY_DATA registers) and will need a trivial rebase on either side.Tested
Linux (Ubuntu 24.04, GCC 13.3), lavapipe (Mesa 25.2.8, LLVM 20), 4 CPU threads, pool of 2 threads. No title or homebrew run: the hardware this is for (NVIDIA, #4897 measured 0.28 to 0.59 pipelines/s with 3 threads; the 5 to 9 s stalls of #5441) is not available here.
New
agc_submit_lookahead(Vulkan mock,agc_driver_graphics_tests --submit-lookahead): the pool builds a draw's pipeline and runs a compute build ahead; the worker's own derivation of the same draw then hits the store and creates nothing; a configuration the worker built first is found present by the pool and not rebuilt; a failed build is counted and the pool goes on; cancelling with 15 builds queued behind a blocking one drops the 15, accepts nothing afterwards, and leaks no Vulkan object (mock.live == 0afterClearCachedPipelines).New
agc_driver_submit_lookaheadandagc_driver_submit_lookahead_off(lavapipe, the same binary withAPS5_NO_SUBMIT_LOOKAHEAD=1): one DCB with aWAIT_REG_MEMon a CPU label, a draw into a linear target (a synchronous draw), a draw into a tiled resident target (a recorded draw) and a dispatch. With the lookahead on, while the worker waits on the label the walk decodes the two draws and the dispatch and the pool builds the three pipelines (two store misses,DispatchPipelineBuildsunchanged); after the label the worker's draws hit the store twice and its dispatch builds nothing; a repeated submission is skipped as seen. With it off, the walk never runs and the worker builds the three pipelines itself. Both variants check the same images (every texel of both targets, in both layouts) and the dispatch's output, so the lookahead changes nothing in what is drawn.agc_driver_submit_lookahead_tests --benchmark N CHAIN(not registered): N new pixel programs (CHAIN multiply-add steps on a user-data word, so the module is not folded) drawn into a tiled resident target and N new compute programs in one DCB, after a warm-up submission that creates the device. Wall time from submit to idle,ANYPS5_NO_SHADER_CACHE=1 APS5_NO_PIPELINE_JOURNAL=1 MESA_SHADER_CACHE_DISABLE=true, two runs each:With pipelines that take time to build, the submission completes 9 to 23 % sooner, with every draw and dispatch finding its pipeline built by the pool (0 built by the worker). With trivial pipelines it is neutral at 24 and 5 % slower at 64: on lavapipe the pool's compile threads share the four cores with the rasterizer threads, which a GPU does not. The walk itself (the decode and recompile of the new configurations, 0.9 to 2.3 s on the worker at 200 steps) is work the worker did at the packets before; it now runs before the first packet.
Validation layer (
VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation) on the lavapipe test with the lookahead on and off: the same two VUIDs in both runs, both already in the base (VUID-VkGraphicsPipelineCreateInfo-pLibraries-06681on the fast link of the pipeline libraries, 12 times, andVUID-VkDeviceCreateInfo-pNext-pNextfrom the layer of Vulkan headers 1.3.275 not knowing a newer device feature struct, 6 times); no VUID the lookahead adds.ctest -R '^(agc_|shader_|guest_shader_)': 539 tests, all pass.agc_driver_draw_cache_reuseandagc_driver_draw_cache_reuse_offnow run withAPS5_NO_SUBMIT_LOOKAHEAD=1: they assert the exact draw-cache lookup counts of three draws, which the walk's own decode of the same draws doubles (6 lookups instead of 3), so they keep testing the worker's draws alone.tools/check_conventions.py --base upstream/mainandtools/check_test_registration.py buildpass.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)agc_driver_tessellationsegfaults the same way onmain)Imported from boykopovar/AnyPS5. Originally posted by fma-rc on 2026-10-14T18:01:34Z.
I ran Astro's Playroom (PPSA01325) on Linux with an RTX 5080 (NVIDIA 615.78.08):
maine34c47921against the same commit with this PR (3339ddd3a, which includes PR 5875). Caches were warm, the scene was the busy gameplay of the first level, and I ran three alternating pairs. The captures of both builds show the same scene.mainGPU busy per present is the same (50.8 vs 51.2 ms). With
APS5_PROFILE_DRAW=1, queue 0 decodes about 140,000 draws ahead per 10 s, and that takes about 2.8 s of the driver thread. Only 1,000 to 5,000 of them are skipped as seen before, so here the decode runs ahead on the thread that already limits the frame. Loading got faster cold (level reached at 109 s against 145 s), and was the same warm (58 against 55 s).pipeline_journal,submit_lookaheadanddraw_cache_reusepass on NVIDIA, RADV and lavapipe.APS5_SUBMIT_LOOKAHEAD_THREADSandAPS5_NO_SUBMIT_LOOKAHEADare environment switches.Imported from boykopovar/AnyPS5. Originally posted by fdfawef324 on 2026-10-14T23:22:37Z.
Windows Server 2025, RTX 3060 (NVIDIA 591.86), WinLibs GCC 15.2.0 r7, Release, head
3339ddd3a. This head has thethread_localkey inCachedPipelinefrom #5875 (details), and it shows here too:prx_thread_local_destructorsfails and namesCachedPipeline.Critical error detected c0000374in libSceAgcDriver.prx'srun_dtor_listas a thread exits:agc_driver_submit_lookahead_tests: 10 of 10 (threadqueue worker 0x0)APS5_NO_SUBMIT_LOOKAHEAD=1: 9 of 10agc_driver_pipeline_journal_tests: 10 of 10The lookahead is not needed for it, so the fix belongs in #5875 and this branch needs it after a rebase. Without a debugger,
ctest --repeat until-fail:10passes 10 of 10 foragc_submit_lookahead,agc_driver_submit_lookahead{,_off},agc_pipeline_journal,agc_driver_pipeline_journal,agc_pipeline_cacheandagc_pipeline_library{,_off,_fast_only}.Not tested: a title, Linux, and the
HostThreadLocalchange on this head (I tried it only on #5875's head).AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-15T13:46:28Z.
PS5 FSR4 Showcase (#6118) on AMD, as @MarcZX100 suggested. The first run still gives up at
stage=fsr4, but the cache warms much faster. With this PR and #5875 the title gets paststage=fsr4on the fourth run. With both turned off, it is still stuck there after nine.Windows 11 (26300), Radeon 860M (RDNA 3.5, driver 32.0.13058.8001), WinLibs GCC 15.2.0, Release. Catalog 01.000.010, relinked with
--windows --trap-sdk-syscall-stubs,APS5_PROFILE_DRAW=1.Tree. This PR conflicts with current
mainin seven files, so I took its head3339ddd3aas it is. On top I applied only themainchanges the title needs: #5648 (VCC buffer tuples), #5163 (out-of-rangesceAgcInitversions) and #5477 (COPY_DATAregister source). Without the last two, the title stops atvkCreateDevice ... = -3and at theCOPY_DATAthrow. Both sides below use that same build. "Off" setsAPS5_NO_SUBMIT_LOOKAHEAD=1 APS5_NO_PIPELINE_JOURNAL=1.Each side starts with a new run folder and an empty
%LOCALAPPDATA%\AMD\VkCache, then reuses the folder:vkQueueSubmit = -4before chapter 0stage=fsr4 after_ms=4523, cache saved 3,773 KiBstage=fsr4 after_ms=4522, 1,446 KiBstage=fsr4, 4,138 KiBstage=fsr4, 1,990 KiBstage=fsr4, stops atstage=compose after_ms=712(#6270's stop)stage=fsr4, 2,186 KiBstage=fsr4 after_ms=4523every time[dispatch] creating a pipeline for 794502 SPIR-V words (program 0x0)and the rest at once). Onmainthe queue worker builds them one by one.replay on 8 threads: 0 graphics and 3 compute built).Not tested: this PR on current
main(because of the conflicts), the full CTest suite, NVIDIA.AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-16T11:43:33Z.
Not merging this head:
DispatchAhead.cppdraw branch), including when warm. That worker already limits the frame, and only 1-5k of ~140k draws per 10 s are skipped as seen. The next head will keep the walk off the worker's critical path once nothing new is found: either it stops walking a queue after submissions that hand nothing to the pool, or the decode moves off the worker. A test will pin that a warm submission is not decoded ahead. The before/after on the same scene will be in the description. @fma-rc, a rerun of that scene on the new head would settle it.main.thread_localdestructor inCachedPipelineis gone frommain(the merged #5875 keeps only trivialthread_local bools), so the rebase drops it from this branch.stage=fsr4on the fourth run) is the cold-start case this is for. It has to stay that way after the change above.Imported from boykopovar/AnyPS5. Originally posted by Amoenus on 2026-10-19T12:48:58Z.
@adriadam10 following the #5648 reference in @LeandroLP23's FSR4 report: our buffer-tuple fix is merged as
23dcb82499. The independent FSR4 title/cache observations are Leandro's.Two source-based coverage suggestions for the rebased head:
VulkanDevice::Dispatchdirectly. Its earlier RTX5080/Radeon results therefore do not exerciseDriver::resolveGroupAhead. Routing a representative MUBUF/MTBUFs104:s105:VCC_LO:VCC_HIcase through the submission fixture, with lookahead on/off and identical output/bounds checks, would cover the specific prerequisite the FSR4 tester needed.pool.enqueued; it can pass while the worker still walks/derives keys. This complements your stated fix and catches a queue being permanently disabled after it first becomes warm.We have a Windows11 Enterprise26200 RTX5080 (610.62/32.0.16.1062) and Radeon(TM) Graphics (32.0.21036.18) available for the updated head. A useful hardware comparison would keep correctness checks separate from cold pipeline-build time and warm worker/frame cost, with the same scene and cache setup. Our current Sonic replay ends during startup, so it supplies no steady-gameplay performance result for this PR.
This is source review of
3339ddd3a, not a fresh build, GPU run or performance measurement of #5925. The author has already identified the warm-cache regression and rebase work; this adds test coverage suggestions rather than repeating those findings. AI-assisted: yes, Codex.Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-19T13:31:17Z.
I tried the FSR4 Showcase (PPSA99011) cold A/B on this head for the warm-up question in #6118, but the head is too old for that title. Setup:
3339ddd3awith #5648 (23dcb82499) cherry-picked, since it doesn't merge into currentmain. Radeon 860M, driver 32.0.13058.8001, Windows 11, relinked with--trap-sdk-syscall-stubs.Every run stops 4 s in with
FSR4_SHOWCASE_ERROR vkCreateDevice(physical, &di, NULL, &device) = -3, with and withoutAPS5_NO_SUBMIT_LOOKAHEAD=1. That is before any pipeline is built, so it says nothing about this change. Currentmaingets past this point on the same machine.I'll rerun the comparison once the branch is rebased: cold, lookahead on and off, counting runs until all 12 chapters play. On
mainthat took 34 runs.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-21T18:55:01Z.
A title this would unblock: Afterglow PPSA47770 (01.000.006) exits with code 1 about 17 s after launch, on
main60976d8a4. Machine: Windows 11, Radeon 680M, AMD Vulkan driver 32.0.21030.ps5-agcsubmit layer) waits for each DCB'sReleaseMemlabel to retire. Its watchdog is2000 × usleep(1000)plus 200 ms, about 2.2 s. After that it prints[ps5-agc] submission retirement failed; terminating application before cleanupand calls_Exit(1). The title redirects its stdout and stderr, so this is indownload0/hui/dev/app.log._Exit:0x21ea8eff0is still 0; the title expects0x474c3701.queue worker 0x0is blocked inAgcDriver::LockSpinning<std::recursive_mutex>onGuestMemory::GpuMutex.AgcDriver::Graphics::LinkPipelineFromLibraries→amdvlk64, linking a draw-time pipeline.[ps5-gallium] compile-shader stage=5 ... bytes=95460 hash=28cacb58). The title logsprogram backdrop built in 7675 ms.GpuMutex, the queue can't retire the earlier submission's label within the title's 2.2 s, so the title ends. This happens on every run, with or without the pipeline cache.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by 00xDisaster on 2026-10-21T22:22:16Z.
Independent Linux/NVIDIA data point for the submit lookahead, from Pumpkin Jack (PPSA03446).
I ported the lookahead feature onto current
main(this PR is based on an old commit and conflicts today, so this is a port of the feature, not of the PR head) and ran the same save twice, at the point where the title freezes for 7.3 s, with a fixed camera. Both runs started from the same 469-pipeline journal with no Vulkan pipeline cache; the only difference wasAPS5_NO_SUBMIT_LOOKAHEAD.[draws] longest draw)The pool saw 144,143 pipeline lookups, built 477 and found 143,666 already present, with 0 build failures and 0 dropped at teardown.
That is a 6.9x reduction of the worst draw: the 7.3 s freeze is gone. It is not a full elimination. About 1,400 draws failed the ahead-decode path over the run and were still built at use, and the remaining 1.07 s hitch is one of them, so the decode coverage of the ahead path is the part that still needs work.
I am not proposing a competing pipeline implementation; this is a measurement of the PR's own idea.
AI-assisted: no
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-22T00:27:33Z.
Another title this would help, with numbers: Borderlands 4 (PPSA01494) on Linux/NVIDIA (RTX 4070 Ti, 615.71.09,
maina6dcea9279).GameThread timed out waiting for RenderThread after 120.00 secs(220 s into one run at 20 GB, 319 s into another at 12 GB). The core of the 220 s run shows the GPU queue thread insidevkCreateComputePipelines:Driver::run→execute→dispatch→VulkanDevice::PrepareDispatch→computePipeline→CreateComputePipeline, in NVIDIA's NVVM.APS5_DUMP_COMPUTE_PIPELINES(at least 50,000 SPIR-V words) captured 128 compute pipelines in its first 320 s. Replayed one at a time withagc_compute_pipeline_replayand the driver's disk cache off, theirvkCreateComputePipelinestake 179 s in total. 63 of them take more than a second, and the slowest 8.7 s (a 2.7 MB capture). No single one is near 120 s. But all of them are built on the queue thread at their first dispatch, so a level that brings dozens of new ones at once keeps the render thread waiting. That's why the stop moves between runs, and why the capture run happened not to hit it.So building these ahead on a pool would take the whole 179 s off the queue thread for this title. I can run a rebased head of this PR on Borderlands 4 if that would help.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-22T00:38:37Z.
A warm control for the Borderlands 4 numbers above, same build (
maina6dcea9279), 16 GB, 600 s. This run kept the shader cache and pipeline journal from the earlier runs. At startup[pipeline-journal] loaded 744 pipelines and 806 modules (276.0 MiB) ... in 255 ms. It ran the full 603 s with no watchdog stop and reached the first-boot Accessibility screen by 420 s (about 1.5 FPS there). That's one run, against two watchdog stops in three cold runs. It points the same way: once the pipelines exist before their first dispatch, the queue thread stops blocking the render thread.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-14T11:26:22Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this change; the reviewed code and reported test results support the submission lookahead design.
What I ran
3339ddd3af77cfc336148966657c0d14e87b6ae1using the prepared diff andrepo_read.pyat the pinned head.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
core/libs/prx/libSceAgcDriver/tests/Graphics.cppandcore/libs/prx/libSceAgcDriver/tests/Recorder.cppwere excluded from the review folder because they were too large; they were not read from the pinned head.DispatchAhead.cppandPacketExecution.cppfiles. No finding is made about unread code.To get this to a good state
Nothing is required.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.