perf(agc): reuse read-only guest buffer uploads #18037

Merged
edubox merged 4 commits from upstream-pr/18037 into main 2026-11-14 04:23:49 +00:00
edubox commented 2026-11-10 07:03:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by edubox on 2026-11-10T07:03:52Z.


What

Cache the Vulkan buffer a build copies a read-only guest range into and reuse it across builds while the write watch reports no store over the range.

GuestBufferMemory::copyRegion copied every descriptor-bound guest range into a fresh VkBuffer on each build, even when the range is read-only and unchanged. Planet Zoo's sparse heaps alone re-uploaded about 25 MiB per build, thousands of times per second, and the copies were the largest CPU cost in the resource build (Upload.CopyRegion about 75 ms of a 196 ms frame).

The cache keys the buffer by address, size, VkBufferUsageFlags and the sparse backing pieces, and stores the CollectWrites generation taken before the copy. A later build reuses it while UnchangedSince holds; a build the plan marks written, or a range whose backing pieces changed, never takes the cache and drops the entry, so every sharer of a cached buffer is a reader and concurrent GPU use is safe. APS5_UPLOAD_CACHE_MIB sets the budget (default 512 MiB, 0 disables).

Tested

  • Linux 7.3.1-1-cachyos, NVIDIA GeForce RTX 4080 SUPER, driver 615.78.08.
  • agc_driver_guest_memory_lifetime, agc_driver_host_import_at_map, agc_driver_host_import_proofs, agc_driver_host_import_teardown, agc_driver_recorded_draw_staging and agc_driver_linear_target_dispatch_access: passed.
  • tools/check_conventions.py --base origin/main: passed.
  • Planet Zoo PPSA18026 (Cobra engine): with the cache, 8000 hits over 100 s served 724 GiB without a CPU copy; the run reached presents, exited clean, with no missing functions and 0 failed shaders (1817 compiled). Cache on vs off on the same build and length: 1173 vs 1037 presents (17.6 vs 15.8 average FPS). The scene advances differently between runs, so this is not a formal A/B on the same save.
  • No GPU or title other than the RTX 4080 SUPER and Planet Zoo was exercised.

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
  • 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 4080 SUPER, driver 615.78.08, Linux 7.3.1-1-cachyos
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5237255043 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18037). Originally posted by [edubox](https://github.com/edubox) on 2026-11-10T07:03:52Z. --- ### What Cache the Vulkan buffer a build copies a read-only guest range into and reuse it across builds while the write watch reports no store over the range. `GuestBufferMemory::copyRegion` copied every descriptor-bound guest range into a fresh `VkBuffer` on each build, even when the range is read-only and unchanged. Planet Zoo's sparse heaps alone re-uploaded about 25 MiB per build, thousands of times per second, and the copies were the largest CPU cost in the resource build (`Upload.CopyRegion` about 75 ms of a 196 ms frame). The cache keys the buffer by address, size, `VkBufferUsageFlags` and the sparse backing pieces, and stores the `CollectWrites` generation taken before the copy. A later build reuses it while `UnchangedSince` holds; a build the plan marks written, or a range whose backing pieces changed, never takes the cache and drops the entry, so every sharer of a cached buffer is a reader and concurrent GPU use is safe. `APS5_UPLOAD_CACHE_MIB` sets the budget (default 512 MiB, `0` disables). ### Tested - Linux 7.3.1-1-cachyos, NVIDIA GeForce RTX 4080 SUPER, driver 615.78.08. - `agc_driver_guest_memory_lifetime`, `agc_driver_host_import_at_map`, `agc_driver_host_import_proofs`, `agc_driver_host_import_teardown`, `agc_driver_recorded_draw_staging` and `agc_driver_linear_target_dispatch_access`: passed. - `tools/check_conventions.py --base origin/main`: passed. - Planet Zoo PPSA18026 (Cobra engine): with the cache, 8000 hits over 100 s served 724 GiB without a CPU copy; the run reached `presents`, exited clean, with no missing functions and 0 failed shaders (1817 compiled). Cache on vs off on the same build and length: 1173 vs 1037 presents (17.6 vs 15.8 average FPS). The scene advances differently between runs, so this is not a formal A/B on the same save. - No GPU or title other than the RTX 4080 SUPER and Planet Zoo was exercised. ### 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 - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's technical debt file - [x] No notes, investigation `.md` files or images added to the repository - [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 4080 SUPER, driver 615.78.08, Linux 7.3.1-1-cachyos - [x] AI-assisted: yes
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!18037
No description provided.