perf(agc): sub-allocate sampled texture memory from shared blocks #1484
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1484"
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 Celegans12 on 2026-10-08T08:57:02Z.
What
Every sampled texture got its own
vkAllocateMemory. On an RTX 3080 Laptop under Windows an allocate plus free costs about 210 µs, and the PPSA26344 world creates about 14,700 textures per frame.ImageMemorykeeps per-device blocks of a 64th of the heap, 16 to 256 MiB.APS5_IMAGE_BLOCK_MIBsets the size; 0 gives every texture its own allocation as before.bufferImageGranularitynever applies.VkMemoryDedicatedRequirements), one over half a block, and one whose new block is refused for memory get their own allocation. After a refusal, no block of that type is tried again until a block's worth of its memory has been freed.APS5_PROFILE_DRAWadds an[imagemem]line.ImageMemory's own allocations through #290'sAllocateGpuMemoryand frees its spare blocks inRelieveGpuMemory.Details
Microbenchmark on the RTX 3080 Laptop, 4,000 BC textures of 64 to 1024 texels with mips: bind plus release 215-223 µs per texture before, 9-12 µs after. 100,000 replacements among 8,000 live textures (2.2 GiB): 353 µs each before, 3.9 µs after, blocks 87% used. lavapipe: 6.4 µs before, 0.7 µs after.
Tested
main4c380ae3: configure-DBUILD_TESTING=ON, full build,--target libs,ctest:ctest --output-on-failure)VK_DRIVER_FILES): 406/406 pass;agc_driver_flat_storeis left out there because it takes several minutes on Windows llvmpipeagc_image_memory(mocked device): packing at each alignment with no overlap, reuse and merging of freed ranges, the spare block, dedicated and large textures, refused blocks and binds, the back-off after a refusal, concurrent binds. Does not build onmain.vkAllocateMemoryfailure.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by EdouardSence on 2026-10-08T13:18:11Z.
Tested on AMD under Linux, since this PR wasn't: RX 9070 XT (RDNA4, GFX1201), RADV / Mesa 26.2.4, Linux 7.2.9 (CachyOS), GCC Release build.
ctest: this PR merged ontomain07c2405c, all 453 tests pass withctest -j8(main alone: 452/452 on the same machine).main+ #759 (needed to boot this title onmain) + this PR, then one scripted run headless from boot through the title screen. No error and no amdgpu fault came from this change.main+ #759 alone: 226, 229, 226.storage image access to depth/stencil surface ... is not implemented(the gap #425 fills). So nothing past the title screen is covered.AI-assisted: the runs and this write-up were done by Claude (Claude Code) on my machine.
Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-08T19:01:45Z.
Linux NVIDIA run with a title that creates a lot of textures.
Demon's Souls (PPSA01341), tutorial level, Nobara 44 (Linux 7.2), RTX 5070 Ti (595.91.07), Ryzen 5 7600X. Our stack is
maindf16c4c2plus open PRs we run (#1201, #1202, #1184) and local fixes, with and without this PR. 2 runs per arm, interleaved, same start point, level window t+150 to t+240 s:Graphics::Drawms in the window[imagemem]at the end7 blocks (1778 MiB), 1643 MiB in 496 images; 7 images in their own allocations (1063 MiB); blocks allocated 7, freed 0, refused 0and8 blocks (2032 MiB), 1922 MiB in 577 images; 7 images in their own allocations (1063 MiB); blocks allocated 8, freed 0, refused 0Neutral here: about 2.0 fps either way, and no new errors or rejected allocations. In this part of the level our stack no longer creates textures in steady state (an earlier build churned through about 800 per 10 s), so the allocate and free cost this PR removes doesn't show up at the frame level. The blocks fill as expected: most textures land in shared blocks, 7 large ones get their own allocation, and nothing was refused or freed.
The cherry-pick applied cleanly. One local change of ours that allocates its own image memory needed the same
ImageMemory::Bindchange the PR makes in the snapshot constructor, so other open PRs that allocate texture memory directly may need it too.Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-08T19:22:01Z.
Closing this. Thanks to fisherjoey for the Demon's Souls run: neither that nor Ghost of Yōtei shows a frame-level gain from it. Once the texture cache stops churning, the allocate and free cost it removes is too small to see, and our last Yōtei run measured no per-texture improvement either, so it isn't worth the review time.
If someone picks the idea up later: any other code that allocates image memory directly would need the same
ImageMemory::Bindchange as the snapshot constructor, as fisherjoey found with a local patch.Pull request closed