perf(agc): submit the recorder's closed batches from a queue submitter thread under APS5_ASYNC_SUBMIT #22190
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/22190"
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 Nesyth on 2026-11-17T08:16:59Z.
What
The draw recorder calls
vkQueueSubmiton the thread that closes a batch. On the drivers measured so far most ofRecorder.Submitis that host call, and the thread that pays for it is the one that records the next draws.With
APS5_ASYNC_SUBMIT(a runtime switch, off by default, soAPS5_ABcan toggle it within one run):Recorder::Submithands each closed batch to a queue submitter thread, one perVkQueue, which callsvkQueueSubmitin order under its own queue lock. The recording thread no longer waits inside the call.QueueAccess): the other submits, the sparse binds on the graphics queue, presentation,vkQueueWaitIdleandvkDeviceWaitIdle. The order the GPU sees is the order of the switched-off path.This is the first part of #18173, split out as agreed there; batch encoding on the encoder pool follows on top of #17943's command stream.
Tests: the new
agc_queue_submitter(submission order, drain on retirement,QueueAccessexclusion, a queue handle reused by another device, a failed submit reaching its own job, refusal after retirement), and async-submit variants ofagc_driver_recorderandagc_submit_progress.Tested
Windows 11 Pro 26300, Radeon RX 7900 XTX (AMD Software 26.10.1), Ryzen 7 7800X3D, Release, MinGW-w64 GCC 15.2. This head is the branch with
main14deacc1f3merged (9b1368ca47).PPSA04264 (v01.011.001), Performance graphics mode, a story save in the city (about 3,000 draws and 95 compute dispatches per frame), the player standing still, warm caches. Every run below sets
APS5_DRAW_PIPELINE=1APS5_PIPELINED_DRAWS=32APS5_PIPELINE_DISPATCH=1in both arms.In-run A/B (
APS5_AB=30:APS5_ASYNC_SUBMIT, phases of 30.0 s from 190.0 s after the first present, 8 pairs, each B phase against its neighbouring A phases):APS5_ASYNC_SUBMIT)The first A phase of this run still ran while the scene settled (56.6 presents per 10 s against about 140 later), which inflates the mean and its error; without the first pair the seven remaining pairs give +1.09 ± 1.25 presents per 10 s (+0.8%), six of them ahead. An earlier in-run A/B on
main2e48261498(the branch before this merge,b6595b4157, 7 pairs) gave +3.73 ± 0.24 presents per 10 s (+2.5%), every B phase ahead of its neighbours.Captures, this PR and
mainin the same session (this PR at 09:39,mainat 10:16), the log not redirected,APS5_TRACE_SECONDS=240:60, both withAPS5_ASYNC_SUBMIT=1.maindoes not readAPS5_ASYNC_SUBMIT; it is set in both arms only so that both summary lines carry the same environment:main14deacc1f39b1368ca47)+3.3% FPS between the two captures; the in-run A/B above is the measurement of the switch alone. The gain on this title is small: here the queue-0 worker and the committer bound the frame, and the committer's share of
vkQueueSubmitis a few percent of it. Testers on #18173 measured large gains on titles that submit often.On this machine
mainshows the picture upside down (#20835); both arms carry it.Traces, both captured on the same machine in one session: main 14deacc1f3, this PR. The summary lines and
tools/trace_digest.pyoutput are below.tools/check_conventions.pypasses.trace_digest: main
14deacc1f3seconds 240:60 from present 4336: 824 presents, frame p50 72.2 / p90 76.3 / p99 86.3 / max 111.5 ms, GPU busy 25.3 ms per present
AMD Radeon RX 7900 XTX, AMD proprietary driver 26.10.1 (LLPC), Windows 10.0.26300, 3840x2160, commit
14deacc1f3, dropped: noSlowest frames (largest slices inside each, inclusive)
Persistent spikes (frame time above the fastest frame that separates it from a longer frame; one entry per stall, not per frame)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 29.8, Graphics.Draw 25.9, batch 25.3, Graphics.Draw.draw_and_resource_release 22.6, Driver.Packet.draw 17.0, Driver.Draw 16.8, Driver.DrawFinish 16.4, Driver.Draw.prepare 11.2, Driver.DrawFinish.draw_enqueued 9.5, Driver.Packet.dispatch 8.8
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
trace_digest: this PR
9b1368ca47seconds 240:60 from present 4456: 843 presents, frame p50 69.7 / p90 73.5 / p99 88.3 / max 642.3 ms, GPU busy 25.3 ms per present
AMD Radeon RX 7900 XTX, AMD proprietary driver 26.10.1 (LLPC), Windows 10.0.26300, 3840x2160, commit
9b1368ca47, dropped: noSlowest frames (largest slices inside each, inclusive)
Persistent spikes (frame time above the fastest frame that separates it from a longer frame; one entry per stall, not per frame)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 27.4, Graphics.Draw 26.7, batch 25.3, Graphics.Draw.draw_and_resource_release 23.5, Driver.DrawFinish 16.0, Driver.Packet.draw 15.7, Driver.Draw 15.5, Driver.Draw.prepare 10.4, Driver.DrawFinish.draw_enqueued 9.5, Driver.Packet.dispatch 8.3
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
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)Summary by CodeRabbit
New Features
APS5_ASYNC_SUBMITenvironment variable.Tests
Documentation
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-19T02:09:23Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this; the points below are optional.
What I ran
Reviewed head
9b1368ca47d1a90f5aaafd04b7d1b7bac63ec13ausing the prepared patch andrepo_read.pyat the pinned head. No commands or tests were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The description reports builds and tests, but these were not run as part of this review. Full text was read for the included changed files. Excluded as too large for the review folder and not read:
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp,core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp. The patch hunks for these files were reviewed. Other changed files listed in the manifest were not individually read in full; hardware behavior and performance measurements were not independently verified.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-19T09:16:17Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: prevent queue submission after the worker records a failed submit, and make device retirement safe against concurrent registration and use.
What I ran
Reviewed head
9e22c0007f16f687d7bb630a97b243b41bed0db3using the prepared diff and pinnedrepo_read.pyreader. I ran no builds or tests; reported test and performance results below are author supplied.Results
Findings
Blocking
core/libs/prx/libSceAgcDriver/Graphics/src/QueueSubmitter.cpp:201: after the first failedvkQueueSubmit, the worker saves the failure instoppedWith, but its loop continues dequeuing and processing queued jobs. Each is then marked failed without being submitted, yet the thread still callsvkQueueSubmitfor nothing more andreturnedadvances. MeanwhileEnqueueonly rejects jobs oncestoppingis set (:136-139), and a full queue can admit more jobs during this failure state. This violates the stated stop-after-failure behavior and can make the recorder treat later, unsubmitted batches as returned and proceed to wait on their fences. Stop accepting queued work and ensure each affected batch is failed and retired without an unsignaled-fence wait.core/libs/prx/libSceAgcDriver/Graphics/src/QueueSubmitter.cpp:66: retirement snapshots matching submitters, releases the registry mutex, then stops and removes them. ConcurrentForcan replace a stale entry during that gap; retirement then skips removal because the entry no longer points to its snapshot (:78-81), leaving a worker registered for the device being destroyed. ConcurrentExistingcan also obtain a raw pointer just before retirement removes it, then use it after its lifetime ends. Serialize registration, lookup/use, and retirement so no worker can be created or accessed during teardown.Non-blocking
None.
Not verified
VulkanDevice.cpp,GuestBufferMemory.cpp, and the changed portions ofRecorder.cpp. Excluded by bundle rule and not read in full:Texture.cpp,tests/Recorder.cpp; other unneeded portions of large files were not inspected.To get this to a good state
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T05:04:15Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this change based on the code reviewed; the async submitter preserves per-queue submit ordering and waits for queued submissions before accessing the queue.
What I ran
Reviewed head
ff6cdf3ff677d1bd2bda1a2d8d72f5b99a81bccausingrepo_read.py. No tests or builds were run.Results
Findings
Blocking
None identified in the inspected code.
Non-blocking
None.
Not verified
The full text of these changed files was excluded for size and only relevant hunks were read:
Execution/src/VulkanDevice.cpp,Graphics/src/GuestBufferMemory.cpp,Graphics/src/Texture.cpp, andtests/Recorder.cpp. Other changed files were not individually inspected. Tests, builds, and the performance measurements described by the author were not independently run or verified.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-30T04:32:09Z.
Review: COMMENTED
Actionable comments posted: 7
Architecture findings (2)
Advisory architecture findings (2)
6c7895bd-f277-48c3-b2b0-168bced3b73aReviewing files that changed from the base of the PR and between
65fe203291anda492c50aff.core/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/include/QueueSubmitter.hppcore/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hppcore/libs/prx/libSceAgcDriver/Graphics/include/RuntimeSwitches.hppcore/libs/prx/libSceAgcDriver/Graphics/src/DeferredDestruction.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/QueueSubmitter.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ResidentMirror.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Resources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/RuntimeSwitches.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/QueueSubmitter.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_recorder_tests.cmakecore/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_submit_progress_tests.cmakecore/libs/prx/libSceAgcDriver/tests/cmake/agc_queue_submitter_tests.cmakedocs/dev/ENVIRONMENT.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-30T04:37:09Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: preserve valid submitter access for batches while the queue handle is replaced or retired.
What I ran
Reviewed head
a492c50aff4298981975d73cf530fe77ff6b0fb2using the prepared diff andrepo_read.py; no build or tests were run. The author reports builds, tests, and convention checks in the PR description.Results
Findings
Blocking
QueueSubmitter::Forreplaces the registry entry for a queue handle, then stops the stale submitter, but leaves that old object allocated and unregistered. Batches retain raw pointers to submitters and later dereference them ingpuDoneandfinish;ExistingandRetireDeviceonly discover the currently registered object. If a queue handle is reused while the old device still has in-flight batches, those batches can keep polling a stopped submitter, and later teardown cannot retire it through the registry. This can leave stale state and make batches unsafe to manage. Keep the old submitter registered until its batches are finished, or otherwise retain and retire it with its device. Evidence:QueueSubmitter.cpp:48andRecorder.cpp:4453.Non-blocking
None.
Not verified
No tests were run by this review. The author-reported Windows build, test results, and performance captures were not independently verified. Full text was read for all changed files included in the review folder. The changed files not included there were read through
repo_read.pyat their changed-line ranges:VulkanDevice.cpp,GuestBufferMemory.cpp,Texture.cpp, andtests/Recorder.cpp. The prepared diff and manifest were reviewed; no repository paths were excluded from review.To get this to a good state
Keep each submitter reachable until no batch can hold its pointer, then retire it safely with its device. Re-run the queue submitter lifecycle tests and recorder async-submit tests on the updated head.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-30T06:09:02Z.
Review: COMMENTED
Architecture findings (3)
Advisory architecture findings (3)
c305d0b5-3f7a-4b69-b53c-cd6e594e87c5Reviewing files that changed from the base of the PR and between
a492c50affand6144ec57f2.core/libs/prx/libSceAgcDriver/tests/Recorder.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-30T06:42:14Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Queue access can overtake a batch enqueued after its drain completes but before it acquires the queue lock, violating the stated submission order.
What I ran
Reviewed head
6144ec57f2dd96d35b8fcd7ffc2f7bb40122aebdfrom the prepared diff and targeted source reads throughrepo_read.py. No tests were run.Results
Findings
Blocking
QueueAccessdrains the submitter and only then locks its queue mutex. A concurrentEnqueuecan add a job afterDrain()returns; ifQueueAccessacquires the mutex before the worker, the external queue operation runs before that already-enqueued submit. This can reorder submits relative to waits, presentation, or other queue operations. Coordinate enqueue admission with queue access so no queued job can be overtaken.core/libs/prx/libSceAgcDriver/Graphics/src/QueueSubmitter.cpp:533Non-blocking
None.
Not verified
No tests or builds were run. Full text was not read for
VulkanDevice.cpp,GuestBufferMemory.cpp,Texture.cpp, ortests/Recorder.cpp; targeted changed hunks were reviewed fromdiff.patch. Other changed files were available in the review folder, but not all were read in full.To get this to a good state
Fix the queue admission race, then rerun the queue submitter and async submit tests.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-01T06:42:14Z.
Review: COMMENTED
Reviewed — no blocking findings
One non-blocking lifetime leak was found at head
6deca791d1f3fdd9883a3ef2a27e6c0c494d259d; no blocking defect was verified.What I ran
Inspected the prepared diff and changed-file manifest, then read relevant pinned-head source and test ranges with
repo_read.py. No tests or builds were run.Results
Negative control
Not run; no test was executed or source changed during this review.
Findings
Blocking
None.
Non-blocking
QueueSubmitter::RetireDeviceerases each retired pointer from the registry but does not delete it. SinceForreleases ownership of each submitter and no later owner remains, device retirement leaks the submitter object and its synchronization state. Repeated device recreation with async submission enabled accumulates these objects. Seecore/libs/prx/libSceAgcDriver/Graphics/src/QueueSubmitter.cpp:83.Sources
Not verified
Changed hunks were reviewed for all 18 changed files. Full file text was available for 14; full text was excluded for
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp,core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp,core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp, andcore/libs/prx/libSceAgcDriver/tests/Recorder.cpp. Hardware behavior, test results reported in the PR description, and CI were not independently verified.To get this to a good state
Nothing is required. The optional submitter cleanup is described under Non-blocking.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-12-01T06:46:18Z.
Review: COMMENTED
🏛️ Architecture findings (2)
Advisory architecture findings (2)
💬 Code review
e8acab68-fc1d-4fcc-b254-68331c6dfe15Reviewing files that changed from the base of the PR and between
6144ec57f2and6deca791d1.core/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Resources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T17:44:46Z.
Review: COMMENTED
Two concurrent
RetireDevicecalls can collect the same submitter. Both callstop()outside the registry lock, andstop()releases its mutex before checking and joiningthread. The two callers can therefore race on the same thread object. The retirement count tracks both calls but does not choose a single join owner. Can retirement give one caller ownership of the join and make any other caller wait for it to finish?This finding is from source inspection at
6deca791d1.AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-12-04T10:09:01Z.
Review: COMMENTED
Actionable comments
95c105f2-9d87-4456-ad70-8c2fbe3a39f7Reviewing files that changed from the base of the PR and between
6deca791d1andf976f38e24.core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-04T10:17:37Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: make
Reapretire and report a batch whose queued submit returned an error, even when its fence or timeline never signals.What I ran
Reviewed head
f976f38e24897c019c8570b96bd43a7a86e20c70using the prepared diff andrepo_read.pyon a Linux host; no compiler or test tool was run.Results
Negative control
Not run; no tests were executed.
Findings
Blocking
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp:5609—Reapnow waits for the queued submit to return, but still only finishes a batch after its fence or timeline reports GPU completion. On a failedvkQueueSubmit, the submitter records the error and returns the job without signaling its fence or timeline. The batch therefore stays at the front ofinFlight;finish, which reports the submit error and releases the batch, is never reached through normal reaping. Make a returned failed submission eligible forfinishregardless of fence or timeline status. Pinned sourceNon-blocking
None.
Sources
Not verified
No build, tests, or runtime behavior were verified. Targeted source ranges were read in
QueueSubmitter.cpp,Recorder.cpp,VulkanDevice.cpp,GuestBufferMemory.cpp, andTexture.cpp(5 of 19 changed files); the diff and metadata were inspected for the changed paths. Full text forVulkanDevice.cpp,GuestBufferMemory.cpp,Texture.cpp, andtests/Recorder.cppwas not bundled.files.jsonlists no rule-excluded files.To get this to a good state
Update
Reapto route failed returned submissions throughfinish, then run the async-submit failure and recorder reaping tests on the new head.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.