Repository navigation
perf(agc): write CPU-path frame dumps through the frame dump writer - #10513
Conversation
|
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
MarcZX10
left a comment
There was a problem hiding this comment.
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.
|
@MarcZX10 thanks for the review. I have now run the new Linux FIFO test on both sides, 3 runs per test per side:
Environment: Ubuntu 24.04.3 on WSL2 (kernel 5.15.167.4), g++ 13.3.0, Release build, Mesa 25.2.8 lavapipe ( Local build edits:
Not tested: CI's |
With APS5_DUMP_FRAMES, PresentDisplayBuffer reads most dumped frames back on the GPU and hands them to the frame dump writer thread. The frames it takes from the CPU were written with WriteFrameBmp on the presenter instead: every dumped frame with APS5_NO_GPU_DUMP=1, and on an HDR10 swapchain the linear display buffers and the tiled ones not shown from a resident image. The write ran inside Driver::Present with the GPU mutex held, and VideoOut completes the flip only after Present returns, so a slow disk stopped the title and the queue workers. A trace on main 4997726 (PPSA14363 at 1920x1080, APS5_NO_GPU_DUMP=1, APS5_DUMP_FRAMES_EVERY=60, during a parallel build and another game) has its five longest presents, 16.0 s, 8.2 s, 3.2 s, 1.0 s and 0.84 s, spent in Driver.Present.present_display_buffer while the queue worker waited for the GPU mutex. The traced display buffer decode inside them takes 11 to 17 ms; the rest is the write of one 518 KB BMP. These frames are now reduced by the dump scale on the presenter, as WriteFrameBmp did, and queued to the writer, which writes them in order on its own thread. Every queued frame is now already reduced, so WriteFrameBmp writes it as it is and the writer no longer carries a scale. What stays the same: - the index is taken before present(), so file names and numbering are unchanged and a dropped presentation keeps its CPU dump; - the queue holds reduced frames, as for GPU readbacks since boykopovar#4320, and the presenter waits only once 64 MiB are queued (boykopovar#8807); - the writer skips frames once the output is disabled and writes the queued ones when the device is torn down, as for GPU dumps. What differs from GPU readbacks: those are usually queued after the GPU mutex is released, while a CPU dump is always queued inside Present, so a wait for the 64 MiB limit still holds the GPU mutex. At the default APS5_DUMP_SCALE=4 that wait starts once 129 frames of 1920x1080 are queued; at APS5_DUMP_SCALE=1 and 3840x2160, from the third. CPU dumps still queued are lost when the process ends without tearing the device down, as GPU dumps already are; before, each was on disk when Present returned. takeScreenshot takes a requested screenshot 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; it moves to a later present only while earlier frames are still being written, as with GPU dumps. video_out_frame_dump_cpu_queue runs the frame dump queue test with APS5_NO_GPU_DUMP=1: frame_000.bmp is a FIFO nobody reads until all four presents have completed. Co-Authored-By: Claude <noreply@anthropic.com>
6289faa to
52f6777
Compare
|
@MarcZX10 I rebased this onto
The Tested section of the description has the details. |
|
Re-checked against current main ( |
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 (fix(agc-driver): make the presenter wait for a full frame dump queue #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:{"commit":"379b1dca32ec","dirty":false,"env":{"APS5_DUMP_FRAMES":"3000","APS5_DUMP_FRAMES_EVERY":"60","APS5_NO_GPU_DUMP":"1","APS5_TRACE_SECONDS":"15:90"},"gpu":"AMD Radeon RX 6700 XT","driver":"AMD proprietary driver 26.10.1 (AMD proprietary shader compiler)","os":"Windows 10.0.26200","cpu":"AMD Ryzen 5 5600X 6-Core Processor","cpu_threads":12,"memory_mib":32690,"title_id":"PPSA14363","title":"METAL GEAR SOLID - Master Collection Version","content_version":"03.000.000","resolution":"1920x1080","window":{"spec":"seconds 15:90","first_present":437,"ms":91748.440},"presents":2983,"frame_ms":{"p50":16.684,"p90":17.085,"p99":21.269,"max":13769.879},"gpu_busy_ms_per_present":1.366,"worker_busy_pct":{"queue worker 0x0":1.909},"top_phases_ms_per_frame":{"VideoOut.Flip":18.582,"VideoOut.Flip.present":16.112,"Driver.Present":16.108,"Driver.Present.present_display_buffer":14.393,"GpuMutex.wait.flush":13.819,"VideoOut.Flip.vblank_wait":2.255,"Driver.Present.acquire_image":1.266,"Vulkan.Acquire":1.264},"trace_dropped":false,"trace":"aps5-trace-379b1dca32ec-23128.json.gz"}{"commit":"8e73ff3adac1","dirty":false,"env":{"APS5_DUMP_FRAMES":"3000","APS5_DUMP_FRAMES_EVERY":"60","APS5_NO_GPU_DUMP":"1","APS5_TRACE_SECONDS":"15:90"},"gpu":"AMD Radeon RX 6700 XT","driver":"AMD proprietary driver 26.10.1 (AMD proprietary shader compiler)","os":"Windows 10.0.26200","cpu":"AMD Ryzen 5 5600X 6-Core Processor","cpu_threads":12,"memory_mib":32690,"title_id":"PPSA14363","title":"METAL GEAR SOLID - Master Collection Version","content_version":"03.000.000","resolution":"1920x1080","window":{"spec":"seconds 15:90","first_present":825,"ms":90005.641},"presents":5385,"frame_ms":{"p50":16.682,"p90":16.964,"p99":19.411,"max":92.534},"gpu_busy_ms_per_present":2.579,"worker_busy_pct":{"queue worker 0x0":4.713},"top_phases_ms_per_frame":{"VideoOut.Flip":12.453,"VideoOut.Flip.vblank_wait":9.368,"VideoOut.Flip.present":2.817,"Driver.Present":2.812,"Driver.Present.acquire_image":1.627,"Vulkan.Acquire":1.625,"Vulkan.Acquire.acquire_fence_wait":1.484,"Driver.Packet":0.780},"trace_dropped":false,"trace":"aps5-trace-8e73ff3adac1-24228.json.gz"}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