fix(agc): complete a flip only once the frame's GPU work has finished #417
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/417"
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 oneandonlydean on 2026-10-02T22:34:49Z.
What
A flip could complete while the GPU was still executing the frame it shows.
With
APS5_FLIP_INFLIGHTat its default of 1,Driver::Presentreported the flip (gpuReady, soflipPendingNumdrops and the flip event fires) as soon as the blit was queued behind the frame's batches. A title reads that completion as "the GPU is done with this frame" and starts reusing the frame's memory: per-draw constants, vertex data, command buffers. The recorded batches read guest memory in place when they finally execute, so draws that had not run yet read the next frame's data.In PPSA21564 on my integration branch this showed up as follows (that branch also delivers end-of-pipe interrupts without draining, as #409 proposes, so the window there is wider than on main, see below):
0x3f800000) from another draw as the count and looped about 1e9 times, stalling the GPU;With
APS5_FLIP_INFLIGHT=0(the render fence wait before the flip completes) none of this happened. In my test runs of the affected level (300 s each), the hits of that loop went from 435 to 0 with this change.The presenter now queues the present as before and then waits for the frame's own fence (
FinishPresent), outside the GPU mutex, before reporting the flip. The swapchain present still goes out at once, so the display does not wait for the CPU; only the completion the title observes moves to the point where the GPU no longer reads the frame.APS5_SYNC_FLIPalready waited and is unchanged. The comment inFlipRequest::GpuReadythat described the old completion point is updated.On main a RELEASE_MEM that raises an interrupt drains the device, so the window is the frame's work recorded after its last such packet, plus anything ordered only by plain labels or waits. That is still enough for a title to see the flip before its last draws have run.
When no blit is submitted (the window is not presentable, e.g. minimised), the flip still completes without waiting, as before.
The flip now completes later, so a present is more likely to end past the next vblank. That moves the next flip's target out by one vblank on main; #416 fixes that and should go in with or before this one.
Tested
BUILD_TESTING=ONandctestpass.video_out_flip_tests aftergpu(needs a GPU and a display, like the file's other presentation modes): submits a busy compute dispatch followed by an end-of-pipe label and a flip, and checks that the flip does not complete before the label lands. The label has no interrupt, so main does not drain at it. Three runs each: on main the flip completed at 2.1, 9.3 and 10.8 ms while the label landed at about 243 ms, and the test failed; with this change the flip completed 0.1 to 0.2 ms after the label (about 243 to 257 ms) and the test passed.video_out_flip_tests presentandbacktobackpass.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)