fix(agc): read a frame capture's memory delta once the accepted submissions completed #11197

Merged
LeandroLP23 merged 2 commits from upstream-pr/11197 into main 2026-10-26 07:48:54 +00:00
LeandroLP23 commented 2026-10-25 21:37:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-25T21:37:16Z.


What

A frame capture could store a memory delta from before an earlier recorded DMA copy had landed. FrameRecorder::writeDelta read the delta's blocks with ReadCommittedUnsynced while GPU work accepted before the call could still write them. At replay the stale bytes were written back over the copy's result. That is the intermittent "the replay did not reproduce the second copy" of agc_driver_frame_replay in #10711 (root cause in https://github.com/boykopovar/AnyPS5/pull/8740#issuecomment-6385315259).

  • Wait before the read. A delta that has blocks to read (new ranges or written blocks) first waits up to 10 s for the submissions already accepted (WaitIdleFor), when any are still in flight. It records the accepted and completed serials after the wait. This is option 1 of that comment. A delta with nothing to read does not wait, so those calls keep their submissions overlapped.
  • Acceptance under the recorder lock. Submit, SubmitFlip and SuspendPoint hand the driver call to the recorder. It runs the call under its lock right after recording it, so every call recorded before a delta has been accepted when the delta waits. Without this, another thread's submission recorded before the delta could be accepted during the wait or after the read, and the replay would submit it before applying stale bytes over its result.
  • Timeout. When the work does not finish, the capture stops with a warning and its writer is finished, like a capture on a full volume. Nothing is thrown: writeDelta runs inside Submit and SubmitFlip, which catch only ProcessShutdown, so an exception would end the title. abandonIfDiskLow and the timeout share stop(reason).
  • Quarantine. The Windows quarantine of agc_driver_frame_replay from #10715 is removed, with its debt entry. BUILD.md describes the wait, and the Frame capture debt entry gains the new way a capture can stop.

@Sumaiter opened the same fix as #11185 (an unconditional wait that throws on timeout). The bot closed it at once for the open-PR limit, so I'm opening this one so the fix isn't blocked. Credit for the independent analysis goes to them. #11157 (janzezno) touches the same quarantine lines; the agreed order in #10711 is the fix first, then #11157 registers the test on Linux without its quarantine changes.

Tested

Windows 11 (10.0.26300), AMD Radeon 860M (AMD 24.30.58.08, LLPC), WinLibs GCC 15.2, Release with BUILD_TESTING=ON, on main 07da04f947.

  • The 10 frame_replay|frame_capture tests pass with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1: agc_frame_capture, agc_driver_frame_capture_eop, agc_driver_frame_replay, the new agc_driver_frame_replay_concurrent and the six agc_driver_frame_replay_* state tests. agc_driver_frame_replay_concurrent submits 64 DMA copies from a second thread during the capture. It checks that every memory delta was read once the submissions recorded before it had completed, and that the replay reproduces all 64 copies.
  • agc_driver_frame_replay under contention. ctest is pinned to two cores with three busy-loop processes on them and ANYPS5_GPU=no-such-device, as on the runner; this is the setup that reproduced the CI failure.
Recorder Passed
main 159 of 200 (41 fail with "the replay did not reproduce the second copy")
this PR (two series, before and after rebasing onto 07da04f947) 200 of 200, 200 of 200
#11185 head b709c0fe3d 200 of 200
  • agc_driver_frame_replay_concurrent under the same contention: 100 of 100 on this head. With only the old Submit order put back (record, release the lock, then driver.Submit) it passes 66 of 100; the failures say a delta was read with a submission recorded before it unfinished.
  • Validation layer (Vulkan SDK 1.4.363.0, same machine): ctest -V with VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, ANYPS5_NO_SHADER_CACHE=1 and ANYPS5_REQUIRE_VULKAN=1 on this head and on its base main 07da04f947. The frame_replay|frame_capture tests pass 10/10 against 9/9 on main. They never load the Vulkan loader, so the layer has nothing to check there. The 22 agc_driver_* GPU tests matching flip|suspend|submit|eop|label give 20 passed and 2 skipped on both. There are 0 VUID- lines in any log, and no was not found but was requested by env var VK_INSTANCE_LAYERS. A direct run with VK_LOADER_DEBUG=all shows the layer inserted.
  • The timeout path is not exercised: that needs GPU work that never completes.
  • check_conventions.py --base origin/main passes. pr_overlap.py finds #11157 (above), and #10760, which adds an unrelated debt entry (capture trace output) next to the Frame capture one, so whichever lands second resolves a text conflict in that list.

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: Fixes #10711
  • Unblocks: none
  • GPUs tested: AMD Radeon 860M (integrated), AMD 24.30.58.08 (LLPC), Windows 11 10.0.26300
  • AI-assisted: yes (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5008957874 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11197). Originally posted by [LeandroLP23](https://github.com/LeandroLP23) on 2026-10-25T21:37:16Z. --- ### What A frame capture could store a memory delta from before an earlier recorded DMA copy had landed. `FrameRecorder::writeDelta` read the delta's blocks with `ReadCommittedUnsynced` while GPU work accepted before the call could still write them. At replay the stale bytes were written back over the copy's result. That is the intermittent "the replay did not reproduce the second copy" of `agc_driver_frame_replay` in #10711 (root cause in https://github.com/boykopovar/AnyPS5/pull/8740#issuecomment-6385315259). - **Wait before the read.** A delta that has blocks to read (new ranges or written blocks) first waits up to 10 s for the submissions already accepted (`WaitIdleFor`), when any are still in flight. It records the accepted and completed serials after the wait. This is option 1 of that comment. A delta with nothing to read does not wait, so those calls keep their submissions overlapped. - **Acceptance under the recorder lock.** `Submit`, `SubmitFlip` and `SuspendPoint` hand the driver call to the recorder. It runs the call under its lock right after recording it, so every call recorded before a delta has been accepted when the delta waits. Without this, another thread's submission recorded before the delta could be accepted during the wait or after the read, and the replay would submit it before applying stale bytes over its result. - **Timeout.** When the work does not finish, the capture stops with a warning and its writer is finished, like a capture on a full volume. Nothing is thrown: `writeDelta` runs inside `Submit` and `SubmitFlip`, which catch only `ProcessShutdown`, so an exception would end the title. `abandonIfDiskLow` and the timeout share `stop(reason)`. - **Quarantine.** The Windows quarantine of `agc_driver_frame_replay` from #10715 is removed, with its debt entry. `BUILD.md` describes the wait, and the Frame capture debt entry gains the new way a capture can stop. @Sumaiter opened the same fix as #11185 (an unconditional wait that throws on timeout). The bot closed it at once for the open-PR limit, so I'm opening this one so the fix isn't blocked. Credit for the independent analysis goes to them. #11157 (janzezno) touches the same quarantine lines; the agreed order in #10711 is the fix first, then #11157 registers the test on Linux without its quarantine changes. ### Tested Windows 11 (10.0.26300), AMD Radeon 860M (AMD 24.30.58.08, LLPC), WinLibs GCC 15.2, Release with `BUILD_TESTING=ON`, on `main` `07da04f947`. - The 10 `frame_replay|frame_capture` tests pass with `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1`: `agc_frame_capture`, `agc_driver_frame_capture_eop`, `agc_driver_frame_replay`, the new `agc_driver_frame_replay_concurrent` and the six `agc_driver_frame_replay_*` state tests. `agc_driver_frame_replay_concurrent` submits 64 DMA copies from a second thread during the capture. It checks that every memory delta was read once the submissions recorded before it had completed, and that the replay reproduces all 64 copies. - `agc_driver_frame_replay` under contention. ctest is pinned to two cores with three busy-loop processes on them and `ANYPS5_GPU=no-such-device`, as on the runner; this is the setup that reproduced the CI failure. | Recorder | Passed | |---|---| | `main` | 159 of 200 (41 fail with "the replay did not reproduce the second copy") | | this PR (two series, before and after rebasing onto `07da04f947`) | 200 of 200, 200 of 200 | | #11185 head `b709c0fe3d` | 200 of 200 | - `agc_driver_frame_replay_concurrent` under the same contention: 100 of 100 on this head. With only the old `Submit` order put back (record, release the lock, then `driver.Submit`) it passes 66 of 100; the failures say a delta was read with a submission recorded before it unfinished. - Validation layer (Vulkan SDK 1.4.363.0, same machine): `ctest -V` with `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, `ANYPS5_NO_SHADER_CACHE=1` and `ANYPS5_REQUIRE_VULKAN=1` on this head and on its base `main` `07da04f947`. The `frame_replay|frame_capture` tests pass 10/10 against 9/9 on `main`. They never load the Vulkan loader, so the layer has nothing to check there. The 22 `agc_driver_*` GPU tests matching `flip|suspend|submit|eop|label` give 20 passed and 2 skipped on both. There are 0 `VUID-` lines in any log, and no `was not found but was requested by env var VK_INSTANCE_LAYERS`. A direct run with `VK_LOADER_DEBUG=all` shows the layer inserted. - The timeout path is not exercised: that needs GPU work that never completes. - `check_conventions.py --base origin/main` passes. `pr_overlap.py` finds #11157 (above), and #10760, which adds an unrelated debt entry (capture trace output) next to the Frame capture one, so whichever lands second resolves a text conflict in that list. ### 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: Fixes #10711 - [x] Unblocks: none - [x] GPUs tested: AMD Radeon 860M (integrated), AMD 24.30.58.08 (LLPC), Windows 11 10.0.26300 - [x] AI-assisted: yes (Claude Code)
MarcZX10 commented 2026-10-25 21:52:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T21:52:06Z.

Review: CHANGES_REQUESTED


I found a race that can leave the original stale-delta bug possible. Driver::WaitIdleFor snapshots accepted on entry and returns once completed reaches that snapshot (Driver/Lifecycle.cpp:253-255); it does not prevent later submissions from being accepted. The public submit wrapper calls recorder->Submit and then driver.Submit separately (Driver/EntryPoints.cpp:22-24), and the recorder lock is released before the driver submission. A second thread can therefore accept a submission while this wait is in progress. This code rereads serial progress at line 376 but proceeds to ReadCommittedUnsynced even if the new accepted is greater than completed, so that write can still land after the delta read. Please serialize acceptance against the wait/read or otherwise establish a stable idle point, and add a regression that accepts another write during the wait. The report also omits the required VK_LAYER_KHRONOS_validation run and VUID comparison for an AGC-driver change; CONTRIBUTING.md requires those on the same GPU for main and change.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5645510512 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11197#pullrequestreview-5645510512). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T21:52:06Z. **Review:** CHANGES_REQUESTED --- I found a race that can leave the original stale-delta bug possible. `Driver::WaitIdleFor` snapshots `accepted` on entry and returns once `completed` reaches that snapshot (`Driver/Lifecycle.cpp:253-255`); it does not prevent later submissions from being accepted. The public submit wrapper calls `recorder->Submit` and then `driver.Submit` separately (`Driver/EntryPoints.cpp:22-24`), and the recorder lock is released before the driver submission. A second thread can therefore accept a submission while this wait is in progress. This code rereads serial progress at line 376 but proceeds to `ReadCommittedUnsynced` even if the new `accepted` is greater than `completed`, so that write can still land after the delta read. Please serialize acceptance against the wait/read or otherwise establish a stable idle point, and add a regression that accepts another write during the wait. The report also omits the required `VK_LAYER_KHRONOS_validation` run and VUID comparison for an AGC-driver change; `CONTRIBUTING.md` requires those on the same GPU for main and change.
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!11197
No description provided.