Skip to content

fix(agc): leave GPU-stored words out of frame capture deltas - #185

Open
Thimo188 wants to merge 72 commits into
mainfrom
upstream-pr/12568
Open

Thimo188 wants to merge 72 commits into
mainfrom
upstream-pr/12568

Conversation

@Thimo188

@Thimo188 Thimo188 commented Dec 2, 2026

Copy link
Copy Markdown
Owner

Imported from boykopovar/AnyPS5#12568, originally opened by chitters2004.

Source commit: bffde0b5025bc4e18865f1cf45df8746455bd701. The import branch preserves this fetched upstream PR snapshot. The description and validation below are copied from upstream; no new code changes or test runs were made for this import. Original reviews, discussions, and attachments remain at the linked upstream PR.


What

Since the last review: thuanquang's 591073f374 (+33 −21, the parked-wait compare below) with its tests f8de2a2bc8 and 6a2e3c12cc, 3ddbd843a0 (restores testParkedRewindReplays, which a merge of main dropped) and e264114de4 (+2 −3: a duplicate flush in restoreGroup, and the debt entries for the unwatched fallback). The rest are merges of main; the last, e0df5b76d8, merges dff7484fd1. boykopovar#12567 is merged, so the diff against main is this PR's own: 16 files, +788 −64.

A delta read while queues are parked (boykopovar#12567) holds what their earlier packets stored: labels, WRITE_DATA, fills. The replay restores those values before it replays the work that writes them, so a queue waiting on such a label is released before the work ahead of the label runs. On GTA V this showed as garbage V# reads, device loss and magenta frames in about half the replays.

  • The packet paths a queue worker executes report what they store through FrameRecorder::NoteGpuStore: labels (noteLabelStore), WRITE_DATA, COPY_DATA, DMA_DATA, COND_WRITE, constant RAM dumps, MEM_SEMAPHORE signals and waits, and sample dumps. Buffer fills report their pattern through NoteGpuFill. Only a capture in progress records them, word by word, up to 64 KiB per store.

  • A delta leaves out each word that still holds the value the driver stored there, counted as gpu_store_bytes in capture.json. A word that holds another value is written and its entry retired, so a later title store of the driver's value is kept. This holds on every delta path, including the host pages a shader delta writes whole.

  • A block of a new range that is all zero is skipped only when no recorded store touches it. Before, a block the title cleared after a GPU fill was skipped and the replayed fill survived.

  • (JJenkx) A delta also samples writable ranges that have no write-watch coverage, such as memory whose watch was lost at a host import, after the queues settle. An unchanged block is skipped only when the GPU was idle with no new submission accepted since its last sample. Before, a CPU store into such memory was never captured, because its write stamp never advanced.

  • (thuanquang) A shader delta is cut to the capture's readable ranges, so it no longer writes a whole 64 KiB block across a page no range holds, and the replay refuses a delta or snapshot that reaches memory no range maps.

  • (thuanquang) When a shader delta or a full delta writes bytes, it forgets the other path's hash records of them (hostPageHashes, unwatchedHashes). Before, each path skipped bytes by a record the other never updated, so a capture could keep code a title had since registered again or restored.

  • (thuanquang) A delta records each WAIT_REG_MEM its queues were parked on with its address, reference, mask, compare function and size (calls format 3), and the replay compares all of them. Before, it recorded only the address, so a queue parked on the first of two waits on one gate counted as parked as captured while the capture had read the delta during the second, and the work between them overwrote a later CPU store. A REWIND park is recorded by its address only. Readers accept formats 1 to 3; a format 2 capture is compared by address as before.

  • A writable range without write-watch coverage is sampled in every delta after GPU work, so on GTA V's city scene a 3-frame capture recorded its ~474 MiB of writable sections again in each group: 10 deltas, 3.5 GiB, against 103 MiB before the fallback. A delta part whose bytes equal the last part recorded at the same address and size now refers to that payload instead of storing it again (7d87265d66, 87111995ec). The writer compares every byte against its own copy of the earlier part before sharing it. The replay still restores the bytes in every group. Memory files are format 2, and readers accept formats 1 and 2. Overlapping collected blocks are merged before they are read, but only when both have 4-byte-aligned edges, so keepTitleWords still leaves out GPU-stored words.

Overlap: boykopovar#12567, which this was stacked on, is merged. The no-coverage fallback is carried here rather than in a separate PR, as agreed with JJenkx (comment): it relies on this PR's GPU-store filtering.

What stays in deltas (GPU copies, larger copies, occlusion counters, CPU-executed RELEASE_MEM timestamps, shader stores, render target write-backs) is a new debt entry.

Tested

Since 34da67b255: a6a53249baa merges main a3fecbe3ded. 4ee175adf01 makes agc_driver_frame_replay_rewind_copy_held poll the recorder under the GPU mutex, so its check no longer races the committer. c9ebb0b25d8 makes agc_driver_frame_replay_gpu_store wait for a label the compute queue writes after its copy before it compares, instead of polling the copy's target. Both are test-only. Fork CI on lavapipe: run 43928056634. The Linux gate and Windows pass, and the report is clean. TSan fails only tests that main itself fails under TSan: the frame replay tests' label polls and bulk copies against test writes, agc_driver_recorder, and agc_graphics_profile_draw (main-only control: run 43906132257).

Capture cost on a title (GTA V city scene, RTX 3080, Windows 11). Each build was booted twice and captured 3 frames 35 s after standing still. Base: main 2f8c843691 + boykopovar#14561. This PR: 34da67b255 + boykopovar#14561.

main this PR
memory deltas 7 10
delta bytes 108 / 112 MiB 3175 / 3170 MiB
written to disk, first boot (raw / stored) 4433 / 1652 MiB 7494 / 2050 MiB
longest capture stall 17.5 / 20.6 s 28.0 / 30.7 s
p50 frame time after the capture 130.7 / 128.9 ms 130.2 / 127.1 ms

The snapshot is the same in both (about 12.5k ranges, 4.22 GiB). Frame time outside a capture is unchanged: every recorder path added here runs only while a capture is in progress, and outside one the store hooks cost one relaxed atomic load. The extra delta volume and the roughly 10 s longer stall come from the no-coverage fallback. It reads and hashes about 300 MiB of writable ranges without write-watch coverage at every delta. 71.2% of the delta bytes repeat the last part recorded at the same address and are shared, so only about 400 MiB more reaches the disk. Details: comment.

Since c161bdbe6c: f51ab73729 keeps the most recently used delta parts and drops the read-back path. Fork CI on lavapipe (run 44399609340): Linux 83 of 83, Windows 82 of 83; agc_driver_frame_replay_cold_pipelines fails on its base too.

Memory cost of the delta cache. FrameCaptureWriter keeps the raw bytes of the most recently used delta parts, keyed by address and size, so a repeated part is compared with memcmp against RAM outside the writer mutex. The copy uses at most FrameCaptureWriter::CachedDeltaBytes = 512 MiB, held until the capture ends.

  • Replacing a key's part releases its old bytes first, and a part that does not fit evicts the least recently used ones, so 512 MiB is the most held at once.
  • A part whose key is no longer cached is stored again; nothing is read back from the file. The budget limits RAM and, past it, how much is shared, never correctness: a part is only shared after every byte matched.
  • The writer no longer hashes parts, so the capture's delta costs line drops the delta hashing time. It now reads <n> repeated parts compared in <s> s, <n> parts evicted from the delta cache.

GTA V, standing, 10 frames, RTX 3080 on PCIe Gen4 x16. Four boots per build in ABBA and BAAB order, all quiet-checked CLEAN. The capture holds 14,383 keys of 901 MiB, and a part repeats 1 to 3 deltas later.

first-come cache (before) least recently used (after)
repeated-part compare 6.26, 6.40, 6.70, 6.59 s 0.53, 0.52, 0.50, 0.54 s
parts read back under the lock 92,269, 92,833, 94,163, 91,950 none (1,707 to 2,542 evicted)
capture wall time 45.1, 45.3, 46.3, 46.8 s (mean 45.9) 40.8, 38.7, 38.3, 38.3 s (mean 39.0)
unwatched block reads 18.46, 18.61, 18.80, 18.55 s (mean 18.61) 20.18, 19.27, 19.24, 19.21 s (mean 19.48)
stored 2,147.9, 2,127.9, 2,133.1, 2,143.4 MiB 2,140.2, 2,130.7, 2,134.5, 2,117.5 MiB
  • Stored bytes. Each boot captures a slightly different game state, so the stored size moves by about 1.5% between boots of either build, and the two ranges overlap. Fed the same recorded deltas offline, both writers store 497.7 MiB and share 7,916.6 MiB, byte for byte the same split. A capture re-encoded through the new writer matches the original in every call, chunk and delta (2,139.2 MiB both). Replaying the original and the re-encoded capture, twice each, gave pixel-identical frames (max channel difference 0) and the same images on all four runs.
  • Unwatched block reads. These are 0.87 s (4.7%) slower with the change, in every boot. That timer covers only the guest read, the GuestMemory::Watched check and the content hash, and no writer code runs inside it. One more boot per build timed the three parts separately (an untimed diagnostic build): every part was 8 to 17% slower with the change. That includes the content hash, which is pure CPU over bytes just read: guest read 0.52 → 0.61 s, Watched 9.96 → 10.79 s, content hash 7.93 → 8.74 s. The same boots showed compare 6.33 → 0.55 s and 92,787 read-backs → none. So the change moves no cost into the read. The recording thread does different work between reads, and the reads run a little slower. The capture is still 6.9 s faster overall.

Head 34da67b255 is Dean's merge of main (4cd4bc371a, on f9dd5dcf5e) plus three commits:

  • 258c3a67a5: a shader delta wrote a host page its ranges cover whole straight to the capture, without the GPU-store filtering of every other delta path, so a label the GPU stored beside shader code entered the delta. agc_driver_frame_replay_shader_host_gpu_store (recorder only) registers a shader whose code sits in a host page, writes a label in that page with a WRITE_DATA submission (so the driver notes the store itself), rewrites the code and registers it again: the captured code must be the new code and the label must not be the GPU's value. It fails without the change ("the shader delta of a host page carried a label the GPU stored there") and passes with it, on Linux and under WinLibs GCC 15 and Wine.
  • 14f9558427: the debt entry for pages that leave the write watch said a store there is not recorded until the tracker notes the page again, which the unwatched-block sampling replaced. It now states the open cost of that sampling.
  • 34da67b255: agc_driver_frame_replay_rewind_copy_held waits until the copy into the stored page is pending, so the CPU store always lands on the page the copy's import took out of the write watch.

Linux (Ubuntu 24.04, lavapipe, Mesa llvmpipe LLVM 20.1.2) on the same two commits before Dean's merge of main (f9dd5dcf5e base):

  • ctest -R "agc_driver_frame_replay|agc_frame_capture|agc_driver_frame_capture": 68 of 68 pass (the three agc_driver_frame_capture tests after rebuilding their test binary, which a build of another branch had left stale). That run had the test's first form, which noted the label store from the test; the WRITE_DATA form in 258c3a67a5 was run alone, on Linux and under Wine.
  • ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer with layer 1.4.363.1 and VK_KHRONOS_VALIDATION_VALIDATE_SYNC=1, ctest -R '^agc_(driver_frame_replay(_shader.*|_unwatched.*|_store.*|_gpu.*)?|frame_capture)$' -V: 30 of 30 pass, 34 Insert instance layer lines, no missing-layer line, 0 VUID- and 0 SYNC-HAZARD lines. No sync canary ran, so this is not a synchronization-validation claim.

On 34da67b255 itself (same tree as the branch its CI ran on), fork CI on lavapipe (run 43726057702): Linux gate (Khronos layer) and Windows (MinGW) each pass 32 of 32 selected tests, with 0 VUID- lines and nothing failing that passes on the base.

The results below are from the heads named and were not rerun on 34da67b255.

Head cf368d991c: fork CI on lavapipe (run 43541821923): Linux 68 of 68 and the ASan build 68 of 68. Windows (MinGW, lavapipe, Khronos layer) 67 of 68; agc_driver_frame_replay_cold_pipelines fails on its base too. 0 VUID- lines. New tests: section_once (an unchanged multi-mapped section block without write-watch coverage is stored once across groups and replayed; it fails on 1243812e74), a forced hash collision, a format 1 memory file, references inside a payload, to another address and past the file, and aligned and unaligned block merges.

Head e0df5b76d8 (main dff7484fd1 merged in):

  • Windows 11 Pro 26320, WinLibs GCC, Ninja Release, NVIDIA GeForce RTX 3080 (driver 621.14): ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ctest -R "frame_(replay|capture)" -V: 62 of 62 pass, including store_second_wait and agc_driver_frame_replay_rewind_copy. 0 VUID- lines in the test log and in the 7 replay subprocess logs; the loader inserted the layer in every run (VK_LOADER_DEBUG=layer: 201 Insert instance layer lines) and no log has was not found but was requested.
  • Linux, fork CI on lavapipe (run 43106669074): this head 62 of 62, its base dff7484fd1 46 of 46, 0 VUID- lines, no missing-layer message.

Earlier results, on the commits named:

Windows 11 Pro 26220, WinLibs GCC, Ninja Release, NVIDIA GeForce RTX 3080 (driver 621.01).

New tests. "Before", measured before the series was restacked onto boykopovar#11436, is this branch with Execution/ at its base (boykopovar#12567):

  • agc_driver_frame_replay_gpu_store: a compute queue waits on a label that a graphics queue's RELEASE_MEM writes after 256 MiB of fills and a copy, and the CPU stores beside the label. The test checks that the delta holds the CPU store but not the label, and that the replayed compute queue copies only after the graphics copy. Before: the memory delta holds the label the graphics queue's RELEASE_MEM wrote, so the replay releases the compute queue before the graphics queue copies.
  • agc_driver_frame_replay_gpu_cleared: a block is filled before its range is first recorded, then cleared. Before: the replay copied the GPU fill of a block the title cleared before its range was first recorded.
  • agc_driver_frame_replay_gpu_fill checks that the filtering keeps a title store that writes back the fill value over an earlier store. It passes here before and after, because host imports keep the write watch on this driver. On Linux/RADV the import drops it, and the test failed until the fallback (JJenkx's report).
  • agc_driver_frame_replay_shader_hole and _delta_hole (thuanquang): a shader in a block with an unmapped page records only what the ranges hold, and a capture holding such a delta is refused. With FrameRecorder.cpp and tools/FrameReplay.cpp from before 78c714060e both fail 3 of 3; on 78c714060e they pass 3 of 3.
  • 4a6daa3cbc fixes _shader_hole on Linux, where a commit inside an allocated block is refused, by releasing the reservation first. It changes only that test. Both hole tests pass 3 of 3 on Windows at that commit with the validation layer, 0 VUID- lines; The NVIDIA run at that commit on Linux reports 0 new failures; its 2 new validation IDs are the known VUID-VkDeviceCreateInfo-pNext-pNext report for the maintenance8 structure.
  • agc_driver_frame_replay_shader_host_rewritten, _shader_host_restored and _shader_unaligned_restored (thuanquang), recorder only: a host page or unaligned unwatched range written by one delta path and then rewritten or restored is recorded again by the other. With FrameRecorder.cpp from 2b39d2ac36 all three fail in 2 of 2 runs; on f21b60440d they pass 3 of 3.
  • f21b60440d, a62a6958ab merged with main 4f41f4c375: full build, then ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ctest -R "frame_(replay|capture)" -V --timeout 120: 43 of 43 pass, 0 VUID- lines in the test log or the replay logs, no missing-layer message. Without the layer 42 of 43; reservation_error times out, the exit hang fix(agc): shut the driver down before frame replay exits with an error boykopovar/AnyPS5#14100 fixes.
  • 137e2d7876, this branch merged with main 3c3b3cda73, which includes fix(agc): snapshot host shader prologues before frame replay boykopovar/AnyPS5#12871: full build, then ctest -R frame_replay -V with the validation layer, 38 of 38 pass, including fix(agc): snapshot host shader prologues before frame replay boykopovar/AnyPS5#12871's three shader_prologue tests and both hole tests, 0 VUID- lines in the test log or the replay logs. The merges of main after it, b3b438c9ae and 2b39d2ac36, have not been run here. The results below are from earlier commits, as stated.
  • agc_driver_frame_replay_gpu_restore_cached, _unwatched_start, _unwatched_late and _unwatched_shared (JJenkx): CPU stores into memory with no write-watch coverage are captured, and an unchanged block isn't skipped across GPU work. 7297b72e93 makes _unwatched_shared map its section views over reset memory on Windows. Before, it threw guest release truncates a host allocation there.

GTA V (PPSA04263, North Yankton prologue), with all four PRs of this series applied: the capture records 3 frames with 13 deltas, gpu_store_bytes 1232. 1 cold-cache replay with --no-synthesize and 5 normal replays all complete with 0 pace timeouts, 0 released waits and 0 synthesized. This is not a pixel-fidelity claim; replayed frames still differ from the title's.

Paired run on main and this branch merged into it, same machine and GPU, full builds on both sides with submodules at their pinned commits, host imports on (the default), ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ctest --test-dir build -R "frame_(replay|capture)" -V: main at bb04a4f1ea: 11 tests, all passed, 0 VUID- lines; this branch at 7297b72e93 merged into it (91292a2062): 35 tests, all passed, 0 VUID- lines. Neither log contains was not found but was requested by env var VK_INSTANCE_LAYERS. After c184a96481, the same run: main at ce9394b844: 11 tests, all passed, 0 VUID- lines; this head merged into it (7627024a73): 35 tests, all passed, 0 VUID- lines; no missing-layer message in either log. On main 4c8cff1916 (after boykopovar#12264's write-tracking changes), the same run: main: 11 tests, all passed, 0 VUID- lines; this head c184a96481 merged into it (ca744e2c66): 35 tests, all passed, 0 VUID- lines; no missing-layer message in either log. Capture overhead and delta volume of the fallback on a title are not measured yet.

After 8e0d485048 (each delta span collected in one call, as main does) and 4ef753497f (boykopovar#12567's fix for oneandonlydean's report, cherry-picked). Full builds, then ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ctest --test-dir build -R "^agc_driver_frame_replay" -V:

  • 8649da1e94, the head before them: 53 of 54 pass. agc_driver_frame_replay_once fails, because the merge of main collected each 64 KiB block separately and the next delta collected the same pages again.
  • 8e0d485048 alone: agc_driver_frame_replay_rewind_store fails with the replay applied the CPU store before the copy that preceded it. The re-collection had hidden this.
  • 4ef753497f: 54 of 54 pass.
  • 8649da1e94 and 4ef753497f: 0 VUID- lines in the test logs or the replay logs, and neither log has the missing-layer message.

The earlier runs: Windows 11 26220, RTX 3080, driver 621.01.

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: NVIDIA GeForce RTX 3080, driver 621.14, Windows 11 Pro 26320 (earlier runs: driver 621.01, 26220); lavapipe on Linux CI
  • AI-assisted: yes

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Frame captures can reuse identical memory-delta data, reducing repeated data in capture files.
    • Captures better track GPU-written memory and changes outside watched ranges.
    • New captures use updated formats, while earlier capture formats remain supported.
  • Bug Fixes
    • Replay better preserves memory changes and checks that captured memory is available in mapped ranges.
    • Replay handles additional wait details in newer captures.
  • Documentation
    • Updated capture-format, replay, and memory-tracking documentation.

chitters2004 and others added 30 commits October 28, 2026 21:58
A delta read while a queue is parked held the labels, WRITE_DATA and
fills the queue's earlier packets had stored, so the replay saw those
values before replaying the work that writes them and released waiting
queues early.

The driver now reports each word a queue worker stores from a packet
(labels, WRITE_DATA, COPY_DATA, DMA_DATA up to 64 KiB, semaphores,
constant RAM and sample dumps, and buffer fills by their pattern), and
a delta leaves out every word that still holds that value, counted as
gpu_store_bytes. A block of a new range that is all zero is skipped only
when no such store touched it, so a block the title cleared after a GPU
fill is no longer lost.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sample writable ranges without coverage while queues are settled. Reuse unchanged samples only when no GPU submission progressed between idle observations. Cover initial and later coverage loss, shared mappings, and restoring cached values after a GPU fill.
…s views on Windows

The fixture block is one committed private allocation, and Windows can't release part of it to make room for the two section views.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Brings in boykopovar#12567's merge of main ce9394b, which landed boykopovar#12566.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	core/libs/prx/libSceAgcDriver/CMakeLists.txt
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nges

The shader path recorded whole 64 KiB blocks and host pages around a shader
pointer even across a gap between recorded ranges, so the replay copied bytes
into a page it never mapped and crashed. Trim them to the readable ranges,
including ranges committed since the snapshot, and have the replay refuse a
snapshot or delta chunk that reaches outside every range of the capture.

Co-Authored-By: Claude <noreply@anthropic.com>
…pieces

Linux and WebAssembly refuse a commit that starts inside a used range, so
committing the two pieces of an allocated block threw on Linux.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	docs/dev/debt/libSceAgcDriver.md
# Conflicts:
#	core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
Shader deltas skip a host page whose hash has not changed, and full
deltas skip an unwatched block whose hash and accepted serial have not
changed. The two paths kept separate records of the same bytes and
neither learned when the other wrote them, so a skip could leave the
replay with bytes the title no longer held.

Reverse: a shader delta writes B to a host page, a full delta writes C
over it, the title writes B again, and the next shader delta skips the
page, so the replayed registration reads C.

Idle forward: a full delta records A for a chunk of a writable host
range, a shader delta writes B into it, the title restores A, and the
next full delta at the same accepted serial skips the chunk, so the
replay keeps B.

Cross-key: full-delta chunks start at the range's address, while shader
deltas cut 64 KiB arena blocks and host pages at the range's edges, so
a range that does not start on a 64 KiB boundary records the same bytes
under two keys, and a write under one key leaves the other in place.

Each block or host page a delta writes now drops every host page hash
and unwatched-block hash that overlaps it before recording its own, so
the other path's next delta writes those bytes again instead of
trusting a hash of an older write.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tores

# Conflicts:
#	core/libs/prx/libSceAgcDriver/tests/FrameReplay.cpp
#	core/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_frame_replay_tests.cmake
#	docs/dev/BUILD.md
…tores

# Conflicts:
#	core/libs/prx/libSceAgcDriver/tests/FrameReplay.cpp
#	core/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_frame_replay_tests.cmake
#	core/libs/prx/libSceAgcDriver/tools/FrameReplay.cpp
The merge of main collected a delta span one 64 KiB block at a time and
kept the smallest returned generation, so the next delta collected again
the pages this one had already read. Collect the span in one call, as main
does, and add the blocks the tracker does not watch whole.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ture did

A memory delta is read once the queues have settled, so its bytes include
GPU work that ran up to the waits the queues were parked on. A replay that
reaches the delta parked earlier, on a wait the delta's own stores
release, ran that GPU work after restoring the delta and overwrote title
stores made after it. The recorder now writes the parked wait addresses
with each delta; the replay applies the delta, waits until its queues park
on the same waits with the same number of submissions in flight, and
applies it again without its REWIND control words.

Also removes a phrase the last merge of main repeated in BUILD.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Keep the GPU store test modes and the second driver flush before a delta is
written, and collect the delta's blocks after the driver settles.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
store_idle gates a DMA copy on a WAIT_REG_MEM the title releases, and
store_idle_rewind puts the copy in the tail of a REWIND the title
releases. In both, the title then stores over the copy's target, and the
delta that holds the release and the store is read with nothing in
flight, so no queue was parked when it was read. store_idle_unwatched
unwatches the copy's target, reserves an EOP flip after the store and
copies the target in the submission that flips. Replayed without early
releases, each must end with the title's store: the replay reaches the
delta parked on the gate, and only applying it again once the queues
park as captured restores the store the released copy overwrote.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…its gate's second value

store_second_wait submits one command buffer that waits for a gate to
hold 1, copies into a target, writes a label and waits for the gate to
hold 2. The title opens the gate with 1, waits for the label, stores
over the target and flips, so the delta before that flip is read while
the queue waits for the gate's second value. Replayed without early
releases, the queue reaches that delta parked on the gate's first wait,
which has the same address, and the replay must still end with the
title's store.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
chitters2004 and others added 30 commits November 15, 2026 14:44
The entry still said a CPU store to a page that left the write watch is
not recorded until the tracker notes the page again, which the
unwatched-block sampling in this change set replaced: each later delta
reads such a block whole. What stays open is the cost of that sampling.
rewind_copy stores beside the copy right after submitting it, so the
store usually lands before the queue worker imports the copy's
destination and leaves the write watch. rewind_copy_held waits until
the copy into the stored page is pending, so the store always lands on
the unwatched page. Before unwatched ranges were sampled, the delta at
the flip missed the store and the replay failed with "no memory delta
was read while 1 submissions waited for the CPU" on every run.
…rder

The poll in copyInFlightAtDelta read the active recorder's pending
writes from the test thread while the draw-commit thread replaced the
open batch and the published snapshot under the GPU mutex, so it could
read a freed batch.
The GPU store test polled the compute queue's copy target with memcmp
while the driver's DMA wrote it, a test-side bulk read racing the copy.
The compute buffer now writes a label after its DMA, and the test waits
for that label with an acquire load before it compares the target.
The recorder tracked GPU stores word by word and dropped a tracked word
whenever a later store overlapped any byte of it. A 2-byte DMA_DATA store
over half of a label RELEASE_MEM wrote, or into a word a buffer fill wrote,
left the other GPU-written bytes untracked, so the memory delta restored
them in the replay before the work that produces them.

Each tracked word now carries the bytes a queue worker wrote with a mask
of which ones are known. A store merges its bytes into the word, a forget
clears only the bytes it covers, and a fill's partly covered boundary
words keep their remaining pattern bytes. The delta leaves out each byte
that still holds its GPU value and keeps the rest.
…tail

A sampled unwatched block merges with an overlapping written block, so a
kept unwatched hash can cover more than one capture block. Forgetting the
hashes a store overlaps looked back only one capture block, so a store
into the tail of a longer key left its hash, and an unchanged later
sample of that key would skip the store. The look-back now spans the
longest key kept.
Resolves the conflict with main b412486: noteLabelStore takes main's new
ordered parameter and still reports the store to the frame recorder first.
…e deltas

A fill whose address and size are multiples of 4 but not of 16 was forgotten
rather than recorded, and the edge words of a split fill took their pattern
word from the address modulo 16. Record every fill of whole words, keep the
fill's origin across splits, and index its pattern from that origin. The word
and fill bookkeeping moves into FrameRecorder::GpuStores so a unit test can
drive a 20-byte fill at an address that is 4- but not 16-aligned.
writeDelta waited up to 10 s for the queues whenever a delta had any readable
range, since it collected written blocks only after the wait. Collect written
and unwatched blocks first and wait only when a block, an added range or a
host page will be read, as main did before unwatched ranges were sampled. A
GPU or CPU store that lands after the collection is collected by the next
delta, whose generation mark is taken here.
…de the writer lock

A delta part whose hash matched an earlier part at the same address and
size was confirmed by flushing the memory file, reading the stored payload
back and decompressing it under the writer mutex. The writer now keeps the
raw bytes of the last part written at each key within a 512 MiB budget and
compares a repeat against them with memcmp outside the mutex; only parts
that did not fit fall back to the stored read-back. The capture prints the
time spent reading unwatched blocks, hashing deltas and comparing repeats,
and how many compares read back from the file.
…ookup

The shader delta looked up readable ranges by the one that starts at or
before a block, keyed by start address. A host page added by the capture
prologue can overlap the tail of a readable range, and a range keyed at the
same start kept only the larger end, so the bytes of an overlapping range
after the found one were missed. Readable ranges are now merged into
disjoint spans before the lookup.
FrameCapture.cpp included common/xxhash.h through zstd's include directory,
an internal header of another library. An xxhash interface target now names
zstd's bundled xxHash directory explicitly, every target that compiles the
frame capture links it, and the source includes <xxhash.h> with
XXH_INLINE_ALL so no zstd symbols are used.
…estored

A title that unmaps a captured range, maps it again at the same address,
writes it and then restores the earlier bytes replays each state. The
remap never becomes an added range, because captured ranges stay
captured and newRanges only adds addresses they do not cover, and every
unwatched block of the captured ranges is read again after the added
ranges in each delta, so no earlier hash survives the write.
…one back

The writer cached the bytes of the first 512 MiB of delta parts and kept
only a hash of every later key, so once the budget filled, a repeated part
of a new key was compared by flushing the memory file and reading and
decompressing the earlier payload under the writer mutex. In a 10-frame GTA V
capture 14,383 keys hold 901 MiB, and 92,321 of the 140,832 repeated parts
were read back that way.

The cache now evicts the least recently used part instead, and a part
whose key is not cached is stored again rather than read back. Repeats in
that capture come within 1 to 3 deltas, so a 512 MiB LRU cache holds all
but 5 of them. Every share is decided by memcmp against bytes held in RAM,
outside the lock, so the hash, the read-back path and the xxHash build
target are gone. The cost line now reports parts evicted from the cache.

Tests replace the forced hash collision with a part that differs in its
last byte, and add least-recently-used eviction, a part larger than the
cache, the same address at two sizes, and eight threads writing the same
keys under eviction.

CI-Tests: agc_frame_capture|agc_driver_frame_capture|agc_driver_frame_replay
CI-Jobs: linux-gate,windows
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PacketMemory dumpSampleCounters: main's per-block mask (boykopovar#22465) skips unselected dump blocks; this branch still notes each written block as a GPU store.
Main's boykopovar#22028 records CPU stores to pages outside the write watch by
comparing each such page with the bytes the delta that last recorded it
read (GuestMemory::ChangedComparedPages). This branch did the same job
by reading every 64 KiB block without write-watch coverage at every
delta and skipping it only when its hash and the accepted serial were
unchanged. The compared copy now carries that job alone: it reads only
4 KiB pages whose bytes changed, also while GPU work is in flight, so
the per-block Watched sampling and its hash cache (UnwatchedHashes,
forget_unwatched_hashes) are gone.

From this branch the compared copy takes the ranges it collects:
writable sections, aliases, file views and host memory, and pages of
write-watched ranges that are outside the watch when the capture
starts, are hashed from the snapshot or the late range's first read. A
queue worker's packet store into a compared page makes it unknown, so
the next delta reads it and leaves out the words the store still holds
(gpu_store_restored). A shader delta's host page updates the compared
hash too. Overlapping blocks are merged only at aligned edges, as
before. section_once now checks that an unchanged section block is
recorded once, and shader_hole writes its shader after the capture
starts, since a shader already in the snapshot is no longer sampled.

The state test modes and BUILD.md take both sides; the duplicate Frame
capture debt entries are one, and the entry for pages leaving the write
watch is gone with main's fix. A new entry states what the compare
cannot see: a title restoring recorded bytes after a write other than a
packet store changed them.
…ide the write watch

A page outside the write watch is recorded when its bytes differ from
the ones the last delta read. A write the driver makes there and a
title store that then puts back the recorded bytes left the page equal
to its compared copy, so the restore was not recorded and the replay
kept the driver's write. Only a queue worker's packet stores made the
page unknown, from the recorder's GPU-store notes.

Every store the driver notes outside the write watch (StoreOwnBytes,
the writes it marks after GPU work, a failed fresh collect) now makes
the compared pages it covers unknown, so the next delta reads them.
That covers the packet stores too, so the recorder no longer forgets
them itself.
The capture filter copies each call unchanged, but its writer always
labelled the output calls format 3. A calls format 2 memory delta lists
each parked wait by its address alone, so the replay read the filtered
capture's wait lists with four values per wait and refused them, and the
minimizer could discard a reduction that still reproduced the failure.

The writer now takes the calls format it writes, 2 or 3, and the filter
passes the source's.
…capture

seedUnwatchedPages stepped whole host pages from the range's first byte, so a range that starts inside a page compared only straddling windows and left its pages out of the compared copy. Walk page boundaries and hash a partly covered page as the bytes read over the live page.
emitShaderDelta clipped host pages to the captured ranges and sent a partly covered page down the write-watch path, which never sees a host page and has no compared copy for a range the title cannot write, so a rewrite of shader code there was lost. Hash each clipped host interval the way whole host pages are hashed.
…st make

Whether a writer shares a cached part depends on how the threads interleave; three addresses through a two-block cache always evict.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants