perf(agc): pool large host buffers by size class #8888

Merged
milescoviello merged 1 commit from upstream-pr/8888 into main 2026-10-27 23:59:36 +00:00
milescoviello commented 2026-10-21 04:46:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-21T04:46:34Z.


What

BufferPool reuses a large host-visible buffer (1 MiB or more) only for a later request of exactly the same size. Large device-local buffers have used size classes since 28345b0eac, an eighth of their octave; host ones kept exact sizes.

Draw snapshots of guest buffers are large host buffers, and their size changes by a few bytes almost every time. With exact sizes the large tier fills its 512 MiB budget with buffers that later requests never match. It misses and evicts several buffers per frame, and each miss and eviction pays an allocation and an unmap in the driver.

In CoD BO2's (PPSA34502) war-room menu, with #5499 and #8756 applied, the large tier hits 373 to 385 times per 10 s and misses 606 to 835 times. On the draw thread, freeing those buffers takes about 12 % of its samples, allocating them about 10 %, and the driver's map and unmap ioctls about 18 %.

Now large host requests take the same classes as device-local ones:

  • The memory is allocated for the class.
  • The VkBuffer and its mapping keep the requested size; a buffer taken from a larger class gets an exact-size VkBuffer bound over it, as device-local buffers already do.
  • A retained buffer serves any later request in its class.

A host request still takes only its own class, not the larger ones a device-local request may use, so at most an eighth of an octave is wasted. The budget and eviction are unchanged. Capacity no longer depends on the memory properties, so the parameter is gone.

Tested

Ubuntu 24.04 (Linux 6.8), GCC 13.3, NVIDIA RTX 4070 Ti, driver 595.99.02, on main 7ab4b2e561.

Test. AddressAndHostUnchanged in tests/BufferPool.cpp asserted that large host buffers keep exact sizes. It's now AddressAndHostClasses (the device-address half is unchanged) and checks that:

  • a 10 MiB + 4 KiB host buffer gets 11 MiB of memory, while its VkBuffer and mapping (Bytes()) keep the requested size;
  • after it is released, a 10 MiB + 8 KiB host request reuses that memory with no new allocation and gets an exact-size VkBuffer;
  • an 11 MiB + 4 KiB request, in the next class, allocates new memory instead of taking the retained 11 MiB buffer.

Built against main's pool code, the new test fails 3 of 3 at those three checks. With this PR it passes 3 of 3.

Suites.

  • agc_buffer_pool and agc_driver_pooled_buffer_range: 3 of 3.
  • ctest -R '^agc_': 850 of 850.
  • Khronos validation layer 1.4.363, on main and on this branch: the pool, pooled-range, snapshot and kept-bytes tests (agc_buffer_pool, agc_driver_pooled_buffer_range, agc_draw_snapshot_cap, agc_draw_inputs_copied, agc_draw_inputs_in_place, agc_recorder_kept_bytes, agc_copy_input_kept_bytes, agc_depth_copy_kept_bytes, agc_driver_large_tracked_snapshot) pass 9 of 9 on both, with no VUID.

CoD BO2 (PPSA34502), war-room menu. The title needs #5499 to get there. Both builds are #5499 rebased on main eea640a5bf plus #8756, and the second adds this change. Release libs, warm caches, APS5_PROFILE_DRAW=1, two runs each, alternated. The figures are the 10 s intervals in the menu:

without with this PR
presents per 10 s 34 to 38 40 to 43
frame time p50 269 to 299 ms 229 to 257 ms
draw committer per draw 28.5 to 30.9 us 20.8 to 21.7 us
large tier per 10 s ([bufferpool]) 373 to 385 hits, 606 to 835 misses, 613 to 833 evictions 1,160 to 1,230 hits, 0 misses, 0 to 5 evictions
large tier retained 62 to 65 buffers, 507 to 508 MiB 390 to 411 buffers, 488 to 505 MiB

Trace windows of a third pair of runs, 30 s from 175 s in the menu (APS5_TRACE_SECONDS=175:30), digested with tools/trace_digest.py:

without with this PR
presents in 30 s 108 128
frame p50 / p99 279.3 / 340.8 ms 230.2 / 299.8 ms
draw committer busy per frame 92.7 ms (33 %) 41.9 ms (18 %)
GPU busy per present 75.2 ms 72.4 ms

Files:

{"commit":"76c494418f46","dirty":false,"env":{"APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_DIR":".","APS5_TRACE_SECONDS":"175:30","APS5_TRACE_SUMMARY_EVERY":"10"},"gpu":"NVIDIA GeForce RTX 4070 Ti","driver":"NVIDIA 595.99.02","os":"Linux 6.8.0-147-generic","cpu":"13th Gen Intel(R) Core(TM) i7-13700K","cpu_threads":24,"memory_mib":32022,"title_id":"PPSA34502","title":"Call of Duty\u00c2\u00ae: Black Ops II","content_version":"01.010.000","resolution":"1920x1080","window":{"spec":"seconds 175:30","first_present":7496,"ms":30193.059},"presents":108,"frame_ms":{"p50":279.324,"p90":307.971,"p99":340.773,"max":374.218},"gpu_busy_ms_per_present":75.218,"worker_busy_pct":{"queue worker 0x0":71.402},"top_phases_ms_per_frame":{"Driver.Packet":195.022,"Driver.Packet.draw":153.786,"Driver.Draw":152.700,"Graphics.Draw":118.949,"Shader.ResolveAbi":111.792,"Graphics.Draw.draw_and_resource_release":111.210,"Shader.ResolveGraphicsStagesAbi":83.508,"Driver.Draw.shader_compile_and_link":69.977},"trace_dropped":true,"trace_dropped_threads":{"title":{"events_full_after_s":12.932,"events_lost":180421,"totals_full":false},"queue worker 0x0":{"events_full_after_s":7.334,"events_lost":814561,"totals_full":false}},"trace":"aps5-trace-76c494418f46-3.json.gz"}
{"commit":"77df0e16ded1","dirty":false,"env":{"APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_DIR":".","APS5_TRACE_SECONDS":"175:30","APS5_TRACE_SUMMARY_EVERY":"10"},"gpu":"NVIDIA GeForce RTX 4070 Ti","driver":"NVIDIA 595.99.02","os":"Linux 6.8.0-147-generic","cpu":"13th Gen Intel(R) Core(TM) i7-13700K","cpu_threads":24,"memory_mib":32022,"title_id":"PPSA34502","title":"Call of Duty\u00c2\u00ae: Black Ops II","content_version":"01.010.000","resolution":"1920x1080","window":{"spec":"seconds 175:30","first_present":7467,"ms":30113.789},"presents":128,"frame_ms":{"p50":230.232,"p90":259.755,"p99":299.779,"max":311.752},"gpu_busy_ms_per_present":72.398,"worker_busy_pct":{"queue worker 0x0":64.388},"top_phases_ms_per_frame":{"Driver.Packet":150.368,"Shader.ResolveAbi":114.972,"Driver.Packet.draw":111.319,"Driver.Draw":110.250,"Shader.ResolveGraphicsStagesAbi":87.984,"Driver.Draw.shader_compile_and_link":69.502,"Graphics.Draw":69.366,"Graphics.Draw.draw_and_resource_release":62.084},"trace_dropped":true,"trace_dropped_threads":{"title":{"events_full_after_s":10.406,"events_lost":253753,"totals_full":false},"queue worker 0x0":{"events_full_after_s":6.227,"events_lost":1013631,"totals_full":false}},"trace":"aps5-trace-77df0e16ded1-3.json.gz"}

Super Meat Boy 3D (PPSA31162), level 1-1, as a check of a second title. The builds are main 7ab4b2e561 and this PR, four runs alternated. This title's large tier already misses 0 times per 10 s on main, because its large sizes repeat exactly, and that stays 0 with this PR. Its per-draw cost follows the run-to-run modes in #8840 on both builds (211 to 273 us in the slow mode). There's no change I can attribute to this PR.

  • Windows 11 Enterprise 26300, NVIDIA GeForce GT 1030 (driver 582.78), WinLibs GCC 15.2.0 r7 (UCRT), Release: the three agc_buffer_pool* tests pass 3 of 3 on main and 3 of 3 with this change.

Not tested: AMD, Intel, other titles. Host memory use stays inside the same 512 MiB large-tier budget; each retained buffer can be up to an eighth of an octave larger than the request it serves.

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 under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none (BO2 itself needs #5499 to reach the menu)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 4070 Ti, driver 595.99.02, Ubuntu 24.04; NVIDIA GeForce GT 1030, driver 582.78, Windows 11
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4946537421 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8888). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-21T04:46:34Z. --- ### What `BufferPool` reuses a large host-visible buffer (1 MiB or more) only for a later request of exactly the same size. Large device-local buffers have used size classes since 28345b0eac, an eighth of their octave; host ones kept exact sizes. Draw snapshots of guest buffers are large host buffers, and their size changes by a few bytes almost every time. With exact sizes the large tier fills its 512 MiB budget with buffers that later requests never match. It misses and evicts several buffers per frame, and each miss and eviction pays an allocation and an unmap in the driver. In CoD BO2's (PPSA34502) war-room menu, with #5499 and #8756 applied, the large tier hits 373 to 385 times per 10 s and misses 606 to 835 times. On the draw thread, freeing those buffers takes about 12 % of its samples, allocating them about 10 %, and the driver's map and unmap ioctls about 18 %. Now large host requests take the same classes as device-local ones: - The memory is allocated for the class. - The `VkBuffer` and its mapping keep the requested size; a buffer taken from a larger class gets an exact-size `VkBuffer` bound over it, as device-local buffers already do. - A retained buffer serves any later request in its class. A host request still takes only its own class, not the larger ones a device-local request may use, so at most an eighth of an octave is wasted. The budget and eviction are unchanged. `Capacity` no longer depends on the memory properties, so the parameter is gone. ### Tested Ubuntu 24.04 (Linux 6.8), GCC 13.3, NVIDIA RTX 4070 Ti, driver 595.99.02, on `main` 7ab4b2e561. **Test.** `AddressAndHostUnchanged` in `tests/BufferPool.cpp` asserted that large host buffers keep exact sizes. It's now `AddressAndHostClasses` (the device-address half is unchanged) and checks that: - a 10 MiB + 4 KiB host buffer gets 11 MiB of memory, while its `VkBuffer` and mapping (`Bytes()`) keep the requested size; - after it is released, a 10 MiB + 8 KiB host request reuses that memory with no new allocation and gets an exact-size `VkBuffer`; - an 11 MiB + 4 KiB request, in the next class, allocates new memory instead of taking the retained 11 MiB buffer. Built against `main`'s pool code, the new test fails 3 of 3 at those three checks. With this PR it passes 3 of 3. **Suites.** - `agc_buffer_pool` and `agc_driver_pooled_buffer_range`: 3 of 3. - `ctest -R '^agc_'`: 850 of 850. - Khronos validation layer 1.4.363, on `main` and on this branch: the pool, pooled-range, snapshot and kept-bytes tests (`agc_buffer_pool`, `agc_driver_pooled_buffer_range`, `agc_draw_snapshot_cap`, `agc_draw_inputs_copied`, `agc_draw_inputs_in_place`, `agc_recorder_kept_bytes`, `agc_copy_input_kept_bytes`, `agc_depth_copy_kept_bytes`, `agc_driver_large_tracked_snapshot`) pass 9 of 9 on both, with no VUID. **CoD BO2 (PPSA34502), war-room menu.** The title needs #5499 to get there. Both builds are #5499 rebased on `main` eea640a5bf plus #8756, and the second adds this change. Release libs, warm caches, `APS5_PROFILE_DRAW=1`, two runs each, alternated. The figures are the 10 s intervals in the menu: | | without | with this PR | |---|---|---| | presents per 10 s | 34 to 38 | 40 to 43 | | frame time p50 | 269 to 299 ms | 229 to 257 ms | | draw committer per draw | 28.5 to 30.9 us | 20.8 to 21.7 us | | large tier per 10 s (`[bufferpool]`) | 373 to 385 hits, 606 to 835 misses, 613 to 833 evictions | 1,160 to 1,230 hits, 0 misses, 0 to 5 evictions | | large tier retained | 62 to 65 buffers, 507 to 508 MiB | 390 to 411 buffers, 488 to 505 MiB | Trace windows of a third pair of runs, 30 s from 175 s in the menu (`APS5_TRACE_SECONDS=175:30`), digested with `tools/trace_digest.py`: | | without | with this PR | |---|---|---| | presents in 30 s | 108 | 128 | | frame p50 / p99 | 279.3 / 340.8 ms | 230.2 / 299.8 ms | | draw committer busy per frame | 92.7 ms (33 %) | 41.9 ms (18 %) | | GPU busy per present | 75.2 ms | 72.4 ms | Files: - without: [trace](https://github.com/milescoviello/AnyPS5/releases/download/perf-bo2pool-2026-10-20/bo2-8756-aps5-trace-76c494418f46-3.json.gz), [digest](https://github.com/milescoviello/AnyPS5/releases/download/perf-bo2pool-2026-10-20/bo2-8756-digest.txt), [summary file](https://github.com/milescoviello/AnyPS5/releases/download/perf-bo2pool-2026-10-20/bo2-8756-aps5-summary.jsonl) - with this PR: [trace](https://github.com/milescoviello/AnyPS5/releases/download/perf-bo2pool-2026-10-20/bo2-8756-pr8888-aps5-trace-77df0e16ded1-3.json.gz), [digest](https://github.com/milescoviello/AnyPS5/releases/download/perf-bo2pool-2026-10-20/bo2-8756-pr8888-digest.txt), [summary file](https://github.com/milescoviello/AnyPS5/releases/download/perf-bo2pool-2026-10-20/bo2-8756-pr8888-aps5-summary.jsonl) ```json {"commit":"76c494418f46","dirty":false,"env":{"APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_DIR":".","APS5_TRACE_SECONDS":"175:30","APS5_TRACE_SUMMARY_EVERY":"10"},"gpu":"NVIDIA GeForce RTX 4070 Ti","driver":"NVIDIA 595.99.02","os":"Linux 6.8.0-147-generic","cpu":"13th Gen Intel(R) Core(TM) i7-13700K","cpu_threads":24,"memory_mib":32022,"title_id":"PPSA34502","title":"Call of Duty\u00c2\u00ae: Black Ops II","content_version":"01.010.000","resolution":"1920x1080","window":{"spec":"seconds 175:30","first_present":7496,"ms":30193.059},"presents":108,"frame_ms":{"p50":279.324,"p90":307.971,"p99":340.773,"max":374.218},"gpu_busy_ms_per_present":75.218,"worker_busy_pct":{"queue worker 0x0":71.402},"top_phases_ms_per_frame":{"Driver.Packet":195.022,"Driver.Packet.draw":153.786,"Driver.Draw":152.700,"Graphics.Draw":118.949,"Shader.ResolveAbi":111.792,"Graphics.Draw.draw_and_resource_release":111.210,"Shader.ResolveGraphicsStagesAbi":83.508,"Driver.Draw.shader_compile_and_link":69.977},"trace_dropped":true,"trace_dropped_threads":{"title":{"events_full_after_s":12.932,"events_lost":180421,"totals_full":false},"queue worker 0x0":{"events_full_after_s":7.334,"events_lost":814561,"totals_full":false}},"trace":"aps5-trace-76c494418f46-3.json.gz"} {"commit":"77df0e16ded1","dirty":false,"env":{"APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_DIR":".","APS5_TRACE_SECONDS":"175:30","APS5_TRACE_SUMMARY_EVERY":"10"},"gpu":"NVIDIA GeForce RTX 4070 Ti","driver":"NVIDIA 595.99.02","os":"Linux 6.8.0-147-generic","cpu":"13th Gen Intel(R) Core(TM) i7-13700K","cpu_threads":24,"memory_mib":32022,"title_id":"PPSA34502","title":"Call of Duty\u00c2\u00ae: Black Ops II","content_version":"01.010.000","resolution":"1920x1080","window":{"spec":"seconds 175:30","first_present":7467,"ms":30113.789},"presents":128,"frame_ms":{"p50":230.232,"p90":259.755,"p99":299.779,"max":311.752},"gpu_busy_ms_per_present":72.398,"worker_busy_pct":{"queue worker 0x0":64.388},"top_phases_ms_per_frame":{"Driver.Packet":150.368,"Shader.ResolveAbi":114.972,"Driver.Packet.draw":111.319,"Driver.Draw":110.250,"Shader.ResolveGraphicsStagesAbi":87.984,"Driver.Draw.shader_compile_and_link":69.502,"Graphics.Draw":69.366,"Graphics.Draw.draw_and_resource_release":62.084},"trace_dropped":true,"trace_dropped_threads":{"title":{"events_full_after_s":10.406,"events_lost":253753,"totals_full":false},"queue worker 0x0":{"events_full_after_s":6.227,"events_lost":1013631,"totals_full":false}},"trace":"aps5-trace-77df0e16ded1-3.json.gz"} ``` **Super Meat Boy 3D (PPSA31162), level 1-1, as a check of a second title.** The builds are `main` 7ab4b2e561 and this PR, four runs alternated. This title's large tier already misses 0 times per 10 s on `main`, because its large sizes repeat exactly, and that stays 0 with this PR. Its per-draw cost follows the run-to-run modes in #8840 on both builds (211 to 273 us in the slow mode). There's no change I can attribute to this PR. - Windows 11 Enterprise 26300, NVIDIA GeForce GT 1030 (driver 582.78), WinLibs GCC 15.2.0 r7 (UCRT), Release: the three `agc_buffer_pool*` tests pass 3 of 3 on `main` and 3 of 3 with this change. Not tested: AMD, Intel, other titles. Host memory use stays inside the same 512 MiB large-tier budget; each retained buffer can be up to an eighth of an octave larger than the request it serves. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none (BO2 itself needs #5499 to reach the menu) - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: NVIDIA GeForce RTX 4070 Ti, driver 595.99.02, Ubuntu 24.04; NVIDIA GeForce GT 1030, driver 582.78, Windows 11 - [x] AI-assisted: yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-21 04:46:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-21T04:46:46Z.


This pull request is labeled perf, so it needs the summary line of a capture on main and one with the change, from the same title, scene and machine, as the Performance report form asks. Please paste both aps5-summary.jsonl lines, attach the two traces and add the output of tools/trace_digest.py.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6308278454 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8888#issuecomment-6308278454). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-21T04:46:46Z. --- <!-- pr-labels-perf --> This pull request is labeled `perf`, so it needs the summary line of a capture on `main` and one with the change, from the same title, scene and machine, as the Performance report form asks. Please paste both `aps5-summary.jsonl` lines, attach the two traces and add the output of `tools/trace_digest.py`.
milescoviello commented 2026-10-21 05:16:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-21T05:16:01Z.


Windows run (Win11 26H2, WinLibs GCC 15.2 r7, Vulkan SDK 1.4.363, GT 1030), main 7ab4b2e561 vs this branch f24d9ce50c, BUILD_TESTING on, both test targets built from clean:

test main (3 runs) PR (3 runs)
agc_buffer_pool pass pass
agc_driver_pooled_buffer_range pass pass

Both builds succeeded. The size-class test (AddressAndHostClasses) passes on Windows too.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6308640296 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8888#issuecomment-6308640296). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-21T05:16:01Z. --- Windows run (Win11 26H2, WinLibs GCC 15.2 r7, Vulkan SDK 1.4.363, GT 1030), main `7ab4b2e561` vs this branch `f24d9ce50c`, BUILD_TESTING on, both test targets built from clean: | test | main (3 runs) | PR (3 runs) | |---|---|---| | `agc_buffer_pool` | pass | pass | | `agc_driver_pooled_buffer_range` | pass | pass | Both builds succeeded. The size-class test (`AddressAndHostClasses`) passes on Windows too. AI-assisted: yes (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!8888
No description provided.