fix(agc): read a frame capture's memory delta once the accepted submissions completed #11197
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11197"
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 LeandroLP23 on 2026-10-25T21:37:16Z.
What
A frame capture could store a memory delta from before an earlier recorded DMA copy had landed.
FrameRecorder::writeDeltaread the delta's blocks withReadCommittedUnsyncedwhile GPU work accepted before the call could still write them. At replay the stale bytes were written back over the copy's result. That is the intermittent "the replay did not reproduce the second copy" ofagc_driver_frame_replayin #10711 (root cause in https://github.com/boykopovar/AnyPS5/pull/8740#issuecomment-6385315259).WaitIdleFor), when any are still in flight. It records the accepted and completed serials after the wait. This is option 1 of that comment. A delta with nothing to read does not wait, so those calls keep their submissions overlapped.Submit,SubmitFlipandSuspendPointhand the driver call to the recorder. It runs the call under its lock right after recording it, so every call recorded before a delta has been accepted when the delta waits. Without this, another thread's submission recorded before the delta could be accepted during the wait or after the read, and the replay would submit it before applying stale bytes over its result.writeDeltaruns insideSubmitandSubmitFlip, which catch onlyProcessShutdown, so an exception would end the title.abandonIfDiskLowand the timeout sharestop(reason).agc_driver_frame_replayfrom #10715 is removed, with its debt entry.BUILD.mddescribes the wait, and the Frame capture debt entry gains the new way a capture can stop.@Sumaiter opened the same fix as #11185 (an unconditional wait that throws on timeout). The bot closed it at once for the open-PR limit, so I'm opening this one so the fix isn't blocked. Credit for the independent analysis goes to them. #11157 (janzezno) touches the same quarantine lines; the agreed order in #10711 is the fix first, then #11157 registers the test on Linux without its quarantine changes.
Tested
Windows 11 (10.0.26300), AMD Radeon 860M (AMD 24.30.58.08, LLPC), WinLibs GCC 15.2, Release with
BUILD_TESTING=ON, onmain07da04f947.frame_replay|frame_capturetests pass withANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1:agc_frame_capture,agc_driver_frame_capture_eop,agc_driver_frame_replay, the newagc_driver_frame_replay_concurrentand the sixagc_driver_frame_replay_*state tests.agc_driver_frame_replay_concurrentsubmits 64 DMA copies from a second thread during the capture. It checks that every memory delta was read once the submissions recorded before it had completed, and that the replay reproduces all 64 copies.agc_driver_frame_replayunder contention. ctest is pinned to two cores with three busy-loop processes on them andANYPS5_GPU=no-such-device, as on the runner; this is the setup that reproduced the CI failure.main07da04f947)b709c0fe3dagc_driver_frame_replay_concurrentunder the same contention: 100 of 100 on this head. With only the oldSubmitorder put back (record, release the lock, thendriver.Submit) it passes 66 of 100; the failures say a delta was read with a submission recorded before it unfinished.ctest -VwithVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ANYPS5_NO_SHADER_CACHE=1andANYPS5_REQUIRE_VULKAN=1on this head and on its basemain07da04f947. Theframe_replay|frame_capturetests pass 10/10 against 9/9 onmain. They never load the Vulkan loader, so the layer has nothing to check there. The 22agc_driver_*GPU tests matchingflip|suspend|submit|eop|labelgive 20 passed and 2 skipped on both. There are 0VUID-lines in any log, and nowas not found but was requested by env var VK_INSTANCE_LAYERS. A direct run withVK_LOADER_DEBUG=allshows the layer inserted.check_conventions.py --base origin/mainpasses.pr_overlap.pyfinds #11157 (above), and #10760, which adds an unrelated debt entry (capture trace output) next to the Frame capture one, so whichever lands second resolves a text conflict in that list.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)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T21:52:06Z.
Review: CHANGES_REQUESTED
I found a race that can leave the original stale-delta bug possible.
Driver::WaitIdleForsnapshotsacceptedon entry and returns oncecompletedreaches that snapshot (Driver/Lifecycle.cpp:253-255); it does not prevent later submissions from being accepted. The public submit wrapper callsrecorder->Submitand thendriver.Submitseparately (Driver/EntryPoints.cpp:22-24), and the recorder lock is released before the driver submission. A second thread can therefore accept a submission while this wait is in progress. This code rereads serial progress at line 376 but proceeds toReadCommittedUnsyncedeven if the newacceptedis greater thancompleted, so that write can still land after the delta read. Please serialize acceptance against the wait/read or otherwise establish a stable idle point, and add a regression that accepts another write during the wait. The report also omits the requiredVK_LAYER_KHRONOS_validationrun and VUID comparison for an AGC-driver change;CONTRIBUTING.mdrequires those on the same GPU for main and change.