Repository navigation
perf(videoout): don't hold a flip thread's CPU flips behind queued work - #6507
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.
|
|
Cross-validation on Windows 11 Pro 26220, NVIDIA RTX 4070 (596.21), MinGW GCC 15.2, PR head
Two review points: (1) Written with Claude Code assistance (validation by a subagent, reviewed in this session). |
|
Rebase handoff — rebased onto current Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
To pick it up: Head is |
|
Re-anchored rebase handoff — Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
To pick it up: Head is |
sceVideoOutSubmitFlip went through queue 0 as a one-packet command buffer, so every CPU flip waited until the queue worker had translated all command buffers submitted before it. The PS5 RADV WSI flips from its own thread once the frame's fence has signaled. vkQuake keeps two frames in flight, so by then the next frame's command buffer is already queued, and the flip waited about 10 ms for the worker to translate it. Presents came in pairs, about 4.7 ms and 29 ms apart. Meanwhile the title waited in acquire for the flip to be shown, leaving the worker idle for about 7.5 ms per pair. A CPU flip from a thread that has never submitted queue-0 work now goes to the presenter at once, unless a command-buffer or EOP flip ahead of it has not been reached yet. Such a thread can only know that its frame is done by waiting for it. A flip from a thread that submits its own frames still waits for the work submitted ahead of it, because a title that flips without waiting for its frame relies on that order. APS5_CPU_FLIP_IN_ORDER=1 orders every CPU flip. vkQuake (PPSA99010) on an RTX 4060: 60 -> 72-74 presents per second, present-interval standard deviation 12.2 -> 2.1 ms, and intervals over 25 ms 40% -> 1%.
f0d9d01 to
db091f5
Compare
|
Rebased onto
These four traces are attached below too. A flip that skips the queue isn't a queue-0 submission, so it takes no serial and isn't kept in the PM4 ring; the description says so now. @screamm, thanks for the Windows run. On your two points:
The traces for the table are attached below. |
|
Traces for the vkQuake runs (PPSA99010, RTX 4060 Laptop, driver 591.86, The table in the description (ae47bd08d, this change on main fa9365c):
The rebased head db091f5 against main 51cee90 (my comment above):
Each file's summary line is in the description or in that comment, in the same order. |
With APS5_ENABLE_TIMING_LOG the driver queues every CPU flip behind queue-0 work (Submission.cpp, #6507), so the flip's frame timing collects the submissions ahead of it. testCpuFlipOrder only expected that order with APS5_CPU_FLIP_IN_ORDER, so video_out_flip_cpuflip failed in every timing log build.
What
A CPU flip (
sceVideoOutSubmitFlip) from a thread that has never submitted queue-0 work no longer waits for the command buffers queued ahead of it. In vkQuake this removes the paired presents (about 4.7 ms then 29 ms apart) that show as stutter, and frame rate rises from 60 to 72-74 presents per second.Title. vkQuake (PPSA99010): mihawk-99's PS5_vkQuake port, which renders through their RADV fork PS5_Mesa and its VideoOut WSI.
Background.
sceVideoOutSubmitFlipreaches the driver as a one-packet queue-0 command buffer (VideoOutDriver::SubmitFlip→sceAgcDriverSubmitDcb). The queue worker runs submissions in order, so a CPU flip waits until the worker has translated every command buffer submitted before it.wsi_common_videoout.cin mihawk-99/PS5_Mesa)queue_presentonly hands{buffer, fence}to a flip thread. That thread waits for the frame's fence, then callssceVideoOutSubmitFlip.vkAcquireNextImageKHRfor frame C needs flip A to be shown. Meanwhile the worker sits idle, about 7.5 ms per pair. On main the worker is busy 76% of the time.How.
VideoOutDriver::SubmitFlipcalls a new driver entry,AgcDriverSubmitFlip_nid_postfix, which builds the same flip packet and submits it as a CPU flip.Each thread records whether it has ever submitted queue-0 work (
Submiton queue 0, orSuspendPoint). The record usesHostThreadLocal, so it ends with the thread.A CPU flip skips the queue when all of the following hold:
flipsAhead == 0, after the usualholdFlipBehindWorker);APS5_SYNC_FLIPis off, and the build is notAPS5_ENABLE_TIMING_LOG.In that case it is reserved and handed to the presenter (
GpuReady) under the driver lock, so it cannot overtake a flip reserved before it. The graphics end-of-pipe event that every flip raises is then delivered at once, since the frame was already finished.Every other CPU flip is queued as before.
The presenter is unchanged.
present()still submits all recorded work before its blit, and the flip completes only after the blit's fence: @oneandonlydean's rule from fix(agc): complete a flip only once the frame's GPU work has finished #417 (d9632d5) holds for these flips too.The flip hold that @AymanFE's Fix/agc hold flip behind worker #1745 and @sridhar777911's fix(agc): hold flip behind worker #2666 added (
holdFlipBehindWorker,flipsAhead) is reused as is. A flip-thread flip still waits there for an unreached flip ahead of it.APS5_CPU_FLIP_IN_ORDER=1queues every CPU flip, as on main.frameSerialis now atomic, because the flip'sFrameTimingcan now be created off the worker thread.A flip that skips the queue is not a queue-0 submission. It takes no serial, so it is not kept in @fdfawef324's per-queue PM4 ring (13b171c), which records queue submissions.
Why only flip threads. A thread that submits its own frames may flip without waiting for them, and then it relies on the flip completing after the work submitted ahead of it:
video_out_flip_tests aftergpu(fix(agc): complete a flip only once the frame's GPU work has finished #417) checks that order;flipPendingNum, like Balatro in @gjonn's Balatro PPSA21402 on Windows: the title overwrites its own register lists when more than 2 flips are pending (VIDEO_OUT_FLIP_QUEUE_CAPACITY is 16) #1034, would otherwise run ahead of the worker.A thread that never submits GPU work can only know its frame is done by waiting for it, which is what the RADV WSI does. The debt note in
libSceVideoOut.mdrecords the inference: whether the console ever orders a CPU flip behind the graphics queue is not measured.Where it matters. Any title that flips from a dedicated thread after waiting for its frame: vkQuake and other ports on the PS5 RADV WSI. ps5-opengl (PPSA99005 and others) waits for GPU idle on its submitting thread before flipping, so it keeps the queued path. Command-buffer flips (
sceAgcDcbSetFlip) and @JJenkx's EOP flips (#5539) are unaffected.Tested
Windows 11, MinGW-w64 GCC 15.2.0, Release. The branch is now rebased onto main 51cee90 (db091f5). In
Submission.cpp,main's queue bound and submission-ring setup come first, then this change;Flip.cppkeeps both theps4andcpuflipmodes. The measurements below are from the first head, on main fa9365c. The runs used a build of ae47bd08d. It has the same code as this commit and differs only in the wording of the debt note.vkQuake (PPSA99010)
r_rtshadows 0,APS5_TRACE_SECONDS=15:10,APS5_SPIRV_OPT=noneandANYPS5_PRESENT_MODE=immediate(the summary line records onlyAPS5_variables).APS5_CPU_FLIP_IN_ORDER=1, this PR, main,APS5_CPU_FLIP_IN_ORDER=1, after a warm-up run of main.Driver.Presentslices in the traces. The vblank buckets are from vkQuake's ownPS5 present:lines (frames taking 1/2/3/4+ vblanks at 60 Hz).APS5_CPU_FLIP_IN_ORDER=1With the default present mode (FIFO), one run each: main 601 presents, p90 30.8 ms, interval sd 12.3 ms; this PR 722 presents, p90 15.9 ms, interval sd 1.9 ms. GPU busy per present is about 10 ms in every run. The frame is now bound by the queue worker.
Summary lines (main ab1, PR ab1, in-order ab1, PR ab2, main ab2, in-order ab2, main fifo, PR fifo)
Black frames. vkQuake shows near-black frames on main as well;
APS5_DUMP_FRAMES=60 APS5_DUMP_FRAMES_EVERY=20gave 5 of 60 on main and 2 of 60 with this PR. Every one is an item pickup ("You got the Grenade Launcher", "You get 3 rockets"): the scene is black and only the HUD text is drawn. They are not caused by flip order, and I haven't looked into them further.Tests
video_out_flip_cpuflip:video_out_flip_cpuflip_in_orderruns the same test withAPS5_CPU_FLIP_IN_ORDER=1and expects the first flip to wait as well.APS5_CPU_FLIP_IN_ORDER=1it passes.video_out_flip_testsmode directly withSDL_VIDEODRIVER=windows ANYPS5_REQUIRE_DISPLAY=1:cpuflip(both ways),aftergpu,lifetime,reopen,deferred,unregistered,pacing,present,backtoback,onedevice,labels,labels_main,overlay,controls,unopenedanddecodepass.eopandeop_mainfail ("EOP packet did not finish its label and reserved flip"), andeop_aftergpucrashes; all three do the same with main's build on this machine.VK_LOADER_DRIVERS_DISABLE=*nv-vk*):cpuflip(both ways),lifetime,deferredandpacingpass.aftergpufails with "the GPU work did not land", also with main's libraries.cpuflip(both ways),aftergpu,lifetime,deferredandpacingpass.agc_driver_flip,agc_driver_flip_compute,agc_driver_flip_stores_small_results,agc_driver_presentation_pass,agc_driver_present_mode,agc_resident_present,agc_driver_gated_dispatch_capture(and_short_timeout),agc_driver_pipelined_predicated_label_order,agc_driver_same_queue_label_wait,agc_driver_unimported_label_order,agc_driver_queue_zero_idle_wait,agc_driver_wait_shutdown,agc_driver_registration_prepare_shutdown,agc_copied_direct_ordering,agc_storage_written_buffer_order,agc_queued_write_groupsandvideo_out_hdr_presentpass.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)Submission.cpp, and fix(agc): name preparation-failure shader dumps apart from dispatch captures #6134, perf(agc): compile uncached draws ahead of queue 0 #6188, perf(agc): replace winpthreads locks and TLS on the draw path #6292, perf(agc): share one image table per heap and write epoch through capture, compare, resolution and descriptors #6454 and perf(agc): queue occlusion counter dumps behind pipelined draws instead of draining #6501 addDriver.hppmembers; the overlap is textual only.