perf(agc): an untracked comparison memo holds until memory it covers is forgotten #14261

Merged
oneandonlydean merged 5 commits from upstream-pr/14261 into main 2026-11-04 03:58:15 +00:00
oneandonlydean commented 2026-11-01 05:05:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-11-01T05:05:44Z.


What

Based on #6187 by @TheAggie, with the main-based port by @tibzejoker as the starting point. The two original commits keep their authorship; the third commit fixes a crash in the new test's teardown and the fourth makes the test skip, instead of passing, when it cannot run.

A storage image over guest memory the write watch does not cover (on Windows, every host-pointer import of the guest mapping, #1441) is checked by comparing its saved bytes with guest memory (StorageTexture::compareUntracked). The comparison is memoized under a stamp, and one part of that stamp was GuestMemory::ForgetSerial, a single counter that moves on every ForgetPages call anywhere in guest memory, so a forget unrelated to the image dropped the memo.

  • ForgetPages also raises a per-block stamp: a fixed table of 65,536 slots, one per 64 KiB block of the forgotten range (block index modulo the table), each holding the newest forget serial that touched it. A range wider than the table raises one shared stamp instead.
  • GuestMemory::ForgetStamp(address, bytes) is the newest of those over a range. A collision between blocks only makes it newer, so the memo is dropped too often, never too rarely.
  • compareUntracked stamps with ForgetStamp of the surface instead of the global serial. A forget in progress (odd ForgetSerial) still disables the memo, as before.

No runtime switch.

Changes against the original PR:

  • Rebased onto current main; the test registration moved to tests/cmake/agc_driver_recorder_tests.cmake.
  • agc_untracked_forget crashed on Linux CI (run 39153907046). The cause was the test, not the memo: it submits refresh work that uses the test's TextureDetiler, and the detiler went out of scope while that work was still in flight. The test now drains the recorder before the detiler is destroyed, and again on every exit path through a small guard. It crashed 3 of 3 times on a software Vulkan device before the change and passed 10 of 10 after it.
  • The test returns the skip code (77) when it cannot run, and prints which write-watch mode (APS5_WRITE_WATCH_IMPORTS) it covered, so a skipped or unwatched run is not read as a pass.

Tested

Linux (kernel 7.2.3), GCC 16.2.1, on main b08c539c50; the branch also merges clean with main b865ce7a93.

  • agc_untracked_forget passes under lavapipe in all three write-watch modes (default probe, APS5_WRITE_WATCH_IMPORTS=watch and =unwatch), 20 of 20 consecutive runs. Only the Recorder test target was built on this base. On the previous base (16452da934) the test crashed 3 of 3 runs before the teardown fix and passed 10 of 10 after it, and the whole ctest -R agc set passed under lavapipe (1146 passed, 73 skipped) with #6192 on top.
  • On a GeForce RTX 4090, agc_untracked_forget passes in watch and unwatch (2 of 2 each) on 16452da934.
  • Windows is untested here. The memo only matters where memory is not write-watched (on Windows, host-pointer imports); on Linux most of guest memory is watched, so this path is rare. The performance figures are in #6192, which carries the stack.

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 4090 (driver 610.57.04, Linux); lavapipe (software Vulkan) for the unit tests
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5104570149 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14261). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-11-01T05:05:44Z. --- ### What Based on #6187 by @TheAggie, with the main-based port by @tibzejoker as the starting point. The two original commits keep their authorship; the third commit fixes a crash in the new test's teardown and the fourth makes the test skip, instead of passing, when it cannot run. A storage image over guest memory the write watch does not cover (on Windows, every host-pointer import of the guest mapping, #1441) is checked by comparing its saved bytes with guest memory (`StorageTexture::compareUntracked`). The comparison is memoized under a stamp, and one part of that stamp was `GuestMemory::ForgetSerial`, a single counter that moves on every `ForgetPages` call anywhere in guest memory, so a forget unrelated to the image dropped the memo. - `ForgetPages` also raises a per-block stamp: a fixed table of 65,536 slots, one per 64 KiB block of the forgotten range (block index modulo the table), each holding the newest forget serial that touched it. A range wider than the table raises one shared stamp instead. - `GuestMemory::ForgetStamp(address, bytes)` is the newest of those over a range. A collision between blocks only makes it newer, so the memo is dropped too often, never too rarely. - `compareUntracked` stamps with `ForgetStamp` of the surface instead of the global serial. A forget in progress (odd `ForgetSerial`) still disables the memo, as before. No runtime switch. Changes against the original PR: - Rebased onto current `main`; the test registration moved to `tests/cmake/agc_driver_recorder_tests.cmake`. - `agc_untracked_forget` crashed on Linux CI (run 39153907046). The cause was the test, not the memo: it submits refresh work that uses the test's `TextureDetiler`, and the detiler went out of scope while that work was still in flight. The test now drains the recorder before the detiler is destroyed, and again on every exit path through a small guard. It crashed 3 of 3 times on a software Vulkan device before the change and passed 10 of 10 after it. - The test returns the skip code (77) when it cannot run, and prints which write-watch mode (`APS5_WRITE_WATCH_IMPORTS`) it covered, so a skipped or unwatched run is not read as a pass. ### Tested Linux (kernel 7.2.3), GCC 16.2.1, on main `b08c539c50`; the branch also merges clean with main `b865ce7a93`. - `agc_untracked_forget` passes under lavapipe in all three write-watch modes (default probe, `APS5_WRITE_WATCH_IMPORTS=watch` and `=unwatch`), 20 of 20 consecutive runs. Only the Recorder test target was built on this base. On the previous base (`16452da934`) the test crashed 3 of 3 runs before the teardown fix and passed 10 of 10 after it, and the whole `ctest -R agc` set passed under lavapipe (1146 passed, 73 skipped) with #6192 on top. - On a GeForce RTX 4090, `agc_untracked_forget` passes in watch and unwatch (2 of 2 each) on `16452da934`. - Windows is untested here. The memo only matters where memory is not write-watched (on Windows, host-pointer imports); on Linux most of guest memory is watched, so this path is rare. The performance figures are in #6192, which carries the stack. ### Checklist - [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: NVIDIA GeForce RTX 4090 (driver 610.57.04, Linux); lavapipe (software Vulkan) for the unit tests - [x] AI-assisted: yes
CnRJay commented 2026-11-01 19:47:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-11-01T19:47:51Z.

Review: COMMENTED


The change itself (a per-block forget stamp instead of the global ForgetSerial in the comparison memo stamp) is reasonable, but the PR is labelled perf(agc) and carries no measurement of its own.

1. No speed evidence. The Tested section says the performance figures are in #6192 and that Windows is untested. Nothing here is a tools/trace_digest.py summary of main and of this change from the same machine and scene. Please add one, on Windows, since the untracked-memory path only exists for host-pointer imports (#1441) and the PR itself says that on Linux most of guest memory is watched.

2. Cost of the lookup. ForgetStamp walks one atomic slot per 64 KiB block of the surface, up to 65,536 slots, on every memo check. For a large storage image that is thousands of loads per refresh, against the single ForgetSerial load it replaces. ForgetPages does the same walk with a CAS loop per slot. Please show this is cheaper than the full compare it avoids on a scene with large untracked images, and say what happens to a ForgetPages of a multi-GiB range.

3. AGC validation. Same-machine main vs change runs of the focused tests with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1 and VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, plus the VUID- comparison, are not shown; the test is described as passing under lavapipe.

4. Stacking. #14262 carries these commits as its first four. Please state the merge order so one of them is not reviewed twice.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5729917101 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14261#pullrequestreview-5729917101). Originally posted by [CnRJay](https://github.com/CnRJay) on 2026-11-01T19:47:51Z. **Review:** COMMENTED --- The change itself (a per-block forget stamp instead of the global `ForgetSerial` in the comparison memo stamp) is reasonable, but the PR is labelled `perf(agc)` and carries no measurement of its own. **1. No speed evidence.** The Tested section says the performance figures are in #6192 and that Windows is untested. Nothing here is a `tools/trace_digest.py` summary of `main` and of this change from the same machine and scene. Please add one, on Windows, since the untracked-memory path only exists for host-pointer imports (#1441) and the PR itself says that on Linux most of guest memory is watched. **2. Cost of the lookup.** `ForgetStamp` walks one atomic slot per 64 KiB block of the surface, up to 65,536 slots, on every memo check. For a large storage image that is thousands of loads per refresh, against the single `ForgetSerial` load it replaces. `ForgetPages` does the same walk with a CAS loop per slot. Please show this is cheaper than the full compare it avoids on a scene with large untracked images, and say what happens to a `ForgetPages` of a multi-GiB range. **3. AGC validation.** Same-machine `main` vs change runs of the focused tests with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1` and `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, plus the `VUID-` comparison, are not shown; the test is described as passing under lavapipe. **4. Stacking.** #14262 carries these commits as its first four. Please state the merge order so one of them is not reviewed twice.
MarcZX10 commented 2026-11-02 07:05:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-02T07:05:18Z.

Review: COMMENTED


Reviewed — no blocking findings; the recorder test was skipped on Windows

The guest-memory "forget" stamps are now kept per 64 KiB block in a fixed table of atomic slots, instead of one global serial, so a comparison memo holds until the memory it covers is forgotten. A block collision only makes a stamp more recent, which keeps the check conservative. The recorder test that covers this path was skipped on the Windows runner, so the change has no hosted pass.

What I ran

  • Head f1a259d63bfd571211c8c4d131f46775c1468333; base f377753dd22fa839d7a9071509ae97c3afaafad2. 5 files, +129/-4: Execution/src/GuestMemory.cpp and Execution/include/GuestMemory.hpp (the slot table, raiseForgetSlot and ForgetStamp), Graphics/src/Texture.cpp (uses the stamp), tests/Recorder.cpp and a CMake fragment (the recorder test).
  • Read the production diff for the two GuestMemory files in full (the slot table, raiseForgetSlot, the forget path and ForgetStamp). Did not read Texture.cpp or the recorder test.
  • Checked the slot maths: a range wider than the slot table returns the global serial (conservative); a narrower range takes the maximum over its blocks, with a shared wide slot.
  • Hosted: agc_driver_recorder is Skipped on the Windows runner (Test #1694), so the new behaviour has no hosted pass.
  • Read-only checks from the trusted main checkout: diff check, conventions and PR template, and the stack check all passed (no declared dependencies, no errors). The ABI audit is not applicable.
  • No MarcZX10 review at this head.

Results

Check Result Note
Diff check passed
Conventions and PR template passed conventions check from the main checkout
Mergeability and dependencies passed stack check passed; no declared dependencies; no errors
Slot maths and the wide-range fallback (read) passed by reading a wide range returns the global serial; a narrow one takes the maximum over its blocks
Collisions only make a stamp more recent (read) passed by reading block % ForgetSlotCount shares slots; the stamp is a maximum
Memory ordering of the stamp (read) passed by reading release on raise, acquire on read
Texture.cpp use and the recorder test (not read) not verified
agc_driver_recorder (hosted, Windows) skipped the test is skipped on the Windows runner
ABI audit not applicable no export changed
Build and runtime tests (Linux) not run Linux is skipped on pull requests
Negative controls not run no local build
Hosted CI passed (build) windows (skipped test), report, conventions and library-portability succeeded; linux, relinkers and write-watch skipped
Read-only check output

Precheck was not run: no PR-head code is run here. Diff check: passed. Conventions: passed. ABI audit: not applicable. Stack check: passed, no errors. Hosted: gh api repos/boykopovar/AnyPS5/commits/f1a259d63bfd571211c8c4d131f46775c1468333/check-runs, and the Windows job log.

Negative control

Not run here. A negative control needs a local build and run of the recorder test, and code from this head is not run here.

Findings

Blocking

None from the code read.

Non-blocking

  • The recorder test is skipped on the Windows runner, so nothing hosted exercises the new stamps. A run of agc_driver_recorder on a host that runs it would show the stale-memo case is covered.

Sources

Not verified

  • Texture.cpp and the recorder test.
  • Whether every caller of the forget path passes the right range.

To get this to a good state

  • Run agc_driver_recorder at this head.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5733071565 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14261#pullrequestreview-5733071565). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-02T07:05:18Z. **Review:** COMMENTED --- # Reviewed — no blocking findings; the recorder test was skipped on Windows The guest-memory "forget" stamps are now kept per 64 KiB block in a fixed table of atomic slots, instead of one global serial, so a comparison memo holds until the memory it covers is forgotten. A block collision only makes a stamp more recent, which keeps the check conservative. The recorder test that covers this path was skipped on the Windows runner, so the change has no hosted pass. ## What I ran - Head `f1a259d63bfd571211c8c4d131f46775c1468333`; base `f377753dd22fa839d7a9071509ae97c3afaafad2`. 5 files, +129/-4: `Execution/src/GuestMemory.cpp` and `Execution/include/GuestMemory.hpp` (the slot table, `raiseForgetSlot` and `ForgetStamp`), `Graphics/src/Texture.cpp` (uses the stamp), `tests/Recorder.cpp` and a CMake fragment (the recorder test). - Read the production diff for the two `GuestMemory` files in full (the slot table, `raiseForgetSlot`, the forget path and `ForgetStamp`). Did not read `Texture.cpp` or the recorder test. - Checked the slot maths: a range wider than the slot table returns the global serial (conservative); a narrower range takes the maximum over its blocks, with a shared wide slot. - Hosted: `agc_driver_recorder` is **Skipped** on the Windows runner (`Test #1694`), so the new behaviour has no hosted pass. - Read-only checks from the trusted main checkout: diff check, conventions and PR template, and the stack check all passed (no declared dependencies, no errors). The ABI audit is not applicable. - No MarcZX10 review at this head. ## Results | Check | Result | Note | | --- | --- | --- | | Diff check | passed | | | Conventions and PR template | passed | conventions check from the main checkout | | Mergeability and dependencies | passed | stack check passed; no declared dependencies; no errors | | Slot maths and the wide-range fallback (read) | passed by reading | a wide range returns the global serial; a narrow one takes the maximum over its blocks | | Collisions only make a stamp more recent (read) | passed by reading | `block % ForgetSlotCount` shares slots; the stamp is a maximum | | Memory ordering of the stamp (read) | passed by reading | release on raise, acquire on read | | `Texture.cpp` use and the recorder test (not read) | not verified | | | `agc_driver_recorder` (hosted, Windows) | skipped | the test is skipped on the Windows runner | | ABI audit | not applicable | no export changed | | Build and runtime tests (Linux) | not run | Linux is skipped on pull requests | | Negative controls | not run | no local build | | Hosted CI | passed (build) | windows (skipped test), report, conventions and library-portability succeeded; linux, relinkers and write-watch skipped | <details><summary>Read-only check output</summary> Precheck was not run: no PR-head code is run here. Diff check: passed. Conventions: passed. ABI audit: not applicable. Stack check: passed, no errors. Hosted: `gh api repos/boykopovar/AnyPS5/commits/f1a259d63bfd571211c8c4d131f46775c1468333/check-runs`, and the Windows job log. </details> ## Negative control Not run here. A negative control needs a local build and run of the recorder test, and code from this head is not run here. ## Findings **Blocking** None from the code read. **Non-blocking** - The recorder test is skipped on the Windows runner, so nothing hosted exercises the new stamps. A run of `agc_driver_recorder` on a host that runs it would show the stale-memo case is covered. ## Sources - Guest memory: https://github.com/boykopovar/AnyPS5/blob/f1a259d63bfd571211c8c4d131f46775c1468333/core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp - Header: https://github.com/boykopovar/AnyPS5/blob/f1a259d63bfd571211c8c4d131f46775c1468333/core/libs/prx/libSceAgcDriver/Execution/include/GuestMemory.hpp - Windows job log: check-run `windows` on f1a259d63bfd571211c8c4d131f46775c1468333 ## Not verified - `Texture.cpp` and the recorder test. - Whether every caller of the forget path passes the right range. ## To get this to a good state - Run `agc_driver_recorder` at this head.
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!14261
No description provided.