feat(agc): capture and replay frames on Linux #11157
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11157"
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 janzezno on 2026-10-25T20:01:18Z.
What
APS5_FRAME_CAPTUREandagc_frame_replayonly work on Windows. On Linux a capture throws at its first frame boundary withframe capture: guest memory capture is implemented on Windows only, so a title that misrenders or hangs on Linux can't be captured and replayed offline. Everything else the recorder uses already runs on Linux (the write watch,ReadCommitted, the guest arena and the allocation registry). The missing parts were the VirtualQuery walk inFrameRecorder::committedRangesand the VirtualAlloc calls in the replay tool. This change adds Linux versions of those and runs the capture tests on Linux.Recorder (
committedRanges, Linux branch). It walks each readable registry allocation's VMAs with a newHostMapping::Walk(PROCMAP_QUERYwhen the kernel has it, else one/proc/self/mapspass).HostMapping::Mappinggains the r/w/x/shared bits and the inode, filled on both paths. Classification follows the Windows branch:Host.PROT_NONEVMA is the Linux form of reserved and uncommitted memory (the arena reserves and resets withPROT_NONE), so it is left out.Watched, other private anonymous memory isUnwatched, and the rest (shared and file-backed) isSection. One difference from Windows: on Linux libkernel registers direct memory views with the write watch (AddMapping→WatchMapping). Those views are watched, so CPU stores to direct memory during the frames are recorded, which Windows section views can't do.protectionstores the WindowsPAGE_*value of the VMA bits. That is the protection vocabulary the arena API already uses on Linux, so the field means the same thing in captures from either host.radv-shader-cache/.../indexfile that way, and the first Linux capture died inReadCommitted./proc/self/map_filesneedsCAP_SYS_ADMIN, so the file size can't be read from there. Instead the recorder probes pages withprocess_vm_readvon its own process (a page past the end givesEFAULT, not a signal), binary-searches the boundary and records the pages past it as an unreadable range. Any other probe error (for exampleEPERMunder a seccomp or ptrace policy) fails the capture instead of dropping memory.APS5_NO_WRITE_WATCH, or a host without one), on both platforms. Without the watch a capture used to start and silently miss every CPU store during the frames.Replay tool.
committedWritable: Linux version throughHostMapping::Walk.mapHostRanges: maps page-aligned envelopes withMAP_FIXED_NOREPLACE. Envelopes merge only where two ranges share a page, so an occupied CPU range doesn't block a free GPU range next to it. Windows merges touching 64 KiB envelopes because of its allocation granularity; Linux doesn't need to.0x200538020). On Linux the arena commit is aMAP_FIXEDmmap, which failed withEINVAL. An unaligned range now has its pages made writable withGuestArenaSetProtection; the exact bytes are still marked used. Windows keepsGuestArenaCommit.agc_driver_frame_replay_shared_pagetest fails with each half of this reverted:guest arena commit failed: Invalid argument, anda range sharing a page with an earlier one was skipped.Tests.
agc_driver_frame_capture_eopand thezero,shaderandshader_hostreplay-state modes are registered on Linux, plus new modes:unwatched(Windows and Linux; a capture withAPS5_NO_WRITE_WATCH=1must throw), and the Linux-onlyshared_pageandhost_neighbors(an occupied CPU host range next to a free GPU host range must skip only the CPU range). Each new mode fails with its fix reverted:a capture started without the write watch,frame replay: cannot map the GPU-visible host range at .... On Linux the write watch covers only ranges someone registers (libkernel does for title memory), while Windows watches arena commits automatically. So the two tests that commit arena memory directly register it withGuestWriteWatchRegisteron Linux.tests/FrameReplay.cppwrapped itsstd::systemcommands (the capture-and-replay case and theconcurrentcase #11197 added) in an extra pair of quotes forcmd.exe, whichshreads as one word; that pair is now added on Windows only.#10711. #11197 fixed the recorder race and lifted the Windows quarantine, so
agc_driver_frame_replayandagc_driver_frame_replay_concurrentare now registered on Linux next to Windows, with no quarantine option. Before #11197, the Linux build ofagc_driver_frame_replayfailed 24 of 50 runs pinned withtaskset -c 0,1(the replay did not reproduce the second copy); on this rebase both tests pass 50 of 50 pinned to two cores, to one core and unpinned.Debt and
BUILD.mdupdated: Linux support, watched direct memory views, the no-access and past-end-of-file cases. macOS still throws.Overlap:
pr_overlapreports #10760, #11435 and #11436 (below). Of the 82 others it could not compare, most share only the libSceAgcDriverCMakeLists.txtor debt file. One changes the same code: #7201 (macOS port) putsHostMapping::Findunder#if defined(__APPLE__)and keeps the Linuxreturn Mapping{...}line in its#else, which this change turns intoreturn FromQuery(query, name). That is a one-line conflict for whichever merges second, and its macOSMapping{begin, end, name}still compiles with the new defaulted fields. #10540 adds anextern char** environ;next to the<unistd.h>include ofFrameRecorder.cpp, a line away from the include added here.The reported overlaps, and the recorder fix this change waited for:
docs/dev/debt/libSceAgcDriver.mdconflicts. Order agreed in #10760: independent, noDepends on, whichever is ready first merges; the second rebases and keeps both entries, "Capture trace output" right above "Frame capture".std::systemcall of the capture-and-replay case intests/FrameReplay.cppinto areplaylambda that keeps thecmd.exeouter quotes and adds--repeat 3and an output redirect. That is a textual conflict on the same lines, and with both merged the Linux test would fail on the outer quotes unless the lambda adds them on Windows only. Order proposed in #11435: either order, noDepends on; whichever merges second makes the lambda's outer quotes Windows-only.Tested
Arch Linux 7.2.11, AMD Radeon RX 7900 GRE (RADV NAVI31, Mesa 26.2.5), Ryzen 5 7500F, Release, on
main7903201bb4.Focused tests with
ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ctest -R 'agc_frame_capture|agc_driver_frame_(capture_eop|replay)' -V:main: 4/4 pass (agc_frame_captureand the replay modesorder,tokensandblocking; the others are not registered on Linux), 0VUID-, no missing-layer line.agc_frame_capture,agc_driver_frame_capture_eop, replay modesorder,tokens,blocking,zero,shader,shader_host,unwatched,shared_page,host_neighbors,agc_driver_frame_replay,agc_driver_frame_replay_concurrent), 0VUID-, no missing-layer line. The replay tests copy with DMA and don't depend on the Vulkan device.agc_driver_frame_replayandagc_driver_frame_replay_concurrent, 50 runs each undertaskset -c 0,1,taskset -c 0and unpinned: 0 failures in 300.ctest -R 'guest|sysmodule|module|unwind|frame' -j6(819 tests, covering theHostMappingusersGuestMemory,sceKernelGetModuleInfoForUnwindandsceSysmoduleGetModuleInfoForUnwind): all pass, 2 skipped (video_out_frame_dump_queue,video_out_frame_dump_wait).On the pre-rebase head
9aad99ba3c(mainae7d59258e; the rebase leaves the recorder and replay tool code unchanged):ccleste PPSA59322 1.00 (homebrew, MIT, sha256
96861b81…), relinked with default options, title screen, no input,APS5_FRAME_CAPTURE_AT_FLIP=300 APS5_FRAME_CAPTURE_FRAMES=10:main: aborts at frame boundary 300 withterminate called after throwing an instance of 'std::runtime_error'/what(): frame capture: guest memory capture is implemented on Windows only.[frame-capture] started at frame boundary 300: 111 ranges, 163.0 MiB snapshot in 0.2 s/10 frames, 32 calls, 33 memory deltas (6.6 MiB), 264.5 MiB raw, 28.0 MiB stored,unreadable_bytes24576 (the shader cache index pages past the end of its file), no warnings.agc_frame_replay capture --frames out:All three display buffers match their reference images pixel for pixel; the replayed title screen is attached.
Not tested: Windows. The Windows recorder walk and the Windows commit path are unchanged; the write-watch check at capture start and the
unwatchedtest also run there. The ownership decision before commits also applies on Windows and changes behaviour only for two ranges in one page.tests/FrameReplay.cppkeeps its outer quotes on Windows.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)