perf(agc): recycle descriptor pools after their last set is released #1333

Merged
TibixDev merged 3 commits from upstream-pr/1333 into main 2026-10-11 09:11:25 +00:00
TibixDev commented 2026-10-07 23:45:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by TibixDev on 2026-10-07T23:45:17Z.


What

Recycle descriptor pools after their last live set is released. Skip full pools and terminate if a pool reset fails. Set owners keep their existing GPU lifetime; no GPU wait is added.

Rebased on 66b8abd8. Merged #1065 already fixes the RADV overrun; its padding is retained. This PR adds pool recycling. A long-lived set delays reuse of the rest of its pool.

Tested

Fedora 44 Release: graphics and reset-failure tests pass. RX 6600 and llvmpipe pass the 3,301-set lifecycle test with core and synchronization validation.

An isolated comparison against upstream including #1065 measured 139→31 ns per allocation/release pair for batches, 139→33 ns with one retained set, and 51→30 ns for a rolling 64-set collection. Pool counts were 3→3, 3→4, and 1→2. These are CPU component timings, not title frame times; peak title memory is unmeasured.

The Windows failure test now installs the guest runtime handler. MinGW compiles the test source. The local full Windows link is blocked by unrelated libc SjLj symbols; Windows CI is pending.

Checklist

  • Current main; merged #1065 checked and retained.
  • One topic.
  • No new code comments.
  • Unsupported paths still throw; UI stubs are documented.
  • No notes, logs, or images in the repository.
  • No new third-party code.
  • General behavior.
  • Depends on: none.
  • AI-assisted: yes.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4779834056 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1333). Originally posted by [TibixDev](https://github.com/TibixDev) on 2026-10-07T23:45:17Z. --- ### What Recycle descriptor pools after their last live set is released. Skip full pools and terminate if a pool reset fails. Set owners keep their existing GPU lifetime; no GPU wait is added. Rebased on `66b8abd8`. Merged #1065 already fixes the RADV overrun; its padding is retained. This PR adds pool recycling. A long-lived set delays reuse of the rest of its pool. ### Tested Fedora 44 Release: graphics and reset-failure tests pass. RX 6600 and llvmpipe pass the 3,301-set lifecycle test with core and synchronization validation. An isolated comparison against upstream including #1065 measured 139→31 ns per allocation/release pair for batches, 139→33 ns with one retained set, and 51→30 ns for a rolling 64-set collection. Pool counts were 3→3, 3→4, and 1→2. These are CPU component timings, not title frame times; peak title memory is unmeasured. The Windows failure test now installs the guest runtime handler. MinGW compiles the test source. The local full Windows link is blocked by unrelated libc SjLj symbols; Windows CI is pending. ### Checklist - [x] Current `main`; merged #1065 checked and retained. - [x] One topic. - [x] No new code comments. - [x] Unsupported paths still throw; UI stubs are documented. - [x] No notes, logs, or images in the repository. - [x] No new third-party code. - [x] General behavior. - [x] Depends on: none. - [x] AI-assisted: yes.
oneandonlydean commented 2026-10-08 03:26:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-08T03:26:19Z.


DescriptorCache::Free prints and retires the pool when vkResetDescriptorPool fails. Failures stay explicit here; please make it fatal like the std::terminate() checks above it. This also replaces #1065's workaround for the same RADV overrun, so only one of the two will go in.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6051545314 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1333#issuecomment-6051545314). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-08T03:26:19Z. --- `DescriptorCache::Free` prints and retires the pool when `vkResetDescriptorPool` fails. Failures stay explicit here; please make it fatal like the `std::terminate()` checks above it. This also replaces #1065's workaround for the same RADV overrun, so only one of the two will go in.
TibixDev commented 2026-10-08 04:14:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by TibixDev on 2026-10-08T04:14:41Z.


Reset failure now terminates. The new isolated test fails on the previous code and passes with this change.

Rebased on current main (a9ba39c9). Graphics tests pass. The 3,301-set lifecycle test also passes on llvmpipe and RX 6600 with core and synchronization validation enabled. Windows was not tested.

This still has no dependency on #1065.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6052072401 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1333#issuecomment-6052072401). Originally posted by [TibixDev](https://github.com/TibixDev) on 2026-10-08T04:14:41Z. --- Reset failure now terminates. The new isolated test fails on the previous code and passes with this change. Rebased on current `main` (`a9ba39c9`). Graphics tests pass. The 3,301-set lifecycle test also passes on llvmpipe and RX 6600 with core and synchronization validation enabled. Windows was not tested. This still has no dependency on #1065.
oneandonlydean commented 2026-10-08 06:37:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-08T06:37:25Z.


Windows CI fails on the new test:

Test #232: agc_descriptor_pool_reset_failure ...............Exit code 0xc0000409***Exception:   0.30 sec

The std::set_terminate handler in descriptorPoolResetFailureTest doesn't catch the terminate on Windows, so the process fast-fails instead of exiting with your code. Please make the test check the exit status in a way that works on both platforms.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6054013350 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1333#issuecomment-6054013350). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-08T06:37:25Z. --- Windows CI fails on the new test: ``` Test #232: agc_descriptor_pool_reset_failure ...............Exit code 0xc0000409***Exception: 0.30 sec ``` The `std::set_terminate` handler in `descriptorPoolResetFailureTest` doesn't catch the terminate on Windows, so the process fast-fails instead of exiting with your code. Please make the test check the exit status in a way that works on both platforms.
TibixDev commented 2026-10-08 06:41:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by TibixDev on 2026-10-08T06:41:20Z.


Rebased on 7a178e22, which includes merged #1065. Its padding stays in place. This PR now needs to be judged as a pool-recycling optimization; it is no longer needed to supply that crash fix.

The Windows test installed a host std::set_terminate handler, but std::terminate enters guest libc. The test now installs the guest handler with the guest ABI. A reset error remains fatal.

I compared the production DescriptorCache methods and declarations from upstream with this PR alone. Fedora 44, GCC 16 -O3 -DNDEBUG, Ryzen 5 5600 pinned to CPU 3, RX 6600 with host RADV. Six processes per variant in ABBA order; each process warms up 20 cycles and measures seven batches of 200 cycles. Each cycle performs 1,100 allocations and releases using 32-storage-buffer layouts. No GPU work or descriptor updates are timed.

Median CPU time per allocation/release pair, ns:

Workload Upstream including #1065 This PR
batch 138.94 31.38
held 139.35 33.16
rolling 50.53 29.65

batch releases all sets after each cycle. held retains one extra set throughout. rolling replaces entries in a 64-set live collection. Pool counts were 3→3, 3→4, and 1→2 respectively. Recycling reduces CPU time in these cases but retains more pool storage when sets overlap. Peak title memory and frame-time gains remain unmeasured.

Linux graphics and reset-failure tests pass. The 3,301-set lifecycle test passes on RX 6600 and llvmpipe with core and synchronization validation. The test source compiles with MinGW; the local full Windows link is blocked by unrelated SjLj symbols in libc. Windows CI is pending.

Updated to 66b8abd8 after #1427 added the PM4 failure test. Both failure tests remain registered; graphics and descriptor reset-failure tests pass again. The measured pool implementation is unchanged.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6054080450 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1333#issuecomment-6054080450). Originally posted by [TibixDev](https://github.com/TibixDev) on 2026-10-08T06:41:20Z. --- Rebased on `7a178e22`, which includes merged #1065. Its padding stays in place. This PR now needs to be judged as a pool-recycling optimization; it is no longer needed to supply that crash fix. The Windows test installed a host `std::set_terminate` handler, but `std::terminate` enters guest libc. The test now installs the guest handler with the guest ABI. A reset error remains fatal. I compared the production `DescriptorCache` methods and declarations from upstream with this PR alone. Fedora 44, GCC 16 `-O3 -DNDEBUG`, Ryzen 5 5600 pinned to CPU 3, RX 6600 with host RADV. Six processes per variant in ABBA order; each process warms up 20 cycles and measures seven batches of 200 cycles. Each cycle performs 1,100 allocations and releases using 32-storage-buffer layouts. No GPU work or descriptor updates are timed. Median CPU time per allocation/release pair, ns: | Workload | Upstream including #1065 | This PR | | --- | ---: | ---: | | batch | 138.94 | 31.38 | | held | 139.35 | 33.16 | | rolling | 50.53 | 29.65 | `batch` releases all sets after each cycle. `held` retains one extra set throughout. `rolling` replaces entries in a 64-set live collection. Pool counts were 3→3, 3→4, and 1→2 respectively. Recycling reduces CPU time in these cases but retains more pool storage when sets overlap. Peak title memory and frame-time gains remain unmeasured. Linux graphics and reset-failure tests pass. The 3,301-set lifecycle test passes on RX 6600 and llvmpipe with core and synchronization validation. The test source compiles with MinGW; the local full Windows link is blocked by unrelated SjLj symbols in libc. Windows CI is pending. Updated to `66b8abd8` after #1427 added the PM4 failure test. Both failure tests remain registered; graphics and descriptor reset-failure tests pass again. The measured pool implementation is unchanged.
oneandonlydean commented 2026-10-09 09:22:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T09:22:05Z.


Conflicts with #1266, which added dedicated pools for oversized sets to DescriptorCache::Allocate and Free; please rebase and keep that path.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6078117713 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1333#issuecomment-6078117713). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-09T09:22:05Z. --- Conflicts with #1266, which added dedicated pools for oversized sets to `DescriptorCache::Allocate` and `Free`; please rebase and keep that path.
adriadam10 commented 2026-10-09 23:04:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-09T23:04:36Z.

Review: CHANGES_REQUESTED


This conflicts with main in ShaderResources.hpp, ShaderResources.cpp, tests/Graphics.cpp and TechnicalDebt.md (#1266 reworked DescriptorCache::Allocate/Free).

  • Please rebase and keep #1266's dedicated pools for oversized sets in both Allocate and Free; the recycling should apply to the chain pools only, or explicitly to both with a test for each.
  • After the rebase, rerun the lifecycle and reset-failure tests, and add a case that mixes an oversized set with regular sets so the two paths are covered together.
  • Keep the TechnicalDebt line away from the end of its section (it conflicts with every other PR that appends there).
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5476196040 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1333#pullrequestreview-5476196040). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-09T23:04:36Z. **Review:** CHANGES_REQUESTED --- This conflicts with `main` in `ShaderResources.hpp`, `ShaderResources.cpp`, `tests/Graphics.cpp` and `TechnicalDebt.md` (#1266 reworked `DescriptorCache::Allocate`/`Free`). - Please rebase and keep #1266's dedicated pools for oversized sets in both `Allocate` and `Free`; the recycling should apply to the chain pools only, or explicitly to both with a test for each. - After the rebase, rerun the lifecycle and reset-failure tests, and add a case that mixes an oversized set with regular sets so the two paths are covered together. - Keep the TechnicalDebt line away from the end of its section (it conflicts with every other PR that appends there).
adriadam10 commented 2026-10-11 09:07:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T09:07:28Z.

Review: APPROVED


Rebased onto current main and kept #1266's dedicated pools (destroyed in Free; recycling applies only to the chain pools, both the regular and the update-after-bind chain). Added on your branch:

  • descriptorCacheTests: an oversized set allocated and freed between regular sets leaves the chain pool's reset count untouched; the pool resets only once the last regular set is freed.
  • Mock adapted to the new Free path (vkResetDescriptorPool instead of vkFreeDescriptorSets); agc_descriptor_pool_recycling (Recorder, 3,301 sets) registered in ctest.
  • TechnicalDebt line moved off the end of its section.

Checked: libSceAgcDriver build + ctest (379) green; agc_driver_graphics and agc_descriptor_pool_reset_failure fail without the change. Merging once CI is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5482693037 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1333#pullrequestreview-5482693037). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T09:07:28Z. **Review:** APPROVED --- Rebased onto current `main` and kept #1266's dedicated pools (destroyed in `Free`; recycling applies only to the chain pools, both the regular and the update-after-bind chain). Added on your branch: - `descriptorCacheTests`: an oversized set allocated and freed between regular sets leaves the chain pool's reset count untouched; the pool resets only once the last regular set is freed. - Mock adapted to the new `Free` path (`vkResetDescriptorPool` instead of `vkFreeDescriptorSets`); `agc_descriptor_pool_recycling` (Recorder, 3,301 sets) registered in ctest. - TechnicalDebt line moved off the end of its section. Checked: libSceAgcDriver build + ctest (379) green; `agc_driver_graphics` and `agc_descriptor_pool_reset_failure` fail without the change. Merging once CI is green.
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!1333
No description provided.