feat(agc): capture and replay frames on macOS #19610
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/19610"
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 imellag on 2026-11-13T15:51:37Z.
What
Frame capture (
APS5_FRAME_CAPTURE) andagc_frame_replaywork on Windows and Linux only; on macOS the recorder throws (docs/dev/debt/libSceAgcDriver.md). This ports both to macOS, following the Linux path:core/libs/prx/libc/include/specifics/macos/HostMapping.hppgives the LinuxHostMappinginterface on macOS:WalkandFinduseproc_pidinfo(PROC_PIDREGIONPATHINFO), which returns the region covering an address or the next one (likePROCMAP_QUERY_COVERING_OR_NEXT_VMA), with protection, share mode, inode and path, andEINVALpast the last region;Readableprobes a page withmach_vm_read_overwrite;PlaceNoReplacemaps withmach_vm_allocate(VM_FLAGS_FIXED), which refuses an occupied range (KERN_NO_SPACE) asMAP_FIXED_NOREPLACEdoes.FrameRecorder::committedRangesand the file-mapping end probe take the Linux code on macOS.agc_frame_replay'scommittedWritable,commitandmapHostRangesdo too, withPlaceNoReplacefor the host ranges.agc_frame_replayis linked without PIE at 0x500000000000 on macOS, as on Windows. A PIE x86-64 executable under Rosetta 2 gets dyld,dyld.aotand the Rosetta runtime (about 2.8 MiB) at a random address between 0x200000000 and about 0x204000000, and the main thread's stack (about 64 MiB) at a random address near 0x300000000, both inside the guest arena (0x200000000 to 0xFC00000000). A captured guest range there cannot be mapped (fixed guest mapping ... overlaps a host region in the guest arena). With the high non-PIE base, the arena range of the replay process holds no host region at all (checked over several launches).agc_driver_frame_capture_eop,agc_driver_frame_replay*, and theagc_driver_frame_replay_state_testsmodes that capture real memory);agc_driver_frame_replay_testsis linked like the tool, sincerewind_splitneeds three guest allocations to ascend, and a PIE test binary has dyld inside the arena;std::systemlaunches of the tool, including therewind_reuseone from #17642, go through onerunToolhelper. It keeps the Windows quoting, and on macOS passesDYLD_LIBRARY_PATHon, which/bin/shdrops (SIP) so the tool would not find the Vulkan loader;host_neighborsmaps its two pages at a hint of 0x400000000000 on macOS, because macOS hands out the lowest free addresses first and reused its freed page before the replay mapped it.StorageTexture::releaseReadTraps,LabelTrapsEnabled, both__APPLE__only), which leaves their pages with no host access until a CPU read resolves them. The recorder skipped a mapping with no access, so a capture taken while a trap was armed left those pages out, and the replay stopped withstorage texture has no committed guest pages(ASTRO BOT, a 17 MiB storage texture at 0x55d700000). The recorder now records the read-trapped runs thatGuestWriteWatchReadTrapsreports, readable, with the allocation's protection. The snapshot reads them throughReadCommitted, whoseFlushGpuWritesflushes and releases the driver's trap.FATAL: an address-based build copies 11732 MiB of 158 registered ranges ... heap not fully write-watched). On Linux and macOS a restoredWatchedrange is now registered withGuestWriteWatchRegister. Windows commits in a write-watched arena already.BUILD.mdand the frame capture debt entry name macOS. The entry also notes two macOS points: shared memory that no other mapping shares reports as private, so it is captured as unwatched, and how aliases are reported by the macOS write watch is not measured.Why: on macOS a title A/B means minutes of boot, menus and pad timing per run, and the measured window is a few seconds of it. With a capture, a driver or shader change can be compared on the same frames in seconds, with the replay's pixel comparison and trace.
Tested
macOS 27.2, Apple M4 Pro, x86-64 Release under Rosetta 2, MoltenVK 1.4.2 and the validation layer of Vulkan SDK 1.4.363.0 (
ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer),main999d6f8ffd.read_trapped(macOS): read-traps a guest block, captures one frame, and requires the block in the capture's ranges;watched_restore(Linux and macOS): restores a capture with aWatchedrange, and requiresGuestWriteWatchCoverson it.read-trapped guest pages were left out of the capture's ranges,the replay did not put a watched range under the write watch) and passes with it.ctest -R 'frame_(replay|capture)': 52 tests on the head (50 on the first commit).main, 13 of these exist on macOS (the tests that need no captured memory) and pass.VUID-and nowas not found but was requested by env var VK_INSTANCE_LAYERS.agc_frame_replay exited with 512(the missingDYLD_LIBRARY_PATH), and withthe guest allocations do not ascend.main1af270fa29(which broughtrewind_reusefrom #17642):ctest -R 'present_upscale|linear_target|frame_(replay|capture)|label', 3 runs on each side. With this PR all 54agc_driver_frame_*tests pass 3 of 3; onmain9 of them exist on macOS and pass. The 5 failing label tests and the 6VUID-VkDeviceCreateInfo-sType-unique(all fromagc_completion_label_wait) are the same on both sides.libcurldoes not link on macOS onmain).APS5_FRAME_CAPTURE_AT_FLIP=600 APS5_FRAME_CAPTURE_FRAMES=10:10 frames, 71 calls, 15 memory deltas, 64 ranges, 159.4 MiB snapshot, 24.4 MiB on disk, no warnings. The title kept running at the same 54 fps.agc_frame_replayon that capture replays 10 frames and 10 submits, with no unfinished submit, no pacing timeout, no released wait and 0 MiB skipped. The 3 display buffers compared are identical to the captured references (pixels_identical1.0,max_channel_diff0; the frame is the controls screen, not blank).--repeat 5gives per-pass p50 frame times of 7.73, 9.11, 8.21, 8.53 and 8.22 ms; the whole run takes 6 s.mainplus #17611, #17976 and our open PRs, which these titles need on macOS) and this PR, replayed with this PR'sagc_frame_replay(--repeat 3):pixels_identical0.999999 andmax_channel_diff5. The menu capture of the same title compares at 1.0 and 0.pixels_identical1.0 andmax_channel_diff0 only with the second commit; before it, the replay stopped on the missing storage texture and then on the import budget.Driver::WaitSettledForbefore a memory delta, and the replay was still waiting after 16 minutes. Not investigated in this PR.python3 tools/check_conventions.py --base upstream/mainpasses.Not run on Windows or Linux. Their code paths are unchanged except that the Windows quoting of the test's tool command moved into
runTool.tools/pr_overlap.py: #12568, #17338 and #19557 change neighbouring lines ofagc_driver_frame_replay_state_tests.cmakeandBUILD.md, so whichever lands later rebases; none of them touches the platform code.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 kurexw on 2026-11-17T06:17:46Z.
Review: COMMENTED
Tested on an Apple M4 (MacBook Air, macOS 27.2, MoltenVK 1.4.2 and the validation layer from the LunarG SDK 1.4.363.1, x86-64 build under Rosetta).
Base:
mainata72186d3cfplus #22056 and #22074, two build fixes thatmaincurrently needs on macOS. This PR merged cleanly onto it.I ran
ctest -R 'present_upscale|linear_target|frame_(replay|capture)|label'3 times on each side withANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer. That is 65 tests on the base and 110 with this PR.44 of the 45 frame capture/replay tests this PR enables on macOS pass 3/3, including
frame_replay_read_trappedandframe_replay_watched_restore. The loader inserts the layer, and there are noVUID-lines and nowas not found but was requested.agc_driver_frame_replay_rewind_reusefails 3/3:This test came from #17642, which merged after this branch's base (
999d6f8ffd). ItstestRewindTargetReuseintests/FrameReplay.cppstill startsagc_frame_replaywith a directstd::system(command.c_str()). Your other modes go throughrunTool, which passesDYLD_LIBRARY_PATHon macOS, so the child loses the Vulkan loader path here. Rebasing and routing that call throughrunToolshould fix it. I haven't tried that change.No regression in the other tests. With this PR,
agc_driver_alias_copy_labelfailed 2 of 3 runs andlabel_ordered_flush_disabled1 of 3; on the base they passed. Because those are timing-sensitive, I ran both binaries alternately, 15 rounds each, outside ctest:alias_copy_labelfailureslabel_ordered_flush --disabledfailuresThe results are identical, so the ctest difference was noise. VUID totals over the 65 shared tests are identical too (18 on each side, none in tests this PR touches).
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T03:59:52Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks merging based on the changed code reviewed; the reported macOS test results were supplied by the author and were not run here.
What I ran
Reviewed head
0809e3647484c888709888ba0b4f81e0a7290ce7. No commands or tests were run. I read the prepared description, commit list, manifest, full diff, and all 11 changed files listed as reviewed; no changed files were excluded.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
Builds, tests, and runtime behavior were not independently verified. Windows and Linux were not tested by the author, per the description. The description reports a remaining ASTRO BOT gameplay replay wait after 16 minutes; it was not investigated in this change.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T22:29:23Z.
Review: COMMENTED
The trial merge onto
c1601e56d5conflicts inFrameReplay.cpp,agc_driver_frame_replay_state_tests.cmake, andBUILD.md. Please preserve the macOS control for a replay mapping colliding with an already occupied address, as well as a capture/replay round trip over a file-backed region. Those exercise the platform changes separately from the shared frame-state logic. My review is source-based and I have no native macOS execution result.AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.