perf(agc): write CPU-path frame dumps through the frame dump writer #10513
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10513"
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 thuanquang on 2026-10-24T06:47:09Z.
What
With
APS5_DUMP_FRAMES,VulkanDevice::PresentDisplayBuffer(Execution/src/VulkanDevice.cpp) reads most dumped frames back on the GPU and hands them to the frame dump writer thread (FrameDumpWriter). The frames it takes from the CPU were written withWriteFrameBmpon the presenter instead: every dumped frame withAPS5_NO_GPU_DUMP=1, and on an HDR10 swapchain the linear display buffers and the tiled ones not shown from a resident image. That write ran insideDriver::Presentwith the GPU mutex held.These frames are now reduced by the dump scale on the presenter, as
WriteFrameBmpdid, and queued withFrameDumpWriter::Enqueue, which writes them in order on the writer thread. Every queued frame is now already reduced, soWriteFrameBmpwrites it as it is, and the writer's per-frame scale (always 1 for GPU readbacks) is gone.What stays the same:
present(): file names and numbering are unchanged, and a dropped presentation keeps its CPU dump, as before.APS5_DUMP_SCALE=4is 518 KB), and the presenter waits only once 64 MiB are queued (#8807).What differs from GPU readbacks:
RetirePresentsruns beforeDriver::Presenttakes it; only its fallbacks inpresent()andensureHdrScaler, andWaitIdlewithAPS5_SYNC_FLIP, retire under it), while a CPU dump is always queued insidePresent. So when the 64 MiB limit is reached, the presenter still waits with the GPU mutex held. At the default scale that starts once 129 frames of 1920x1080 are queued; atAPS5_DUMP_SCALE=1and 3840x2160, from the third._Exit, an abort, a crash), as GPU dumps already are. Before, each one was on disk whenPresentreturned.Screenshots:
takeScreenshottakes a requested screenshot (#4891) only while the writer has nothing queued. A present's CPU dump is queued after that check, so the dump of the same frame does not hold the screenshot back. A screenshot moves to a later present only while earlier frames are still being written, which GPU dumps already do.Overlap: #9602 (also mine) merged first. It changed the GPU readback's log line directly above the
dumpWriter.Enqueuecall this change edits, so this head is rebased ontomain6f58a046b1, keeping #9602'sProfilePrint_nid_no_patchline; that line was the only conflict. #9673 also editsVulkanDevice.cpp(ResidentPresentable); a three-way merge of the file with its head3840ec60b1has no conflict.Why
VideoOut completes the flip only after
Driver::Presentreturns, so every CPU-path dump write was on the guest's frame time. The queue workers waited for the GPU mutex for as long as the write took. On a slow or busy disk, one write stopped the title for seconds.A trace on
main4997726a5f, PPSA14363 (METAL GEAR SOLID Master Collection Vol. 1, own dump) at 1920x1080 withAPS5_NO_GPU_DUMP=1andAPS5_DUMP_FRAMES_EVERY=60, while a parallel build (about 14 compile jobs on the same disk) and a League of Legends match were running, has its five longest presents at 16.0 s, 8.2 s, 3.2 s, 1.0 s and 0.84 s. All of each one is spent inDriver.Present.present_display_buffer, while the queue worker sits inGpuMutex.wait.flush. The traced display buffer decode inside each of those presents takes 11 to 17 ms. The untraced rest is the write of one 518 KB BMP. The three synchronous calls are unchanged on currentmain:VulkanDevice.cpp:3331,:3333and:3393at6f58a046b1.PPSA14363,
mainagainst this change under disk load.main379b1dca32and this change (8e73ff3ada, see Tested), each built from a clean commit in the same tree; the same prepared run folder with onlylibSceAgcDriver.prxswapped (hash-checked). Each run starts the launcher and runs 120 s without input, withAPS5_DUMP_FRAMES=3000,APS5_DUMP_FRAMES_EVERY=60andAPS5_NO_GPU_DUMP=1, and capturesAPS5_TRACE_SECONDS=15:90, no otherAPS5_TRACE_*orAPS5_PROFILE_*switch. A warm-up run came first. Disk load: two processes stream 4 GiB files and one makes 64 KB writes to a file, flushing each, on the same disk as the run folder, started 10 s before the run; in a 45 s calibration without the title, writing one 518 KB file took up to 42.4 s. Exclusive GPU, no build or test running; a League of Legends match was running during the warm-up, A1, B1 and B2, only its client during A2, and only the Riot Client service during the two unloaded runs.APS5_TRACE_SECONDS=15:90windowmainA1mainA2main, no loadOn
main, the loaded runs spend 36.2 ms (A1) and 14.4 ms (A2) per frame of the window inDriver.Present.present_display_bufferwhile the queue worker waits inGpuMutex.wait.flush(35.5 and 13.8 ms per frame); with the change neither phase appears in the top phases. Without disk load both sides present 5388-5393 frames. Onmainunder load the window opens at an earlier present (420-437 against 815-825), because the stalls began before 15 s; its measured length is 94.5 and 91.7 s.Summary lines of A2 and B2,
mainfirst:tools/performance_compare.pyon them: mean frame 30.757 to 16.714 ms, p99 21.269 to 19.411 ms, max 13769.879 to 92.534 ms. The traces are not attached, because these runs come from a commercial title.Tested
New test (Linux only):
video_out_frame_dump_queuealready holdsframe_000.bmpas a FIFO that nobody reads until all four 3840x2160 presents have completed. It runs only off Windows (mkfifo), on the GPU readback path.video_out_frame_dump_cpu_queueruns the same executable withAPS5_NO_GPU_DUMP=1andAPS5_DUMP_SCALE=4. Onmainthe first present blocks in the BMP write once the pipe is full, so the flip cannot complete within the test's 15 s wait, and the test fails with "the flip did not complete". With this change all four presents complete. Run on both sides on Linux (WSL2, lavapipe, X11 display driver), 3 runs each:maincd0591c8f4plus this test entry failed 3 of 3 withthe flip did not complete, this change at6289faa256passed 3 of 3 (details in this comment). With the defaultoffscreendriver, which the Linux CI job uses, the test skips on both sides.As a stand-in, a Linux (WSL2, g++ 13.3) probe compiled the text of
FrameDumpWriter,QueueFrameDumpandWriteFrameBmpfrom this change,main'sWriteFrameBmp, and the realFrameDumpIo.hpp, then heldframe_000.bmpas a FIFO the way the test does:main'sWriteFrameBmpof a 3840x2160 frame at scale 4 had not returned after 3 s, and it returned once the FIFO was read.QueueFrameDumpof the same frame returned after 1.9 to 2.0 ms (three runs) while the writer stayed blocked.Current head
52f67778cc: this change rebased ontomain6f58a046b1after #9602 merged. The only conflict was #9602's log line above thedumpWriter.Enqueuecall, kept asProfilePrint_nid_no_patch;git range-diffagainst6289faa256shows no other difference. On this head (RX 6700 XT, AMD driver 32.0.21045.16010, Windows 11 26200; the flip tests configured withANYPS5_VIDEO_OUT_TEST_DRIVER=windows, since the defaultoffscreendriver skips them):agc_frame_dump_io,agc_screenshot, the 16video_out_flip_*tests,video_out_hdr_probeandvideo_out_hdr_present) pass 3 of 3, none skipped.video_out_hdr_presentwithAPS5_NO_GPU_DUMP=1passes 3 of 3 and prints nodisplay read back on the GPUline, so its dumps take the CPU path through the writer.APS5_NO_GPU_DUMP=1run pass with 0VUID-lines;VK_LOADER_DEBUG=layershows the layer inserted in 16 of the 20 test processes and in theAPS5_NO_GPU_DUMP=1run, and no "was not found" line.Earlier, Windows, RX 6700 XT (
main379b1dca32and this change on it, each built from a clean commit in the same tree; the change was built and tested at8e73ff3ada. The previous head6289faa256was the same change minus one comment line inVulkanDevice.cpp, rebased ontomaincd0591c8f4, where the files it touches were unchanged):agc_frame_dump_io,agc_screenshot,video_out_hdr_present,video_out_hdr_probeand the 14video_out_flip_*tests.video_out_hdr_presentwithAPS5_NO_GPU_DUMP=1passes 3 of 3 on both sides. Here every dump takes the CPU path (nodisplay read back on the GPUline is printed), so on this change the dumps go through the writer. The test reads the BMPs back after shutdown and finds each of its three buffers (tiled, linear, DCC-cleared) with a largest difference of 0 from the CPU conversion.VUID-lines;VK_LOADER_DEBUG=layershows the layer inserted in 14 of the 18 related test processes and in theAPS5_NO_GPU_DUMP=1run, the same on both sides, and no "was not found" line.tools/check_conventions.py --base origin/mainpasses, and so does the check of this title and body.Not tested: Linux locally; the HDR10 passthrough branches (no HDR output here); other GPUs.
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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T11:14:16Z.
Review: APPROVED
Reviewed the CPU dump path: it reduces pixels before enqueueing, then uses the existing FIFO writer, preserving the previous sample positions, numbering, and dropped-present behavior. The tests and report cover BMP equivalence, HDR CPU paths, and a measured presentation trace; the large-frame queue wait with the GPU mutex held is called out explicitly. The newly added Linux FIFO test has not yet been run by the author; the WSL probe is a useful stand-in but does not replace that integration test. I have not run the GPU/display tests locally, and hosted product jobs are skipped, so the hardware and performance results remain the author-reported Windows RX 6700 XT results.