feat(agc): capture frames at the driver boundary and replay them offline #8740
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8740"
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 Sam-mon7 on 2026-10-20T23:11:00Z.
What
A frame capture at the AGC driver boundary and a tool that replays it through the driver with no title running, so a driver change can be run against a few real frames of a title in a minute or two instead of a full boot, load and route per run.
APS5_FRAME_CAPTURE=<dir>records, from process start, the shader registrations and ABI resolutions, video output registrations and unregistrations, and EOP flip reservations. At a frame boundary (APS5_FRAME_CAPTURE_AT_FLIP, or the fileAPS5_FRAME_CAPTURE_TRIGGERnames appearing) it waits for the driver to go idle and snapshots every readable guest allocation of the allocation registry (zstd, all-zero 64 KiB blocks skipped). For the nextAPS5_FRAME_CAPTURE_FRAMESframes it records each submission, flip and suspend point with its thread and serial progress, preceded by the pages the write tracker saw the CPU write before it (GuestMemory::CollectWrittenBlocks), plus the blocks holding the code of each registered or resolved shader. At the end it stores the presented display buffers as reference images.agc_frame_replay <capture>maps the memory back at its addresses, repeats the registrations and replays each captured thread's calls on its own thread in captured order; memory deltas and video output registration and unregistration complete before the next captured call starts. It paces GPU work to the in-flight depth the title had, and releases GPU waits that the title's CPU threads released without calling the driver, using the newAgcDriverAwaitedWaits(per-queue blocked wait fields, one atomic store per blocked wait). It prints one JSON line: frame times, released waits (recorded, earlier or derived), unfinished submissions, and the share of identical pixels against the reference images (--frameswrites both images).Changes since review
agc_driver_frame_capture_eopcaptures three of six EOP frames and checks the counts (fails on the first commit).agc_driver_frame_replay_order;agc_driver_frame_replay_blockingchecks that a submission, flip or reservation that blocks until a later delta lands still completes);agc_driver_frame_replay_shader,agc_driver_frame_replay_shader_host);agc_driver_frame_replay_tokens);UnregisterVideoOutput;agc_driver_frame_replaynow closes and reopens its output before and during the capture,agc_frame_captureround-trips the new call);agc_driver_frame_replay_zero).late_rangesin the header;agc_driver_frame_replaycopies its second frame from a block committed during the capture);agc_driver_frame_capture_eopchecks that a flip submitted on another thread leaves this thread's count unchanged). Both tests fail without the fix.Tested
Windows 11 Pro 10.0.26200, NVIDIA GeForce RTX 4070 (driver 610.88), WinLibs GCC 15.2.
agc_frame_capture(format round trip, zero-block elision, truncated and corrupt files),agc_driver_frame_capture_eop, the sixagc_driver_frame_replay_*state tests above, andagc_driver_frame_replay(two captured frames of CPU writes and DMA copies replayed inagc_frame_replay, copies compared, output closed and reopened): pass.ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ctest -R '^agc_(frame_capture|driver_frame_capture_eop|driver_frame_replay.*|driver_flip.*|driver_pm4.*|driver_wait_shutdown|driver_eop_interrupts|driver_graphics|driver_bda_device|driver_compute_table_calls|driver_dispatch_move|driver_draw_cache_reuse)$' -V: main7e95bde79425/25; this PR at 4acf448602 oneea640a5bf34/34 (the same 25 plus the nine new tests), and again at 430a251603 34/34. Neither log has "was not found but was requested by env var VK_INSTANCE_LAYERS"; 0VUID-lines in both (the loader inserts VK_LAYER_KHRONOS_validation, checked withVK_LOADER_DEBUG=all).nvidia-smi -lgc 2400,3135 -lmc 10501) 80.3, 71.9 and 69.9 s (first run warms up), median frame 5.6, 5.3, 5.2 s.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
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T23:12:28Z.
Code review location:
core/libs/prx/libSceAgcDriver/Execution/src/Driver/EntryPoints.cpp; line 128Could you verify the EOP path does not count one displayed frame twice?
ReserveEopFliprecords a pending token here, and laterDriver::Submitconsumes that token intosubmission.flips; theSubmitwrapper also callsFrameBoundary()whenFlipSubmissions()changes. For EOP-driven titles both events appear to represent the same flip, soAPS5_FRAME_CAPTURE_FRAMES=Nmay stop after about N/2 displayed frames (and the first capture boundary may fire at reservation time). Could you deduplicate these signals or add a focused regression test that exercises reserve + submit and asserts the captured frame count?Imported from boykopovar/AnyPS5. Originally posted by Sam-mon7 on 2026-10-20T23:18:38Z.
Code review location:
core/libs/prx/libSceAgcDriver/Execution/src/Driver/EntryPoints.cpp; line 128Confirmed, thanks.
reserveOutputsputs the flip of an EOP release with a reserved token intosubmission.flips, so theSubmitwrapper ended the same displayed frame a second time afterReserveEopFliphad already ended it, and a capture could start between the reservation and the submission that flips.Fixed in 59638297ce: the reservation is still recorded (the replay needs its token) but no longer ends a frame. A frame now ends only at a CPU flip or at a submission that flips (a flip packet, or the EOP release of a reserved token).
Added
agc_driver_frame_capture_eop: it reserves and submits six EOP flips withAPS5_FRAME_CAPTURE_FRAMES=3and asserts that the capture starts after the first flipping submission and holds three frames with exactly one reservation and one submission each. On the previous commit it fails with "the capture started between a reservation and the submission that flips it"; with the fix it passes (3/3 runs, also withVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, noVUID-lines). BUILD.md and ENVIRONMENT.md now describe frame boundaries this way.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T23:22:21Z.
Review: APPROVED
The updated EOP boundary handling addresses the double-counting issue: reservations remain recorded for replay, and only the submission that carries the token advances the frame boundary. The new regression checks both the captured frame count and that capture does not start between reservation and submission. The author reports three Linux runs with Vulkan validation; hosted build/runtime jobs for this head were skipped, so those checks are not available here.
Small documentation nit: in docs/dev/BUILD.md, the sentence listing agc_frame_capture and agc_driver_frame_capture_eop needs “and” between the test descriptions.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T23:37:30Z.
Thanks for checking the EOP path and adding the focused test. I reviewed the updated
Submit/ReserveEopFlipchanges andagc_driver_frame_capture_eop: the reservation remains captured for replay, but the frame boundary now comes from the flipping submission, and the test checks that capture begins at the reservation and contains exactly three reservations plus three submissions. That resolves the double-count/start-between concern I raised. The hosted platform/runtime jobs are still skipped, so I’m acknowledging this specific issue rather than treating it as full validation of the entire PR.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T00:13:41Z.
Code review location:
core/libs/prx/libSceAgcDriver/Execution/src/Driver/EntryPoints.cpp; line 128Thanks for the regression details. I checked the updated implementation and test wiring; this addresses the double-boundary concern I raised. The thread remains visible because GitHub denies my account permission to resolve it. The hosted runtime jobs for this head are skipped, so I am treating your local 3/3 Vulkan-validated runs as reported evidence, not hosted CI.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-21T19:16:49Z.
@Sam-mon7 thanks for this. I looked into the Linux failures in our full CI run.
agc_driver_frame_capture_eop,agc_driver_frame_replay,agc_driver_frame_replay_orderandagc_driver_frame_replay_blockingeach stop after about 0.02 s withguest arena: unmapped protection value. Windows is green.The cause is the protection value passed to
GuestArenaCommit_nid_postfixon non-Windows builds. In the#elsebranch of#ifdef _WIN32, the PR passes3, which is POSIXPROT_READ | PROT_WRITE. The guest arena takes WindowsPAGE_*values on every platform, though. On Linux,GuestArenaCommit_nid_postfixcallsPlaceAt, andPosixProtection()incore/libs/prx/libc/src/GuestArena.cppmaps only0x01..0x40to POSIX flags and throws for anything else. That's also how the Linux code onmaincalls it:DirectMemory.cppconverts withWinProtFromPosix(prot)first.It happens in four places:
core/libs/prx/libSceAgcDriver/tests/FrameCaptureEop.cpp:65core/libs/prx/libSceAgcDriver/tests/FrameReplay.cpp:88core/libs/prx/libSceAgcDriver/tests/FrameReplayState.cpp:25core/libs/prx/libSceAgcDriver/tools/FrameReplay.cpp:228The last one is the replay tool itself, so a replay on Linux would throw the same way, not only the tests.
The fix is to pass
0x04(the value ofPAGE_READWRITE) on all platforms and drop the#ifdefat those four sites. A named constant such asconstexpr std::uint32_t ArenaReadWrite = 0x04;would keep it readable on Linux, wherePAGE_READWRITEisn't defined.