fix(agc): yield the queue-idle storage write-back to new work #13621
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/13621"
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 beardsciences on 2026-10-30T19:53:15Z.
What
Queue 0's idle store (
VulkanDevice::StoreIdleResults, from #3777, with the 50 ms quiet period of #4410) wrote every pending storage image back to guest memory in one pass. Once a pass started it could not stop, and a title's next flip waited behind it inDriver::holdFlipBehindWorker.In MediEvil: Resurrection (PPSA07550), Sony's PSP emulator plays the intro movies at about 25 fps, so the gap between two frames is 40–65 ms and now and then passes 50 ms. Each time, the idle store wrote back about 15 upscaled 3840x2176 render targets (
0x1fe0000bytes each, about 0.5 GB), took about 0.6 s, and the movie froze for that long, 17–21 times a minute (runs below). Found with all-thread stack dumps during the freezes (the emulator thread insceAgcDriverSubmitDcb→holdFlipBehindWorker, queue 0 inStorageTexture::FlushAllPending("idle")→writeBackLayers) andAPS5_TRACE_FLUSH.The change:
StorageTexture::FlushAllPendingUntil(reason, stop)stores the pending images 4 MiB at a time throughFlushPending, so an image tracked in 64 KiB block units is stored in pieces with the units it already has; it callsstopbefore each piece and returns whether everything was stored.StoreIdleResultstakes thatstop; queue 0 passes "queue 0 has queued work, or another queue is running". What is left stays pending and is stored at the next idle period, as any pending image already is.The quiet period stays at 50 ms. A title that polls guest memory for an image result without a flush, wait or later submission (#3272, the case #3777 was added for) still gets every result as before: nothing submits, so nothing stops the store. What changes is the idle store of a title that keeps submitting: it no longer delays that title's next frame by more than one 4 MiB piece. A title whose frame gaps pass 50 ms can still start a store between two frames, and the next frame then waits for the piece in progress (the 85–97 ms frames in the runs below); recorded in
docs/dev/debt/libSceAgcDriver.md.New test
agc_driver_idle_store_yields: two pending images, a store asked to stop after the first check stores exactly one and leaves the other pending; one 8 MiB image with results at row 0 and row 1000, a store asked to stop after one piece leaves the second piece's results pending; the following stores bring both results to guest memory. Negative controls: with the stop check removed it fails ("a store asked to stop after one image reported that every image was stored"), 2/2; with the whole image as one piece it fails ("a store asked to stop after one piece reported that the large image was stored"), 2/2.Overlap: #10940 adds a
VkDeviceargument toFlushPendingandFlushAllPendingand passesstate->deviceinStoreIdleResults; whichever merges second passes it throughFlushAllPendingUntilas well. #10750 addsAPS5_NO_IDLE_STOREon the neighbouring lines of the queue worker. #9673 adds its own entry todocs/dev/debt/libSceAgcDriver.mdat the line this one is added before; whichever merges second keeps both entries.tools/pr_overlap.py --branchconfirms only #9673 and #10940; the 86 open pull requests it could not compare (they conflict withmain) were compared by hand against their merge base: none of them changesStoreIdleResults,FlushAllPending, the quiet period or the idle-store condition except #10750 and #10940 above, and the rest change other lines of the same files. Neither #10750 nor #10940 changes when an idle store starts or whether it can stop.The same 25 s of the movie from presented-frame dumps (
APS5_DUMP_FRAMES, played back at the times they were presented),mainon the left, this PR on the right:https://github.com/user-attachments/assets/b27cb20f-4631-4fb1-93d6-fae2d4386216
Tested
Windows 11 (10.0.26200), RTX 3060 Ti, NVIDIA 621.01, Ryzen 5 5600X;
maind3118d1946and this PR859777b551built with WinLibs GCC 15.2.0.MediEvil: Resurrection (PPSA07550, 01.000.003), the intro movie, 60 s from 40 s after the first present (
APS5_TRACE_SECONDS=40:60and no other trace or profile switch), warm caches, fixed pad input, log not redirected, alternating runs in one session:maind3118d1946, run 1859777b551, run 1maind3118d1946, run 2859777b551, run 2Summary lines (
mainrun 1, PR run 1,mainrun 2, PR run 2):Traces and
tools/trace_digest.pyoutput attached. The 85–97 ms frames of this PR are where an idle store started between two movie frames and the next frame waited for the 4 MiB piece in progress.ctest -R "idle|storage|store|write_?back|flush|queue_zero" -VwithVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ANYPS5_NO_SHADER_CACHE=1,ANYPS5_REQUIRE_VULKAN=1:maind3118d1946108/108, this PR859777b551109/109 (the new test is the extra one); neither log reportswas not found but was requested by env var VK_INSTANCE_LAYERS, both show the same 24WARNING-VkImageSubresourceRange-layerCount-compatibilitylines from the layer, and neither has aVUID-error. Each log starts with its commit, its tree, an emptygit status --porcelainand the number of compile/link stepsninja -C buildran just before the tests (0). Logs attached.agc_driver_idle_store_yields3/3 on859777b551, and the two negative controls above (2/2 each on that commit).@JJenkx ran
agc_driver_idle_store_yieldson 46e30b5465 (the test and the store are unchanged since) on a Radeon RX 6700 XT, AMD 26.10.1, Windows 11, with the validation layer: 3/3, no VUIDs (comment below).@blawesom built
agc_driver_idle_store_yieldsfrom 46e30b5465 on Linux, AMD Radeon RX 9070 XT, RADV (Mesa 26.2.4), with the validation layer: 5/5, no VUIDs;main's idle-store tests 3/3 there with no VUIDs (comment below).digest-pr-1.txt
digest-pr-2.txt
validation-main-d3118d1946.txt
validation-pr-859777b551.txt
aps5-trace-859777b5518e-12096.json.gz
aps5-trace-859777b5518e-24464.json.gz
aps5-trace-d3118d194631-41172.json.gz
aps5-trace-d3118d194631-47300.json.gz
digest-main-1.txt
digest-main-2.txt
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 MarcZX10 on 2026-10-30T20:08:27Z.
Review: COMMENTED
Tests run and reviewed — exact-head validation evidence needed
The source review found no blocker, and the attached paired validation logs show no VUIDs, but I cannot resolve the PR-side test revision named in the log and the hosted Windows job is still pending.
What I ran
Reviewed head
46e30b5465330f5368bb2439c73a0b73ccda5e65against PR base9310f48f1599d0b0a73ccdba39ed8bacee861bb7; the merge preview against currentmainbadd7cd5b8d3f06118d7aced81e8875cc71da407was clean. Environment: Linux x86-64, Python 3.11.2, Git 2.39.5. I did not build or run CTest.Results
VUID-entries and zero missing-layer markers; the PR log showsagc_driver_idle_store_yieldspassed.40a59e337e, which GitHub cannot resolve, so I cannot establish that this run tested the exact submitted head or compare its source tree.Relevant unedited output
Findings
Blocking
None identified in the source reviewed.
Non-blocking
The required AGC validation results are useful and appear clean, but their PR-side run cannot currently be tied to a retrievable source revision. Approval is withheld until that provenance and the pending Windows result are clear.
Sources
Not verified
I did not reproduce the GPU runs, compile, or run CTest locally. I could not confirm what source tree the PR-side validation log used, and hosted Windows remains pending.
To get this to a good state
Please provide the full resolvable SHA or source-tree identity for
40a59e337eand show how it relates to the reviewed head, or rerun the paired focused validation tests on the exact current source. Once Windows completes and the test provenance is clear, I’ll re-check the same evidence on the current head.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-31T00:53:19Z.
Review: APPROVED
Re-checked — new head, looks good
At head
859777b5518ebdebc29ddd20b38fca0792884894on basee49d43d6256b7c2283539d86b42325a36653275a, the update restores the 50 ms quiet period and removes the title ID from the debt entry; the stop-aware flush processes 4 MiB pieces and leaves the remaining range pending (implementation).I ran
git diff --check, the repository conventions check, and the PR stack/merge preview against the stated base; each passed, and the preview was clean. The test-quality heuristic's unregistered-test warning is a false positive: CMake discoverstests/execution/*.cppthrough aCONFIGURE_DEPENDSglob. I did not build or run C++ tests locally. The PR description reports exact-head CTest results, negative controls, and matched performance captures; these are author-provided evidence, not runs I reproduced. Hosted Windows CI is still in progress; Linux and specialized product jobs were skipped.