perf(agc): keep the buffer pool's free slots by key and retain 4096 #401

Merged
MichonGoddijn231849 merged 1 commit from upstream-pr/401 into main 2026-10-04 09:56:49 +00:00
MichonGoddijn231849 commented 2026-10-02 18:36:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-02T18:36:07Z.


What

BufferPool::Take scanned every retained slot of its tier for one with the same size, usage and memory properties. That kept the slot bound at 512 per tier.

  • In GTA V's Prologue the in-game builds keep more than 512 small buffers in use. The small tier overflowed with only about 27 of its 64 MiB used. Each draw then evicted and recreated buffers: about 5,900 vkAllocateMemory / vkFreeMemory pairs per second, all on the submission thread.
  • Sampling that thread's instruction pointer put most of its time in the driver's NtGdiDdDDICreateAllocation, DestroyAllocation2 and MapGpuVirtualAddress.
  • Free slots are now kept in lists per (size, usage, properties), oldest first. Take pops the newest slot of its key. Eviction takes the oldest front among the lists, so the least-recently-used order is unchanged.
  • The default bound is 4096 slots per tier, held to a sixth of maxMemoryAllocationCount so the three tiers keep half of it free on drivers with a low limit. APS5_BUFFER_POOL_SLOTS still overrides it. The byte budgets are unchanged.

Tested

Windows 11 Pro, AMD Ryzen 5 7600, NVIDIA GeForce RTX 5080 (driver 32.0.16.1074), 32 GB DDR5-5600, MinGW-w64 GCC 15.2.0.

  • GTA V (PPSA04264), with the rendering fixes still in progress (#373–#377, #394, #395), at the same spot of the Prologue, APS5_PROFILE_DRAW=1:
    • 512 slots (as on main, APS5_BUFFER_POOL_SLOTS=512): 2.2 fps. The small tier missed about 58,700 times per 10 s, and Graphics::Draw took 252 µs per draw packet.
    • This PR (4096 slots): 6 to 7 fps. The small tier missed about 70 times per 10 s, with about 1,900 slots and 60 MiB retained. Graphics::Draw took 67 µs per draw packet.
  • Dreaming Sarah (PPSA02929): the first scene renders as on main.
  • ctest: all tests pass.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none. #290 adds BufferPool::Trim, which walks the free slots; whichever of the two merges second needs that loop adapted to the per-key lists.
  • AI-assisted: yes. Written with Claude (Anthropic) under my direction; I reviewed and tested it.

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4720054285 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/401). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-02T18:36:07Z. --- ### What `BufferPool::Take` scanned every retained slot of its tier for one with the same size, usage and memory properties. That kept the slot bound at 512 per tier. - In GTA V's Prologue the in-game builds keep more than 512 small buffers in use. The small tier overflowed with only about 27 of its 64 MiB used. Each draw then evicted and recreated buffers: about 5,900 `vkAllocateMemory` / `vkFreeMemory` pairs per second, all on the submission thread. - Sampling that thread's instruction pointer put most of its time in the driver's `NtGdiDdDDICreateAllocation`, `DestroyAllocation2` and `MapGpuVirtualAddress`. - Free slots are now kept in lists per (size, usage, properties), oldest first. `Take` pops the newest slot of its key. Eviction takes the oldest front among the lists, so the least-recently-used order is unchanged. - The default bound is 4096 slots per tier, held to a sixth of `maxMemoryAllocationCount` so the three tiers keep half of it free on drivers with a low limit. `APS5_BUFFER_POOL_SLOTS` still overrides it. The byte budgets are unchanged. ### Tested Windows 11 Pro, AMD Ryzen 5 7600, NVIDIA GeForce RTX 5080 (driver 32.0.16.1074), 32 GB DDR5-5600, MinGW-w64 GCC 15.2.0. - GTA V (PPSA04264), with the rendering fixes still in progress (#373–#377, #394, #395), at the same spot of the Prologue, `APS5_PROFILE_DRAW=1`: - 512 slots (as on `main`, `APS5_BUFFER_POOL_SLOTS=512`): 2.2 fps. The small tier missed about 58,700 times per 10 s, and `Graphics::Draw` took 252 µs per draw packet. - This PR (4096 slots): 6 to 7 fps. The small tier missed about 70 times per 10 s, with about 1,900 slots and 60 MiB retained. `Graphics::Draw` took 67 µs per draw packet. - Dreaming Sarah (PPSA02929): the first scene renders as on `main`. - `ctest`: all tests pass. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in TechnicalDebt - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none. #290 adds `BufferPool::Trim`, which walks the free slots; whichever of the two merges second needs that loop adapted to the per-key lists. - [x] AI-assisted: yes. Written with Claude (Anthropic) under my direction; I reviewed and tested it. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!401
No description provided.