fix(agc): avoid host allocations when returning slab slots #6943

Merged
Ondra97 merged 1 commit from upstream-pr/6943 into main 2026-10-19 14:18:52 +00:00
Ondra97 commented 2026-10-16 20:41:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Ondra97 on 2026-10-16T20:41:41Z.


What

Returning a slot to a full buffer slab can grow Slab::available inside noexcept cleanup. Host allocation failure can therefore also break resource release.

Count all live blocks in each slab class and reserve return-list capacity before publishing another block, including full blocks. Decrement the count when an empty block is retired or reclaimed. Returning a slot then needs no new C++ allocation.

Rebased onto main at c9e6c45de9ccccc4f714e153252a8fa48efbf367; head 5001f87bc97e95335dcb45a59ed0818691ec7e0e. Prerequisites #6882 and #6452 are merged; this PR now contains only the slab-return fix and its regression tests. The test dispatcher also preserves the small-device mode added by merged #7056. Range-diff review found only the required dispatcher adaptation; the production patch is unchanged. Manual inspection of the remaining shared-file PRs found no equivalent return-path fix.

Tested

Release builds, BUILD_TESTING=ON, SPIRV-Tools disabled. Fresh validation below targets the rebased head above.

Windows (native host)

AMD Ryzen 9 7900X, 32 GB RAM, NVIDIA GeForce RTX 4070 Ti SUPER, driver 617.42 / 32.0.16.1742, Windows 11 Pro 10.0.26300, WinLibs GCC 15.2.0 r7.

  • Full production application/library build (relinker, libs) and all selected test executables: passed, using --parallel 2.
  • Selected related tests, including both small-device CLI modes from #7056: 21/21 passed, 0 failed, 0 skipped. Vulkan tests used ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1 and ANYPS5_GPU=NVIDIA GeForce RTX 4070 Ti SUPER.
  • Both isolated --slab-return-device and --slab-return-host probes passed in the CPU and NVIDIA fixtures, each completing 26 protected returns per memory type.
ctest --test-dir build-windows --output-on-failure -R "^(agc_buffer_pool(_small_device_(shared|no_staging))?|agc_driver_(pooled_buffer_range|buffer.*|bda_span_reads|flat_cache_bits|storage_cache_budget|sampled_cache_budget|constant_store)|patched_libraries)$"

Linux (VirtualBox)

Ubuntu 24.04.5 LTS, kernel 7.0.0-38-generic, GCC 13.3.0, 4 vCPU and 8 GiB assigned RAM, VirtualBox 7.2.20r175154 on the Windows host above. Graphics: not exercised.

  • Full production application/library build (relinker, libs) and GPU-fixture compilation: passed. The selected CPU executables and agc_driver_pooled_buffer_range_tests were built with --parallel 2.
  • Selected CPU tests, including both small-device CLI modes from #7056: 8/8 passed, 0 failed, 0 skipped. Both isolated --slab-return-device and --slab-return-host probes also passed, each completing 26 protected returns.
ctest --test-dir build --output-on-failure -R "^(patched_libraries|agc_buffer_pool(_small_device_(shared|no_staging))?|agc_structurizer|agc_shader_mode_register|agc_shader_control_flow|agc_constant_phi)$"

Conventions, whitespace, test registration and clean-main integration checks passed on both Windows (native host) and Linux (VirtualBox).

Historical regression comparison — original revisions

The following measurements are from the original validation, not new measurements of the rebased head. Original production base: ea4cc112a04e6144740756bcd6494bbab5377331; original fixed head: 42fb6584d43c6a49332adb56d7b8cc1516ce5b95.

On the same Windows host above, the regression filled 512 KiB slots across 4, 6 and 3 blocks, armed failure of the next C++ allocation during returns, then checked reuse without loss or duplication, live mapped siblings and empty-block retirement. Injection targeted host metadata without exhausting physical memory. The base failed in the first return batch; the fix completed 26 protected returns per memory type.

Metric Before (base) After (fix)
NVIDIA Vulkan-memory return probes failing under injected host allocation failure 2/2 0/2
CPU mock return probes failing under the same injection 2/2 0/2

Both agc_buffer_pool_tests.exe and agc_driver_pooled_buffer_range_tests.exe used --slab-return-device and --slab-return-host. NVIDIA probes identified vendor 0x10de, device 0x2705, and exercised Vulkan allocation, mapping and cleanup. This establishes the synthetic cleanup regression; no retail-title run or FPS measurement was performed.

Linux graphics/Vulkan tests: NOT RUN — intentionally excluded from VirtualBox validation.
Native/bare-metal Linux was not tested.
Native Linux GPU validation: not tested.

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: NVIDIA GeForce RTX 4070 Ti SUPER, driver 617.42 / 32.0.16.1742, Windows 11 Pro 10.0.26300
  • AI-assisted: yes — Codex
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4894028218 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6943). Originally posted by [Ondra97](https://github.com/Ondra97) on 2026-10-16T20:41:41Z. --- ### What Returning a slot to a full buffer slab can grow `Slab::available` inside `noexcept` cleanup. Host allocation failure can therefore also break resource release. Count all live blocks in each slab class and reserve return-list capacity before publishing another block, including full blocks. Decrement the count when an empty block is retired or reclaimed. Returning a slot then needs no new C++ allocation. Rebased onto `main` at `c9e6c45de9ccccc4f714e153252a8fa48efbf367`; head `5001f87bc97e95335dcb45a59ed0818691ec7e0e`. Prerequisites #6882 and #6452 are merged; this PR now contains only the slab-return fix and its regression tests. The test dispatcher also preserves the small-device mode added by merged #7056. Range-diff review found only the required dispatcher adaptation; the production patch is unchanged. Manual inspection of the remaining shared-file PRs found no equivalent return-path fix. ### Tested Release builds, `BUILD_TESTING=ON`, SPIRV-Tools disabled. Fresh validation below targets the rebased head above. **Windows (native host)** AMD Ryzen 9 7900X, 32 GB RAM, NVIDIA GeForce RTX 4070 Ti SUPER, driver 617.42 / 32.0.16.1742, Windows 11 Pro 10.0.26300, WinLibs GCC 15.2.0 r7. - Full production application/library build (`relinker`, `libs`) and all selected test executables: **passed**, using `--parallel 2`. - Selected related tests, including both small-device CLI modes from #7056: **21/21 passed, 0 failed, 0 skipped**. Vulkan tests used `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1` and `ANYPS5_GPU=NVIDIA GeForce RTX 4070 Ti SUPER`. - Both isolated `--slab-return-device` and `--slab-return-host` probes passed in the CPU and NVIDIA fixtures, each completing 26 protected returns per memory type. ```text ctest --test-dir build-windows --output-on-failure -R "^(agc_buffer_pool(_small_device_(shared|no_staging))?|agc_driver_(pooled_buffer_range|buffer.*|bda_span_reads|flat_cache_bits|storage_cache_budget|sampled_cache_budget|constant_store)|patched_libraries)$" ``` **Linux (VirtualBox)** Ubuntu 24.04.5 LTS, kernel 7.0.0-38-generic, GCC 13.3.0, 4 vCPU and 8 GiB assigned RAM, VirtualBox 7.2.20r175154 on the Windows host above. Graphics: not exercised. - Full production application/library build (`relinker`, `libs`) and GPU-fixture compilation: **passed**. The selected CPU executables and `agc_driver_pooled_buffer_range_tests` were built with `--parallel 2`. - Selected CPU tests, including both small-device CLI modes from #7056: **8/8 passed, 0 failed, 0 skipped**. Both isolated `--slab-return-device` and `--slab-return-host` probes also passed, each completing 26 protected returns. ```text ctest --test-dir build --output-on-failure -R "^(patched_libraries|agc_buffer_pool(_small_device_(shared|no_staging))?|agc_structurizer|agc_shader_mode_register|agc_shader_control_flow|agc_constant_phi)$" ``` Conventions, whitespace, test registration and clean-main integration checks passed on both Windows (native host) and Linux (VirtualBox). **Historical regression comparison — original revisions** The following measurements are from the original validation, not new measurements of the rebased head. Original production base: `ea4cc112a04e6144740756bcd6494bbab5377331`; original fixed head: `42fb6584d43c6a49332adb56d7b8cc1516ce5b95`. On the same Windows host above, the regression filled 512 KiB slots across 4, 6 and 3 blocks, armed failure of the next C++ allocation during returns, then checked reuse without loss or duplication, live mapped siblings and empty-block retirement. Injection targeted host metadata without exhausting physical memory. The base failed in the first return batch; the fix completed 26 protected returns per memory type. | Metric | Before (base) | After (fix) | | --- | --- | --- | | NVIDIA Vulkan-memory return probes failing under injected host allocation failure | 2/2 | 0/2 | | CPU mock return probes failing under the same injection | 2/2 | 0/2 | Both `agc_buffer_pool_tests.exe` and `agc_driver_pooled_buffer_range_tests.exe` used `--slab-return-device` and `--slab-return-host`. NVIDIA probes identified vendor `0x10de`, device `0x2705`, and exercised Vulkan allocation, mapping and cleanup. This establishes the synthetic cleanup regression; no retail-title run or FPS measurement was performed. Linux graphics/Vulkan tests: NOT RUN — intentionally excluded from VirtualBox validation. Native/bare-metal Linux was not tested. Native Linux GPU validation: not tested. <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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: NVIDIA GeForce RTX 4070 Ti SUPER, driver 617.42 / 32.0.16.1742, Windows 11 Pro 10.0.26300 - [x] AI-assisted: yes — Codex
github-actions[bot] commented 2026-10-16 20:53:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-16T20:53:34Z.


Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 4472 core/libs/prx/libSceAgcDriver/Graphics/include/BufferPool.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/BufferPool.cpp
core/libs/prx/libSceAgcDriver/tests/BufferPool.cpp
PR 6292 core/libs/prx/libSceAgcDriver/Graphics/include/BufferPool.hpp
PR 6615 core/libs/prx/libSceAgcDriver/Graphics/include/BufferPool.hpp
PR 7332 core/libs/prx/libSceAgcDriver/tests/execution/PooledBufferRange.cpp
PR 7800 core/libs/prx/libSceAgcDriver/Graphics/include/BufferPool.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/BufferPool.cpp
core/libs/prx/libSceAgcDriver/tests/BufferPool.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6224493707 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6943#issuecomment-6224493707). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-16T20:53:34Z. --- <!-- pr-overlap --> Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 4472](https://www.github.com/boykopovar/AnyPS5/pull/4472) | `core/libs/prx/libSceAgcDriver/Graphics/include/BufferPool.hpp`<br>`core/libs/prx/libSceAgcDriver/Graphics/src/BufferPool.cpp`<br>`core/libs/prx/libSceAgcDriver/tests/BufferPool.cpp` | | [PR 6292](https://www.github.com/boykopovar/AnyPS5/pull/6292) | `core/libs/prx/libSceAgcDriver/Graphics/include/BufferPool.hpp` | | [PR 6615](https://www.github.com/boykopovar/AnyPS5/pull/6615) | `core/libs/prx/libSceAgcDriver/Graphics/include/BufferPool.hpp` | | [PR 7332](https://www.github.com/boykopovar/AnyPS5/pull/7332) | `core/libs/prx/libSceAgcDriver/tests/execution/PooledBufferRange.cpp` | | [PR 7800](https://www.github.com/boykopovar/AnyPS5/pull/7800) | `core/libs/prx/libSceAgcDriver/Graphics/include/BufferPool.hpp`<br>`core/libs/prx/libSceAgcDriver/Graphics/src/BufferPool.cpp`<br>`core/libs/prx/libSceAgcDriver/tests/BufferPool.cpp` |
keravyn-ops commented 2026-10-17 09:21:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by keravyn-ops on 2026-10-17T09:21:43Z.


AMD / Windows run of this PR at 42fb6584d: Radeon 780M (RDNA 3, 0x15bf), AMD driver 25.10.20.01 (32.0.21020.1007), Windows 11 Home 10.0.26100, WinLibs GCC 15.2.0 r7, Release.

  • agc_buffer_pool: pass (slab metadata failures checked: 4, 0.12 s)
  • agc_driver_pooled_buffer_range: pass (slab metadata total leaked bytes=0, 0.19 s)

AI-assisted: yes (runs made on the device above).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6232233756 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6943#issuecomment-6232233756). Originally posted by [keravyn-ops](https://github.com/keravyn-ops) on 2026-10-17T09:21:43Z. --- AMD / Windows run of this PR at 42fb6584d: Radeon 780M (RDNA 3, 0x15bf), AMD driver 25.10.20.01 (32.0.21020.1007), Windows 11 Home 10.0.26100, WinLibs GCC 15.2.0 r7, Release. - `agc_buffer_pool`: pass (`slab metadata failures checked: 4`, 0.12 s) - `agc_driver_pooled_buffer_range`: pass (`slab metadata total leaked bytes=0`, 0.19 s) AI-assisted: yes (runs made on the device above).
adriadam10 commented 2026-10-19 14:21:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T14:21:34Z.


Checked the invariant available.capacity() >= blocks across TakeSlot, PutSlot and trim: full blocks are no longer a hidden growth point in the noexcept return path. The new test fails on main (returning 4 full blocks grows available under the allocation-failure countdown) and covers device and host memory types; merged.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6269490010 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6943#issuecomment-6269490010). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-19T14:21:34Z. --- Checked the invariant `available.capacity() >= blocks` across TakeSlot, PutSlot and trim: full blocks are no longer a hidden growth point in the `noexcept` return path. The new test fails on main (returning 4 full blocks grows `available` under the allocation-failure countdown) and covers device and host memory types; merged.
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!6943
No description provided.