fix(agc): stop frame capture deltas from collecting the previous delta's pages again #14137

Merged
thuanquang merged 21 commits from upstream-pr/14137 into main 2026-11-09 02:16:03 +00:00
thuanquang commented 2026-10-31 20:30:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by thuanquang on 2026-10-31T20:30:34Z.


What

docs/dev/BUILD.md describes each memory delta of a frame capture as the guest pages the CPU wrote since the previous call that handed work to the GPU. On main each delta also collects again the pages the previous delta collected (line numbers on main 91ecd2d974):

  • Full deltas. emitDelta gives every range since = generation, reads mark = WriteGeneration() before the walk and sets generation = mark after it (FrameRecorder.cpp L329-334). CollectWrittenBlocks raises the tracker generation and only then stamps the pages its walk finds (GuestMemory.cpp L1681, L1608-1610). So every page a delta's own walk reports carries a stamp newer than mark, and the next delta lists it again.
  • Shader deltas take mark the same way (L401, L409) and start from generation (L405), and emitDelta clears their marks (L335). A page a full delta collected is therefore collected again by the next shader delta of its 64 KiB block as well.
  • Ranges added during the capture are read whole without a collect (L432-451). Their pages written before the add come back in the next delta through their write-watch bits.

Each repeat is read and written again, and a delta made only of repeats still waits for the driver to go idle before the call it precedes (L422), so that call is recorded with nothing in flight. In a Persona 5 Royal capture made on main at 86fb985abb (the delta bookkeeping is unchanged since), the second full delta (group 47) holds every page of the first, 2,610.9 MiB by the chunk headers.

This change:

  • keeps, for each watched or unwatched range, the generation its last CollectWrittenBlocks returned (read under the tracker lock after the walk), and starts the range's next collect there. start() takes these values from its reset walks;

  • keeps, for each shader block, the generation its last collect returned. A block lying wholly inside those ranges starts from the newer of that value and the oldest value of its ranges, so it skips what their full deltas took. Any other block starts from its own value, and the first time from the tracker generation read right after the reset walks (GuestMemory::TrackerGeneration), so it never lists a page stamped before the capture started;

  • collects a watched or unwatched range the registry gained just before reading it, so the next delta takes only what was written after that collect, and writes every 64 KiB block of such a range in the delta that adds it, zero or not. main writes only the nonzero blocks there and records what the CPU wrote before the add, a clear included, in its next delta. That delta now starts after the add's collect, so a skipped all-zero block would keep what the replay already holds at its address (found by @chitters2004; late_clear below);

  • reads every delta through GuestMemory::ReadCommitted, as the snapshot already does. A delta read on main uses ReadCommittedUnsynced, so it can miss a result the driver still keeps on the GPU for that page (pending_result below). Since the next delta no longer reads the page again, the read now stores those results first;

  • has the replay land those results too: agc_frame_replay reads each delta chunk, calls AgcDriverPrepareCommandWrite_nid_no_patch over its range and then copies it, the order #12567's restoreGroup uses. calls.bin becomes format 2 (aps5-frame-calls 2); FrameCaptureReader still reads format 1 and reports the format (Version()), and the replay refuses a format 1 capture before it restores any memory, since such a capture does not record whether GPU writes had landed before each delta was read. With the ReadCommitted read in the bullet above, these are the four items @chitters2004 asked for on #12567 and we agreed on in #12568's thread;

  • closes the two tracker gaps @oneandonlydean named, which main's repeated read covered:

    • a store between the two walks of GuestMemory::StoreOwnBytes. While a capture records (the recorder turns GuestMemory::SetOwnStoreCompare on in start() before its reset collects, and off in stop() and finish()), a driver store from the CPU that gives its bytes (Write, WriteChanged, the guest label store, the span form of StoreOwnBytes, and a new StoreOwnBytes form whose callback writes the bytes it stores into a span it receives) copies its page-rounded range before its first walk and applies its own bytes to the copy; a page its second walk takes that then differs from the copy, or can no longer be read, is noted, and CollectWrittenBlocks lists it. A store that gives no bytes (MEM_SEMAPHORE signal and wait, buffer copies on the CPU, and main's compare-exchange write-back WriteChangedIfHeld, which stops at the first byte it loses) notes every page its second walk takes. A keep-guest write-back (WriteChangedKeepingGuest, #6185) leaves the guest's bytes in its copy, as its store does. No stamp changes, so UnchangedSince, StoredOver, UnchangedSinceCollected and ChangedBlocks answer as before, with or without a capture;
    • a page only a MarkWritten fresh collect noted. CollectWrittenBlocks also admits a 64 KiB block whose block stamp is newer than since, so such a page is listed: the fresh collect raises the block stamp, not the CPU block stamp the loop checked first. The whole clip of a block is listed only when its CPU block stamp is newer and no page in the clip has a newer CPU note.

    agc_driver_frame_replay_store_between_walks and agc_driver_frame_replay_fresh_note are @chitters2004's tests (c9a87b435c, unchanged). His fix (5458ad80b2) is not taken; the reason and the measurements are in the comment with this push.

Not changed here:

  • A page first collected by a shader delta is collected again by the next full delta of its range, and a page a full delta collected is collected again by the next shader delta of a block its range covers only in part.
  • When a 64 KiB tracker block holds parts of two ranges, a new CPU stamp in one part makes the next collect of the other range list its part of the block whole.
  • Pages a host import's write-watch window stamps during the capture are collected like CPU writes.
  • A CPU store to a page that leaves the write watch (Unwatch, an import that unwatches it, a failed fresh collect) after a delta collected it is not recorded until the tracker notes the page again; main read such a page once more in the next delta. A delta's own walk also skips every 64 KiB block that holds such a page, as on main. Debt entry "Pages that leave the write watch during a frame capture".
  • When a driver store from the CPU gives its bytes, a store another thread makes during it that puts back bytes a GPU write into a watched host import changed during that store leaves the page equal to the store's copy, so it is recorded only when another store gets the page listed; main also recorded it when the previous delta had found the page written. Debt entry "Driver stores during a frame capture".
  • The pages of stores that give no bytes (MEM_SEMAPHORE packets, buffer copies the driver runs on the CPU, WriteChangedIfHeld) are listed after every such store, and the replay writes the captured bytes there over what its own semaphore or copy stored. How much of the casino capture below they make up, and whether they change replayed waits, is not measured.
  • Import-window walks also note the pages they find changed in the new windowPages map in every run; only CollectWrittenBlocks reads it, and its memory is not measured.
  • In every run, a CPU store another thread makes into a page while a driver store from the CPU covers it still counts as the driver's for UnchangedSinceCollected, the CPU flag of ChangedBlocks and StoredOver beside the stored bytes, as on main. This PR changes only what CollectWrittenBlocks lists while a capture records. Debt entry "CPU stores during driver stores".
  • No row stores from another thread during Write, WriteChanged, the guest label store or the span form of StoreOwnBytes. On Windows none of them runs anything between its two walks, and WriteChanged and the label store run nothing there on any OS; on Linux the span form and a Write of 4 KiB or more call the shared-backing writer between the walks, which no row drives. Each store builds its copy from its own input (source, value, current), never by reading memory back.
  • No row can fail when the copy is taken after the first walk instead of before it, or when start() turns the switch on after its reset collects instead of before them.
  • The capture-time cost of the copies: in one casino capture per build (separate runs of the route below), this head recorded 692 groups and 610.6 MiB in 23.8 s (snapshot 13.1 s), and a local build of it whose recorder never turns the compare on recorded 719 groups and 618.1 MiB in 25.9 s (snapshot 13.9 s). One run each, so this shows no large cost, not a small one.
  • A host or section range the registry gained during the capture is still added with only its nonzero 64 KiB blocks and not collected afterwards, as on main.
  • On Windows a page that the snapshot or an added range's read touches first can be reported as written, so the next delta may record it once more.

Side effect: a call whose delta would have held only repeated pages now gets no memory record and no idle wait, so a new capture records it at the depth the title had; a delta made only of pages of stores that give no bytes still gets both. That is not the aim of this PR: #12568 makes every full delta wait for a settled driver while work is in flight, and recording the in-flight depth stays with the follow-up stacked on #12568 (#15136).

Overlap (trial merges of each open PR's head with this head, listing only conflicts this PR adds to what the PR already has with main 91ecd2d974):

  • #14899 (merged) changed the tracker generations to 64 bits in the same GuestMemory.cpp struct and write-tracking test registration; the merge of main keeps both sides.
  • #12567: the delta copy in tools/FrameReplay.cpp, the mode list of the state tests and the frame capture paragraph of docs/dev/BUILD.md. It has the identical readGuest change and already flushes before each delta copy in restoreGroup; whichever merges second drops its copy.
  • #12568 (stacked on #12567): FrameRecorder.hpp/.cpp, the tool, the mode list and BUILD.md. As before, it moves the CollectWrittenBlocks loop behind its settled wait and collects per 64 KiB piece; whichever merges second keeps a since per collect call set to the value that call returned, gives every piece a starting value from a reset walk, drops shaderMarks.clear() from emitDelta and passes !collected && zero for added ranges. I'll post a rebase of #12568 onto this PR.
  • #12318 replaces the same delta-copy loop with its own restoreGroup, which has no flush; #12567, stacked on it, adds the flush there. Whichever of this PR and #12318 merges second keeps the AgcDriverPrepareCommandWrite_nid_no_patch call before each delta copy.
  • #15136 (mine, draft, on #12568) also touches the calls format (it writes version 2 too and moves to 3 when restacked onto this PR) and FrameRecorder::finish().
  • #13021, and #13023 which contains it, change storeOwn's signature next to this PR's new imaged parameter and the compare switch in GuestMemory.cpp.
  • #12452 adds a bounds check at the top of WindowCopy::Holds, where this PR adds the store-image compare.
  • #12565 (FrameRecorder.hpp, BUILD.md), #13984 (mine; FrameReplayState.cpp), #12696 and #11436 (the mode list) conflict mechanically.
  • #11435 and #6186 add no conflict beyond the ones they have with main.

Tested

Windows 11 26200, Ryzen 5 5600X, Radeon RX 6700 XT (gfx1031), AMD driver 32.0.21045.16010, WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON, full builds with submodules at their pins: main 91ecd2d9743b831b575d293e6c8fafbe737e1e88 (merged into this branch) and this PR's head 702492e63e.

This head (ca4553365f) merges main 1c8c0efc8c to resolve the conflict with #13021 in GuestMemory.cpp: storeOwn keeps #13021's complete flag next to this PR's imaged flag, and WriteChangedIfHeld (new on main) stores through the form that gives no bytes. On it, the focused set below passes 36 of 36 in 3 of 3 runs (main 1c8c0efc8c: 23 of 23), agc_driver_native_multisample_depth (a WriteChangedIfHeld caller) 1 of 1 in 3 runs on both, the validation-layer run shows 0 VUID- lines on both, and git diff --check is clean. Every other result below is from the previous head 702492e63e (main 91ecd2d974 merged), whose capture and tracker code is the same apart from that store.

Modes of agc_driver_frame_replay_state_tests drive FrameRecorder directly and need no GPU. From the previous revision:

  • agc_driver_frame_replay_once writes a page before each of two suspend points and commits a range during the capture. Between the suspend points it writes a page in the second of the two 64 KiB blocks a shader header marks, and registers that shader twice; the header shares the first page's block. The page written before each suspend point, and the written page of the added range, must each be in exactly one memory delta, the one before their suspend point, and the second registration must collect nothing. Every page of both ranges is written before the capture or before the add, so no snapshot or delta read is a page's first access.
  • agc_driver_frame_replay_pending_result installs a flush hook that stores a result word over a page the CPU wrote, standing in for a storage result the driver keeps on the GPU until the page is read. The delta before the first suspend point, and the delta that adds a range committed during the capture, must each hold the stored value.
  • agc_driver_frame_replay_partly_covered writes a 16 KiB allocation before the capture and registers a shader whose header lies in it, so the header's 64 KiB block is only partly inside the captured ranges. The written page must be in no memory delta, since the snapshot holds it.
  • agc_driver_frame_replay_late_clear (@chitters2004's test from this thread) starts the capture, then commits a range, writes a page in it, registers a shader whose header lies in the 64 KiB block before that page's block, clears the page and reaches two suspend points. The last memory delta holding the page must hold the clear.

New in this push:

  • gpu_write_before_delta: a delta copy over a GPU write the replay still has pending must hold the delta's bytes; calls_v1: a calls format 1 capture is refused before any memory is restored.
  • store_between_walks, fresh_note (@chitters2004's).
  • store_window: a label store through the StoreOwnBytes form that gives no bytes while another thread writes the same page, then four driver stores with given bytes into pages nothing else writes; the other thread's byte must be in a delta and the four pages in none, and a driver store after finish() must not be listed.
  • store_window_unwritten: the same store from another thread into a page the CPU has not written.
  • store_window_stopped: the capture stops when it starts (APS5_FRAME_CAPTURE_MIN_FREE_BYTES above any free space); a driver store after that must not be listed.
  • agc_write_tracking_fresh_view (Windows): a section view whose first page alone is collected before a GPU write's fresh collect takes the rest; those pages must be listed. agc_write_tracking gains two guards: a page only an import window stamped is listed, a block only a GPU write stamped lists nothing.
  • agc_write_tracking_own_store_images (Windows; on Linux the last check of agc_write_tracking): a driver store made before the compare is on lists nothing; then with it on, a Write, a store of given bytes, a label store, a write-back and a keep-guest write-back over a page the guest wrote list nothing; a store from another thread beside the bytes of a two-page driver store lists only its page; one over a driver store's bytes is listed; one that undoes a store which gives no bytes is listed; a listed page is not listed again.

Each row, 3 runs per tree:

row main 91ecd2d974 + the rows this head, tracker changes reverted this head
store_between_walks passes 3/3 fails 3/3 passes 3/3
fresh_note fails 3/3 fails 3/3 passes 3/3
store_window fails 3/3 fails 3/3 passes 3/3
store_window_unwritten fails 3/3 fails 3/3 passes 3/3
store_window_stopped not run passes 3/3 passes 3/3
agc_write_tracking_fresh_view fails 3/3 fails 3/3 passes 3/3
agc_write_tracking_own_store_images does not build on main (it calls SetOwnStoreCompare and the new StoreOwnBytes form) fails 3/3 passes 3/3

Messages on main (store_between_walks passes there because main's repeated read records the store; it guards this PR's cutoff, as late_clear does):

store_window: the store another thread made in the page of a driver store during the store is in no memory delta and not in the snapshot, not 126
store_window_unwritten: the store another thread made during a driver store into a page the CPU has not written is in no memory delta and not in the snapshot, not 126
fresh_note: the written byte is in no memory delta
fresh_view: write tracking test failed: pages only a fresh collect took were not listed

With the three tracker commits reverted on this head (git revert --no-commit of the keep-guest, store-compare and fresh-collect fixes; GuestMemory.cpp then equals main's apart from the StoreOwnBytes form refactor), the same four fail with the same messages, and also:

store_between_walks: the last memory delta holding the page has byte 0, not the 107 the CPU stored between the walks of a driver store
own_store_images: write tracking test failed: a store another thread made beside a driver store during the store did not list exactly its page; ...

Each term of the tracker change, dropped one at a time (incremental build of the two test executables and libs), turns a named row red. 31 drop runs (29 distinct terms) on 2710134746 (D14 and Dkeep again on this head), each red: the window-page note and listing (D1, D2, D19), the held stamp kind (D3, D9a, D9b), the window passed to the second walk (D4), which stores take an image (D5, D6, D20, D21), the store and page offsets into the image (D7, D23), the empty-image check before the compare (D8), each store's own bytes applied to its image (D10-D14), the recorder turning the compare on (D15), the fresh and CPU block-stamp admission terms (D16, D17, and the same two again as TB-no-stamp-admission and TB-no-cpu-admission), the whole-clip fallback condition (D18), the copy itself (D22), the keep-guest rule (Dkeep), the switch forced on, default and setter (Don), the compare forced on outside a capture (Dcmp), and the switch cleared in finish() (Dfin) and in stop() (Dstop). For example Dstop: store_window_stopped: a driver store made after the capture stopped was listed as a CPU write; Dkeep: own_store_images: a keep-guest write-back that kept a guest byte was listed as a CPU write.

ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 ctest --test-dir build -R "frame_(replay|capture)|^agc_write_tracking|^agc_(resident_direct_remap|rewatched_direct_shared|import_alias_shared|compared_shared_generations)$", 3 runs per build, then one run with VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation and -V, a local Vulkan-ValidationLayers build, implicit layers disabled and VK_LOADER_DEBUG=layer:

build tests passed, 3 runs passed with the layer VUID- lines "was not found but was requested" lines
main 91ecd2d974 23 23, 23, 23 23 0 0
this PR 702492e63e 36 36, 36, 36 36 0 0

No test in this set creates a Vulkan instance (the loader inserted the layer 0 times in both logs), so the layer had nothing to check here.

ANYPS5_REQUIRE_VULKAN=1 ctest -R "^(agc|shader)_" on the previous local revision 2710134746 (the same code; this head adds one premise check to a test and rewords a debt entry): 1310 passed, 15 skipped, 3 failed of 1328. The three, agc_driver_direct_write_completion, agc_driver_scratch_pool and agc_driver_sample_order_grid_reference, also fail on main 91ecd2d974 on this GPU (3 of 3 runs each).

Linux: a WSL2 build of this head (Ubuntu 24.04, lavapipe) compiles, and gpu_write_before_delta, calls_v1, order, zero, tokens, blocking, unwatched and agc_frame_capture pass there (3 runs with APS5_WRITE_WATCH_IMPORTS=unwatch, 1 without). agc_write_tracking skips and the capture rows cannot start: this WSL2 kernel (5.15) has no asynchronous userfaultfd write protection, so the guest write watch is unavailable. The new rows have not run on Linux.

Persona 5 Royal (PPSA05110), casino gameplay, shared GPU, one 20-frame capture per build, each started 45 s after the gameplay HUD appeared in its own run of the same route: main 91ecd2d974 recorded 1,554 memory groups and 1,114.4 MiB of deltas, this head 692 and 610.6 MiB (capture.json memory_groups, delta_bytes). The runs reached the scene separately, so the title's own work differs between them. agc_frame_replay --strict of each capture through its own build, twice each: 20 frames and 120 submits, 0 unfinished, 0 pacing timeouts, and both reference frames pixel-identical (pixels_identical 1.000000).

Not tested: macOS (frame capture throws there), a native Linux run, other GPUs. @chitters2004's runs of his two tests on an RTX 3080 (c9a87b435c, 5458ad80b2) and TechLevelZero's NVIDIA CI run of c7a4fc97bb are on earlier revisions.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: AMD Radeon RX 6700 XT (gfx1031), AMD Windows driver 32.0.21045.16010, Windows 11 26200
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5101276515 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14137). Originally posted by [thuanquang](https://github.com/thuanquang) on 2026-10-31T20:30:34Z. --- ### What `docs/dev/BUILD.md` describes each memory delta of a frame capture as the guest pages the CPU wrote since the previous call that handed work to the GPU. On `main` each delta also collects again the pages the previous delta collected (line numbers on `main` `91ecd2d974`): - **Full deltas.** `emitDelta` gives every range `since = generation`, reads `mark = WriteGeneration()` before the walk and sets `generation = mark` after it (`FrameRecorder.cpp` L329-334). `CollectWrittenBlocks` raises the tracker generation and only then stamps the pages its walk finds (`GuestMemory.cpp` L1681, L1608-1610). So every page a delta's own walk reports carries a stamp newer than `mark`, and the next delta lists it again. - **Shader deltas** take `mark` the same way (L401, L409) and start from `generation` (L405), and `emitDelta` clears their marks (L335). A page a full delta collected is therefore collected again by the next shader delta of its 64 KiB block as well. - **Ranges added during the capture** are read whole without a collect (L432-451). Their pages written before the add come back in the next delta through their write-watch bits. Each repeat is read and written again, and a delta made only of repeats still waits for the driver to go idle before the call it precedes (L422), so that call is recorded with nothing in flight. In a Persona 5 Royal capture made on `main` at `86fb985abb` (the delta bookkeeping is unchanged since), the second full delta (group 47) holds every page of the first, 2,610.9 MiB by the chunk headers. This change: - keeps, for each watched or unwatched range, the generation its last `CollectWrittenBlocks` returned (read under the tracker lock after the walk), and starts the range's next collect there. `start()` takes these values from its reset walks; - keeps, for each shader block, the generation its last collect returned. A block lying wholly inside those ranges starts from the newer of that value and the oldest value of its ranges, so it skips what their full deltas took. Any other block starts from its own value, and the first time from the tracker generation read right after the reset walks (`GuestMemory::TrackerGeneration`), so it never lists a page stamped before the capture started; - collects a watched or unwatched range the registry gained just before reading it, so the next delta takes only what was written after that collect, and writes every 64 KiB block of such a range in the delta that adds it, zero or not. `main` writes only the nonzero blocks there and records what the CPU wrote before the add, a clear included, in its next delta. That delta now starts after the add's collect, so a skipped all-zero block would keep what the replay already holds at its address (found by @chitters2004; `late_clear` below); - reads every delta through `GuestMemory::ReadCommitted`, as the snapshot already does. A delta read on `main` uses `ReadCommittedUnsynced`, so it can miss a result the driver still keeps on the GPU for that page (`pending_result` below). Since the next delta no longer reads the page again, the read now stores those results first; - has the replay land those results too: `agc_frame_replay` reads each delta chunk, calls `AgcDriverPrepareCommandWrite_nid_no_patch` over its range and then copies it, the order #12567's `restoreGroup` uses. `calls.bin` becomes format 2 (`aps5-frame-calls 2`); `FrameCaptureReader` still reads format 1 and reports the format (`Version()`), and the replay refuses a format 1 capture before it restores any memory, since such a capture does not record whether GPU writes had landed before each delta was read. With the `ReadCommitted` read in the bullet above, these are the four items @chitters2004 asked for on #12567 and we agreed on in #12568's thread; - closes the two tracker gaps @oneandonlydean named, which `main`'s repeated read covered: - **a store between the two walks of `GuestMemory::StoreOwnBytes`.** While a capture records (the recorder turns `GuestMemory::SetOwnStoreCompare` on in `start()` before its reset collects, and off in `stop()` and `finish()`), a driver store from the CPU that gives its bytes (`Write`, `WriteChanged`, the guest label store, the span form of `StoreOwnBytes`, and a new `StoreOwnBytes` form whose callback writes the bytes it stores into a span it receives) copies its page-rounded range before its first walk and applies its own bytes to the copy; a page its second walk takes that then differs from the copy, or can no longer be read, is noted, and `CollectWrittenBlocks` lists it. A store that gives no bytes (MEM_SEMAPHORE signal and wait, buffer copies on the CPU, and `main`'s compare-exchange write-back `WriteChangedIfHeld`, which stops at the first byte it loses) notes every page its second walk takes. A keep-guest write-back (`WriteChangedKeepingGuest`, #6185) leaves the guest's bytes in its copy, as its store does. No stamp changes, so `UnchangedSince`, `StoredOver`, `UnchangedSinceCollected` and `ChangedBlocks` answer as before, with or without a capture; - **a page only a `MarkWritten` fresh collect noted.** `CollectWrittenBlocks` also admits a 64 KiB block whose block stamp is newer than `since`, so such a page is listed: the fresh collect raises the block stamp, not the CPU block stamp the loop checked first. The whole clip of a block is listed only when its CPU block stamp is newer and no page in the clip has a newer CPU note. `agc_driver_frame_replay_store_between_walks` and `agc_driver_frame_replay_fresh_note` are @chitters2004's tests (`c9a87b435c`, unchanged). His fix (`5458ad80b2`) is not taken; the reason and the measurements are in the comment with this push. Not changed here: - A page first collected by a shader delta is collected again by the next full delta of its range, and a page a full delta collected is collected again by the next shader delta of a block its range covers only in part. - When a 64 KiB tracker block holds parts of two ranges, a new CPU stamp in one part makes the next collect of the other range list its part of the block whole. - Pages a host import's write-watch window stamps during the capture are collected like CPU writes. - A CPU store to a page that leaves the write watch (`Unwatch`, an import that unwatches it, a failed fresh collect) after a delta collected it is not recorded until the tracker notes the page again; `main` read such a page once more in the next delta. A delta's own walk also skips every 64 KiB block that holds such a page, as on `main`. Debt entry "Pages that leave the write watch during a frame capture". - When a driver store from the CPU gives its bytes, a store another thread makes during it that puts back bytes a GPU write into a watched host import changed during that store leaves the page equal to the store's copy, so it is recorded only when another store gets the page listed; `main` also recorded it when the previous delta had found the page written. Debt entry "Driver stores during a frame capture". - The pages of stores that give no bytes (MEM_SEMAPHORE packets, buffer copies the driver runs on the CPU, `WriteChangedIfHeld`) are listed after every such store, and the replay writes the captured bytes there over what its own semaphore or copy stored. How much of the casino capture below they make up, and whether they change replayed waits, is not measured. - Import-window walks also note the pages they find changed in the new `windowPages` map in every run; only `CollectWrittenBlocks` reads it, and its memory is not measured. - In every run, a CPU store another thread makes into a page while a driver store from the CPU covers it still counts as the driver's for `UnchangedSinceCollected`, the CPU flag of `ChangedBlocks` and `StoredOver` beside the stored bytes, as on `main`. This PR changes only what `CollectWrittenBlocks` lists while a capture records. Debt entry "CPU stores during driver stores". - No row stores from another thread during `Write`, `WriteChanged`, the guest label store or the span form of `StoreOwnBytes`. On Windows none of them runs anything between its two walks, and `WriteChanged` and the label store run nothing there on any OS; on Linux the span form and a `Write` of 4 KiB or more call the shared-backing writer between the walks, which no row drives. Each store builds its copy from its own input (source, value, current), never by reading memory back. - No row can fail when the copy is taken after the first walk instead of before it, or when `start()` turns the switch on after its reset collects instead of before them. - The capture-time cost of the copies: in one casino capture per build (separate runs of the route below), this head recorded 692 groups and 610.6 MiB in 23.8 s (snapshot 13.1 s), and a local build of it whose recorder never turns the compare on recorded 719 groups and 618.1 MiB in 25.9 s (snapshot 13.9 s). One run each, so this shows no large cost, not a small one. - A host or section range the registry gained during the capture is still added with only its nonzero 64 KiB blocks and not collected afterwards, as on `main`. - On Windows a page that the snapshot or an added range's read touches first can be reported as written, so the next delta may record it once more. Side effect: a call whose delta would have held only repeated pages now gets no memory record and no idle wait, so a new capture records it at the depth the title had; a delta made only of pages of stores that give no bytes still gets both. That is not the aim of this PR: #12568 makes every full delta wait for a settled driver while work is in flight, and recording the in-flight depth stays with the follow-up stacked on #12568 (#15136). Overlap (trial merges of each open PR's head with this head, listing only conflicts this PR adds to what the PR already has with `main` `91ecd2d974`): - #14899 (merged) changed the tracker generations to 64 bits in the same `GuestMemory.cpp` struct and write-tracking test registration; the merge of `main` keeps both sides. - #12567: the delta copy in `tools/FrameReplay.cpp`, the mode list of the state tests and the frame capture paragraph of `docs/dev/BUILD.md`. It has the identical `readGuest` change and already flushes before each delta copy in `restoreGroup`; whichever merges second drops its copy. - #12568 (stacked on #12567): `FrameRecorder.hpp`/`.cpp`, the tool, the mode list and BUILD.md. As before, it moves the `CollectWrittenBlocks` loop behind its settled wait and collects per 64 KiB piece; whichever merges second keeps a `since` per collect call set to the value that call returned, gives every piece a starting value from a reset walk, drops `shaderMarks.clear()` from `emitDelta` and passes `!collected && zero` for added ranges. I'll post a rebase of #12568 onto this PR. - #12318 replaces the same delta-copy loop with its own `restoreGroup`, which has no flush; #12567, stacked on it, adds the flush there. Whichever of this PR and #12318 merges second keeps the `AgcDriverPrepareCommandWrite_nid_no_patch` call before each delta copy. - #15136 (mine, draft, on #12568) also touches the calls format (it writes version 2 too and moves to 3 when restacked onto this PR) and `FrameRecorder::finish()`. - #13021, and #13023 which contains it, change `storeOwn`'s signature next to this PR's new `imaged` parameter and the compare switch in `GuestMemory.cpp`. - #12452 adds a bounds check at the top of `WindowCopy::Holds`, where this PR adds the store-image compare. - #12565 (`FrameRecorder.hpp`, BUILD.md), #13984 (mine; `FrameReplayState.cpp`), #12696 and #11436 (the mode list) conflict mechanically. - #11435 and #6186 add no conflict beyond the ones they have with `main`. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Windows 11 26200, Ryzen 5 5600X, Radeon RX 6700 XT (gfx1031), AMD driver 32.0.21045.16010, WinLibs GCC 15.2.0 r7, Release, `BUILD_TESTING=ON`, full builds with submodules at their pins: `main` `91ecd2d9743b831b575d293e6c8fafbe737e1e88` (merged into this branch) and this PR's head `702492e63e`. **This head (`ca4553365f`) merges `main` `1c8c0efc8c`** to resolve the conflict with #13021 in `GuestMemory.cpp`: `storeOwn` keeps #13021's `complete` flag next to this PR's `imaged` flag, and `WriteChangedIfHeld` (new on `main`) stores through the form that gives no bytes. On it, the focused set below passes 36 of 36 in 3 of 3 runs (`main` `1c8c0efc8c`: 23 of 23), `agc_driver_native_multisample_depth` (a `WriteChangedIfHeld` caller) 1 of 1 in 3 runs on both, the validation-layer run shows 0 `VUID-` lines on both, and `git diff --check` is clean. Every other result below is from the previous head `702492e63e` (`main` `91ecd2d974` merged), whose capture and tracker code is the same apart from that store. Modes of `agc_driver_frame_replay_state_tests` drive `FrameRecorder` directly and need no GPU. From the previous revision: - `agc_driver_frame_replay_once` writes a page before each of two suspend points and commits a range during the capture. Between the suspend points it writes a page in the second of the two 64 KiB blocks a shader header marks, and registers that shader twice; the header shares the first page's block. The page written before each suspend point, and the written page of the added range, must each be in exactly one memory delta, the one before their suspend point, and the second registration must collect nothing. Every page of both ranges is written before the capture or before the add, so no snapshot or delta read is a page's first access. - `agc_driver_frame_replay_pending_result` installs a flush hook that stores a result word over a page the CPU wrote, standing in for a storage result the driver keeps on the GPU until the page is read. The delta before the first suspend point, and the delta that adds a range committed during the capture, must each hold the stored value. - `agc_driver_frame_replay_partly_covered` writes a 16 KiB allocation before the capture and registers a shader whose header lies in it, so the header's 64 KiB block is only partly inside the captured ranges. The written page must be in no memory delta, since the snapshot holds it. - `agc_driver_frame_replay_late_clear` (@chitters2004's test from this thread) starts the capture, then commits a range, writes a page in it, registers a shader whose header lies in the 64 KiB block before that page's block, clears the page and reaches two suspend points. The last memory delta holding the page must hold the clear. New in this push: - `gpu_write_before_delta`: a delta copy over a GPU write the replay still has pending must hold the delta's bytes; `calls_v1`: a calls format 1 capture is refused before any memory is restored. - `store_between_walks`, `fresh_note` (@chitters2004's). - `store_window`: a label store through the `StoreOwnBytes` form that gives no bytes while another thread writes the same page, then four driver stores with given bytes into pages nothing else writes; the other thread's byte must be in a delta and the four pages in none, and a driver store after `finish()` must not be listed. - `store_window_unwritten`: the same store from another thread into a page the CPU has not written. - `store_window_stopped`: the capture stops when it starts (`APS5_FRAME_CAPTURE_MIN_FREE_BYTES` above any free space); a driver store after that must not be listed. - `agc_write_tracking_fresh_view` (Windows): a section view whose first page alone is collected before a GPU write's fresh collect takes the rest; those pages must be listed. `agc_write_tracking` gains two guards: a page only an import window stamped is listed, a block only a GPU write stamped lists nothing. - `agc_write_tracking_own_store_images` (Windows; on Linux the last check of `agc_write_tracking`): a driver store made before the compare is on lists nothing; then with it on, a `Write`, a store of given bytes, a label store, a write-back and a keep-guest write-back over a page the guest wrote list nothing; a store from another thread beside the bytes of a two-page driver store lists only its page; one over a driver store's bytes is listed; one that undoes a store which gives no bytes is listed; a listed page is not listed again. Each row, 3 runs per tree: | row | `main` `91ecd2d974` + the rows | this head, tracker changes reverted | this head | |---|---|---|---| | `store_between_walks` | passes 3/3 | fails 3/3 | passes 3/3 | | `fresh_note` | fails 3/3 | fails 3/3 | passes 3/3 | | `store_window` | fails 3/3 | fails 3/3 | passes 3/3 | | `store_window_unwritten` | fails 3/3 | fails 3/3 | passes 3/3 | | `store_window_stopped` | not run | passes 3/3 | passes 3/3 | | `agc_write_tracking_fresh_view` | fails 3/3 | fails 3/3 | passes 3/3 | | `agc_write_tracking_own_store_images` | does not build on `main` (it calls `SetOwnStoreCompare` and the new `StoreOwnBytes` form) | fails 3/3 | passes 3/3 | Messages on `main` (`store_between_walks` passes there because `main`'s repeated read records the store; it guards this PR's cutoff, as `late_clear` does): ``` store_window: the store another thread made in the page of a driver store during the store is in no memory delta and not in the snapshot, not 126 store_window_unwritten: the store another thread made during a driver store into a page the CPU has not written is in no memory delta and not in the snapshot, not 126 fresh_note: the written byte is in no memory delta fresh_view: write tracking test failed: pages only a fresh collect took were not listed ``` With the three tracker commits reverted on this head (`git revert --no-commit` of the keep-guest, store-compare and fresh-collect fixes; `GuestMemory.cpp` then equals `main`'s apart from the `StoreOwnBytes` form refactor), the same four fail with the same messages, and also: ``` store_between_walks: the last memory delta holding the page has byte 0, not the 107 the CPU stored between the walks of a driver store own_store_images: write tracking test failed: a store another thread made beside a driver store during the store did not list exactly its page; ... ``` Each term of the tracker change, dropped one at a time (incremental build of the two test executables and `libs`), turns a named row red. 31 drop runs (29 distinct terms) on `2710134746` (D14 and Dkeep again on this head), each red: the window-page note and listing (D1, D2, D19), the held stamp kind (D3, D9a, D9b), the window passed to the second walk (D4), which stores take an image (D5, D6, D20, D21), the store and page offsets into the image (D7, D23), the empty-image check before the compare (D8), each store's own bytes applied to its image (D10-D14), the recorder turning the compare on (D15), the fresh and CPU block-stamp admission terms (D16, D17, and the same two again as TB-no-stamp-admission and TB-no-cpu-admission), the whole-clip fallback condition (D18), the copy itself (D22), the keep-guest rule (Dkeep), the switch forced on, default and setter (Don), the compare forced on outside a capture (Dcmp), and the switch cleared in `finish()` (Dfin) and in `stop()` (Dstop). For example Dstop: `store_window_stopped: a driver store made after the capture stopped was listed as a CPU write`; Dkeep: `own_store_images: a keep-guest write-back that kept a guest byte was listed as a CPU write`. `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 ctest --test-dir build -R "frame_(replay|capture)|^agc_write_tracking|^agc_(resident_direct_remap|rewatched_direct_shared|import_alias_shared|compared_shared_generations)$"`, 3 runs per build, then one run with `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` and `-V`, a local Vulkan-ValidationLayers build, implicit layers disabled and `VK_LOADER_DEBUG=layer`: | build | tests | passed, 3 runs | passed with the layer | `VUID-` lines | "was not found but was requested" lines | |---|---|---|---|---|---| | `main` `91ecd2d974` | 23 | 23, 23, 23 | 23 | 0 | 0 | | this PR `702492e63e` | 36 | 36, 36, 36 | 36 | 0 | 0 | No test in this set creates a Vulkan instance (the loader inserted the layer 0 times in both logs), so the layer had nothing to check here. `ANYPS5_REQUIRE_VULKAN=1 ctest -R "^(agc|shader)_"` on the previous local revision `2710134746` (the same code; this head adds one premise check to a test and rewords a debt entry): 1310 passed, 15 skipped, 3 failed of 1328. The three, `agc_driver_direct_write_completion`, `agc_driver_scratch_pool` and `agc_driver_sample_order_grid_reference`, also fail on `main` `91ecd2d974` on this GPU (3 of 3 runs each). Linux: a WSL2 build of this head (Ubuntu 24.04, lavapipe) compiles, and `gpu_write_before_delta`, `calls_v1`, `order`, `zero`, `tokens`, `blocking`, `unwatched` and `agc_frame_capture` pass there (3 runs with `APS5_WRITE_WATCH_IMPORTS=unwatch`, 1 without). `agc_write_tracking` skips and the capture rows cannot start: this WSL2 kernel (5.15) has no asynchronous userfaultfd write protection, so the guest write watch is unavailable. The new rows have not run on Linux. Persona 5 Royal (PPSA05110), casino gameplay, shared GPU, one 20-frame capture per build, each started 45 s after the gameplay HUD appeared in its own run of the same route: `main` `91ecd2d974` recorded 1,554 memory groups and 1,114.4 MiB of deltas, this head 692 and 610.6 MiB (`capture.json` `memory_groups`, `delta_bytes`). The runs reached the scene separately, so the title's own work differs between them. `agc_frame_replay --strict` of each capture through its own build, twice each: 20 frames and 120 submits, 0 unfinished, 0 pacing timeouts, and both reference frames pixel-identical (`pixels_identical` 1.000000). Not tested: macOS (frame capture throws there), a native Linux run, other GPUs. @chitters2004's runs of his two tests on an RTX 3080 (`c9a87b435c`, `5458ad80b2`) and TechLevelZero's NVIDIA CI run of `c7a4fc97bb` are on earlier revisions. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: AMD Radeon RX 6700 XT (gfx1031), AMD Windows driver 32.0.21045.16010, Windows 11 26200 - [x] AI-assisted: yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
XairRrR commented 2026-11-03 13:03:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T13:03:58Z.

Review: APPROVED


Reviewed — approved

The merged tree builds, and all 28 frame capture/replay and write-tracking tests pass on native Linux with the guest write watch active. That includes the capture rows the description says have not run on Linux. A three-stage negative control made every new row fail, and I found nothing blocking.

What I ran

Head 702492e63ea6f9b96280654c1b1733a02e059377, main 4f41f4c375f5abb487dbd184fbc150f31994d762, merged with --no-ff (tree 23da7e8b9297967958c6b8f5082d0550652a760e). Machine: Debian 13 VM, 32 vCPU Xeon Gold 6136, GCC 14.2.0, Release, Ninja, BUILD_TESTING=ON, lavapipe (Mesa 26.1.6), no GPU.

git diff --check 4f41f4c375f5abb487dbd184fbc150f31994d762...702492e63ea6f9b96280654c1b1733a02e059377
python3 tools/check_conventions.py --base 4f41f4c375f5abb487dbd184fbc150f31994d762
ANYPS5_REQUIRE_VULKAN=1 ctest --test-dir build -j8 --test-load 32 --output-on-failure -R "frame_(replay|capture)|^agc_write_tracking"
ctest --test-dir build -V -R "agc_driver_frame_replay_(store_window|late_clear|once)$"
# negative control, stages A-C below, each followed by:
ninja -C build -j32 -l32 agc_driver_frame_replay_state_tests agc_write_tracking_tests
ctest --test-dir build -j8 --test-load 32 --output-on-failure -R "agc_driver_frame_replay_|^agc_write_tracking"
# restore, then:
ninja -C build -j32 -l32 agc_driver_frame_replay_state_tests agc_write_tracking_tests libs
git status --porcelain

Results

Check Result
git diff --check clean
check_conventions.py All conventions checks passed
Configure, build, libs (script) passed
Selected tests (script): 2216 run 0 new failures, 0 timeouts. The 7 known failures also fail on main (agc_driver_division, the denormal-mode rows, vector_constant_factor_tininess, one unwrap test)
Validation layer (script): 770 tests, layer loaded in 769, missing in none 0 tests with new VUID- lines
Focused set: frame replay/capture plus agc_write_tracking* 28/28 pass
Capture rows really record on this host yes, see below
The capture rows run on native Linux (excerpt)
1747: [frame-capture] started at frame boundary 1: 1 ranges, 0.1 MiB snapshot in 0.0 s
1747: [frame-capture] 1 frames, 3 calls, 2 memory deltas (1.1 MiB), 1.2 MiB raw, 0.0 MiB stored in .../frame-replay-late_clear
1747: frame replay state test passed
1751: [frame-capture] started at frame boundary 1: 2 ranges, 0.1 MiB snapshot in 0.0 s
1751: [frame-capture] 1 frames, 1 calls, 1 memory deltas (0.0 MiB), 0.1 MiB raw, 0.0 MiB stored in .../frame-replay-store_window

agc_write_tracking reports Passed, not Skipped, so on Linux it also runs CheckOwnStoreImages.

The description says the new capture rows and agc_write_tracking have not run on Linux, because the author's WSL2 kernel has no asynchronous userfaultfd write protection. On this kernel (6.12) the write watch is available. Here they run and pass: once, pending_result, partly_covered, late_clear, store_between_walks, store_window, store_window_unwritten, store_window_stopped, gpu_write_before_delta, calls_v1, agc_frame_capture and agc_write_tracking, including the Linux tail of own_store_images. fresh_note, agc_write_tracking_fresh_view and the separate own_store_images registration are Windows-only and were not run.

Negative control

The new tests call the new API (SetOwnStoreCompare, the span form of StoreOwnBytes, FrameCaptureReader::Version()). Restoring every production file from main would therefore not compile, so I reverted in three stages.

A. FrameRecorder.hpp, FrameRecorder.cpp and tools/FrameReplay.cpp restored from main (tracker and reader as merged). Six rows failed:

Stage A failures
store_window_unwritten: the store another thread made during a driver store into a page the CPU has not written is in no memory delta and not in the snapshot, not 126
pending_result: the memory delta before the first suspend point read the page before the result pending over it was stored: it holds 0, not 1; the memory delta that added the range committed during the capture read the page before the result pending over it was stored: it holds 0, not 1
calls_v1: the replay restored a calls format 1 capture, which does not record whether GPU writes had landed before its memory deltas were read
gpu_write_before_delta: the replay restored a memory delta while a GPU write over its range was still pending, and the next read landed that write over it: the page holds byte 90, not the 0 the capture recorded after the write
store_window: the store another thread made in the page of a driver store during the store is in no memory delta and not in the snapshot, not 126
once: the page written before the first suspend point is in memory delta groups 1 2 4, not only in group 1; ... the second registration of the shader collected its blocks again

late_clear, store_between_walks and partly_covered pass with main's recorder. This matches the description: main's repeated read covers them, and they guard the new cutoff.

B. Merged recorder, with two tracker terms disabled in GuestMemory.cpp: compare forced to false in storeOwn, and the block-stamp admission in CollectWrittenBlocks removed (if (!cpu) continue;). Four rows failed: store_window, store_window_unwritten, store_between_walks ("has byte 0, not the 107"), and agc_write_tracking ("a store another thread made beside a driver store during the store did not list exactly its page; ... over a driver store's bytes ... was not listed; ... that undid a driver store which gives no bytes was not listed").

C. Two single terms dropped: the keep-guest condition in writeChanged's image update, and || collected in the added-range loop. Two rows failed: agc_write_tracking ("a keep-guest write-back that kept a guest byte was listed as a CPU write") and late_clear ("group 1 of 1 holding it) has byte 90, not the 0").

After restoring with git show 23da7e8b…:<path>, git status --porcelain was empty, the rebuild including libs succeeded, and the focused set passed 28/28 again.

Findings

Blocking

None.

Non-blocking

  • The compare switch stays on if start() throws after turning it on. FrameRecorder::start() calls GuestMemory::SetOwnStoreCompare(true) at core/libs/prx/libSceAgcDriver/Execution/src/FrameRecorder.cpp:548. It then creates the writer at line 553, and that can throw: FrameRecorder.cpp L547-L553. FrameCaptureWriter's constructor throws when the capture directory cannot be created (FrameCapture.cpp L202-L205). On that path neither stop() nor finish() runs. The process-wide switch then stays on with no capture, so every driver store from the CPU keeps copying its pages under the tracker lock and noting pages in windowPages. On main this throw left no global state behind.
    • Suggested fix: turn the switch on right after the writer exists and before the reset collects at line 556. That keeps the order the description asks for (on before the reset collects). Alternatively, use a guard that turns it off when start() exits by an exception.

Not verified

  • The Windows-only rows (fresh_note, agc_write_tracking_fresh_view, the own_store_images registration) and any Windows-only paths of the store compare (the section view and fresh-collect cases): this host is Linux.
  • The Persona 5 Royal capture sizes (1,114.4 MiB on main against 610.6 MiB here) and the --strict replays: I did not launch any title.
  • The capture-time cost of the store copies, and the memory windowPages uses in long runs, beyond the author's single-run figures.
  • The validation comparison covers 770 tests. None of the focused frame capture tests creates a Vulkan instance, so the layer had nothing to check for them, as the author also notes.
  • Behaviour on hardware GPUs: lavapipe only here. Two contributor CI runs on this head, AMD RX 6300 (RADV) and NVIDIA RTX 2000 Ada, reported 0 new failures and no new validation IDs.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5752630834 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14137#pullrequestreview-5752630834). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-11-03T13:03:58Z. **Review:** APPROVED --- # Reviewed — approved The merged tree builds, and all 28 frame capture/replay and write-tracking tests pass on native Linux with the guest write watch active. That includes the capture rows the description says have not run on Linux. A three-stage negative control made every new row fail, and I found nothing blocking. ## What I ran Head `702492e63ea6f9b96280654c1b1733a02e059377`, `main` `4f41f4c375f5abb487dbd184fbc150f31994d762`, merged with `--no-ff` (tree `23da7e8b9297967958c6b8f5082d0550652a760e`). Machine: Debian 13 VM, 32 vCPU Xeon Gold 6136, GCC 14.2.0, Release, Ninja, `BUILD_TESTING=ON`, lavapipe (Mesa 26.1.6), no GPU. ``` git diff --check 4f41f4c375f5abb487dbd184fbc150f31994d762...702492e63ea6f9b96280654c1b1733a02e059377 python3 tools/check_conventions.py --base 4f41f4c375f5abb487dbd184fbc150f31994d762 ANYPS5_REQUIRE_VULKAN=1 ctest --test-dir build -j8 --test-load 32 --output-on-failure -R "frame_(replay|capture)|^agc_write_tracking" ctest --test-dir build -V -R "agc_driver_frame_replay_(store_window|late_clear|once)$" # negative control, stages A-C below, each followed by: ninja -C build -j32 -l32 agc_driver_frame_replay_state_tests agc_write_tracking_tests ctest --test-dir build -j8 --test-load 32 --output-on-failure -R "agc_driver_frame_replay_|^agc_write_tracking" # restore, then: ninja -C build -j32 -l32 agc_driver_frame_replay_state_tests agc_write_tracking_tests libs git status --porcelain ``` ## Results | Check | Result | |---|---| | `git diff --check` | clean | | `check_conventions.py` | All conventions checks passed | | Configure, build, `libs` (script) | passed | | Selected tests (script): 2216 run | 0 new failures, 0 timeouts. The 7 known failures also fail on `main` (`agc_driver_division`, the denormal-mode rows, `vector_constant_factor_tininess`, one unwrap test) | | Validation layer (script): 770 tests, layer loaded in 769, missing in none | 0 tests with new `VUID-` lines | | Focused set: frame replay/capture plus `agc_write_tracking*` | 28/28 pass | | Capture rows really record on this host | yes, see below | <details><summary>The capture rows run on native Linux (excerpt)</summary> ``` 1747: [frame-capture] started at frame boundary 1: 1 ranges, 0.1 MiB snapshot in 0.0 s 1747: [frame-capture] 1 frames, 3 calls, 2 memory deltas (1.1 MiB), 1.2 MiB raw, 0.0 MiB stored in .../frame-replay-late_clear 1747: frame replay state test passed 1751: [frame-capture] started at frame boundary 1: 2 ranges, 0.1 MiB snapshot in 0.0 s 1751: [frame-capture] 1 frames, 1 calls, 1 memory deltas (0.0 MiB), 0.1 MiB raw, 0.0 MiB stored in .../frame-replay-store_window ``` `agc_write_tracking` reports Passed, not Skipped, so on Linux it also runs `CheckOwnStoreImages`. </details> The description says the new capture rows and `agc_write_tracking` have not run on Linux, because the author's WSL2 kernel has no asynchronous userfaultfd write protection. On this kernel (6.12) the write watch is available. Here they run and pass: `once`, `pending_result`, `partly_covered`, `late_clear`, `store_between_walks`, `store_window`, `store_window_unwritten`, `store_window_stopped`, `gpu_write_before_delta`, `calls_v1`, `agc_frame_capture` and `agc_write_tracking`, including the Linux tail of `own_store_images`. `fresh_note`, `agc_write_tracking_fresh_view` and the separate `own_store_images` registration are Windows-only and were not run. ## Negative control The new tests call the new API (`SetOwnStoreCompare`, the span form of `StoreOwnBytes`, `FrameCaptureReader::Version()`). Restoring every production file from `main` would therefore not compile, so I reverted in three stages. **A. `FrameRecorder.hpp`, `FrameRecorder.cpp` and `tools/FrameReplay.cpp` restored from `main`** (tracker and reader as merged). Six rows failed: <details><summary>Stage A failures</summary> ``` store_window_unwritten: the store another thread made during a driver store into a page the CPU has not written is in no memory delta and not in the snapshot, not 126 pending_result: the memory delta before the first suspend point read the page before the result pending over it was stored: it holds 0, not 1; the memory delta that added the range committed during the capture read the page before the result pending over it was stored: it holds 0, not 1 calls_v1: the replay restored a calls format 1 capture, which does not record whether GPU writes had landed before its memory deltas were read gpu_write_before_delta: the replay restored a memory delta while a GPU write over its range was still pending, and the next read landed that write over it: the page holds byte 90, not the 0 the capture recorded after the write store_window: the store another thread made in the page of a driver store during the store is in no memory delta and not in the snapshot, not 126 once: the page written before the first suspend point is in memory delta groups 1 2 4, not only in group 1; ... the second registration of the shader collected its blocks again ``` </details> `late_clear`, `store_between_walks` and `partly_covered` pass with `main`'s recorder. This matches the description: `main`'s repeated read covers them, and they guard the new cutoff. **B. Merged recorder, with two tracker terms disabled in `GuestMemory.cpp`:** `compare` forced to `false` in `storeOwn`, and the block-stamp admission in `CollectWrittenBlocks` removed (`if (!cpu) continue;`). Four rows failed: `store_window`, `store_window_unwritten`, `store_between_walks` ("has byte 0, not the 107"), and `agc_write_tracking` ("a store another thread made beside a driver store during the store did not list exactly its page; ... over a driver store's bytes ... was not listed; ... that undid a driver store which gives no bytes was not listed"). **C. Two single terms dropped:** the keep-guest condition in `writeChanged`'s image update, and `|| collected` in the added-range loop. Two rows failed: `agc_write_tracking` ("a keep-guest write-back that kept a guest byte was listed as a CPU write") and `late_clear` ("group 1 of 1 holding it) has byte 90, not the 0"). After restoring with `git show 23da7e8b…:<path>`, `git status --porcelain` was empty, the rebuild including `libs` succeeded, and the focused set passed 28/28 again. ## Findings ### Blocking None. ### Non-blocking - **The compare switch stays on if `start()` throws after turning it on.** `FrameRecorder::start()` calls `GuestMemory::SetOwnStoreCompare(true)` at `core/libs/prx/libSceAgcDriver/Execution/src/FrameRecorder.cpp:548`. It then creates the writer at line 553, and that can throw: [FrameRecorder.cpp L547-L553](https://github.com/boykopovar/AnyPS5/blob/702492e63ea6f9b96280654c1b1733a02e059377/core/libs/prx/libSceAgcDriver/Execution/src/FrameRecorder.cpp#L547-L553). `FrameCaptureWriter`'s constructor throws when the capture directory cannot be created ([FrameCapture.cpp L202-L205](https://github.com/boykopovar/AnyPS5/blob/702492e63ea6f9b96280654c1b1733a02e059377/core/libs/prx/libSceAgcDriver/Execution/src/FrameCapture.cpp#L202-L205)). On that path neither `stop()` nor `finish()` runs. The process-wide switch then stays on with no capture, so every driver store from the CPU keeps copying its pages under the tracker lock and noting pages in `windowPages`. On `main` this throw left no global state behind. - Suggested fix: turn the switch on right after the writer exists and before the reset collects at line 556. That keeps the order the description asks for (on before the reset collects). Alternatively, use a guard that turns it off when `start()` exits by an exception. ## Not verified - The Windows-only rows (`fresh_note`, `agc_write_tracking_fresh_view`, the `own_store_images` registration) and any Windows-only paths of the store compare (the section view and fresh-collect cases): this host is Linux. - The Persona 5 Royal capture sizes (1,114.4 MiB on `main` against 610.6 MiB here) and the `--strict` replays: I did not launch any title. - The capture-time cost of the store copies, and the memory `windowPages` uses in long runs, beyond the author's single-run figures. - The validation comparison covers 770 tests. None of the focused frame capture tests creates a Vulkan instance, so the layer had nothing to check for them, as the author also notes. - Behaviour on hardware GPUs: lavapipe only here. Two contributor CI runs on this head, AMD RX 6300 (RADV) and NVIDIA RTX 2000 Ada, reported 0 new failures and no new validation IDs. <!-- anyps5-bots job=2222 head=702492e63ea6f9b96280654c1b1733a02e059377 -->
XairRrR commented 2026-11-03 23:43:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T23:43:46Z.

Review: APPROVED


Re-checked — approved

The only change since my last review is the merge of main 1c8c0efc8c (ca4553365f). It resolves the storeOwn conflict with #13021 correctly. The focused set passes on the merged tree, and the negative control still makes the tracker rows fail. One non-blocking finding from my last review is still open.

What changed since my last review

  • The range-diff shows commits 1–14 unchanged (f0ef36adee…702492e63e). The only new commit is the merge ca4553365f of main 1c8c0efc8c.
  • The merge resolution is in GuestMemory.cpp:
    • storeOwn now takes this PR's imaged flag together with #13021's complete default argument.
    • WriteChangedIfHeld, which is new on main, stores through the form that gives no bytes (storeOwn(address, size, false, …) at core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp:3170). That gives it an empty image. WindowCopy::Holds returns false for an empty image, so while a capture records, every page its second walk takes is listed. This matches the description and the debt entry: a compare-exchange write-back that can stop at the first lost byte has no complete image to compare against, so treating it like the MEM_SEMAPHORE and CPU-copy stores is the conservative choice.
  • The description and a comment now report results for this head (author-reported, Windows / RX 6700 XT).
  • No test file changed in the PR's own commits.

What I ran

Head ca4553365ffc41b27ee5aed87322616b071db376, main 1c8c0efc8c41314402e6966da5bef6ea3d639d10, merged tree 0d003ec7f41be0a5c2e7c456ca988f6c2878f520. Debian 13 VM, Xeon Gold 6136, GCC 14.2.0, Release, lavapipe, no GPU.

git diff --check 1c8c0efc8c41314402e6966da5bef6ea3d639d10...ca4553365ffc41b27ee5aed87322616b071db376
python3 tools/check_conventions.py --base 1c8c0efc8c41314402e6966da5bef6ea3d639d10
git diff 1c8c0efc8c41314402e6966da5bev... 0d003ec7f4... -- GuestMemory.cpp GuestMemory.hpp
ANYPS5_REQUIRE_VULKAN=1 ctest --test-dir build -j8 --test-load 32 --output-on-failure -R "frame_(replay|capture)|^agc_write_tracking|^agc_driver_native_multisample_depth$"
# negative control: compare forced to false in storeOwn
ninja -C build -j32 -l32 agc_driver_frame_replay_state_tests agc_write_tracking_tests
ctest --test-dir build -j8 --test-load 32 -R "agc_driver_frame_replay_(store_|once)|^agc_write_tracking$"
# restore with git show 0d003ec7f4…:<path>, then
ninja -C build -j32 -l32 agc_driver_frame_replay_state_tests agc_write_tracking_tests libs
ctest --test-dir build -j8 --test-load 32 -R "agc_driver_frame_replay_(store_|once)|^agc_write_tracking$"
git status --porcelain
Check Result
git diff --check clean
check_conventions.py All conventions checks passed
Configure, build, libs (script) passed
Selected tests (script): 2245 run 0 new failures, 0 timeouts. The 7 known failures also fail on main
Validation (script): 784 tests, layer loaded in 783, missing in none 1 test with new VUID- lines, agc_driver_image_gather_volume. That test came in with main's side of the merge (ImageGatherVolume.cpp is not in the PR's files) and is marked "test not run on main" because the baseline 1e658521a0 is older than main. It is not counted against this PR
Focused set, including agc_driver_native_multisample_depth (a WriteChangedIfHeld caller) 29/29 pass
Negative control after the merge 4 rows fail, as expected
Restore worktree clean, rebuild including libs OK, 6/6 pass
Negative control (compare forced off on the merged tree)
agc_driver_frame_replay_store_window_unwritten ...***Failed
agc_driver_frame_replay_store_between_walks ......***Failed
agc_driver_frame_replay_store_window .............***Failed
agc_write_tracking ...............................***Failed
33% tests passed, 4 tests failed out of 6

Previous findings

  • Still open (non-blocking): the compare switch stays on if start() throws after turning it on. GuestMemory::SetOwnStoreCompare(true) still runs at core/libs/prx/libSceAgcDriver/Execution/src/FrameRecorder.cpp:548, before std::make_unique<FrameCaptureWriter>(directory) at line 553, and the writer can throw: FrameRecorder.cpp L547-L553. The fix suggested last time still applies: turn the switch on after the writer exists and before the reset collects, or add a guard that turns it off when start() exits by an exception.

New findings

Blocking

None.

Non-blocking

None.

Not verified

  • The Windows-only rows (fresh_note, agc_write_tracking_fresh_view, the separate own_store_images registration): this host runs Linux.
  • Capture sizes and --strict replays on a title: I launched no title.
  • The capture-time cost of the full listing of WriteChangedIfHeld pages. It is not measured anywhere.
  • Hardware GPUs: I ran on lavapipe only. The contributor CI runs on AMD and NVIDIA are for the previous head 702492e63e.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5761075765 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14137#pullrequestreview-5761075765). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-11-03T23:43:46Z. **Review:** APPROVED --- # Re-checked — approved The only change since my last review is the merge of `main` `1c8c0efc8c` (`ca4553365f`). It resolves the `storeOwn` conflict with #13021 correctly. The focused set passes on the merged tree, and the negative control still makes the tracker rows fail. One non-blocking finding from my last review is still open. ## What changed since my last review - The range-diff shows commits 1–14 unchanged (`f0ef36adee`…`702492e63e`). The only new commit is the merge `ca4553365f` of `main` `1c8c0efc8c`. - The merge resolution is in `GuestMemory.cpp`: - `storeOwn` now takes this PR's `imaged` flag together with #13021's `complete` default argument. - `WriteChangedIfHeld`, which is new on `main`, stores through the form that gives no bytes (`storeOwn(address, size, false, …)` at `core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp:3170`). That gives it an empty image. `WindowCopy::Holds` returns false for an empty image, so while a capture records, every page its second walk takes is listed. This matches the description and the debt entry: a compare-exchange write-back that can stop at the first lost byte has no complete image to compare against, so treating it like the MEM_SEMAPHORE and CPU-copy stores is the conservative choice. - The description and a comment now report results for this head (author-reported, Windows / RX 6700 XT). - No test file changed in the PR's own commits. ## What I ran Head `ca4553365ffc41b27ee5aed87322616b071db376`, `main` `1c8c0efc8c41314402e6966da5bef6ea3d639d10`, merged tree `0d003ec7f41be0a5c2e7c456ca988f6c2878f520`. Debian 13 VM, Xeon Gold 6136, GCC 14.2.0, Release, lavapipe, no GPU. ``` git diff --check 1c8c0efc8c41314402e6966da5bef6ea3d639d10...ca4553365ffc41b27ee5aed87322616b071db376 python3 tools/check_conventions.py --base 1c8c0efc8c41314402e6966da5bef6ea3d639d10 git diff 1c8c0efc8c41314402e6966da5bev... 0d003ec7f4... -- GuestMemory.cpp GuestMemory.hpp ANYPS5_REQUIRE_VULKAN=1 ctest --test-dir build -j8 --test-load 32 --output-on-failure -R "frame_(replay|capture)|^agc_write_tracking|^agc_driver_native_multisample_depth$" # negative control: compare forced to false in storeOwn ninja -C build -j32 -l32 agc_driver_frame_replay_state_tests agc_write_tracking_tests ctest --test-dir build -j8 --test-load 32 -R "agc_driver_frame_replay_(store_|once)|^agc_write_tracking$" # restore with git show 0d003ec7f4…:<path>, then ninja -C build -j32 -l32 agc_driver_frame_replay_state_tests agc_write_tracking_tests libs ctest --test-dir build -j8 --test-load 32 -R "agc_driver_frame_replay_(store_|once)|^agc_write_tracking$" git status --porcelain ``` | Check | Result | |---|---| | `git diff --check` | clean | | `check_conventions.py` | All conventions checks passed | | Configure, build, `libs` (script) | passed | | Selected tests (script): 2245 run | 0 new failures, 0 timeouts. The 7 known failures also fail on `main` | | Validation (script): 784 tests, layer loaded in 783, missing in none | 1 test with new `VUID-` lines, `agc_driver_image_gather_volume`. That test came in with `main`'s side of the merge (`ImageGatherVolume.cpp` is not in the PR's files) and is marked "test not run on main" because the baseline `1e658521a0` is older than `main`. It is not counted against this PR | | Focused set, including `agc_driver_native_multisample_depth` (a `WriteChangedIfHeld` caller) | 29/29 pass | | Negative control after the merge | 4 rows fail, as expected | | Restore | worktree clean, rebuild including `libs` OK, 6/6 pass | <details><summary>Negative control (compare forced off on the merged tree)</summary> ``` agc_driver_frame_replay_store_window_unwritten ...***Failed agc_driver_frame_replay_store_between_walks ......***Failed agc_driver_frame_replay_store_window .............***Failed agc_write_tracking ...............................***Failed 33% tests passed, 4 tests failed out of 6 ``` </details> ## Previous findings - **Still open (non-blocking): the compare switch stays on if `start()` throws after turning it on.** `GuestMemory::SetOwnStoreCompare(true)` still runs at `core/libs/prx/libSceAgcDriver/Execution/src/FrameRecorder.cpp:548`, before `std::make_unique<FrameCaptureWriter>(directory)` at line 553, and the writer can throw: [FrameRecorder.cpp L547-L553](https://github.com/boykopovar/AnyPS5/blob/ca4553365ffc41b27ee5aed87322616b071db376/core/libs/prx/libSceAgcDriver/Execution/src/FrameRecorder.cpp#L547-L553). The fix suggested last time still applies: turn the switch on after the writer exists and before the reset collects, or add a guard that turns it off when `start()` exits by an exception. ## New findings ### Blocking None. ### Non-blocking None. ## Not verified - The Windows-only rows (`fresh_note`, `agc_write_tracking_fresh_view`, the separate `own_store_images` registration): this host runs Linux. - Capture sizes and `--strict` replays on a title: I launched no title. - The capture-time cost of the full listing of `WriteChangedIfHeld` pages. It is not measured anywhere. - Hardware GPUs: I ran on lavapipe only. The contributor CI runs on AMD and NVIDIA are for the previous head `702492e63e`. <!-- anyps5-bots job=3718 head=ca4553365ffc41b27ee5aed87322616b071db376 -->
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!14137
No description provided.