fix(agc): give pooled buffers a VkBuffer of exactly the requested size #2233
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2233"
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 TideOPL on 2026-10-09T12:37:27Z.
What
BufferandDeviceBuffercreated theirVkBufferat the pool's size class (BufferPool::Capacity: power-of-two classes below 1 MiB, finer device classes above), not at the size the caller asked for. WithrobustBufferAccess, a shader read past the requested size therefore stayed inside theVkBufferand returned whatever an earlier user of the pooled memory left there, instead of an out-of-range result (zero or a value inside the buffer).Each
VkBuffernow has exactly the requested size, created with the pool's usage (BufferPool::Usage) and bound to memory sized for its class, or to its slab slot, so the allocation stays reusable.BufferAllocationrecords the size itsVkBufferwas created with (bufferBytes). A buffer taken from the pool for a different size gets a newVkBufferover the same memory at the same offset; a same-size reuse keeps the existing one.tests/BufferPool.cppfollowed a pooled buffer by itsVkBufferhandle and checked a class by theVkBuffer's size. With exact-size buffers the class is held by the memory, so those checks now follow the bound memory (MemoryOf/ClassOf); the cases are unchanged, and the first one also checks that theVkBufferis created at the requested size.Open PRs #1896, #1201 and #290 also change
BufferPool.cpp/.hpp, but only eviction and retained-byte bookkeeping; none touches theBuffer/DeviceBufferconstructors orBufferAllocation.Tested
Windows 11, RTX 5070 (driver 595.x), MinGW-w64 GCC, Release,
BUILD_TESTING=ON, onmain5edae353.agc_driver_pooled_buffer_range:0xababababand released. A 100-byte buffer then takes the same pooled memory, and a compute shader reads word 28 (byte 112) through aVK_WHOLE_SIZEstorage descriptor withrobustBufferAccessenabled. Onmainthis returns0xabababab, the earlier user's bytes; with the fix it returns zero or a value inside the buffer.vkCreateBuffer(fresh, pooled-at-another-size and same-size-reusedBufferandDeviceBuffer), with the classes taken fromBufferPool::Capacity.main(5edae353), passes with this change.ctest -R "^agc_driver|^agc_buffer_pool": 255/255 pass. Fullctest: 710/710 pass (display-dependent video-out tests skipped).python tools/check_conventions.py --base origin/mainpasses.Not run: Linux (tested there on the earlier revision by @Kikoarl), AMD.
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 Kikoarl on 2026-10-09T14:04:23Z.
Linux run: Linux 7.2 (x86_64), Intel(R) Graphics (RPL-S) (Mesa 26.3.0-devel, Vulkan 1.4.363), GCC 16.2.1, Release,
-DBUILD_TESTING=ON, #2233 (12da51f3) tested on currentmain(d70b8998).tests/agc_driver_pooled_buffer_range_tests: passes cleanly on Vulkan (device Intel(R) Graphics (RPL-S),pooled buffer range tests passed).tools/check_conventions.py: passes cleanly.agc_driverexecution tests.Tested on Linux to cover the platform noted in the description ("Not run: Linux").
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T06:01:05Z.
Review: CHANGES_REQUESTED
Thanks. The test passes here on the PR head alone, and fails with the three non-test files reverted, so it pins the fix. Needs a rebase before it can land:
mainincore/libs/prx/libSceAgcDriver/Graphics/src/Resources.cppsince "perf(agc): pool device staging buffers by size class" (28345b0ea).mainnow hasBufferPool::Usage(usage, properties),Capacity(size, properties)and setscapacity = allocation->bytesafterTake.BindExactBuffer(Resources.cpp:18, called at :55 and :143) must receive the pool-adjustedthis->usage, not the constructor argument, or a pooled buffer re-created at the exact size gets different usage flags than the pooled memory was keyed on.deviceClassBits), soClassBytes/the "4096-byte class" expectations inPooledBufferRange.cpp(:25, :311) need rechecking againstBufferPool::Capacity(size, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT); better to derive them from it than hardcode.agc_driver_pooled_buffer_rangeand the otheragc_drivertests on the rebased tree.Imported from boykopovar/AnyPS5. Originally posted by TideOPL on 2026-10-10T14:36:43Z.
Rebased onto
5edae353and addressed each point:28345b0e: keptBufferPool::Usage,Capacity(size, properties)andcapacity = allocation->bytes.BindExactBuffernow gets the pool-adjustedthis->usage, both for a fresh buffer and for a rebind.PooledBufferRange.cpptakes its classes fromBufferPool::Capacity(...)and checks that each pair of requests shares one, instead of hardcoding 256/4096.765619a0), so a recreated slab buffer is rebound at its own offset, and that offset is checked against the new buffer's alignment.One more change to flag:
tests/BufferPool.cpp(from28345b0e) tracked a pooled buffer by itsVkBufferhandle and checked a class by theVkBuffer's size. With exact-size buffers, the class lives in the memory and a reuse at another size gets a new handle over that same memory. Those 8 checks now follow the pooled memory instead (MemoryOf/ClassOf). The cases mean the same thing, and the first one also checks that theVkBufferis created at the requested size.agc_driver_pooled_buffer_rangestill fails on main (0xabababab) and passes with the fix.ctest -R "^agc_driver|^agc_buffer_pool": 255/255. Full ctest: 710/710.check_conventions.py --base origin/mainpasses.Imported from boykopovar/AnyPS5. Originally posted by orishamir on 2026-10-10T17:52:37Z.
Checked
aa9ee1b0merged onto currentmain(57f96fd2; clean merge) on Linux (Ubuntu 26.04 in WSL2, GCC 15.2.0, Release,BUILD_TESTING=ON) on llvmpipe (Mesa, LLVM 21.1.8), so a third driver after NVIDIA and Intel:agc_driver_pooled_buffer_rangeandagc_buffer_poolpass.ctest -R '^(agc_driver|agc_buffer_pool)': 255 tests, 0 failures, 27 capability skips (mesh, DPP, DS/GDS append, conservative rasterization and the like, which llvmpipe lacks).BufferPool.hpp,Resources.hppandResources.cppreverted tomain(tests kept):agc_driver_pooled_buffer_rangefails with "a robust read of word 28 of a 100-byte pooled buffer returned 0xabababab, the bytes a 256-byte earlier user left in its memory", andagc_buffer_poolwith "a 10 MiB + 4 KiB device buffer was created with 11534336 bytes, not the requested size" and "a reused device buffer kept the VkBuffer of the earlier size". Restored, both pass again.BindExactBufferreceivesthis->usageon the fresh and the rebind path, inBufferandDeviceBuffer;capacity = allocation->bytesis kept afterTake;PooledBufferRange.cpptakes its classes fromBufferPool::Capacity(...)(80/100 host, 2500/3000 device) and asserts each pair shares one; the slab rebind checks the offset against the new buffer's alignment.BufferPool.cpp, which this PR does not touch. #290 does editBuffer::Buffer,DeviceBuffer::DeviceBufferand bothrelease()paths (thevkAllocateMemory/vkFreeMemorylines next to thecache->Putlines changed here), and merging it on top of this PR conflicts inResources.cppandBufferPool.hpp; #290 already needs a rebase againstmainon its own.Not checked here: a game, or a hardware driver.
AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-10T22:29:31Z.
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/Resources.cppL5-6, L9Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T22:33:22Z.
Review: APPROVED
Checked the PR merged onto current
mainon Linux :agc_buffer_poolandagc_driver_pooled_buffer_rangepass, and both fail with the three non-test files reverted, so they pin the fix. Slab slots are bounded by the slot size and the rebind checks size and alignment; no conflicts withmain. Also confirmed by @Kikoarl (Intel), @orishamir (llvmpipe) and @Mouhand-Kaddo (Windows). Merging.