perf(agc): pool device staging buffers by size class #1004

Merged
Celegans12 merged 1 commit from upstream-pr/1004 into main 2026-10-09 19:06:33 +00:00
Celegans12 commented 2026-10-06 22:52:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-06T22:52:27Z.


What

The device-local tier of BufferPool only reused a buffer of the exact same size and usage. Partial storage-image detiles and retiles ask for a new size and the other transfer direction almost every time, so in PPSA26344 the tier sits at its 512 MiB budget and misses and evicts ~77 buffers per frame. The release thread then spends ~38 ms per frame in vkFreeMemory, which on NVIDIA also holds up vkQueueSubmit (mean ~0.7 ms).

  • Device-tier requests of 1 MiB and more round up to an eighth of their octave (at most 12.5% larger); smaller ones keep their power-of-two classes.
  • Device-tier buffers are created with STORAGE | TRANSFER_SRC | TRANSFER_DST added (BufferPool::Usage), so uploads, write-backs and staging shadows share a list; SHADER_DEVICE_ADDRESS and INDIRECT requests keep their own.
  • Take serves a request from the smallest retained buffer of its class up to twice its size; the buffer returns to its own class. Callers bind and copy explicit sizes, as with the small classes.
  • Host tiers, the budget, LRU eviction and reuse only after release are unchanged. APS5_NO_BUFFER_CLASSES=1 still matches exact sizes.
  • #290 adds GPU memory accounting in the same files; the Resources.cpp conflict is textual, so whichever lands second needs a small rebase.

Tested

  • Windows 11, MinGW-w64 GCC 15.2.0, based on main ab9437e3: configure -DBUILD_TESTING=ON, full build, --target libs, ctest:
  • 368/368 tests pass (ctest --output-on-failure)
  • Same build on lavapipe (Mesa 26.2.4 llvmpipe, 8-wide subgroups, VK_DRIVER_FILES): 367/367 pass; agc_driver_flat_store is left out there because it takes several minutes on Windows llvmpipe
  • New agc_buffer_pool (mock device): size classes, shared directions, the 2x fit, reuse only after release, budget. Fails on main.
  • Scratch detile/retile benchmark, RTX 3080 Laptop: frees 68 to 9 per frame, release thread 46 to 4 ms, submit mean 0.48 to 0.17 ms.
  • PPSA26344 v1.008 (with #903): device-tier misses 79 to 40 and release thread 43 to 17 ms per frame, submit mean 0.69 to 0.55 ms; same frames.
  • Not tested: Linux (CI), console behaviour.

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 in TechnicalDebt
  • 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
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4765528099 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1004). Originally posted by [Celegans12](https://github.com/Celegans12) on 2026-10-06T22:52:27Z. --- ### What The device-local tier of `BufferPool` only reused a buffer of the exact same size and usage. Partial storage-image detiles and retiles ask for a new size and the other transfer direction almost every time, so in PPSA26344 the tier sits at its 512 MiB budget and misses and evicts ~77 buffers per frame. The release thread then spends ~38 ms per frame in `vkFreeMemory`, which on NVIDIA also holds up `vkQueueSubmit` (mean ~0.7 ms). - Device-tier requests of 1 MiB and more round up to an eighth of their octave (at most 12.5% larger); smaller ones keep their power-of-two classes. - Device-tier buffers are created with `STORAGE | TRANSFER_SRC | TRANSFER_DST` added (`BufferPool::Usage`), so uploads, write-backs and staging shadows share a list; `SHADER_DEVICE_ADDRESS` and `INDIRECT` requests keep their own. - `Take` serves a request from the smallest retained buffer of its class up to twice its size; the buffer returns to its own class. Callers bind and copy explicit sizes, as with the small classes. - Host tiers, the budget, LRU eviction and reuse only after release are unchanged. `APS5_NO_BUFFER_CLASSES=1` still matches exact sizes. - #290 adds GPU memory accounting in the same files; the `Resources.cpp` conflict is textual, so whichever lands second needs a small rebase. ### Tested - Windows 11, MinGW-w64 GCC 15.2.0, based on `main` ab9437e3: configure `-DBUILD_TESTING=ON`, full build, `--target libs`, `ctest`: - 368/368 tests pass (`ctest --output-on-failure`) - Same build on lavapipe (Mesa 26.2.4 llvmpipe, 8-wide subgroups, `VK_DRIVER_FILES`): 367/367 pass; `agc_driver_flat_store` is left out there because it takes several minutes on Windows llvmpipe - New `agc_buffer_pool` (mock device): size classes, shared directions, the 2x fit, reuse only after release, budget. Fails on main. - Scratch detile/retile benchmark, RTX 3080 Laptop: frees 68 to 9 per frame, release thread 46 to 4 ms, submit mean 0.48 to 0.17 ms. - PPSA26344 v1.008 (with #903): device-tier misses 79 to 40 and release thread 43 to 17 ms per frame, submit mean 0.69 to 0.55 ms; same frames. - Not tested: Linux (CI), console behaviour. ### 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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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] AI-assisted: yes
github-actions[bot] commented 2026-10-07 00:03:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-07T00:03:29Z.


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
#1147 core/libs/prx/libSceAgcDriver/Graphics/include/BufferPool.hpp L93-94
core/libs/prx/libSceAgcDriver/Graphics/src/BufferPool.cpp L58
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6027806608 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1004#issuecomment-6027806608). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-07T00:03:29Z. --- <!-- pr-overlap --> 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 | |---|---|---|---| | #1147 | `core/libs/prx/libSceAgcDriver/Graphics/include/BufferPool.hpp` [L93-94](https://github.com/boykopovar/AnyPS5/blob/df16c4c256be3c44e03eb9149a6ce5f8e8a038b2/core/libs/prx/libSceAgcDriver/Graphics/include/BufferPool.hpp#L93-L94)<br>`core/libs/prx/libSceAgcDriver/Graphics/src/BufferPool.cpp` [L58](https://github.com/boykopovar/AnyPS5/blob/df16c4c256be3c44e03eb9149a6ce5f8e8a038b2/core/libs/prx/libSceAgcDriver/Graphics/src/BufferPool.cpp#L58) | | |
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!1004
No description provided.