perf(videoout): don't hold a flip thread's CPU flips behind queued work #6507
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6507"
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 karanvora2599 on 2026-10-15T18:05:20Z.
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 #417 (d9632d552) holds for these flips too.The flip hold that @AymanFE's #1745 and @sridhar777911's #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 (
13b171cab), 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(#417) checks that order;flipPendingNum, like Balatro in @gjonn's #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
51cee9031(db091f5fb). InSubmission.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 mainfa9365ca7. 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).fa9365ca7APS5_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 #6134, #6188, #6292, #6454 and #6501 addDriver.hppmembers; the overlap is textual only.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T18:27:14Z.
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.
core/libs/prx/libSceVideoOut/CMakeLists.txtcore/libs/prx/libSceVideoOut/src/VideoOutDriver.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/EntryPoints.cppdocs/dev/debt/libSceVideoOut.mdcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/EntryPoints.cppcore/libs/prx/libSceVideoOut/CMakeLists.txtcore/libs/prx/libSceVideoOut/src/VideoOutDriver.cppcore/libs/prx/libSceVideoOut/tests/Flip.cppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceVideoOut/CMakeLists.txtcore/libs/prx/libSceVideoOut/tests/Flip.cppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/EntryPoints.cppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Queues/Submission.cppcore/libs/prx/libSceVideoOut/src/VideoOutDriver.cppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/EntryPoints.cppcore/libs/prx/libSceVideoOut/CMakeLists.txtcore/libs/prx/libSceVideoOut/tests/Flip.cppdocs/dev/debt/libSceVideoOut.mdcore/libs/prx/libSceAgcDriver/Execution/include/VideoOutput.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Queues/Submission.cppcore/libs/prx/libSceVideoOut/src/VideoOutDriver.cppcore/libs/prx/libSceVideoOut/CMakeLists.txtcore/libs/prx/libSceVideoOut/src/VideoOutDriver.cppcore/libs/prx/libSceVideoOut/src/VideoOutDriver.cppcore/libs/prx/libSceVideoOut/tests/Flip.cppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppImported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-16T08:28:35Z.
Cross-validation on Windows 11 Pro 26220, NVIDIA RTX 4070 (596.21), MinGW GCC 15.2, PR head
f0d9d0122merged on main5d9dcc42d(together with #6504, no overlap, no conflicts). Only NVIDIA on Windows: no AMD, Intel or Linux run from me. The host was shared (other agents were compiling, CPU load 41 to 100% during the runs), so read the numbers as direction, not magnitude.alignasAGC test fails (#6452/#6478). The two new flip tests skip under ctest's offscreen driver; run directly withSDL_VIDEODRIVER=windows ANYPS5_REQUIRE_DISPLAY=1, 3 times each:cpuflippasses,cpuflipwithAPS5_CPU_FLIP_IN_ORDER=1passes,aftergpupasses.video_out_flip_tests cpuflipagainst main's libraries fails 3 of 3 ("a flip from a thread that never submitted queue-0 work waited for a held queue-0 submission"), passes withAPS5_CPU_FLIP_IN_ORDER=1;aftergpupasses on main's libraries.agc_driver_*andvideo_out_flip*excluded): 13 load timeouts, all pass on serial rerun or when run directly; none touches flips.check_conventions.pyandgit diff --checkpass.APS5_TRACE_SECONDS=15:10,APS5_SPIRV_OPT=none,ANYPS5_PRESENT_MODE=immediate,r_rtshadows 0) plusAPS5_TRACE_SUMMARY_EVERY=10, 120 s per run, default window size, sharewareid1/pak0.pak, main/PR runs interleaved: 5 runs on main, 6 on the PR. Medians (range) over runs of the per-run median of the 10 s intervals: presents per 10 s 378 (183 to 546) on main, 544 (411 to 735) with the PR; frame p50 22.4 ms (15.2 to 48.1) vs 15.2 ms (12.6 to 21.9); frame p90 40.4 ms (33.5 to 102) vs 24.3 ms (18.0 to 34.7); queue worker busy 83.5% (75.7 to 97.6) vs 97.5% (96.1 to 97.6). Host CPU load: main median 76% (41 to 100), PR 66% (41 to 97). At the quietest pair (41% load): main p50/p90 15.2/34.3 ms, PR 12.6/18.0 ms. The ranges overlap because of the load, and two PR runs had a poor 15 s to 25 s window (167 and 223 presents) while their interval medians were normal, so the direction and the saturated worker match your description but I cannot confirm 60 to 72 presents per second or the interval sd.agc_driver_*andvideo_out_flip*GPU suites, and a title that renders on one thread and flips from a thread that never submits (the case the debt note describes).Two review points: (1)
APS5_CPU_FLIP_IN_ORDERis a new environment switch; the condition already honoursAPS5_SYNC_FLIP, which the in-order test could use instead. (2) Per the perf policy this still needs AMD, Intel and Linux runs; mine only adds a second NVIDIA/Windows sample.Written with Claude Code assistance (validation by a subagent, reviewed in this session).
Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-16T17:22:55Z.
Rebase handoff — rebased onto current
main(authorship unchanged). One conflict inSubmission.cpp:mainextended the compute-queue bound toSubmissionQueueEndand added the submission-ring preparation, while this PR adds the flip-ordering logic (flipsInOrder/unorderedFlip/submitsQueue0) at the same spot; the merged version keepsmain's queue bound and ring setup followed by this PR's flip logic.Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
BUILD_TESTING=ON, AMD RX 9070 XT / RADV):tools/check_conventions.py --base origin/mainpassesmainregression (agc_driver_tessellationsegfault, #4727), not this PRTo pick it up:
Head is
7510b102d.Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-17T12:14:14Z.
Re-anchored rebase handoff —
mainmoved since the earlier handoff; rebased onto currentmainagain (authorship unchanged). The same resolution:main's queue bound and ring preparation followed by your flip-ordering logic, and both flip test modes (ps4,cpuflip) kept.Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
BUILD_TESTING=ON, AMD RX 9070 XT / RADV):tools/check_conventions.py --base origin/mainpassesmainregression (agc_driver_tessellationsegfault, #4727), not this PRTo pick it up:
Head is
ca5ce7ad3.Imported from boykopovar/AnyPS5. Originally posted by karanvora2599 on 2026-10-18T00:57:56Z.
Rebased onto
main51cee9031(db091f5fb). Thanks @blawesom for the two rebase handoffs. I redid the rebase on my side with the same resolution:main's queue bound and submission-ring setup first, then the flip ordering, and both theps4andcpuflipmodes kept. On the new head, all 18video_out_flip_testsmodes I can run pass on the RTX 4060 (ps4andcpuflipamong them;cpuflippasses both by default and withAPS5_CPU_FLIP_IN_ORDER=1). A vkQuake A/B againstmain51cee9031(main, PR, main, PR; same settings as the table) repeats the result:main51cee9031db091f5fbThese 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:
APS5_SYNC_FLIPisn't the same asmain. It also parks the queue worker until the presenter has finished each flip (FlipRequest::GpuReady), and it turns off in-flight presentation (FlipInFlight()returns 0). A control run with it would change two things at once.APS5_CPU_FLIP_IN_ORDER=1restores onlymain's flip order, which is why the control rows in the table matchmain. I'd keep it as the A/B switch, and it's listed in the debt note.The traces for the table are attached below.
Imported from boykopovar/AnyPS5. Originally posted by karanvora2599 on 2026-10-18T01:29:58Z.
Traces for the vkQuake runs (PPSA99010, RTX 4060 Laptop, driver 591.86,
APS5_TRACE_SECONDS=15:10,APS5_SPIRV_OPT=none,ANYPS5_PRESENT_MODE=immediateexcept the two FIFO runs), in run order.The table in the description (ae47bd08d, this change on main
fa9365ca7):fa9365ca7, ab1: main-cf-ab1-aps5-trace-fa9365ca74ac-7948.json.gzAPS5_CPU_FLIP_IN_ORDER=1, ab1: fix-cf-ord1-aps5-trace-ae47bd08d7d1-33736.json.gzfa9365ca7, ab2: main-cf-ab2-aps5-trace-fa9365ca74ac-27036.json.gzAPS5_CPU_FLIP_IN_ORDER=1, ab2: fix-cf-ord2-aps5-trace-ae47bd08d7d1-6908.json.gzThe rebased head
db091f5fbagainst main51cee9031(my comment above):51cee9031, r1: main-r1-aps5-trace-51cee90311b4-36732.json.gz51cee9031, r2: main-r2-aps5-trace-51cee90311b4-16048.json.gzEach file's summary line is in the description or in that comment, in the same order.