refactor(agc): create, bind and free buffers through the device function table #11920
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11920"
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 milescoviello on 2026-10-27T12:34:22Z.
What
Follow-up to #10764, as agreed with oneandonlydean there (comment). BiladeiroSupremo's lookup cache (BiladeiroSupremo/AnyPS5Wolverine@fccc2547a) gets a home in the resolved device-function table, not a separate per-thread cache. BiladeiroSupremo is credited with a
Co-authored-bytrailer.Graphics::Context::Functionlooks a Vulkan device function up by name, through the loader and every implicit layer, on each call. #10764 moved the texture detiler ontoContext::Resolved. That readsDeviceFunctionsand falls back toFunctiononly while the table is absent or lacks the entry.I counted lookups by name in Call of Duty: Black Ops II (PPSA34502 01.010.000, 300 s of campaign gameplay). The build was
mainplus #10764 and #9656 plus a local counter (not in this PR). It made 2.1 million lookups by name, and four buffer calls account for 1.9 million of them:vkCreateBuffervkBindBufferMemoryvkGetBufferMemoryRequirementsvkDestroyBuffervkCmdPipelineBarriervkMapMemoryvkCreateImageView/vkDestroyImageViewvkResetDescriptorPool, fence calls, submit, command buffer begin/end/reset, framebuffersThey come from
ShaderResources::addDataBuffer→Buffer::Buffer→BindExactBuffer: a pooled buffer rebound at a new exact size for a draw's data.This PR:
createBuffer,destroyBuffer,getBufferMemoryRequirements,bindBufferMemory,allocateMemory,freeMemory,mapMemoryandunmapMemorytoDeviceFunctionsand toFillDeviceFunctions;BindExactBuffer,Buffer::Buffer,Buffer::release,DeviceBuffer::DeviceBuffer,DeviceBuffer::release,BufferPool's constructor andMemoryAccounting::Allocate/Free. The onevkGetFenceStatuscall inCommandBatch::~CommandBatchalso uses the table entry it already had.Every other
Functioncall site stays as it is. An earlier version of this PR converted 366 call sites in 23 files. CnRJay pointed out that the counts above put the saving in these few, so the rest is out.How
Resolvedreturns the table entry when the device has filled its table, and otherwise callsFunctionas before. So contexts without a table (mocks,APS5_NO_PROC_TABLE, calls made before the table is filled) behave exactly as onmain. The table is filled once at device creation and only read afterwards.Tests, in
agc_buffer_pool:TableFillfills a table throughFillDeviceFunctionsfrom a mockvkGetDeviceProcAddr. It checks that each of the 8 new members holds the mock function of the name it is filled from, so a member filled from the wrong name fails.TableLookups: the mock counts lookups by name. A cycle of a host-visibleBufferand aDeviceBufferat sizes the pool hasn't seen forces the exact-size rebind path. Without a table the cycle must look something up, so the counter sees these calls. With a table holding the buffer and memory functions, a second cycle must make no lookup.Tested
At head
860450ba7f(rebased ontomainabe492bfea), same machine: a fullcmake --build buildsucceeds, and the 15 tests matchingBufferPool|buffer_pool|memory_accounting|device_functions|pipeline_cache_allocpass.Earlier, Linux (Ubuntu 26.04.1, GCC 15.2), RTX 4070 Ti (NVIDIA 615.71.09), at head
8b7a2ae407:main5bae1a4bc2(bfb5e10bbc, clean): a fullcmake --build buildof every target succeeds, and the 8 tests in the next item pass on the merge too.agc_buffer_pool(3 entries),agc_memory_accounting,agc_memory_accounting_budget_cap,agc_memory_accounting_budget_floorandagc_deferred_memory_accountingpass, 8 of 8 in each of 3 runs.main-side base52ca9f0137(#10764 alone) against this head: 8 of 8 pass on both, one Vulkan device created on each, no validation IDs on either.VK_LOADER_DEBUG=layer: merge base13b19a1dcavs head7ed8fb0434, withagc_buffer_pool, theagc_memory_accounting*tests and theagc_driver_image_memory*execution tests this PR touches. 13 of 13 pass on both sides, the loader inserted the layer for each of the 8 Vulkan devices per side, and there are no VUIDs. It replaces the 1.4.363 run above, whose layer load can't be confirmed (#17896).Windows 11 VM (GeForce GT 1030, WinLibs GCC, Release),
agc_buffer_pool,agc_memory_accounting*andagc_deferred_memory_accounting: 8 of 8 in each of 3 runs, on this head and onmain0e9dc7bc4c.Red control for
TableFill: this head withdestroyBufferfilled from"vkDestroyBufferView"(35e1d136a0, branchtest/11920-fill-mutanton my fork) failsagc_buffer_poolin all 3 runs on the VM:the device function table's member for vkDestroyBuffer was not filled from that name.I haven't re-measured CPU time for this narrowed commit, and I don't claim a frame-time change.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)libSceAgcDriveroffagc_pipeline_cache_allocation_tests's link line; this PR rebases onto it)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-11-01T19:49:25Z.
Review: COMMENTED
1. Speed claim without
trace_digest. The title isperf(agc), and the evidence is an env-gated timer aroundvkGetDeviceProcAddr(96a3a18601, not in this PR): 846-868 ms before and 48-50 ms after, per 300 s run. That is about 0.8 s of CPU in 300 s, roughly 0.27% of one core, or about 100 ns per lookup, and it is not the metric the project accepts. Please posttools/trace_digest.pysummaries of main and of this branch on the same machine and scene. If frame p50/p99 do not move, this is a cleanup and should be described as one.2. The win is three call sites; the diff is 366. The lookup table in the description shows
vkCreateBuffer,vkBindBufferMemory,vkGetBufferMemoryRequirementsandvkDestroyBufferat about 485k each, with everything else at 3,000-7,500 per 300 s (10-25 per second). Adding the buffer and memory entries toDeviceFunctionsand convertingBuffer::Buffer/BindExactBufferwould capture essentially all of it. Converting the per-present, overlay and framebuffer calls across 23 files buys nothing measurable and, by the author's own account, conflicted with main in 8 files on the last rebase. Please split it, or justify the rest with numbers.3. Carries #10764. The branch is #10764 rebased plus this commit, so the diff here includes another open PR. Please state the merge order or retarget so only this commit is reviewed.
4. Fallback in
Resolved. When the table lacks an entry it silently falls back toFunction. With 19 new members and 366 converted sites, a typo in a member/name pair (&DeviceFunctions::x, "vkY") resolves to the wrong function with no compile error. A test that checks every converted pair against the name it was filled from would catch that;TableLookupsonly covers the buffer calls.Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T12:46:58Z.
Review: APPROVED
Reviewed — approved
The PR adds 8 buffer and memory entries to
DeviceFunctionsand resolves the hotBuffer/DeviceBuffer/BindExactBuffercalls through the table; it merges cleanly, builds, passes, and its new tests catch the regressions they target.What I ran
Head
860450ba7f34b65cf1353d529ac8ef7b37c3dccd,main4f41f4c375f5abb487dbd184fbc150f31994d762, merged tree9bbbb24811667ede59329e345f4fb4613bdba579(Debian 13 VM, GCC 14.2.0, Release, Ninja, lavapipe / Mesa 26.1.6).Results
git diff --checkcheck_conventions.pymainmainvs merge)agc_buffer_pool*,agc_*memory_accounting*,agc_deferred_memory_accountinggit status --porcelainempty),agc_buffer_poolpasses againNegative control
I restored
Resources.cpp,BufferPool.cppandMemoryAccounting.cppfrommainand kept the mergedContext.hppso the test still compiles.agc_buffer_poolfailed inTableFill:output
I kept the merged
Resources.cpp(which has the table fill) and changed only its 4bindBufferMemorycall sites back tocontext.Function<PFN_vkBindBufferMemory>.TableLookupsfailed:output
I restored only
BufferPool.cppandMemoryAccounting.cppfrommain. The test passed (see the non-blocking note below).I then restored the merged files, rebuilt, and confirmed the worktree is clean and the test passes.
Findings
Blocking
None.
Non-blocking
MemoryAccountingandBufferPool-constructor conversions have no test coverage.core/libs/prx/libSceAgcDriver/Graphics/src/MemoryAccounting.cpp:54and:74and theBufferPoolconstructor (core/libs/prx/libSceAgcDriver/Graphics/src/BufferPool.cpp:43) can be reverted without failingTableLookups(control 3). The pool's own allocations go through the members it captured once in its constructor, so the cycle never reachesMemoryAccounting::Allocate/Free(context, …)through the table. This doesn't affect correctness:TableFillchecks that the members are filled from the right names. But the description reads as ifTableLookupscovers these sites. I suggest narrowing that wording, or extending the cycle to cover a non-pooled allocate/free.IsDeferredMemoryFreestill sees the same pointer after the change. I checked this becauseMemoryAccounting::Freecompares the free function againstdeferredFreeMemory(core/libs/prx/libSceAgcDriver/Graphics/src/MemoryAccounting.cpp:60).VulkanDeviceinstallsDeferDestructionToIdle's resolver (core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp:2312) beforeFillDeviceFunctionsruns (:2372). The table therefore holds the same deferringvkFreeMemory/vkDestroyBufferthatFunctionwould return, so the pointer check behaves as onmain. No action needed. I'm noting it because a future reorder of those two lines would break this silently.Depends on: #15440line describes a link-line change, but the current diff no longer touchestests/cmake/agc_pipeline_cache_allocation_tests.cmake. The PR merges and builds onmainwithout #15440, so the dependency now looks like merge order only. Saying so would help the maintainer. The merge-order agreement with #13796 that the author mentioned in the discussion is also not on the current Depends-on line.Not verified