fix(agc): bound the upload buffers that recorder batches keep alive #1113

Merged
Celegans12 merged 1 commit from upstream-pr/1113 into main 2026-10-08 07:39:57 +00:00
Celegans12 commented 2026-10-07 12:54:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-07T12:54:51Z.


What

A recorded texture upload keeps its staging, tiled and linear buffers until its batch completes, and nothing limited how much a batch keeps.

  • Recorder::Keep takes an optional byte count, passed by the sampled upload (Texture constructor) and the StorageTexture upload and write-back scratch buffers.
  • Recorder::BoundKeptBytes runs at the start of cachedTexture and cachedStorageTexture, before anything is recorded (the flush hook's SyncThrough can already submit there). It submits the open batch once it keeps KeptBytesBudget (512 MiB). While the batches in flight plus those this thread already finished in the hold (Sync, Reap) keep more than twice that, it destroys the finished ones' objects, then waits for the oldest in flight and destroys its objects, not at the unlock, so the buffers return to BufferPool within a hold.
  • PPSA26344 v1.008: one DRAW_INDIRECT uploads ~10.6k BC textures for its image table into one batch during a 10-12 s hold; at 219 s a 0.7 MiB texture allocation fails with VK_ERROR_OUT_OF_DEVICE_MEMORY (6.6 GiB of device buffers live) and the draw is skipped.
  • #290 retries a draw after such an error; this keeps the burst from causing one. #425, #639, #788, #866 and #1059 edit the same functions without conflicting with this change.

Tested

  • Windows 11, MinGW-w64 GCC 15.2.0, based on main e2b527bb: configure -DBUILD_TESTING=ON, full build, --target libs, ctest:
  • 386/386 tests pass (ctest --output-on-failure)
  • Same build on lavapipe (Mesa 26.2.4 llvmpipe, 8-wide subgroups, VK_DRIVER_FILES): 385/385 pass; agc_driver_flat_store is left out there because it takes several minutes on Windows llvmpipe
  • New agc_recorder_kept_bytes (mock device): a batch is submitted at the budget, not below; six budget batches leave two in flight and the four oldest released under the GPU mutex, and six synced one by one in one hold leave at most two alive. Does not compile on main.
  • PPSA26344 v1.008: in a 2,700 s run with this change no allocation fails, although the image-table DRAW_INDIRECT records 585k texture uploads; device buffers peak at 2.7 GiB. A 1,500 s run without it failed at the first such burst (~700 s, 6.6 GiB of device buffers live).
  • 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:4772935384 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1113). Originally posted by [Celegans12](https://github.com/Celegans12) on 2026-10-07T12:54:51Z. --- ### What A recorded texture upload keeps its staging, tiled and linear buffers until its batch completes, and nothing limited how much a batch keeps. - `Recorder::Keep` takes an optional byte count, passed by the sampled upload (`Texture` constructor) and the `StorageTexture` upload and write-back scratch buffers. - `Recorder::BoundKeptBytes` runs at the start of `cachedTexture` and `cachedStorageTexture`, before anything is recorded (the flush hook's `SyncThrough` can already submit there). It submits the open batch once it keeps `KeptBytesBudget` (512 MiB). While the batches in flight plus those this thread already finished in the hold (`Sync`, `Reap`) keep more than twice that, it destroys the finished ones' objects, then waits for the oldest in flight and destroys its objects, not at the unlock, so the buffers return to `BufferPool` within a hold. - PPSA26344 v1.008: one `DRAW_INDIRECT` uploads ~10.6k BC textures for its image table into one batch during a 10-12 s hold; at 219 s a 0.7 MiB texture allocation fails with `VK_ERROR_OUT_OF_DEVICE_MEMORY` (6.6 GiB of device buffers live) and the draw is skipped. - #290 retries a draw after such an error; this keeps the burst from causing one. #425, #639, #788, #866 and #1059 edit the same functions without conflicting with this change. ### Tested - Windows 11, MinGW-w64 GCC 15.2.0, based on `main` e2b527bb: configure `-DBUILD_TESTING=ON`, full build, `--target libs`, `ctest`: - 386/386 tests pass (`ctest --output-on-failure`) - Same build on lavapipe (Mesa 26.2.4 llvmpipe, 8-wide subgroups, `VK_DRIVER_FILES`): 385/385 pass; `agc_driver_flat_store` is left out there because it takes several minutes on Windows llvmpipe - New `agc_recorder_kept_bytes` (mock device): a batch is submitted at the budget, not below; six budget batches leave two in flight and the four oldest released under the GPU mutex, and six synced one by one in one hold leave at most two alive. Does not compile on `main`. - PPSA26344 v1.008: in a 2,700 s run with this change no allocation fails, although the image-table `DRAW_INDIRECT` records 585k texture uploads; device buffers peak at 2.7 GiB. A 1,500 s run without it failed at the first such burst (~700 s, 6.6 GiB of device buffers live). - 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 19:36:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-07T19:36:37Z.


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
#1180 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp L89-96
core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp L315-317, L1492
#1199 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp L285-286
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6045393041 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1113#issuecomment-6045393041). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-07T19:36:37Z. --- <!-- 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 | |---|---|---|---| | #1180 | `core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp` [L89-96](https://github.com/boykopovar/AnyPS5/blob/df16c4c256be3c44e03eb9149a6ce5f8e8a038b2/core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp#L89-L96)<br>`core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp` [L315-317](https://github.com/boykopovar/AnyPS5/blob/df16c4c256be3c44e03eb9149a6ce5f8e8a038b2/core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp#L315-L317), [L1492](https://github.com/boykopovar/AnyPS5/blob/df16c4c256be3c44e03eb9149a6ce5f8e8a038b2/core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp#L1492) | | | | #1199 | `core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp` [L285-286](https://github.com/boykopovar/AnyPS5/blob/df16c4c256be3c44e03eb9149a6ce5f8e8a038b2/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp#L285-L286) | | |
adriadam10 commented 2026-10-08 07:39:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T07:39:53Z.


Checked on current main: build + full ctest (424/424, agc_recorder_kept_bytes included); the new test doesn't compile without the change; every path that takes a batch out of inFlight goes through finish, so the byte count stays consistent. CI is green on the current head. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6055109817 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1113#issuecomment-6055109817). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-08T07:39:53Z. --- Checked on current `main`: build + full ctest (424/424, `agc_recorder_kept_bytes` included); the new test doesn't compile without the change; every path that takes a batch out of `inFlight` goes through `finish`, so the byte count stays consistent. CI is green on the current head. Merging.
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!1113
No description provided.