fix(agc): discard device buffers after memory binding fails #7057

Merged
Ondra97 merged 2 commits from upstream-pr/7057 into main 2026-10-17 22:18:10 +00:00
Ondra97 commented 2026-10-17 09:20:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Ondra97 on 2026-10-17T09:20:54Z.


What

A failed vkBindBufferMemory left DeviceBuffer with both handles, so constructor cleanup returned the unbound buffer to the reuse pool. A same-size retry then reused it without another bind call, potentially passing an unusable buffer into GPU work.

Track completed construction, as Buffer already does, and retain only successfully bound device buffers. Failed construction destroys its buffer and frees its memory. Fresh allocations, same-size pool hits and resized pooled buffers remain reusable after successful construction.

The CPU mock and native Vulkan regressions inject VK_ERROR_OUT_OF_HOST_MEMORY and VK_ERROR_OUT_OF_DEVICE_MEMORY, check cleanup, make three same-size retries per error and verify normal pool reuse. The native fixture also verifies 256-byte GPU copy/readback data for every valid retry. Invalid baseline retries are detected before submission; physical memory is not exhausted.

Tested

Current base: c9e6c45de9ccccc4f714e153252a8fa48efbf367. Current head: 785c1079794662177df7d5e85530b353e8df0948. Release; SPIRV-Tools and Tracy disabled. Full application/library builds used BUILD_TESTING=OFF; focused tests used BUILD_TESTING=ON.

The branch contains only the two PR commits. Their added/deleted lines are identical to the original commits; range-diff changes only the surrounding test main(argc, argv) context introduced by #7056. The carried #6882 merge is removed, and both #6882 and #7056 are already in the base. The binding regression remains separate from cache-pressure regressions.

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.

Full application/library build passed:

cmake --build build --target all libs --parallel 2

After enabling BUILD_TESTING and building the 20 selected test executables, 22/22 tests passed, 0 failed, 0 skipped, with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1 and ANYPS5_GPU=NVIDIA GeForce RTX 4070 Ti SUPER:

ctest --test-dir build --output-on-failure -V -R "^(agc_buffer_pool(_small_device_(shared|no_staging))?|agc_device_memory_fallback|agc_driver_(pooled_buffer_range|buffer.*|bda_span_reads|flat_cache_bits|storage_cache_budget|sampled_cache_budget|constant_store)|patched_libraries)$"

The native pooled fixture selected NVIDIA (vendor=0x10de, device=0x2705). Both error cases retained 0 bytes and produced 0 invalid retries, in both the CPU mock and native fixture. All six native retries verified GPU copy/readback data. Two bind attempts per error case (one injected failure, one success) also verify normal reuse. The suite includes #7056's separate/shared pool and zero-staging controls.

Original controlled regression comparison (before rebase)

The previously recorded comparison used baseline bb4fada71465029432b6ef85d7a3f4c8502827f9 (main adb0e7a8cb68232f457c788afa90e53648c0f15f plus #6882, with the new regressions) and fixed head 801f6e44592eb394252cc87347efc54cb84ffd0a, on the Windows hardware above. Each binding-error case requests a 3 MiB buffer and makes three same-size retries. These are the original before/after measurements; the current-head checks are reported above.

Metric Before (base) After (fix)
Unbound device-buffer retries, two error cases x three retries, NVIDIA 6/6 0/6
Unbound device-buffer retries, same CPU mock cases 6/6 0/6
Failed allocation retained immediately after each bind error 3 MiB 0 bytes

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 application/library build passed with cmake --build build --target all libs --parallel 2. After enabling BUILD_TESTING, the six selected CPU executables and the native pooled-buffer fixture compiled successfully. 8/8 CPU tests passed, 0 failed, 0 skipped:

ctest --test-dir build --output-on-failure -V -R "^(agc_buffer_pool(_small_device_(shared|no_staging))?|agc_device_memory_fallback|agc_structurizer|agc_shader_mode_register|agc_shader_control_flow|agc_constant_phi)$"

Both binding-error cases retained 0 bytes, returned 0 invalid retries and made exactly two bind attempts. The small-device shared-pool and zero-staging controls also passed.

All 2,756 source files and 13,298 dependency files were verified against Git blobs, including dependency symlinks, for the current head. The native Vulkan fixture was compiled without running Linux graphics tests.

Conventions, test registration, whitespace and main-sync checks passed. Full hosted platform builds require a maintainer's manual workflow dispatch.

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

No retail title run, FPS improvement or other GPU-vendor result is claimed.

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:4898907572 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7057). Originally posted by [Ondra97](https://github.com/Ondra97) on 2026-10-17T09:20:54Z. --- ### What A failed `vkBindBufferMemory` left `DeviceBuffer` with both handles, so constructor cleanup returned the unbound buffer to the reuse pool. A same-size retry then reused it without another bind call, potentially passing an unusable buffer into GPU work. Track completed construction, as `Buffer` already does, and retain only successfully bound device buffers. Failed construction destroys its buffer and frees its memory. Fresh allocations, same-size pool hits and resized pooled buffers remain reusable after successful construction. The CPU mock and native Vulkan regressions inject `VK_ERROR_OUT_OF_HOST_MEMORY` and `VK_ERROR_OUT_OF_DEVICE_MEMORY`, check cleanup, make three same-size retries per error and verify normal pool reuse. The native fixture also verifies 256-byte GPU copy/readback data for every valid retry. Invalid baseline retries are detected before submission; physical memory is not exhausted. ### 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. --> Current base: `c9e6c45de9ccccc4f714e153252a8fa48efbf367`. Current head: `785c1079794662177df7d5e85530b353e8df0948`. Release; SPIRV-Tools and Tracy disabled. Full application/library builds used `BUILD_TESTING=OFF`; focused tests used `BUILD_TESTING=ON`. The branch contains only the two PR commits. Their added/deleted lines are identical to the original commits; `range-diff` changes only the surrounding test `main(argc, argv)` context introduced by #7056. The carried #6882 merge is removed, and both #6882 and #7056 are already in the base. The binding regression remains separate from cache-pressure regressions. **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. Full application/library build passed: ```text cmake --build build --target all libs --parallel 2 ``` After enabling `BUILD_TESTING` and building the 20 selected test executables, **22/22 tests passed, 0 failed, 0 skipped**, with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1` and `ANYPS5_GPU=NVIDIA GeForce RTX 4070 Ti SUPER`: ```text ctest --test-dir build --output-on-failure -V -R "^(agc_buffer_pool(_small_device_(shared|no_staging))?|agc_device_memory_fallback|agc_driver_(pooled_buffer_range|buffer.*|bda_span_reads|flat_cache_bits|storage_cache_budget|sampled_cache_budget|constant_store)|patched_libraries)$" ``` The native pooled fixture selected NVIDIA (`vendor=0x10de`, `device=0x2705`). Both error cases retained 0 bytes and produced 0 invalid retries, in both the CPU mock and native fixture. All six native retries verified GPU copy/readback data. Two bind attempts per error case (one injected failure, one success) also verify normal reuse. The suite includes #7056's separate/shared pool and zero-staging controls. **Original controlled regression comparison (before rebase)** The previously recorded comparison used baseline `bb4fada71465029432b6ef85d7a3f4c8502827f9` (main `adb0e7a8cb68232f457c788afa90e53648c0f15f` plus #6882, with the new regressions) and fixed head `801f6e44592eb394252cc87347efc54cb84ffd0a`, on the Windows hardware above. Each binding-error case requests a 3 MiB buffer and makes three same-size retries. These are the original before/after measurements; the current-head checks are reported above. | Metric | Before (base) | After (fix) | | --- | --- | --- | | Unbound device-buffer retries, two error cases x three retries, NVIDIA | 6/6 | 0/6 | | Unbound device-buffer retries, same CPU mock cases | 6/6 | 0/6 | | Failed allocation retained immediately after each bind error | 3 MiB | 0 bytes | **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 application/library build passed with `cmake --build build --target all libs --parallel 2`. After enabling `BUILD_TESTING`, the six selected CPU executables and the native pooled-buffer fixture compiled successfully. **8/8 CPU tests passed, 0 failed, 0 skipped**: ```text ctest --test-dir build --output-on-failure -V -R "^(agc_buffer_pool(_small_device_(shared|no_staging))?|agc_device_memory_fallback|agc_structurizer|agc_shader_mode_register|agc_shader_control_flow|agc_constant_phi)$" ``` Both binding-error cases retained 0 bytes, returned 0 invalid retries and made exactly two bind attempts. The small-device shared-pool and zero-staging controls also passed. All 2,756 source files and 13,298 dependency files were verified against Git blobs, including dependency symlinks, for the current head. The native Vulkan fixture was compiled without running Linux graphics tests. Conventions, test registration, whitespace and main-sync checks passed. Full hosted platform builds require a maintainer's manual workflow dispatch. Linux graphics/Vulkan tests: NOT RUN — intentionally excluded from VirtualBox validation. Native/bare-metal Linux was not tested. Native Linux GPU validation: not tested. No retail title run, FPS improvement or other GPU-vendor result is claimed. ### 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-17 09:29:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-17T09:29:23Z.


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/tests/BufferPool.cpp
PR 5987 core/libs/prx/libSceAgcDriver/Graphics/src/Resources.cpp
core/libs/prx/libSceAgcDriver/tests/BufferPool.cpp
PR 6177 core/libs/prx/libSceAgcDriver/Graphics/include/Resources.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Resources.cpp
PR 6222 core/libs/prx/libSceAgcDriver/tests/execution/PooledBufferRange.cpp
PR 6553 core/libs/prx/libSceAgcDriver/Graphics/src/Resources.cpp
core/libs/prx/libSceAgcDriver/tests/BufferPool.cpp
PR 6947 core/libs/prx/libSceAgcDriver/Graphics/include/Resources.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Resources.cpp
PR 7119 core/libs/prx/libSceAgcDriver/tests/BufferPool.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6232299959 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7057#issuecomment-6232299959). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-17T09:29:23Z. --- <!-- 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/tests/BufferPool.cpp` | | [PR 5987](https://www.github.com/boykopovar/AnyPS5/pull/5987) | `core/libs/prx/libSceAgcDriver/Graphics/src/Resources.cpp`<br>`core/libs/prx/libSceAgcDriver/tests/BufferPool.cpp` | | [PR 6177](https://www.github.com/boykopovar/AnyPS5/pull/6177) | `core/libs/prx/libSceAgcDriver/Graphics/include/Resources.hpp`<br>`core/libs/prx/libSceAgcDriver/Graphics/src/Resources.cpp` | | [PR 6222](https://www.github.com/boykopovar/AnyPS5/pull/6222) | `core/libs/prx/libSceAgcDriver/tests/execution/PooledBufferRange.cpp` | | [PR 6553](https://www.github.com/boykopovar/AnyPS5/pull/6553) | `core/libs/prx/libSceAgcDriver/Graphics/src/Resources.cpp`<br>`core/libs/prx/libSceAgcDriver/tests/BufferPool.cpp` | | [PR 6947](https://www.github.com/boykopovar/AnyPS5/pull/6947) | `core/libs/prx/libSceAgcDriver/Graphics/include/Resources.hpp`<br>`core/libs/prx/libSceAgcDriver/Graphics/src/Resources.cpp` | | [PR 7119](https://www.github.com/boykopovar/AnyPS5/pull/7119) | `core/libs/prx/libSceAgcDriver/tests/BufferPool.cpp` |
oneandonlydean commented 2026-10-17 11:58:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T11:58:56Z.


Thanks @Ondra97. #6882 and #7056 have both merged into main, and GitHub now reports this PR as conflicting with main (most likely in BufferPool.cpp, which #7056 also changed). Could you rebase onto current main and drop the carried #6882 merge, as you did for #7065? Once the new head is up, we'll check the two PR commits are unchanged and run full CI on it.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6233616235 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7057#issuecomment-6233616235). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-17T11:58:56Z. --- Thanks @Ondra97. #6882 and #7056 have both merged into main, and GitHub now reports this PR as conflicting with main (most likely in BufferPool.cpp, which #7056 also changed). Could you rebase onto current main and drop the carried #6882 merge, as you did for #7065? Once the new head is up, we'll check the two PR commits are unchanged and run full CI on it.
Ondra97 commented 2026-10-17 12:18:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Ondra97 on 2026-10-17T12:18:46Z.


Thanks @oneandonlydean. I rebased onto c9e6c45de9 and pushed 785c107979, dropping the carried #6882 merge. Only the two PR commits remain, with identical added/deleted lines; range-diff only differs in the surrounding main(argc, argv) context from #7056. GitHub now reports CLEAN/MERGEABLE.

Local validation on this head passed; environment details and commands are in the updated PR description:

  • Windows (native host): full application/library build and 22/22 focused tests, including native NVIDIA GPU checks.
  • Linux (VirtualBox): full application/library build, pooled Vulkan fixture compiled, and 8/8 CPU tests.

No local test failures or skips.

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

Automatic checks passed; full hosted Windows/Linux builds are still policy-skipped. The new head is ready for the full CI run you mentioned.

AI-assisted: yes — Codex

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6233794367 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7057#issuecomment-6233794367). Originally posted by [Ondra97](https://github.com/Ondra97) on 2026-10-17T12:18:46Z. --- Thanks @oneandonlydean. I rebased onto `c9e6c45de9` and pushed `785c107979`, dropping the carried #6882 merge. Only the two PR commits remain, with identical added/deleted lines; `range-diff` only differs in the surrounding `main(argc, argv)` context from #7056. GitHub now reports CLEAN/MERGEABLE. Local validation on this head passed; environment details and commands are in the updated PR description: - Windows (native host): full application/library build and 22/22 focused tests, including native NVIDIA GPU checks. - Linux (VirtualBox): full application/library build, pooled Vulkan fixture compiled, and 8/8 CPU tests. No local test failures or skips. Linux graphics/Vulkan tests: NOT RUN — intentionally excluded from VirtualBox validation. Native/bare-metal Linux was not tested. Native Linux GPU validation: not tested. Automatic checks passed; full hosted Windows/Linux builds are still policy-skipped. The new head is ready for the full CI run you mentioned. AI-assisted: yes — Codex
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!7057
No description provided.