fix(agc): release the texture caches when a device allocation runs out of memory #6174
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6174"
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 ee6aba54 on 2026-10-15T00:29:27Z.
What
A device allocation that fails with
VK_ERROR_OUT_OF_DEVICE_MEMORY(orOUT_OF_HOST_MEMORY) now releases the texture caches before it is retried:BufferPool::AllocateMemorytrims its own idle tiers first, then calls a reclaim hook thatGraphics::ReleaseTextureCachesserves, and retries. The hook evicts sampled textures oldest first and storage images without pending results oldest first. Storage images with pending results stay cached, because storing their results needs a staging buffer from the heap that just ran out. A failure inside the release stops it and is reported; the outer allocation reports the recovery ([bufferpool] ... recovered: allocation= reclaimed= released= ...).Texture and storage image memory is allocated through the pool's recovery path as well, so an image allocation that runs out of memory gets the same trim, release and retry.
The staging pool's device tier is sized from the device's reported memory budget (
VK_EXT_memory_budget) when the extension is present: the largest device-local heap counts with at most its reported budget, then #5893's rule applies (a sixty-fourth on system memory with a 128 MiB floor, an eighth otherwise with a 512 MiB floor).APS5_STAGING_POOL_MIBstill overrides it.Tested
Linux, Ubuntu 24.04, NVIDIA GeForce RTX 5080 (driver 595.99.02). PPSA15304 ran out of device memory after 460 s in the section after the first drop with the storage cache budget alone (#5483); with this change five runs of 900 to 1000 s without budget variables showed no
OUT_OF_DEVICE_MEMORY, the recovery line fired 45 to 49 times per 900 s with sampled and storage images released, and a 25 min run of the merged working branch (currentmainwith these and its other commits) showed no allocation failure either.ctest -R agc_passes (565 tests) including the newCacheReclaimRecoverypool test with a mock hook and the extendedStorageCacheBudgetexecution test (the release takes clean storage images and keeps the ones with pending results).Checklist
main; no other open PR implements the same functions.mdfiles or images added to the repositoryTexture.cpp; its host placement can follow this PR as the step after the pool's reclaim and retry)Imported from boykopovar/AnyPS5. Originally posted by ee6aba54 on 2026-10-15T01:00:58Z.
Overlaps noted. #5987 goes first: it falls back to a host memory type once the pool's retry failed, while this PR adds the texture cache release before that retry, so after #5987 the texture and storage image allocations here will go through
Context::AllocateDeviceMemory. #5893 changesDeviceBudgetas well. I will rebase onto both once they are in;Depends onis updated.Imported from boykopovar/AnyPS5. Originally posted by ee6aba54 on 2026-10-15T09:51:55Z.
Rebased onto main now that #5893 is in. The only conflict was
BufferPool::DeviceBudget: the largest device-local heap now counts with at most its reported budget, and #5893's rule is applied to that (a sixty-fourth on system memory with a 128 MiB floor, an eighth otherwise with a 512 MiB floor).stagingPoolBudgetTestskeeps #5893's cases and the reported-budget cases.ctest -R agc_passes on Linux with an RTX 5080 (576 tests, 4 skipped), and check_conventions passes.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T10:12: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/Graphics/src/BufferPool.cppL67core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppL6, L295, L586, L1150core/libs/prx/libSceAgcDriver/tests/execution/StorageCacheBudget.cppL54-55, L70-71core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppL295-296core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppL5-6core/libs/prx/libSceAgcDriver/Graphics/src/BufferPool.cppL39, L72-73core/libs/prx/libSceAgcDriver/tests/BufferPool.cppL596Some 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/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Context.hppcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/include/BufferPool.hppcore/libs/prx/libSceAgcDriver/Graphics/include/Context.hppcore/libs/prx/libSceAgcDriver/Graphics/src/BufferPool.cppcore/libs/prx/libSceAgcDriver/tests/BufferPool.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Context.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/include/BufferPool.hppcore/libs/prx/libSceAgcDriver/Graphics/include/Context.hppcore/libs/prx/libSceAgcDriver/Graphics/src/BufferPool.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/BufferPool.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Context.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Context.hppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Context.hppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Context.hppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Context.hppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Context.hppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Context.hppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Context.hppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppImported from boykopovar/AnyPS5. Originally posted by ee6aba54 on 2026-10-15T14:09:13Z.
The overlap with #5998 is the
Storehelper intests/execution/StorageCacheBudget.cpp. This PR adds aflushparameter, so a test can keep an image dirty, and #5998 moves the dispatch intoRecordunder the GPU mutex. The two changes are compatible: whichever lands second takes both in a short rebase. There is no dependency either way. @MarcZX100 for visibility.Imported from boykopovar/AnyPS5. Originally posted by Pipodi on 2026-10-15T17:36:16Z.
@ee6aba54 I tried this on Ghost of Yōtei (PPSA26344) in our run162: RTX 4090 (24 GB), driver 617.42, Windows 11, main
0dab493f5+ #5815 #5781 #6227 #5405 #6402 + this PR, warm shader cache.The first recovery worked: a 685 KiB texture allocation failed, the pool trim freed 2.24 GB, and the retry succeeded. By the wolf scene, device memory had spilled into the shared host heap (memory type 0, 15.9 GB) until that was full too. From then on the release itself failed 798 times:
The release seems to need a 4 MiB buffer, presumably the write-back staging for a dirty storage image, from the same heap that just ran out. So it frees nothing at the point where it's needed. The run aborted at frame ~824 with
VK_ERROR_OUT_OF_DEVICE_MEMORY.Suggestion: once an allocation has failed, the release shouldn't allocate. It could drop what needs no write-back first (sampled entries nobody else holds, clean storage images), or keep the write-back staging buffer reserved up front.
In our case most of the memory wasn't in the texture caches at all. Resource-cache entries kept dropped sampled textures alive, and #6492 fixes that. With #6492 the same scene stays under the device budget, so the release path never runs there.
Imported from boykopovar/AnyPS5. Originally posted by ee6aba54 on 2026-10-15T18:31:52Z.
@Pipodi Thanks, that is a real defect in the release path, fixed in
d6fe6551b.Storing a storage image's pending results needs a staging buffer, and under that pressure it comes from the heap whose allocation just failed. The release took dirty images once the clean ones did not cover the request, so it failed on that 4 MiB buffer. There was a second effect:
StorageTexture::Flushclears the pending state before it stores, so each failed store also dropped that image's results.The release now takes only what needs no allocation: sampled entries and storage images without pending results. Images with pending results stay cached and are counted in the release line (
..., N with pending results kept). TheStorageCacheBudgetexecution test now requires that a release of everything keeps the dirty image, and that a release takes it once its results are stored. Without the change it fails with "a release of everything took the image with pending results".I did not add a reserved write-back buffer. A buffer large enough for the largest surface would hold that memory for the whole session, and #6492 removes the cause in your scene.
Tested on Linux (RTX 5080, 595.99.02):
ctest -R ^agcpasses (574 tests, 4 skipped as before). The PPSA26344 case is not reproduced here.Imported from boykopovar/AnyPS5. Originally posted by savvaniss on 2026-10-17T13:10:15Z.
Windows data: the new
agc_buffer_poolcases fail on Windows with both an Intel UHD 770 and an AMD RX 9070 XT.Windows 11 Pro 26300, WinLibs GCC 15.2.0 r7, Release, every execution test built,
ANYPS5_NO_SHADER_CACHE=1, serial CTest. Intel UHD Graphics 770 (8086:a780), driver 32.0.101.7088. AMD Radeon RX 9070 XT (1002:7550), driver 32.0.31041.1004, withVkCacheemptied first. "Without" means this PR's test files onmainc9e6c45de, with none of its other changes.This head
d6fe6551bmerged intomainc9e6c45de: 20 tests (agc_buffer_pool,agc_driver_graphicsand the tests built fromtests/Graphics.cpp,agc_driver_storage_cache_budget), ×3. 19 pass on both GPUs.agc_buffer_poolfails every run on both:Every
[bufferpool] ... recovered:line before them showsreleased=0.agc_driver_storage_cache_budgetpasses on both GPUs. There is no without-run: this PR's test files don't compile againstmain.Full CTest (
--parallel 4) onmainc9e6c45dewith seven open GPU PRs merged (#6258, #6657, #6324, #6246, #6174, #6360, #6598): UHD 770 1381 of 1389, RX 9070 XT 1383 of 1389.mainalone passes 1378 of 1385 and 1381 of 1385. The merge adds only two failures:agc_buffer_pool(#6174, both GPUs) andagc_driver_indirect_dispatch_limit(#6360, RX 9070 XT).AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by ee6aba54 on 2026-10-17T14:37:45Z.
@savvaniss Thanks, that pinned it down.
agc_buffer_pool_testscompilesGraphics/src/BufferPool.cppinto the test executable and also linkslibSceAgcDriver. The test registered its mock withBufferPool::SetCacheReclaim, which stored it in a function-local static. On Windows the executable and the DLL each have their own copy of that static: the test set the executable's copy, whileDeviceBuffer(in the DLL) allocated through the DLL's copy, which stayed null. That is why every line showsreleased=0. On Linux the executable's definitions interpose the library's, so the test passed there.0f1564cc2removes the static: the release callback is now aContextfield (cacheReclaim), set inVulkanDevice::buildContextand read by the pool when it is constructed, the same way the test already injectsmemoryProperties2. The test sets it on its mock context.Tested on Linux with this head merged into
main47a266cf9: theagc_buffer_pooltests,agc_driver_graphicsandagc_driver_storage_cache_budgetpass, and all 654agctests pass except 3 that skip on this machine. I could not run it on Windows; a rerun ofagc_buffer_poolthere would confirm it.Ubuntu 24.04, kernel 7.0.0, NVIDIA GeForce RTX 5080, driver 595.99.02, Release build.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by savvaniss on 2026-10-17T17:15:25Z.
Windows confirmation for
0f1564cc2:agc_buffer_poolnow passes on an Intel UHD 770 and on an AMD RX 9070 XT.Windows 11 Pro 26300, WinLibs GCC 15.2.0 r7, Release, every execution test built,
ANYPS5_NO_SHADER_CACHE=1, serial CTest. Intel UHD Graphics 770 (8086:a780), driver 32.0.101.7088. AMD Radeon RX 9070 XT (1002:7550), driver 32.0.31041.1004, withVkCacheemptied first. Both heads are merged into the samemain,66702f1cf.d6fe6551b(previous):agc_buffer_poolreleased=00f1564cc2: 20 tests: the threeagc_buffer_pooltests, those built fromtests/Graphics.cpp,agc_driver_graphicsandagc_driver_storage_cache_budgetFull CTest (
--parallel 4) with0f1564cc2merged fails the same tests asmain66702f1cfalone on this machine, none of them in code this PR touches:agc_driver_sample_multisample_target(#6957).agc_driver_quad_pixel_mask(#6255) andagc_driver_layered_volume_vertex_no_gpl(#4768).AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T17:34:09Z.
Thanks for running the Windows regression on both Intel UHD 770 and RX 9070 XT, including the previous head as a control. The 3/3 failures before and 20/20 passes on the fix head confirm the DLL-local callback diagnosis and the
Context-owned callback correction across both vendors. The full-suite failures you listed are outside this change and match the unchanged-main baseline.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-17T21:15:46Z.
A data point from a second title: Forspoken (PPSA03984). Linux 6.8, RTX 4070 Ti 12 GB (NVIDIA 595.99.02), Release, warm shader and pipeline caches, scripted pad input,
APS5_PROFILE_DRAW=1for the per-10 s present lines. The heap budget reported byVK_EXT_memory_budgetwas about 9.65 GB.Base is
main82cad6b5fcwith #6917 (df26342075). Onmainalone the title is slower and doesn't reach this point within 120 s. Given 240 s,mainstopped at 192 s on an unrelated refusal (Rect-list SPIR-V: custom per-vertex interpolation is unsupported) without a-2. The other build adds this PR's head0f1564cc20(84da3ffe3f). Two interleaved rounds, 150 s each:vkAllocateMemory texture: Vulkan result -2; 374 presents-2; 3[bufferpool] ... recoveredlines-2; 6 recovery linesEarlier runs of the same base without this PR stopped the same way at 85 s and 110 s, on
vkAllocateMemory storage texture: Vulkan result -2.The recovery lines from the second run with this PR:
Most recoveries came from trimming the pool's idle tiers (
reclaimed); the texture caches had to be released in three of the nine. The first recovery came 90 to 100 s in. In the 10 s intervals after it there were 37 to 44 presents (run 1) and 32 to 43 (run 2), against 22 to 48 in the minute before, so I saw no stall from the releases. I only ran 150 s, so this says nothing about longer sessions.AI-assisted: yes (Claude Code)