fix(agc): release buffer slabs when metadata allocation fails #6882
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6882"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by Ondra97 on 2026-10-16T15:53:38Z.
What
BufferPool::TakeSlotlost an already allocated Vulkan memory block when a subsequent C++ metadata allocation threw. Failure while inserting the block into the pool could also leave a published block that no later request could reuse. Under host memory pressure, these failures retained additional device-local or mapped host memory.The new block now owns its Vulkan allocation through a scoped deleter until publication succeeds. The available-block vector reserves capacity before ownership is transferred, and the map allocates its node before receiving the block. Subsequent publication steps do not allocate. Mapping errors use the same cleanup path.
The CPU regression sweeps metadata allocation failures, checks unmapping/freeing and successful retries, and covers
VK_ERROR_MEMORY_MAP_FAILED. The existing native Vulkan buffer fixture adds the same single-fault sweep for mapped host-visible and unmapped device-local memory. It then runs its original compute/readback and buffer-reuse controls. Both test executables compile the production buffer-pool translation unit with a shared test allocator so that metadata failures can be injected on Windows too; the test allocator is not linked into the runtime library.The cleanup follows Vulkan's memory lifetime rules. This change concerns newly allocated slabs that have not been handed to a buffer or submitted to GPU work.
Tested
Base
4524944396dfe91bd7c6949a3d7ac01935a2b840; heada4485bd8216075064799fd023d6147a326961be3. The full upstream delta82ddae75b6761757f3d3ba9c0723647469270f76..4524944396dfe91bd7c6949a3d7ac01935a2b840and this patch were reviewed before execution, including build/workflow paths and new test files. Related buffer-pool PR implementations/tests and complete large-PR file lists were checked; no existing PR fixes this slab-publication failure path.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, Release,
BUILD_TESTING=ON,ANYPS5_ENABLE_SPIRV_TOOLS=OFF.Vulkan was required (
ANYPS5_REQUIRE_VULKAN=1) and the selected physical NVIDIA device and driver were verified.ANYPS5_GPU=NVIDIA GeForce RTX 4070 Ti SUPERandANYPS5_NO_SHADER_CACHE=1were set. The allocation regression uses native Vulkan directly; the wider AGC suite exercises the recompiler/runtime. Driver caches were not controlled.Before / after — Windows (native host)
Same final CPU/native fixtures, Release build, hardware and inputs, one invocation per variant. The negative control restored the exact base
BufferPool.cpp, then restored and checked the fixed source bytes. The native fixture injects one C++ allocation failure at each of four metadata allocations per memory type, with a successful retry/control. Each newly requested block is 2 MiB.The following counts are unreleased
VkDeviceMemorypayloads, summed fromallocationSize, after the local pools are destroyed and before the fixture's teardown cleanup. They are not process RSS measurements.The base also leaves one unusable published block in each memory-type sweep. Both new regression groups fail on base and pass with the fix; existing allocation retry, mapping-error and native buffer controls pass with the fix.
4fe92c9c23c7bd861d63664d4efde3033b6226f6) temporarily applied. It was removed and is not in this PR.With the configured full build and environment above:
Linux (VirtualBox): Ubuntu 24.04.5 LTS, kernel 7.0.0-31-generic, GCC 13.3.0; VirtualBox 7.2.20 on the Windows host above, 4 vCPU / 8 GiB assigned. Release,
BUILD_TESTING=ON,ANYPS5_ENABLE_SPIRV_TOOLS=OFF. Graphics: not exercised.agc_buffer_pool(including metadata fault injection and mapping failure),agc_structurizer,agc_shader_mode_register,agc_shader_control_flowandagc_constant_phi: 5/5 passed, 0 failures, 0 skips.The existing Linux build retained its CMake cache paths through its compatibility directory:
Linux graphics/Vulkan tests: NOT RUN — intentionally excluded from VirtualBox validation. Native/bare-metal Linux was not tested. Native Linux GPU validation: not tested.
The full CTest suite was not run. The failure scenarios are synthetic, bounded fault injection; no title, actual system exhaustion, FPS improvement or AMD/PS5 run is claimed. Full hosted builds require a collaborator's manual dispatch under the current CI policy.
Checklist
main; no other open PR implements this slab-publication cleanupImported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T16:04:55Z.
Review: COMMENTED
I reviewed the ownership and publication sequence in
BufferPool::TakeSlot. The new block remains under its scoped deleter through mapping, free-slot initialization, available-vector reserve, andslabBlocks.try_emplace; ownership transfers only after all allocating publication steps complete, and the finalpush_backuses reserved capacity. The map/vector failure paths therefore release the native allocation and mapping, while the tests exercise retry and map-failure cleanup for mock and native Vulkan paths. I did not find a concrete defect in this diff. Hosted conventions, eligibility, intake and report pass; the Linux/Windows build jobs are skipped by path filters. I have not independently run the tests, so I’m relying on the detailed native Windows and Linux VirtualBox results in the description.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-16T16:11:56Z.
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.
main)core/libs/prx/libSceAgcDriver/tests/BufferPool.cppL2, L46Some 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.
core/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/BufferPool.cppcore/libs/prx/libSceAgcDriver/tests/BufferPool.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/execution/PooledBufferRange.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/BufferPool.cppcore/libs/prx/libSceAgcDriver/tests/BufferPool.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtImported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-16T18:00:33Z.
Review: COMMENTED
A native Linux GPU run, which the description lists as not tested (the Linux run there was VirtualBox, graphics excluded).
Machine: Linux, NVIDIA GeForce RTX 3070 (driver 595.99.02) and lavapipe (Mesa 26.0.3, LLVM 21.1.8) on the same box. Ubuntu 26.04, i7-8700, GCC 15.2, Release,
BUILD_TESTING=ON. Heada4485bd82merged intomain66e290f1c(clean). Red run: same tree with onlyGraphics/src/BufferPool.cpprestored tomain.agc_buffer_pool, fixagc_driver_pooled_buffer_range, fixagc_buffer_pool,main'sBufferPool.cppleaked the slab's device memory at allocation 0..3,did not unmap its slab,published an unusable slab)agc_driver_pooled_buffer_range,main'sBufferPool.cppleaked=6291456, type 3 (mapped)leaked=6291456, total 12582912leaked=6291456The RTX 3070 numbers match your Windows table (6 MiB device-local, 6 MiB mapped host-visible, one unusable block per sweep at allocation 3). lavapipe exposes a single host-visible memory type, so only the mapped sweep runs there; with the fix it reports
leaked=0for all four failure points.Not run: AMD, the full suite, any title.
GPUs tested: NVIDIA GeForce RTX 3070 (595.99.02), lavapipe (Mesa 26.0.3, LLVM 21.1.8), Ubuntu 26.04
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by simonbbby on 2026-10-16T18:24:09Z.
Independent native RADV allocation-failure check at exact head
a4485bd8216075064799fd023d6147a326961be3, adding the AMD case to the NVIDIA/lavapipe results above.Host: Ubuntu 24.04, kernel 7.0.0-38, GCC 13.3, Ryzen 9 9950X. Selected Vulkan device:
AMD Ryzen 9 9950X 16-Core Processor (RADV RAPHAEL_MENDOCINO), vendor/device1002:13c0, Mesa/RADV 25.2.8 (driverVersion=0x6402008).VK_DRIVER_FILESpoints only toradeon_icd.json, andANYPS5_GPU=AMDis checked by the fixture.To bypass the unrelated SDL/XRandR full-build blocker, I isolated the prefix of
PooledBufferRange.cppthroughSlabMetadataFailures: the nativeDevicesetup, allocation/map/free counters and fault sweeps are unchanged. Removed the unused shader/resource test includes and replaced only SDL's three dynamic-loader calls withdlopen/dlsym/dlclose. The scratch entry point runs that allocation subtest and final handle/live-byte checks. It links the complete unchanged productionBufferPool.cppand upstreamAllocationFailure.cpp, with function/data sections and linker garbage collection. All Vulkan allocation/map/unmap/free calls reach the actual RADV device.Same native fixture and fault-injection object, changing only production
BufferPool.cpptoHEAD^for the negative control. Three fresh processes per variant:These are counted
VkDeviceMemoryallocation sizes before the fixture's final teardown cleanup, not RSS. The parent retains a 2 MiB allocation at every injected point before retry; point 3 also exposes one published unusable block in each memory-type sweep. With the PR every point reportsretained=0 blocks=0, retries return the correct mapped/unmapped state, and final cleanup reports no invalid handle/mapping state. The selected device and all eight exercised fault points are verified in each process; nothing skips.This rules out a software-driver fallback or a test that fails before a native allocation exists. The matched pool object identifies the cleanup/publication change as the difference. Repository worktree is clean; the extraction/build script and six full logs are retained separately.
Scope: native allocation cleanup, mapping and retry behavior on RADV. I did not run
RobustReadPastEnd,ExactSizes, the fullagc_driver_pooled_buffer_rangeexecutable, shader compute/readback, the wider runtime suite or a title; this is not a full-fixture pass or a merge onto newer main.Imported from boykopovar/AnyPS5. Originally posted by Amoenus on 2026-10-17T11:30:22Z.
Validation at composition
fa544a6a2containing main20a84154ff: the changed BufferPool/PooledBufferRange source is byte-identical to main. Full Windows/Linux relinker/library builds pass.agc_driver_pooled_buffer_rangepasses3/3 on verified NVIDIA RTX5080, driver32.0.16.1062, Windows11 Enterprise26200, with Khronos core1.4.363 and zero errors/warnings; it also passes3/3 on Mesa25.2.8 llvmpipe/LLVM20.1.2, Ubuntu24.04 WSL2. Each run reportsslab metadata total leaked bytes=0. These are composition tests, not an unchanged PR-head or full-suite claim.Follow-up against unchanged main
1846719e46: explicitly requesting AMD selects NVIDIA and throws before device creation, 3/3 fresh processes. The independent fixture-only correction is now #7104 (fork commit). At that exact changed head the full pooled-buffer fixture passes 6 AMD processes (full name and substring, three each), 12 NVIDIA processes and 9 llvmpipe processes; six unmatched-name controls still refuse explicitly. Actual vendor/device identity is verified per run; all positive runs report zero retained slab-metadata bytes. Windows positives use Khronos core1.4.363 with zero validation errors/warnings. Full relinker/library targets build on Windows/Linux and the separate CPU graphics group passes3/3 per OS. The PR contains the concise reproduction and complete selector matrix.The fa544 composition evidence above retains its original scope; the new AMD coverage is the separately tested #7104 head. This is a fixture-selection fix, not a defect attribution to your cleanup or a title-startup improvement.
AI-assisted: yes (Codex); author responsible.