perf(agc): wait at submit only for the preparations of the programs a submission binds #6867
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6867"
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 Pipodi on 2026-10-16T14:59:00Z.
What
Driver::Submitwaits on the submitting thread only for the registration preparations of the programs the submission binds, and moves each to the front of the queue (PrioritizeRegistrationPreparation), instead of waiting for every queued preparation (#5007). The scan reads the program address registers (SPI_SHADER_PGM_LO/HIof the pixel, geometry, export, hull and local stages,COMPUTE_PGM_LO/HI) written bySET_SH_REGand bySET_SH_REG_INDIRECTlists, including packets insideINDIRECT_BUFFERandCOND_INDIRECT_BUFFERtargets (they are copied into the submission before the scan).Rebased on
mainbb04a4f1ea. The pool part reusesmain'sPrioritizeRegistrationPreparation, as Dextroid17's port did.AwaitRegistrationPreparationand the pool's sequence tracking stay as they are, because the wait-for-all fallback below uses them. The pool also records which preparation owns each queued or running task, so the submit wait can wait for that task.Change since the review: a submission that writes only one register of a program pair (the other half came from an earlier submission) is not proven by the scan. It now waits for all queued preparations at submit, as
maindoes, instead of leaving that program to an unbounded wait in the queue worker at first use (CnRJay's #5007 concern). A bound after N seconds was not chosen: continuing without the program would skip the draw, which is invented behaviour.Change since jotitadev's run on 10-27: the wait for a bound program waited on its snapshot's
settledcondition wheneverpendingwas set. A preparation marked pending with no pool task, asagc_driver_prepared_shaders_dispatch_ahead_prewarm(#8735) does, was never settled, and the submission hung. The wait now moves the program's pool task to the front and waits for that task to finish. It does not wait for a preparation the pool does not hold.The scan also falls back to the wait-for-all when it cannot see every program the submission uses: the submission ends in a
REWIND(the tail is copied later in the queue worker), aSET_SH_REG_INDIRECTlist has an invalid register (the worker reads such a list again at execution), a draw (a dispatch) comes before any graphics (the compute) program pair written in the same submission, so the program may have been bound by an earlier submission, or a program address is written by a predicatedSET_SH_REGor one inside aCOND_EXECrange, which may not run.Not covered, and recorded in the technical debt entry: a draw that writes one graphics pair but also uses a stage bound by an earlier submission, and a program registered again at an address an earlier submission bound, then used without rebinding while the submission writes a different graphics pair. Their first draw waits in the queue worker with no bound. The longest preparation seen is 74 s on one thread (cold, 55,144-dword shader, Ghost of Yōtei), and a submission that binds such a shader waits as long at submit. A submission the scan cannot prove waits for every queued preparation, as on
main(76.3 s first-submission wait on Yōtei, cold, earlier measurement). The measured waits below are machine and cache dependent; no bound is claimed.Tested
Tests on the rebased branch (Windows, MinGW GCC 15.2, Release, RTX, ANYPS5_REQUIRE_VULKAN=1)
^agc_driver_(prepared|registered), 28 tests,--repeat until-fail:3: 28/28 (a3c2759583); the fouragc_driver_prepared_shaders*variants pass again on ccbf4f29e3.maine5f23554c9and on this branch,ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ctest -R "^agc_driver_(prepared|registered)" -V: 28/28 on both. Neither log has the "was not found but was requested" line. Both logs have the same 14VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605errors, all inagc_driver_prepared_exports, so this branch adds no new validation errors.UnprovenProgramsAtSubmit(inagc_driver_prepared_shaders): a slow (1500 ms) queued preparation, then a realsceAgcDriverSubmitDcb:SET_SH_REG)INDIRECT_BUFFERtargetREWIND(tail not scanned)The rows prove the early return or the wait by whether the preparation had finished when Submit returned, not by a time bound. Scan-level rows cover an invalid indirect list, a draw or dispatch with no pair written before it in the submission (a bind by an earlier submission and none now), a predicated pair, a pair inside a
COND_EXECrange (not complete, no address resolved), and a pair after aCOND_EXECrange that holds only another register (still complete). The invalid-list fallback is tested at scan level only: through Submit, the queue worker throws on such a list ("indirect register sentinel semantics are not implemented"), so it never reaches the wait.if (false && !scan.complete)) the test fails at the first row ("a submission writing half of a program address did not wait for the queued preparations"); with the REWIND fallback removed it fails with "a submission ending in a REWIND did not wait ..."; with the draw/dispatch check disabled it fails with "a dispatch that binds no program in its submission was reported as fully scanned"; without the predication check it fails with "a predicated program pair was reported as fully scanned", and without theCOND_EXECcheck with "a program pair inside a conditional execution range was reported as fully scanned". In that state the program would be waited for at first use in the queue worker, for the whole remaining preparation (1500 ms here; 74 s for the cold shader above).AwaitedRegistrationPreparation(main's ticket-rule test) is kept.mainbb04a4f1ea): 3028/3029;guest_freebsd_clocksaborts with 0xc0000409 as in #12736 (host zone not UTC), a libkernel test this branch does not touch.agc_host_import_cut_lifetimeandagc_driver_depth_plane_partial_storefail; both fail the same way on plainmaine5f23554c9on this machine.Ghost of Yōtei, this revision, cold: total submit wait 182 s → 7 s, first wait 49–52 s → 1 s
Windows, RTX 4090, driver 617.42. Both builds have a fully cold recompiler cache and a drained NVIDIA pipeline cache, a fresh profile, and the same environment. Each run is 900 s. A is
maine5f23554c9(run499, and run501 as a rerun for the trace). B is this branch, 4703b22bde (run500). Both builds carry the same local log line for submit waits of 100 ms or more; it is not part of this PR. On plainmainthe intro stays dark for the whole 900 s in all three runs, with or without this PR, so first-lit-frame times are missing.main)Frame 330 is later in B because a 116 s compute compile stall (shader 0x8000196500, the same in both builds) falls earlier there; this PR does not change compile times.
Trace digest, frames 100–200, queue worker (the hottest thread), inclusive ms per frame, A (run501) / B (run500). The window covers 277 s in A and 258 s in B.
The worker waits a third as long for preparations. That time now goes to compiling pipelines that are no longer held back behind the submit wait, so per-frame work in the window is higher, not lower.
Summary lines of the two traces above (aps5-summary.jsonl, frames 100–200)
maine5f23554c9(run501), then this branch 4703b22bde (run500). Both are markeddirtybecause both builds carry the local submit-wait log line described above. 4703b22bde is the measured revision; the head since adds only the fix for a pending preparation with no pool task (761ef1105e), and was not remeasured. The traces are kept locally and can be shared on request. Thetitlefield is written asY\u014dteihere; the summary writer had stored it double-encoded (\u00c5\u008d), which GitHub does not keep intact.Earlier measurements (before this revision)
main, 1.6 / 4.9 / 4.2 s with a port of this PR; longest queue-worker WorkerWait 1.5 / 2.7 / 2.0 s.main, 194 / 134 ms with the port; p90 357 / 362 vs 359 / 347 ms; presents 96 / 115 vs 114 / 121. No visible cost ofReferencedPrograms; it was not timed on its own.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🤖 Generated with Claude Code
https://claude.ai/code/session_01Q9BMpf1muQhujJd4AbteUA
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T15:05:29Z.
I traced the new scan against the driver paths:
readRegisterListskeys each indirect list by packet offset, and draw/dispatch resolve the same program address encoding from the SH register pairs. The per-snapshot wait still prioritizes and settles a demanded registration; work not found by the scan falls back to the existing first-use wait in the queue worker. The regression exercises direct compute binding, indirect vertex binding, half-written addresses, bound-vs-unrelated preparation, and a submission behind unrelated work.I did not find a concrete correctness issue in the diff. I attempted the focused Linux build locally, but GCC 12 stops earlier in unchanged
SrtDescriptorEvaluation.cpp:183(read.read->Flags<MemoryFlags>()), so I could not runagc_driver_prepared_shadershere. The platform CI jobs are currently skipped; I am not treating the reported Windows/Yōtei runs as my own validation.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T15:07:41Z.
One small regression-coverage gap: in
ReferencedRegistrationPreparation,boundSnapshot->preparedis marked pending and then settled bySettleLateron a separatestd::asyncthread. It does exercise the wait on a referenced snapshot while the unrelated pool task is pending, but it does not exercise the newly integrated path where the bound snapshot's own registration task is queued inRegistrationPreparePoolandPrioritizeRegistrationPreparationmoves that task ahead of unrelated queued work (the pool only receives the unrelated snapshot in this fixture).Could the fixture queue the bound preparation through
SubmitRegistrationPreparation(..., boundSnapshot->prepared.get())as well, then verify that the bound task settles before a blocked/unrelated task completes? The separate queue-priority test is useful, but this would connect registry lookup, task identity, prioritization and the submission wait in one regression. I see this as coverage hardening rather than a code defect.Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-16T16:24:45Z.
Review: COMMENTED
A Linux run of the regression, which the description (Windows) and the review above (GCC 12 stopped before it) do not have.
Machine: NVIDIA GeForce RTX 3070, driver 595.99.02, Vulkan 1.4.329, plus lavapipe (Mesa 26.0.3, LLVM 21.1.8) on the same machine. Ubuntu 26.04, i7-8700, GCC 15.2, Release,
BUILD_TESTING=ON. Head20cc5ae56merged intomain452494439(clean merge). The build ofPreparedShaders.cppand the changed driver sources goes through on GCC 15.2.agc_driver_prepared_shaders: 3/3 pass on the RTX 3070 (Selected GPU name=NVIDIA GeForce RTX 3070) and 3/3 on lavapipe, about 3.4 to 3.9 s per run (1.1 s onmainwithmain's test).^agc_driver_(prepared|registered), 18 tests,-j1: 18/18 on both devices, no skips.main'sSubmission.*andShaderRegistry.*the new test does not compile (ReferencedProgramsis not a member ofAgcDriver::DriverDetail).This does not address the coverage gap raised above (the bound snapshot's own task queued in
RegistrationPreparePool); I did not try that variant.Not run: Windows, AMD, the full suite, any title.
GPUs tested: NVIDIA GeForce RTX 3070 (595.99.02), lavapipe (Mesa 26.0.3, LLVM 21.1.8), Ubuntu 26.04
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by Pipodi on 2026-10-16T16:27:52Z.
Thanks, good catch. 7241b052b now queues the bound preparation through
SubmitRegistrationPreparationas well. The test occupies every preparation worker, queues the unrelated preparation ahead of the bound one, and frees a single worker once the submit wait has demanded the bound one. The bound task must run first and the unrelated one must still be pending when the wait returns. With thePrioritizeRegistrationPreparationcall removed fromAwaitReferencedPreparations, the test fails ("the queued preparation of a bound program was not moved ahead of unrelated queued work").Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-16T17:15:49Z.
Timed this on Ghost of Yōtei (PPSA26344) on Linux with lavapipe, cold shader cache on every run, base and PR runs interleaved:
Base averages 221 s and the PR 171 s (2 runs each), so the first frame came about 50 s (23%) earlier. The ranges do not overlap (base 211–231 s, PR 161–181 s). The time comes from a memory probe that logs every 10 s, so each value can be up to 10 s after the actual first frame.
Setup: both builds are
main5d9dcc42dplus the same 11 local commits that are not inmain. These are thesceNetCtlGetInfocode 12 fix (the same fix as #6227), sRGB and min/max texture copies this title needs to get past three early stops, two shader-cache checks, and the env-gated memory probe used for the timing. The PR build adds 20cc5ae56 and 7241b052b, which cherry-picked cleanly. The two trees differ only by those two commits, andlibSceAgcDriver.prxis the only library built from the files they change. -O2 build (CMAKE_BUILD_TYPE empty), lavapipe from Mesa 26.2.4 (LLVM 23.1.1), same game files, same host.For comparison, your Windows runs had the first frame at 40 s with this PR against 101 s on
main(61 s), andmainranged 80–181 s across your three runs. A 50 s gain here is in the same range. I did not measure the submit waits themselves.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by parl0v on 2026-10-16T19:03:16Z.
Data point: RTX 3060 12 GB (NVIDIA 617.42), i5-12400F, Windows 10 19045, MinGW GCC Release. Minecraft Dungeons II (PPSA16064 01.100.100), title screen, no input, 200 s rows,
APS5_PROFILE_DRAW=1 APS5_PROFILE_GPU=1;main93e54ceddvsmain+ this PR, interleaved with three other PRs in one batch, two rounds. FPS is the mean of the last 10[present]windows, GPU busy and idle gaps per frame over the last 8.mainNeutral on this scene (mean +0.7 %, within the row spread); no regression. 0 fatal.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T20:23:43Z.
I have an independent follow-up in progress for #8470: at shutdown, finish the running library prebuild but discard queued speculative prebuilds, leaving registration preparation and device-replacement waits unchanged. The candidate touches
RegistrationPreparePool::Closeand the ticket/wait bookkeeping that this PR also refactors, so the current-main branch may need a rebase/adaptation if #6867 lands first. I have not opened or pushed a PR; the candidate still needs a runtime test. Please let me know if you prefer a particular merge order or want me to wait for this pool refactor before preparing the follow-up.Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-21T17:53:57Z.
Review: COMMENTED
The result is large and measured (Ghost of Yotei, cold cache, first frame 101 s to 40 s, first submission wait 76.3 s to under 3 s), and moving a bound program's preparation to the front of the queue (#4404) is the right use of the scan. The part I would not merge as is is the fallback.
Driver::Submitwait for every queued preparation for one reason: a title that sees a submission take seconds treats the GPU as hung. Goat Simulator 3 (PPSA04159) failed a 10 s timeout when the wait sat in the queue worker. Waiting "in the queue worker at first use" is what this PR leaves for any program the scan misses: bound by an earlier submission, a half-written address, an address reached another way, or an indirect buffer the scan didn't follow. Those cases reproduce the Goat Simulator situation (the GPU side of a submission blocked on a long preparation), and the PR does not say how long such a wait can be. The cold-cache 55,144-dword shader this was found on took 74 s on one thread. If a program the scan misses is bound by a draw, the queue worker blocks for that long.ReferencedProgramswalks every copied command on every submit).main; rebase before it can be tested again.Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-27T06:24:29Z.
Review: COMMENTED
Follow-up on
d5bcd0c6c. My earlier run had no negative control and noted the bound-task gap; the new tests cover both. But merged with currentmain, a test that came in with #8735 now hangs.Setup: Ubuntu 26.04, i7-8700, GCC 15.2, Release. Head merged onto
mainfe2b52c7e(clean merge).ANYPS5_NO_SHADER_CACHE=1,ctest -j1. Devices: RTX 3070 (595.99.02) and lavapipe (Mesa 26.0.3), picked withVK_ICD_FILENAMES.agc_driver_prepared_shaders: passes 3/3 on each device. The unproven submits wait 1500 ms and the proven pair waits 0 ms.Submitalways callingAwaitRegistrationPreparation(), as onmain:a submission writing a whole program address waited for an unrelated preparation.!scan.completefallback:a submission writing half of a program address did not wait for the queued preparations.PrioritizeRegistrationPreparationinAwaitReferencedPreparations:the queued preparation of a bound program was not moved ahead of unrelated queued work. That is the gap I raised before, so it is covered now.agc_driver_prepared_shaders_dispatch_ahead_prewarmtimes out 3/3 on each device, at 30 s and at 60 s. On plainmainfe2b52c7eit passes 3/3 in under 1 s.DispatchAheadPrewarmsets the pending snapshot'sprepared->pending = truewith no queued task, then submits an ACB that writes its full0x20c/0x20dpair. The scan is complete, soSubmitwaits onsettledinAwaitReferencedPreparations, and nothing settles it. With the first control applied, the test passes 3/3 again.^agc_driver_(prepared|registered|registration|preparation), plusagc_driver_recorderandagc_driver_graphics. The other 34 pass on both devices.GPUs tested: NVIDIA GeForce RTX 3070 (595.99.02), lavapipe (Mesa 26.0.3, LLVM 21.1.8), Ubuntu 26.04
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-30T14:28:14Z.
Review: COMMENTED
Follow-up on the
dispatch_ahead_prewarmhang from my last review: fixed on08fe590f6.Linux, Ubuntu 26.04, i7-8700, GCC 15.2, Release. Head merged
--no-commitontomainf91137142e,ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1,ctest -j1.agc_driver_prepared_shadersandagc_driver_prepared_shaders_dispatch_ahead_prewarm: 3/3 on lavapipe (Mesa 26.0.3) and 3/3 on the RTX 3070 (595.99.02).dispatch_ahead_prewarmtakes 0.06 s on lavapipe and 0.6 s on the 3070. The unproven submits still wait 1500 ms and the proven pair 0 ms.08fe590f6'sShaderRegistry.cpphunk reverted,dispatch_ahead_prewarmtimes out at 30 s, 3/3 on lavapipe.agc_driver_prepared_shadersstill passes, as before.^agc_driver_(prepared|registered|registration|preparation)plusagc_driver_recorderandagc_driver_graphics(38 tests) pass on lavapipe.The branch conflicts with
mainagain since #12147 (merged today), inShaderRegistry.cpp's worker loop:mainaddedconst bool budgeted = task.budgeted;where this PR addsconst auto* const prepared = task.prepared;. I kept both lines for these runs. Nothing else conflicted.GPUs tested: NVIDIA GeForce RTX 3070 (595.99.02), lavapipe (Mesa 26.0.3, LLVM 21.1.8), Ubuntu 26.04
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T08:45:06Z.
Review: APPROVED
Reviewed — approved
The merged tree builds, and all 24
agc_driver_prepared_shaders*tests pass with the Khronos validation layer. Three targeted negative controls each fail with the expected message, and the one new VUID in the script's comparison also appears withmain's production files.What I ran
Head
36fc8f9cc93098b621694564d4432fc9a3973c75,main4f41f4c375f5abb487dbd184fbc150f31994d762, merged tree2e2c8ac56814ee32fb9eab40be05cf8b4c32771d, in a clean worktree. Debian 13 VM, 2× Xeon Gold 6136 (32 vCPU), GCC 14.2.0, Release, lavapipe (Mesa 26.1.6, LLVM 19).Results
git diff --checkcheck_conventions.pylibs(script)mainagc_driver_prepared_shaders*(23) +agc_driver_native_depth_uniform_planes, with validationagc_driver_prepared_shaders9.3 s (longest of the four*_shadersvariants: 10.1 s), all under 30 sUnprovenProgramsAtSubmiton this machineINDIRECT_BUFFER1500 ms, proven pair 0 msagc_driver_native_depth_uniform_planesVUID-vkCmdDispatch-groupCountX-00386errors appear withmain's production files (the baseline run was on an oldermain,d1ae628bc2, where this test did not run)VUID check with main's production files
Negative control
When
main's four production files are restored, the test does not compile ('ReferencedPrograms' is not a member of 'AgcDriver::DriverDetail'), as jotitadev already reported. So I changed single lines in the mergedSubmission.cppinstead, rebuilding and running the test after each change:0x048uremoved fromprogramRegisters(the classic-VS fix taken from JJenkx)a pixel and classic vertex program pair did not both reach the submit preparation waitSubmitalways waits for every queued preparation (main's behaviour)a submission writing a whole program address waited for an unrelated preparation!scan.completefallback removeda submission writing half of a program address did not wait for the queued preparationsAfterwards I restored the merged file and rebuilt. The test passes again, and
git status --porcelainis empty. This confirms on Linux and lavapipe the controls jotitadev ran and the classic-VS regression JJenkx reported.Findings
Blocking
None.
Non-blocking
perfPR to attach its traces. The description has both summary lines and a digest table, but says the traces "are kept locally and can be shared on request". JJenkx's archive has amain/change trace pair, but it is for Severed Steel. Suggested fix: attach the twoaps5-trace-*.json.gzfiles that the summary lines name.4703b22bde. Since then the branch gained the pool-ownership wait (761ef1105e) and the0x048vertex pair. The0x048fix makes submit wait for more programs. So the "3.2 s longest, 7 s total" figure indocs/dev/debt/libSceAgcDriver.md:333may be too low for the current code. Suggested fix: re-measure, or say in the debt entry which revision the figure is from.Unblocks: PPSAxxxxx #N), which CONTRIBUTING asks for.What I checked in the code without finding a problem:
AwaitReferencedPreparations(core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp:1919) uses the sameupper_boundand code-range lookup asRegisteredProgram.AwaitOwned(ShaderRegistry.cpp:1658) waits on the pool'sunfinishedsequences under the pool mutex.ownedis cleaned up both when a worker finishes a task and when queued tasks are dropped. Thependingcheck takesprepared.mutexand releases it before the pool lock, so the two locks are never held together.ReferencedPrograms(core/libs/prx/libSceAgcDriver/Execution/src/Driver/Queues/Submission.cpp:229) builds the address the same way asBoundGraphicsPrograms, and its register list now matchesBoundGraphicsProgramsplus0x20c.Not verified