perf(agc): hold a staged region's changed-copy snapshot only while a batch uses it #18388

Merged
simnJS merged 2 commits from upstream-pr/18388 into main 2026-11-16 05:56:21 +00:00
simnJS commented 2026-11-11 13:15:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by simnJS on 2026-11-11T13:15:53Z.


What

Every staged region of a cached build keeps two device-local buffers: its shadow, and the snapshot the changed-byte copy-back compares the shader's stores against. The snapshot is only read between the copy-in and the copy-back of one use, and no descriptor names it. It stayed with the build anyway, so half of the device memory held by staging grew with the build cache. That growth is what #18356 bounds.

The region now keeps a weak reference once its copy-back is recorded:

  • A use recorded while an earlier batch still holds the snapshot takes the same one, exactly as before.
  • Once no batch holds it, the buffer returns to the buffer pool's device tier, and the next use takes one from there.

Nothing changes in what is copied or stored.

This composes with #18356 (a local merge is clean): under its bound, the snapshots no longer count against the limit while idle, so about twice as many regions can stay staged.

Tested

  • Linux, lavapipe (Mesa 25.2.8, llvmpipe), GCC 13, Release. No hardware GPU and no title: not measured on a game.
  • Same focused tests on main (a57e435a53) and on this branch, with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation: ctest -R '^agc_driver_(recorded_draw_staging|overlap_staged_copies|partially_resident_snapshot|prepared_publication|resident_heap_mirror|recorder)|^agc_(buffer_pool|adaptive_staging)' -V.
    • Both runs: 10 of 10 pass, with agc_driver_recorded_draw_staging skipped on both (lavapipe does not keep host imports write-watched).
    • Neither log contains was not found but was requested by env var VK_INSTANCE_LAYERS.
    • Both logs hold the same single VUID-VkDeviceCreateInfo-pNext-pNext, 18 times each. No new VUID-.
  • agc_driver_overlap_staged_copies now checks that each of its three rounds over the same builds takes its snapshots again and that none outlives its batch. With the release removed, it fails with 1024 bytes of changed-copy snapshots are still held after the queue went idle.
  • To measure on a title: compare the device-local heap use and the [buffers] staging line under APS5_PROFILE_DRAW between main and this branch in a long session, e.g. the #18020 scene.

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: lavapipe only (llvmpipe, Mesa 25.2.8, Ubuntu 24.04); no hardware GPU
  • AI-assisted: yes ( fable 5.2 )
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5260150521 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18388). Originally posted by [simnJS](https://github.com/simnJS) on 2026-11-11T13:15:53Z. --- ### What Every staged region of a cached build keeps two device-local buffers: its shadow, and the snapshot the changed-byte copy-back compares the shader's stores against. The snapshot is only read between the copy-in and the copy-back of one use, and no descriptor names it. It stayed with the build anyway, so half of the device memory held by staging grew with the build cache. That growth is what #18356 bounds. The region now keeps a weak reference once its copy-back is recorded: - A use recorded while an earlier batch still holds the snapshot takes the same one, exactly as before. - Once no batch holds it, the buffer returns to the buffer pool's device tier, and the next use takes one from there. Nothing changes in what is copied or stored. This composes with #18356 (a local merge is clean): under its bound, the snapshots no longer count against the limit while idle, so about twice as many regions can stay staged. ### Tested - Linux, lavapipe (Mesa 25.2.8, llvmpipe), GCC 13, Release. No hardware GPU and no title: **not measured on a game**. - Same focused tests on `main` (a57e435a53) and on this branch, with `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`: `ctest -R '^agc_driver_(recorded_draw_staging|overlap_staged_copies|partially_resident_snapshot|prepared_publication|resident_heap_mirror|recorder)|^agc_(buffer_pool|adaptive_staging)' -V`. - Both runs: 10 of 10 pass, with `agc_driver_recorded_draw_staging` skipped on both (lavapipe does not keep host imports write-watched). - Neither log contains `was not found but was requested by env var VK_INSTANCE_LAYERS`. - Both logs hold the same single `VUID-VkDeviceCreateInfo-pNext-pNext`, 18 times each. No new `VUID-`. - `agc_driver_overlap_staged_copies` now checks that each of its three rounds over the same builds takes its snapshots again and that none outlives its batch. With the release removed, it fails with `1024 bytes of changed-copy snapshots are still held after the queue went idle`. - To measure on a title: compare the device-local heap use and the `[buffers] staging` line under `APS5_PROFILE_DRAW` between `main` and this branch in a long session, e.g. the #18020 scene. ### 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: lavapipe only (llvmpipe, Mesa 25.2.8, Ubuntu 24.04); no hardware GPU - [x] AI-assisted: yes ( fable 5.2 )
MarcZX10 commented 2026-11-12 14:25:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-12T14:25:08Z.

Review: COMMENTED


Reviewed — no blocking findings

Nothing blocks this; the points below are optional.

What I ran

Head a0d1e9fc50b57fe8cd780664fed9bc1e19e4b24c, base main. I read the description, the commits, the manifest and the diff of the four changed files, then the changed code at head through the reader:

python3 repo_read.py search shadowCopy core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
python3 repo_read.py cat core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp 6650 6700
python3 repo_read.py cat core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp 6735 6806
python3 repo_read.py search "stagingBuffer(" core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
python3 repo_read.py cat core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp 5832 5860
python3 repo_read.py search WithinDeviceLocalHeadroom core/libs/prx/libSceAgcDriver
python3 repo_read.py cat core/libs/prx/libSceAgcDriver/Graphics/src/Resources.cpp 58 80

No build and no test run in this pass.

Results

Check Result Note
Diff of the four changed files passed every changed hunk read
Lifetime of the snapshot at head passed both Keep calls hold it until its batch completes
Build and unit tests not run no build in this pass
Author's lavapipe run not run reported by the author, not reproduced

Findings

Blocking

None.

Non-blocking

  1. core/libs/prx/libSceAgcDriver/tests/execution/OverlapStagedCopies.cpp:229: changedCopyBacks is set from round 1 alone, and the snapshot check for rounds 2 and 3 runs only when round 1 took a snapshot. If round 1 takes none, the snapshot check and the byte check both pass without testing anything, so a regression that stops snapshots from being taken would not show. Suggest checking snapshots != 0 for round 1 directly and dropping the flag.

Not verified

  • Compilation, the new test run and the negative control (the release removed, 1024 bytes still held): not run here. The author reports them on lavapipe; I did not reproduce them.
  • The Buffer destructor returning the snapshot to the buffer pool's device tier: I read only the constructor path (core/libs/prx/libSceAgcDriver/Graphics/src/Resources.cpp, lines 58 to 80).
  • Memory savings ("half of the device memory", "about twice as many regions" with #18356): not measured, and the PR says so.
  • The namespace of the new test calls (AgcDriver::Graphics::) was not checked against the header's enclosing namespace.
  • Full text not read: GuestBufferMemory.hpp (diff hunks only), OverlapStagedCopies.cpp (changed hunks only), docs/dev/debt/libSceAgcDriver.md (diff hunk at lines 374 to 378 only, 451 lines in all), and GuestBufferMemory.cpp (too large for the review folder; read only at the ranges above and at the changed lines in the diff).
  • Excluded by rule: none.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5876082282 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18388#pullrequestreview-5876082282). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-12T14:25:08Z. **Review:** COMMENTED --- # Reviewed — no blocking findings Nothing blocks this; the points below are optional. ## What I ran Head `a0d1e9fc50b57fe8cd780664fed9bc1e19e4b24c`, base `main`. I read the description, the commits, the manifest and the diff of the four changed files, then the changed code at head through the reader: ``` python3 repo_read.py search shadowCopy core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp python3 repo_read.py cat core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp 6650 6700 python3 repo_read.py cat core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp 6735 6806 python3 repo_read.py search "stagingBuffer(" core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp python3 repo_read.py cat core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp 5832 5860 python3 repo_read.py search WithinDeviceLocalHeadroom core/libs/prx/libSceAgcDriver python3 repo_read.py cat core/libs/prx/libSceAgcDriver/Graphics/src/Resources.cpp 58 80 ``` No build and no test run in this pass. ## Results | Check | Result | Note | |---|---|---| | Diff of the four changed files | passed | every changed hunk read | | Lifetime of the snapshot at head | passed | both `Keep` calls hold it until its batch completes | | Build and unit tests | not run | no build in this pass | | Author's lavapipe run | not run | reported by the author, not reproduced | ## Findings ### Blocking None. ### Non-blocking 1. `core/libs/prx/libSceAgcDriver/tests/execution/OverlapStagedCopies.cpp:229`: `changedCopyBacks` is set from round 1 alone, and the snapshot check for rounds 2 and 3 runs only when round 1 took a snapshot. If round 1 takes none, the snapshot check and the byte check both pass without testing anything, so a regression that stops snapshots from being taken would not show. Suggest checking `snapshots != 0` for round 1 directly and dropping the flag. ## Not verified - Compilation, the new test run and the negative control (the release removed, 1024 bytes still held): not run here. The author reports them on lavapipe; I did not reproduce them. - The `Buffer` destructor returning the snapshot to the buffer pool's device tier: I read only the constructor path (`core/libs/prx/libSceAgcDriver/Graphics/src/Resources.cpp`, lines 58 to 80). - Memory savings ("half of the device memory", "about twice as many regions" with #18356): not measured, and the PR says so. - The namespace of the new test calls (`AgcDriver::Graphics::`) was not checked against the header's enclosing namespace. - Full text not read: `GuestBufferMemory.hpp` (diff hunks only), `OverlapStagedCopies.cpp` (changed hunks only), `docs/dev/debt/libSceAgcDriver.md` (diff hunk at lines 374 to 378 only, 451 lines in all), and `GuestBufferMemory.cpp` (too large for the review folder; read only at the ranges above and at the changed lines in the diff). - Excluded by rule: none. ## To get this to a good state Nothing is required.
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!18388
No description provided.