Skip to content

fix(agc): commit the pages of a sub-page capture range when replaying on Windows - #22181

Merged
oneandonlydean merged 2 commits into
boykopovar:mainfrom
LeandroLP23:fix/agc-replay-subpage-ranges
Nov 26, 2026
Merged

oneandonlydean merged 2 commits into
boykopovar:mainfrom
LeandroLP23:fix/agc-replay-subpage-ranges

Conversation

@LeandroLP23

@LeandroLP23 LeandroLP23 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

What

agc_frame_replay on Windows could not restore a capture whose guest allocation registry holds ranges smaller than a page. A title's heap can register allocations of a few bytes at addresses inside a page. The replay committed each captured range at its own address and size. GuestArenaCommit then tried to split the arena's placeholder at that address, and Windows refuses to split a placeholder inside a page. The replay stopped with split guest placeholder prefix before it restored any memory.

  • On Windows, commit now commits the 4 KiB host pages (dwPageSize) that hold the range. For a later range in a page that is already committed, WindowsMappings::Commit takes its committed-memory branch, which only calls VirtualProtect (and resets the write-tracking state of shared views there).
  • commit always uses read-write (0x04), as before. A host page shared by several captured ranges is therefore read-write as a whole, and so are the bytes of that page outside any captured range. Those bytes belong to no captured range, so the replay never reads or restores them. Linux already sets the whole page read-write this way.
  • The registration (GuestAllocations::Mutation::Add) still uses the captured address and size, so the replayed registry matches the captured one.
  • Linux keeps its own path, which already rounds a sub-page range to the pages that hold it and sets their protection.

Found with a capture of SuperTuxKart (PPSA69421, open-source homebrew). Its heap registers ranges of 1 to 16 bytes, for example 1 byte at 0x200220020. No capture data is attached.

Tested

Windows 11, MinGW-w64 GCC 15.2, Release, AMD Radeon 860M (driver 32.0.32015.12012).

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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 860M, driver 32.0.32015.12012, Windows 11
  • AI-assisted: yes (Claude Code)

Summary by CodeRabbit

  • Bug Fixes
    • Improved frame replay handling for memory ranges smaller than a system page, including more consistent behavior on Windows.
  • Documentation
    • Expanded frame capture and replay testing guidance with additional coverage for sub-page registrations and memory reset scenarios.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — no blocking findings

Nothing blocks this; the points below are optional.

What I ran

  • Head reviewed: 1ecb8949154223cc6b343cbdef183d8bd656bf9a (base main).
  • Read the review folder: description, commits, manifest, the diff, and the four changed files in the diff.
  • Read the head code through the reader:
python3 repo_read.py cat core/libs/prx/libSceAgcDriver/tools/FrameReplay.cpp 150 250
python3 repo_read.py cat core/libs/prx/libSceAgcDriver/tools/FrameReplay.cpp 296 335
python3 repo_read.py cat core/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_frame_replay_tests.cmake 1 30
python3 repo_read.py search "committedWritable" core/libs/prx/libSceAgcDriver/tools/FrameReplay.cpp
python3 repo_read.py search "commit(chunk" core/libs/prx/libSceAgcDriver/tools/FrameReplay.cpp
python3 repo_read.py search "WindowsMappings::Commit" core/libs
  • No build and no test run in this review.

Results

Check Result Note
Diff and description read passed 4 files
Head code of commit and its caller passed Linux path unchanged
Build of the test target not run
agc_driver_frame_replay_subpage not run Author reports Windows runs only
Negative control not run Author reports one; not reproduced
Commands and output

Only the reader commands listed under What I ran were run. No test command was run.

Findings

Blocking

None.

Non-blocking

  • core/libs/prx/libSceAgcDriver/tests/FrameReplay.cpp:302 sets Second to 0x1010, while First is 0x20 (line 301). On Windows the host page is 4 KiB on x64, so the two ranges round to different host pages and the test does not reach the case the description names, a later range in a page that is already committed. Keeping both in one page would need only a small change:
    constexpr std::size_t Second = 0x40;

Not verified

  • The helpers the new test calls (allocate, pattern, copyFrame, FrameCaptureReader, at, readFile, check) were not read at head. Only the diff hunks of tests/FrameReplay.cpp were read.
  • WindowsMappings::Commit: the description says a range in an already committed page only changes that page's protection. The reader search at head did not find its definition, so this was not checked.
  • Protection: commit sets every touched host page to read-write (0x04) on Windows, including bytes outside the captured range. The effect on neighbouring ranges was not checked.
  • The description says both ranges are "inside one guest page". The guest page size was not checked.
  • Linux: the cmake file registers agc_driver_frame_replay_subpage on Linux as well as Windows (tests/cmake/agc_driver_frame_replay_tests.cmake:2, :23). No Linux run was reported.
  • The Windows runs, the ctest result, and the negative control come from the description. They were not reproduced here.

To get this to a good state

Nothing is required. The optional point is under Findings.

Sources

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 12568 core/libs/prx/libSceAgcDriver/tests/FrameReplay.cpp L1620-1621

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 1835 docs/dev/BUILD.md
PR 11435 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
docs/dev/BUILD.md
PR 11436 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
docs/dev/BUILD.md
PR 15136 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
docs/dev/BUILD.md
PR 15456 docs/dev/BUILD.md
PR 16793 docs/dev/BUILD.md
PR 18208 docs/dev/BUILD.md
PR 18210 docs/dev/BUILD.md
PR 19557 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
docs/dev/BUILD.md
PR 19610 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
docs/dev/BUILD.md
PR 19670 docs/dev/BUILD.md
PR 20315 docs/dev/BUILD.md
PR 21222 docs/dev/BUILD.md
PR 21939 docs/dev/BUILD.md
PR 22004 docs/dev/BUILD.md
PR 22434 docs/dev/BUILD.md
PR 22594 docs/dev/BUILD.md
PR 22647 docs/dev/BUILD.md
PR 24402 docs/dev/BUILD.md
PR 26131 docs/dev/BUILD.md
PR 26298 core/libs/prx/libSceAgcDriver/tests/FrameReplay.cpp
core/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_frame_replay_tests.cmake
PR 26613 docs/dev/BUILD.md
PR 26615 docs/dev/BUILD.md
PR 27133 docs/dev/BUILD.md

@LeandroLP23

Copy link
Copy Markdown
Contributor Author

Thanks for the review.

  1. You're right: +0x20 and +0x1010 are in different 4 KiB host pages, so the test never committed a range into a page an earlier range had already committed. da11124 adds a 16-byte range at +0x40, in the host page of the 1-byte one, and keeps the 48-byte range at +0x1010 in the next page; the replay restores all three. With the tools/FrameReplay.cpp change reverted the test still fails (split guest placeholder prefix, exit 2); with it, all 48 agc_driver_frame_replay* tests pass on a Radeon 860M.
  2. Checked against the code:
    • WindowsMappings::Commit on a committed page takes the MEM_COMMIT branch, which only resets the tracking state of shared views on that page and calls VirtualProtect. The +0x40 range now goes through it.
    • Read-write over the whole page: commit already used 0x04 for every range and still does, so no captured range changes protection. The other bytes of a shared page belong to no captured range, and the replay neither reads nor restores them. Linux already sets the whole page read-write through GuestArenaSetProtection.
    • Page size: the unit is the 4 KiB Windows host page (dwPageSize), not the 16 KiB PS5 page. The body and BUILD.md said "guest page"; both now say host page.
    • Linux: not run. The Linux branch of commit is unchanged, and the body now says the test was not run there.

I also corrected the body: gpu_write_before_delta passes after a full build; its std::bad_alloc came from a partial build.

AI-assisted: yes (Claude Code)

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — looks good

The changed code implements Windows page-rounded commits for replayed ranges; all four changed files and their added lines were read, and no concrete defect was found in the inspected code.

What I ran

No commands were run. Reviewed head da111246be6a0456a853a7a0fd838fed31e12af0 using the supplied diff and repo_read.py.

Results

Check Result Note
Changed lines read passed All four changed files
Build and tests not run Author reports Windows tests; not independently run

Findings

Blocking

None.

Non-blocking

None.

Not verified

Builds, tests, Linux behavior, and console behavior were not independently verified. The author reports Windows 11 testing and passing replay tests. No files were excluded from the review; all four changed files listed in the manifest were read.

To get this to a good state

Nothing is required.

@Jazeupoi Jazeupoi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on NVIDIA, since the description's run is on an AMD iGPU.

Setup: Windows 11 Pro (build 26300), AMD Ryzen 5 3400G, NVIDIA GeForce RTX 2060 (driver 621.24), WinLibs GCC 15.2.0, Release. Base: main 1118567b8b with #22373 (a test-build fix only). "This PR" is the same tree with head da111246be merged.

All ^agc_driver_frame_replay tests, 3 runs each, with VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, VK_LOADER_DEBUG=layer, ANYPS5_NO_SHADER_CACHE=1 and ANYPS5_REQUIRE_VULKAN=1 (ctest -V, validation layer 1.4.363):

tests result layer inserted not found lines VUID-
main 47 3/3 runs pass 44 per run 0 0
this PR 48 3/3 runs pass 45 per run 0 0

The extra test is the new agc_driver_frame_replay_subpage, which passes in every run. No new validation errors.

AI-assisted: yes (Claude Code)

@Lyrnc

Lyrnc commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Windows run on two more GPUs, one of them NVIDIA. Head da111246be merged onto main 6286d36449 (clean merge).

Setup: Windows 11 Pro 10.0.26200, WinLibs GCC 15.2.0 r7 UCRT, Ninja, Release, ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, GPU picked with ANYPS5_GPU. No validation layer on this machine.

test NVIDIA GeForce RTX 5080 (610.88) AMD Radeon Graphics, Ryzen 7 9800X3D iGPU (2026.04.17)
agc_driver_frame_replay_subpage 3 of 3 pass 3 of 3 pass
agc_driver_frame_replay 3 of 3 pass 3 of 3 pass
agc_driver_frame_replay_gpu_write_before_delta 3 of 3 pass 3 of 3 pass

ctest -R frame_replay on the RTX 5080 (-j 8): 50 of 50 pass.

AI-assisted: yes

@Colewiz7

Copy link
Copy Markdown
Contributor

Head da111246be merged onto main 26604382a5 as 308832721d, no conflict. Linux 7.3.4, GCC 16.2.1 Release, Mesa 26.2.6 RADV, RX 7900 XT (gfx1100) and 7800X3D iGPU (gfx1036).

No new failures and no new validation messages on either GPU.

RX 7900 XT iGPU
tests run (6176 on the 7900 XT, the 2008 GPU ones on the iGPU), new failures vs main none none
-R '^agc' (1941 tests) with the layer, new failures vs main none none
VUID- / SYNC-HAZARD lines 0 / 0 0 / 0

Layer runs used VK_LAYER_KHRONOS_validation 1.4.363.1 with VK_LOADER_DEBUG=layer and ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1; the loader inserted the layer in every run, and the set of distinct validation messages matches main.

AI-assisted: yes

@ShootanoJumper

Copy link
Copy Markdown
Contributor

Windows 11 22631, RTX 4060 (616.56): the new agc_driver_frame_replay_subpage passes. Of the 1270 tests the change reaches, the only failures are 2 that main also fails on this GPU (#23232, msaa_dcc_unwatch).

@rafaconvaitis

Copy link
Copy Markdown
Contributor

A Windows confirmation with captures of a real title, on two GPUs.

Setup: Windows 11 25H2 (build 26200), WinLibs GCC 15.2.0 r7 UCRT, Release. Two GPUs in one machine, picked with ANYPS5_GPU: AMD Radeon 760M (AMD Software 26.11.2) and NVIDIA GeForce RTX 3050 (610.88). Two captures of SwanStationPS5 (PPSA98510, releases 1.6.2 and 1.6.6, open-source homebrew) recorded on main dd9b766645 with APS5_FRAME_CAPTURE_AT_FLIP=900 and APS5_FRAME_CAPTURE_FRAMES=3 (130 ranges, 173 MB of snapshot for 1.6.6). agc_frame_replay <capture> --frames <dir>:

agc_frame_replay capture Radeon 760M RTX 3050
main dd9b766645 1.6.2 stops: split guest placeholder prefix stops: split guest placeholder prefix
main dd9b766645 1.6.6 stops: split guest placeholder prefix stops: split guest placeholder prefix
head da111246be merged onto dd9b766645 1.6.2 3 frames, 4 submits, 0 unfinished, 99.2% identical pixels 3 frames, 4 submits, 0 unfinished, 100% identical
head da111246be merged onto dd9b766645 1.6.6 3 frames, 3 submits, 0 unfinished 3 frames, 3 submits, 0 unfinished, 100% identical
  • On main each replay stops before restoring any memory, with the Windows message for ERROR_INVALID_PARAMETER after split guest placeholder prefix.
  • The captures were made on the RTX 3050, so the reference images are that GPU's. The 1.6.6 capture is the black-frame case of AGC: SwanStationPS5 (PPSA98510) presents only black frames from release 1.6.3 on; 1.6.2 renders #23964: the replay reproduces it, black on the RTX 3050 and the library screen on the Radeon 760M (hence 0% identical there), which makes it usable for that issue.

AI-assisted: yes (build and runs scripted with an AI assistant, on the hardware above).

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — looks good

The Windows page rounding change and its regression test are consistent with the stated sub-page replay failure; no blocking defect was found in the changed code read.

What I ran

Reviewed head bfa37d58c46743d17e325d39c50b8d3d92b4878e in boykopovar/AnyPS5. Read the prepared description, commits, diff, manifest, and all four changed files; inspected the affected replay logic and test registration with repo_read.py reader tools. No build or test commands were run. The description reports Windows 11 tests and notes Linux was not run; those results were not independently verified.

Results

Check Result Note
Diff and changed code review passed Four changed files read
Build and tests not run Author-reported results only
Files excluded by rule not applicable files.json was unavailable

Findings

Blocking

None.

Non-blocking

None.

Not verified

The runtime behavior, reported test outcomes, and validation on Linux were not independently verified. files.json was unavailable, so the excluded-file list could not be checked.

To get this to a good state

Nothing is required.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Nov 26, 2026
LeandroLP23 and others added 2 commits November 26, 2026 13:15
… on Windows

A guest allocation registry can hold ranges smaller than a page at
addresses inside one (SuperTuxKart's heap registers allocations of a few
bytes). agc_frame_replay committed each captured range at its own
address and size, which on Windows splits the arena's placeholder there,
and VirtualFree refuses a split inside a page: the replay stopped at
"split guest placeholder prefix" before restoring any memory. Commit the
pages that hold the range instead; a later range in a page already
committed only changes its protection. Linux keeps its own path.

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@LeandroLP23
LeandroLP23 force-pushed the fix/agc-replay-subpage-ranges branch from bfa37d5 to 4960cbb Compare November 26, 2026 13:12
@LeandroLP23

Copy link
Copy Markdown
Contributor Author

Rebased onto main 37749b6cd5 (head 4960cbb5ff). The only conflict was the mode list in tests/FrameReplay.cpp, where main added gpu_only and this PR adds subpage; both are kept. Nothing else changed.

On the Radeon 860M laptop (AMD 26.10.2, Windows 11 26300, WinLibs GCC 15.2.0 r7, Release), ctest -R '^agc_driver_frame_replay' -V was run with the four validation variables set. main passes 61 of 61 and this head passes 62 of 62; the extra test is this PR's subpage case. Both logs have 0 VUID- lines, the layer is inserted in every GPU test, and no layer is reported missing.

AI-assisted: yes (Claude Code)

@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Changes: Sub-page Frame Replay

Layer / File(s) Summary
Page-aligned Windows commits
core/libs/prx/libSceAgcDriver/tools/FrameReplay.cpp
On Windows, commit rounds the chunk range to system-page boundaries before committing it. Other platforms retain the original pointer and byte count.
Sub-page capture and replay coverage
core/libs/prx/libSceAgcDriver/tests/FrameReplay.cpp, core/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_frame_replay_tests.cmake, docs/dev/BUILD.md
The subpage mode tests capture and strict replay of three registered sub-page ranges. CTest registers the mode, and the build documentation lists it with related replay tests.

Suggested reviewers: janzezno, marczx10, jazeupoi

Change: Bug fix

Merge Risk: Minimal · up to 4960c

This change fixes Windows frame replay failures for captured memory ranges smaller than a page, and adds a test and documentation for it. No merge-blocking risk was found. The Linux path is unchanged.

Security architecture risk: Minimal · up to 4960c

Windows replay can now restore small captured allocations by making their containing pages writable. It still registers and restores the original byte ranges. The review did not identify a new security or failure-containment risk.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The changed permission scope is the set of host pages intersecting accepted guest ranges in the local Windows replay process. The rounded interval remains subject to arena bounds, and the mapping operation targets the current process.

Trust Boundaries and Controls

  • observed — Capture-provided addresses and lengths reach the mapping operation through the existing replay path. The guest-arena claim rejects overlapping byte ranges, and the Windows commit checks the full page envelope before changing permissions.

Resilience and Maintainability Implications

  • inferred — Initial mapping is serialized before snapshot workers start. A later range on an already committed page uses the existing protection-update path rather than replacing the page. A commit exception aborts initial replay and exits the process rather than continuing with partial mappings; repeat passes use the existing reset path instead of rerunning initial commit.
Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 94a06988-a533-4f98-a603-b06eb8eb4d33
Commits

Reviewing files that changed from the base of the PR and between c636b0c and 4960cbb.

Files selected for processing: 4

  • 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
  • docs/dev/BUILD.md

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — looks good

The change rounds Windows replay commits to host-page boundaries and adds coverage for multiple sub-page ranges that share committed pages.

What I ran

Reviewed head 4960cbb5ff4318ab23bfa29992192edd1e65cc3c. No commands or tests were run in this review session; the test results in the PR description are author-reported.

Read all changed files: core/libs/prx/libSceAgcDriver/tools/FrameReplay.cpp, core/libs/prx/libSceAgcDriver/tests/FrameReplay.cpp, core/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_frame_replay_tests.cmake, and docs/dev/BUILD.md. All four are listed as included in review/manifest.json; no excluded-file list was available.

Results

Check Result Note
Changed-file review passed All four changed files read
Tests in this session not run Results in description are author-reported
Windows page rounding passed Uses the system page size

Findings

Blocking

None.

Non-blocking

None.

Not verified

The reported Windows test suite and negative control were not independently rerun. Linux runtime behavior was not tested in this review session.

To get this to a good state

Nothing is required.

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Nov 26, 2026
@oneandonlydean
oneandonlydean merged commit 566e3c6 into boykopovar:main Nov 26, 2026
15 of 17 checks passed
@LeandroLP23
LeandroLP23 deleted the fix/agc-replay-subpage-ranges branch November 26, 2026 21:17
CPritch pushed a commit to CPritch/AnyPS5 that referenced this pull request Nov 26, 2026
…ubpage-ranges

fix(agc): commit the pages of a sub-page capture range when replaying on Windows
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants