perf(agc): stop pooling released device buffers over the memory budget #4472

Open
solbjorg1245 wants to merge 4 commits from upstream-pr/4472 into main
solbjorg1245 commented 2026-10-12 12:52:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by solbjorg1245 on 2026-10-12T12:52:50Z.


What

The buffer pool's device tier keeps released device-local buffers up to an eighth of the largest device-local heap (at least 512 MiB), however full that heap is. Near the budget that VK_EXT_memory_budget reports, this retained memory is what pushes the process over it. Past the budget an allocation can still succeed while the OS starts paging device memory or DeviceMemoryType places it in host memory, so the out-of-memory trim in BufferPool::AllocateMemory comes late or not at all.

  • VramBudget (new, Graphics/src/VramBudget.cpp) holds the policy for the largest device-local heap: the target is the reported budget itself (never below a quarter of the heap or 1 GiB, whichever is smaller). It does not query the driver itself. The pool's existing heap budget read (heapOverBudget, at most every 100 ms, the one the image memory path already uses) feeds it, so buffer and image releases share one vkGetPhysicalDeviceMemoryProperties2 call.
  • BufferPool::Put: while the reported usage, minus what the pool freed from the device tier since that read, is over the target, the pool first gives back retained image memory (the image path already frees it over the reported budget, and image takes are not demand). Then the device tier keeps released buffers only up to a demand floor: what it handed out (hits and misses) in the last second, in eight 125 ms buckets, capped at a sixteenth of the heap. Anything beyond the floor is destroyed, least recently used first. A title that doesn't churn has a small floor and gives back everything else; one whose working set sits just over the budget keeps what it is about to ask for again instead of re-allocating it every frame. Host tiers, the small tier and slabs are unchanged, and a Put that lands in another tier is not counted as device memory released.
  • Every device-tier free the pool makes counts as released until the next read: Put evictions, image memory dropped or evicted in PutImageMemory, ReclaimIdleDevice under storage cache pressure, and trim() before an allocation retry. The bytes are counted under the pool mutex before the memory is destroyed, so Excess() never counts a free twice.
  • The pool behaves exactly as before in three cases: without the extension, on an integrated GPU (Context::integratedGpu, set from the device type: there the device-local heap is a carve-out the driver spills into system memory) and with APS5_NO_VRAM_BUDGET=1. APS5_VRAM_BUDGET_MIB caps the budget, which lets a large card behave like a smaller one. Both are in docs/dev/ENVIRONMENT.md.
  • A [vram] line is printed once, at the first read: the heap, its budget and usage. With APS5_PROFILE_DRAW, another [vram] line follows the [bufferpool] line every 10 s with the budget, usage, target, floor, the released device allocations not kept (count and MiB), the device allocations made while the pool was dropping (the churn) and the allocations placed in host memory, both by DeviceMemoryType and by the refused-allocation fallback in AllocateMemory (counted in HostPlacements() instead of two function-local statics).

When it matters. The pool only drops buffers once the device-local heap is over the budget VK_EXT_memory_budget reports. At default settings Minecraft Dungeons II on an 8 GB card settles below it, and nothing changes. It matters for a heap that is already full: a bigger title, a forced or oversized APS5_TEXTURE_CACHE_MIB, or other processes using VRAM. There, without this PR, the pool's retained buffers push new device allocations into host memory.

The crash it prevents (@AlxcBTW, RTX 5070 Laptop 8 GB, Minecraft Dungeons II world load + walk): with the device-local heap over its budget, the automatic budget evicted a 256 MiB 3D storage texture (1024x1024x256 R8). It was re-created in host memory, and a compute pass over it ran past the 2 s TDR limit (nvlddmkm 153 / LiveKernelEvent 141). Over the earlier rows that stack lost the device in 2 of 11; with this PR, 0 of 5. Logs: to be attached by @AlxcBTW.

Found with Demon's Souls on our fork: on a 16 GiB card the device-local heap reached 15.3 GiB at a level load while about 2 GiB of it was released buffers held for reuse. The demand floor replaces the first version's fixed headroom after @CnRJay's churn review; it is @parl0v's commit, with his lab rows in the thread (RTX 4060 8 GB, forced 3 GiB texture cache: walk 3.94 FPS with the headroom, 5.63 with the 1 s floor). Reclaiming cold cache entries would be a separate follow-up. The change itself has no title check.

Tested

On main 85a4d7f8c: agc_buffer_pool, agc_buffer_pool_small_device_shared, agc_buffer_pool_small_device_no_staging, agc_device_memory_fallback, the sampled and storage cache budget tests and agc_driver_pooled_buffer_range pass; python tools/check_conventions.py --base origin/main passes.

  • agc_buffer_pool budget tests (mock device, no GPU needed):
    • the target is the budget, with the quarter-heap / 1 GiB lower bound;
    • under the target, released device buffers are still kept;
    • over the target, the floor keeps what was taken in the last second and gives everything back once the window has passed;
    • over the target with no recent demand, released buffers are destroyed and the next request allocates;
    • a small device-tiered Put that evicts from the small tier leaves Excess() unchanged;
    • when usage rises after a fresh read, Put trims the oldest retained buffers;
    • an integrated GPU keeps its pool and the budget stays disabled;
    • a buffer release and an image release within 100 ms make one budget query;
    • image memory freed over the budget and buffers freed by ReclaimIdleDevice lower Excess() by their size;
    • over the target, retained image memory goes before the buffers the floor keeps.
  • Main's image pool, idle reclaim, attachment reclaim and host placement tests run unchanged.
  • Not yet run in a title on current main.

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 (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
  • AI-assisted: yes

🤖 Generated with Claude Code

https://claude.ai/code/session_01VFVE5WbaUJ2vyj8NAW44CS

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4829684134 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4472). Originally posted by [solbjorg1245](https://github.com/solbjorg1245) on 2026-10-12T12:52:50Z. --- ### What The buffer pool's device tier keeps released device-local buffers up to an eighth of the largest device-local heap (at least 512 MiB), however full that heap is. Near the budget that `VK_EXT_memory_budget` reports, this retained memory is what pushes the process over it. Past the budget an allocation can still succeed while the OS starts paging device memory or `DeviceMemoryType` places it in host memory, so the out-of-memory trim in `BufferPool::AllocateMemory` comes late or not at all. - `VramBudget` (new, `Graphics/src/VramBudget.cpp`) holds the policy for the largest device-local heap: the target is the reported budget itself (never below a quarter of the heap or 1 GiB, whichever is smaller). It does not query the driver itself. The pool's existing heap budget read (`heapOverBudget`, at most every 100 ms, the one the image memory path already uses) feeds it, so buffer and image releases share one `vkGetPhysicalDeviceMemoryProperties2` call. - `BufferPool::Put`: while the reported usage, minus what the pool freed from the device tier since that read, is over the target, the pool first gives back retained image memory (the image path already frees it over the reported budget, and image takes are not demand). Then the device tier keeps released buffers only up to a demand floor: what it handed out (hits and misses) in the last second, in eight 125 ms buckets, capped at a sixteenth of the heap. Anything beyond the floor is destroyed, least recently used first. A title that doesn't churn has a small floor and gives back everything else; one whose working set sits just over the budget keeps what it is about to ask for again instead of re-allocating it every frame. Host tiers, the small tier and slabs are unchanged, and a `Put` that lands in another tier is not counted as device memory released. - Every device-tier free the pool makes counts as released until the next read: `Put` evictions, image memory dropped or evicted in `PutImageMemory`, `ReclaimIdleDevice` under storage cache pressure, and `trim()` before an allocation retry. The bytes are counted under the pool mutex before the memory is destroyed, so `Excess()` never counts a free twice. - The pool behaves exactly as before in three cases: without the extension, on an integrated GPU (`Context::integratedGpu`, set from the device type: there the device-local heap is a carve-out the driver spills into system memory) and with `APS5_NO_VRAM_BUDGET=1`. `APS5_VRAM_BUDGET_MIB` caps the budget, which lets a large card behave like a smaller one. Both are in `docs/dev/ENVIRONMENT.md`. - A `[vram]` line is printed once, at the first read: the heap, its budget and usage. With `APS5_PROFILE_DRAW`, another `[vram]` line follows the `[bufferpool]` line every 10 s with the budget, usage, target, floor, the released device allocations not kept (count and MiB), the device allocations made while the pool was dropping (the churn) and the allocations placed in host memory, both by `DeviceMemoryType` and by the refused-allocation fallback in `AllocateMemory` (counted in `HostPlacements()` instead of two function-local statics). **When it matters.** The pool only drops buffers once the device-local heap is over the budget `VK_EXT_memory_budget` reports. At default settings Minecraft Dungeons II on an 8 GB card settles below it, and nothing changes. It matters for a heap that is already full: a bigger title, a forced or oversized `APS5_TEXTURE_CACHE_MIB`, or other processes using VRAM. There, without this PR, the pool's retained buffers push new device allocations into host memory. **The crash it prevents** (@AlxcBTW, RTX 5070 Laptop 8 GB, Minecraft Dungeons II world load + walk): with the device-local heap over its budget, the automatic budget evicted a 256 MiB 3D storage texture (1024x1024x256 R8). It was re-created in host memory, and a compute pass over it ran past the 2 s TDR limit (nvlddmkm 153 / LiveKernelEvent 141). Over the earlier rows that stack lost the device in 2 of 11; with this PR, 0 of 5. Logs: to be attached by @AlxcBTW. Found with Demon's Souls on our fork: on a 16 GiB card the device-local heap reached 15.3 GiB at a level load while about 2 GiB of it was released buffers held for reuse. The demand floor replaces the first version's fixed headroom after @CnRJay's churn review; it is @parl0v's commit, with his lab rows in the thread (RTX 4060 8 GB, forced 3 GiB texture cache: walk 3.94 FPS with the headroom, 5.63 with the 1 s floor). Reclaiming cold cache entries would be a separate follow-up. The change itself has no title check. ### Tested On main `85a4d7f8c`: `agc_buffer_pool`, `agc_buffer_pool_small_device_shared`, `agc_buffer_pool_small_device_no_staging`, `agc_device_memory_fallback`, the sampled and storage cache budget tests and `agc_driver_pooled_buffer_range` pass; `python tools/check_conventions.py --base origin/main` passes. - `agc_buffer_pool` budget tests (mock device, no GPU needed): - the target is the budget, with the quarter-heap / 1 GiB lower bound; - under the target, released device buffers are still kept; - over the target, the floor keeps what was taken in the last second and gives everything back once the window has passed; - over the target with no recent demand, released buffers are destroyed and the next request allocates; - a small device-tiered `Put` that evicts from the small tier leaves `Excess()` unchanged; - when usage rises after a fresh read, `Put` trims the oldest retained buffers; - an integrated GPU keeps its pool and the budget stays disabled; - a buffer release and an image release within 100 ms make one budget query; - image memory freed over the budget and buffers freed by `ReclaimIdleDevice` lower `Excess()` by their size; - over the target, retained image memory goes before the buffers the floor keeps. - Main's image pool, idle reclaim, attachment reclaim and host placement tests run unchanged. - Not yet run in a title on current main. ### 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](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01VFVE5WbaUJ2vyj8NAW44CS
oneandonlydean commented 2026-10-13 00:20:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T00:20:34Z.


Is there a before/after for this change alone? The 15.3 GiB figure is one reading from a fork that carries the whole budget, and this hasn't run in a title on main; perf PRs need numbers for the change itself (#218). The [vram] line and presents per 10 s at that level load, with and without APS5_NO_VRAM_BUDGET=1, would do.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6135179171 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4472#issuecomment-6135179171). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-13T00:20:34Z. --- Is there a before/after for this change alone? The 15.3 GiB figure is one reading from a fork that carries the whole budget, and this hasn't run in a title on main; perf PRs need numbers for the change itself (#218). The `[vram]` line and presents per 10 s at that level load, with and without `APS5_NO_VRAM_BUDGET=1`, would do.
solbjorg1245 commented 2026-10-13 03:38:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by solbjorg1245 on 2026-10-13T03:38:22Z.


Thanks, fair point. I could not get a clean before/after of this change alone on main, and I would rather say so than quote the 15.3 GiB figure as if it were one.

What I tried:

  1. Main does not run Demon's Souls on my setup. It aborts at boot because the presenter throws on a DB_RENDER_CONTROL depth resummarize state. With a local-only workaround on top of this PR (skip that draw instead of rejecting it, not part of the PR) the title boots on main, shows the intro logos, then aborts about seven minutes in with compute shader ...: runtime image descriptor is invalid. It never reaches a level load, so there is no level-load reading on main. The [vram] lines up to that point show usage of 4.8 GiB of a 14.9 GiB budget, so the pool trim never engaged.
  2. So the numbers below come from my fork, which carries the whole budget (this PR's pool trim plus cache reclaim and admission checks), and they are not this change alone. APS5_NO_VRAM_BUDGET=1 there turns the whole budget off, not only the pool part. They show what the budget is for, not what this PR contributes by itself.

Setup: Windows 11, RTX 5080 16 GiB (heap 15977 MiB, driver budget about 15.2 GiB), same binary and same save, interleaved on / off / off / on, 330 s settle after the load, APS5_PROFILE_DRAW=1 in all four runs (it prints the [present] and [vram] lines, so frame rates are a little lower than without it, equally in both arms).

run budget peak device-local usage windows over the driver budget [present] per 10 s, steady windows (mean / min / max) FATAL
1 on 13.5 GiB (94.7% of budget) 0 of 47 59.2 / 50 / 63 0
2 off 14.7 GiB (103.4%) 9 of 47 51.2 / 36 / 63 0
3 off 14.2 GiB (100.4%) 5 of 47 54.3 / 40 / 59 0
4 on 13.6 GiB (95.5%) 0 of 47 60.4 / 53 / 64 0

With the budget on the first [vram] line reads: heap 15977 MiB, budget 15209 MiB, target 14210 MiB. With it off, usage went past the budget the driver reports in 5 and 9 of the 10 s windows (allocations still succeeded; past that budget the OS is free to move device memory to system memory). Mean steady presents were 59.8 with the budget and 52.8 without, two runs each, so the spread between runs (36 to 64 inside a window) is about as large as the difference; I would call the frame rate a small gain at best and the memory behaviour the point.

What I can still do: my fork gets past both aborts above, so I can send those fixes as separate PRs first and then post the same two arms on main, or run them on a title that already boots on main. Without a title that loads a level there I cannot give a reading for the pool trim alone.

On #4446: the bot is right that both PRs touch tests/BufferPool.cpp. The conflict is two places where each PR adds lines next to the other's (the mock device fields and the list of calls in main). Keeping both sides resolves it, the source files merge cleanly. Whichever lands second will rebase.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6137662909 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4472#issuecomment-6137662909). Originally posted by [solbjorg1245](https://github.com/solbjorg1245) on 2026-10-13T03:38:22Z. --- Thanks, fair point. I could not get a clean before/after of this change alone on main, and I would rather say so than quote the 15.3 GiB figure as if it were one. What I tried: 1. Main does not run Demon's Souls on my setup. It aborts at boot because the presenter throws on a DB_RENDER_CONTROL depth resummarize state. With a local-only workaround on top of this PR (skip that draw instead of rejecting it, not part of the PR) the title boots on main, shows the intro logos, then aborts about seven minutes in with `compute shader ...: runtime image descriptor is invalid`. It never reaches a level load, so there is no level-load reading on main. The `[vram]` lines up to that point show usage of 4.8 GiB of a 14.9 GiB budget, so the pool trim never engaged. 2. So the numbers below come from my fork, which carries the whole budget (this PR's pool trim plus cache reclaim and admission checks), and they are not this change alone. `APS5_NO_VRAM_BUDGET=1` there turns the whole budget off, not only the pool part. They show what the budget is for, not what this PR contributes by itself. Setup: Windows 11, RTX 5080 16 GiB (heap 15977 MiB, driver budget about 15.2 GiB), same binary and same save, interleaved on / off / off / on, 330 s settle after the load, `APS5_PROFILE_DRAW=1` in all four runs (it prints the `[present]` and `[vram]` lines, so frame rates are a little lower than without it, equally in both arms). | run | budget | peak device-local usage | windows over the driver budget | `[present]` per 10 s, steady windows (mean / min / max) | FATAL | |---|---|---|---|---|---| | 1 | on | 13.5 GiB (94.7% of budget) | 0 of 47 | 59.2 / 50 / 63 | 0 | | 2 | off | 14.7 GiB (103.4%) | 9 of 47 | 51.2 / 36 / 63 | 0 | | 3 | off | 14.2 GiB (100.4%) | 5 of 47 | 54.3 / 40 / 59 | 0 | | 4 | on | 13.6 GiB (95.5%) | 0 of 47 | 60.4 / 53 / 64 | 0 | With the budget on the first `[vram]` line reads: heap 15977 MiB, budget 15209 MiB, target 14210 MiB. With it off, usage went past the budget the driver reports in 5 and 9 of the 10 s windows (allocations still succeeded; past that budget the OS is free to move device memory to system memory). Mean steady presents were 59.8 with the budget and 52.8 without, two runs each, so the spread between runs (36 to 64 inside a window) is about as large as the difference; I would call the frame rate a small gain at best and the memory behaviour the point. What I can still do: my fork gets past both aborts above, so I can send those fixes as separate PRs first and then post the same two arms on main, or run them on a title that already boots on main. Without a title that loads a level there I cannot give a reading for the pool trim alone. On #4446: the bot is right that both PRs touch `tests/BufferPool.cpp`. The conflict is two places where each PR adds lines next to the other's (the mock device fields and the list of calls in `main`). Keeping both sides resolves it, the source files merge cleanly. Whichever lands second will rebase.
oneandonlydean commented 2026-10-13 06:51:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T06:51:57Z.


Thanks for saying so plainly. Send the two boot fixes as their own PRs first; this stays open, and the two arms on main once the title reaches a level load will do.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6140023015 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4472#issuecomment-6140023015). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-13T06:51:57Z. --- Thanks for saying so plainly. Send the two boot fixes as their own PRs first; this stays open, and the two arms on main once the title reaches a level load will do.
solbjorg1245 commented 2026-10-13 09:07:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by solbjorg1245 on 2026-10-13T09:07:56Z.


Update: the two boot aborts I reported are already gone on current main, so there is nothing to send for them. My first try was on this PR's older base, sorry for the noise.

I rebuilt on main (c2565f014) with this PR on top and ran the title again on the RTX 5080 16 GiB. The depth resummarize draw is accepted now (that is #4049, which merged after my first try), and the compute shader abort did not show up in two runs. The title plays the intro, reaches the main menu and starts loading the save.

It then aborts during the load, in a pixel shader recompile: GetImageResource dword 0 is not a valid runtime value, where the image descriptor address comes from a 64-bit pointer loaded out of memory (the case #758 and #757 implement, both open and not merged). So I still cannot give the on/off numbers at a level load on main.

Up to the abort the budget never mattered: device-local usage stayed at about 4.7 GiB of the 14.9 GiB budget, nothing was released over the target, and there were no failures before the shader abort.

I will rerun the two arms (APS5_NO_VRAM_BUDGET unset and =1, interleaved) as soon as a title reaches a level load on main with this PR, and post the table here. The earlier numbers from my fork stay as they were: they carry the whole budget, not only this change.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6142179301 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4472#issuecomment-6142179301). Originally posted by [solbjorg1245](https://github.com/solbjorg1245) on 2026-10-13T09:07:56Z. --- Update: the two boot aborts I reported are already gone on current main, so there is nothing to send for them. My first try was on this PR's older base, sorry for the noise. I rebuilt on main (c2565f014) with this PR on top and ran the title again on the RTX 5080 16 GiB. The depth resummarize draw is accepted now (that is #4049, which merged after my first try), and the compute shader abort did not show up in two runs. The title plays the intro, reaches the main menu and starts loading the save. It then aborts during the load, in a pixel shader recompile: `GetImageResource dword 0 is not a valid runtime value`, where the image descriptor address comes from a 64-bit pointer loaded out of memory (the case #758 and #757 implement, both open and not merged). So I still cannot give the on/off numbers at a level load on main. Up to the abort the budget never mattered: device-local usage stayed at about 4.7 GiB of the 14.9 GiB budget, nothing was released over the target, and there were no failures before the shader abort. I will rerun the two arms (`APS5_NO_VRAM_BUDGET` unset and =1, interleaved) as soon as a title reaches a level load on main with this PR, and post the table here. The earlier numbers from my fork stay as they were: they carry the whole budget, not only this change.
CnRJay commented 2026-10-14 00:54:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-14T00:54:07Z.

Review: COMMENTED


One behaviour to check in the title run requested above: allocation churn near the budget. VK_EXT_memory_budget usage covers the whole process (textures, images, the pipeline cache, other pools), so the pool can be over target for reasons it can't fix. In that state every device-tier Put destroys its buffer, and the next Take of the same size calls vkAllocateMemory again. On Windows/WDDM that allocation can take milliseconds and is a known source of frame-time spikes. A level that sits just over the target would then alternate free and allocate every frame, which is worse than keeping a small pool.

Some ways to bound it:

  • Hysteresis: start dropping at the target, keep dropping until usage is some margin below it, and only then start pooling again.
  • Keep a small floor in the device tier (for example the sizes requested in the last N frames) even when over target.
  • Count the vkAllocateMemory calls that follow a dropped Put within a frame in the [vram] line, so the trace shows whether churn happens.

The rest looks good. The integrated-GPU and missing-extension paths are left alone, and reading the budget at most every 100 ms keeps vkGetPhysicalDeviceMemoryProperties2 (which can be a kernel call) off the per-Put path.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5511817077 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4472#pullrequestreview-5511817077). Originally posted by [CnRJay](https://github.com/CnRJay) on 2026-10-14T00:54:07Z. **Review:** COMMENTED --- One behaviour to check in the title run requested above: **allocation churn near the budget.** `VK_EXT_memory_budget` usage covers the whole process (textures, images, the pipeline cache, other pools), so the pool can be over target for reasons it can't fix. In that state every device-tier `Put` destroys its buffer, and the next `Take` of the same size calls `vkAllocateMemory` again. On Windows/WDDM that allocation can take milliseconds and is a known source of frame-time spikes. A level that sits just over the target would then alternate free and allocate every frame, which is worse than keeping a small pool. Some ways to bound it: - Hysteresis: start dropping at the target, keep dropping until usage is some margin below it, and only then start pooling again. - Keep a small floor in the device tier (for example the sizes requested in the last N frames) even when over target. - Count the `vkAllocateMemory` calls that follow a dropped `Put` within a frame in the `[vram]` line, so the trace shows whether churn happens. The rest looks good. The integrated-GPU and missing-extension paths are left alone, and reading the budget at most every 100 ms keeps `vkGetPhysicalDeviceMemoryProperties2` (which can be a kernel call) off the per-`Put` path.
oneandonlydean commented 2026-10-14 21:33:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T21:33:26Z.


#757 and #758 merged on 10-14, so the GetImageResource dword 0 is not a valid runtime value abort during the save load should be gone on main. Could you rebase and post the on/off numbers at the level load ([vram] line and presents per 10 s, with and without APS5_NO_VRAM_BUDGET=1)?

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6178983806 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4472#issuecomment-6178983806). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-14T21:33:26Z. --- #757 and #758 merged on 10-14, so the `GetImageResource dword 0 is not a valid runtime value` abort during the save load should be gone on main. Could you rebase and post the on/off numbers at the level load (`[vram]` line and presents per 10 s, with and without `APS5_NO_VRAM_BUDGET=1`)?
parl0v commented 2026-10-16 07:53:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by parl0v on 2026-10-16T07:53:15Z.


On/off numbers for this change at a level load, on an 8 GB card: RTX 4060 8 GB, i5-14400F, 16 GB RAM, Windows 10. Minecraft Dungeons II (PPSA16064 01.100.100), the first world load from a save without a character (intro cutscene, then the HUD in "Escape from Squid Coast"), then 120 s of scripted walking. Same libs per table, APS5_TEXTURE_CACHE_MIB=3072, arms alternating, toggled with APS5_NO_VRAM_BUDGET=1. This PR's head 2d90e03e3 merges with current main except tests/BufferPool.cpp (main's side kept; tests not built here). The heap reports a 7189 MiB budget, so the target is 6691 MiB (headroom 497).

main 5d9dcc42d + #6308 + this PR (#6308 is needed for the world load on main):

arm walk FPS (mean of the 10 s windows) placements in host memory (cumulative, last log line) pool retained at the end [vram] at the end
on, round 1 1.79 0 3 MiB usage 6741 MiB, 45314 released device buffers (39326 MiB) not pooled
off, round 1 3.82 8192, 2870 MiB 958 MiB
on, round 2 1.38 2, 256 MiB 5 MiB usage 6846 MiB, 93867 (55170 MiB) not pooled
off, round 2 1.43 2048, 3431 MiB 937 MiB
on, round 3 1.43 65536, 63665 MiB 0 MiB usage 7474 MiB, 52570 (14215 MiB) not pooled
off, round 3 1.82 4096, 4452 MiB 923 MiB

Walking runs at 1.4-1.8 FPS on this base whatever the arm, so these FPS numbers say little. Round 3 "on" is worth a look: the heap stayed above its budget, so new device buffers kept being placed in host memory and released without pooling, 65536 placements and 63.7 GB through host memory in one row.

The same with #5372 and #6490 under it (main + #6308 + #5372 + #6490 + this PR, the stack our gameplay rows use), 11 rows, all reached the HUD and survived the walk:

arm walk FPS placements (cumulative MiB) pool retained not pooled per row
on 3.43 / 3.35 / 3.48 / 4.14 0 / 0 / 4 / 0 0-18 MiB 62k-209k buffers (10-27 GB)
on, APS5_VRAM_HEADROOM_MIB=1 3.81 / 3.82 / 3.83 982 / 928 / 350 136-402 MiB 280-338 buffers (0.2-0.4 GB)
off 4.02 / 3.14 / 3.60 / 4.05 1964 / 4254 / 2038 / 1410 149-458 MiB
  • FPS: no difference I can separate from the row spread (3.1-4.1 across the off rows alone).
  • Placements: with the default headroom the host placements are gone. Without the PR, 1.4-4.3 GB per row land in host memory, almost all of them storage textures (measured with a lab counter in the same scene). On a 16 GB machine heap 1's budget is 7448 MiB and host-pointer imports already hold ~4.7 GB of it, so those placements are what ends a world load with vkAllocateMemory ... memoryType=0 ... initialResult=-2 (2 of 3 first loads on this box this morning, both before this PR was in).
  • Cost: in steady state the reported usage sits 3-155 MiB above the target, so the pool keeps nothing for the whole row and every released device buffer is destroyed (62k-209k per row). With a 1 MiB headroom the pool keeps working and drops only ~300 buffers per row, but placements come back (350-982 MiB). A headroom between the two, or a small floor the pool may keep while over the target, would be the next thing to try.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6210790361 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4472#issuecomment-6210790361). Originally posted by [parl0v](https://github.com/parl0v) on 2026-10-16T07:53:15Z. --- On/off numbers for this change at a level load, on an 8 GB card: RTX 4060 8 GB, i5-14400F, 16 GB RAM, Windows 10. Minecraft Dungeons II (PPSA16064 01.100.100), the first world load from a save without a character (intro cutscene, then the HUD in "Escape from Squid Coast"), then 120 s of scripted walking. Same libs per table, `APS5_TEXTURE_CACHE_MIB=3072`, arms alternating, toggled with `APS5_NO_VRAM_BUDGET=1`. This PR's head 2d90e03e3 merges with current `main` except `tests/BufferPool.cpp` (main's side kept; tests not built here). The heap reports a 7189 MiB budget, so the target is 6691 MiB (headroom 497). **`main` 5d9dcc42d + #6308 + this PR** (#6308 is needed for the world load on `main`): | arm | walk FPS (mean of the 10 s windows) | placements in host memory (cumulative, last log line) | pool retained at the end | `[vram]` at the end | |---|---|---|---|---| | on, round 1 | 1.79 | 0 | 3 MiB | usage 6741 MiB, 45314 released device buffers (39326 MiB) not pooled | | off, round 1 | 3.82 | 8192, 2870 MiB | 958 MiB | | | on, round 2 | 1.38 | 2, 256 MiB | 5 MiB | usage 6846 MiB, 93867 (55170 MiB) not pooled | | off, round 2 | 1.43 | 2048, 3431 MiB | 937 MiB | | | on, round 3 | 1.43 | 65536, 63665 MiB | 0 MiB | usage 7474 MiB, 52570 (14215 MiB) not pooled | | off, round 3 | 1.82 | 4096, 4452 MiB | 923 MiB | | Walking runs at 1.4-1.8 FPS on this base whatever the arm, so these FPS numbers say little. Round 3 "on" is worth a look: the heap stayed above its budget, so new device buffers kept being placed in host memory and released without pooling, 65536 placements and 63.7 GB through host memory in one row. **The same with #5372 and #6490 under it** (`main` + #6308 + #5372 + #6490 + this PR, the stack our gameplay rows use), 11 rows, all reached the HUD and survived the walk: | arm | walk FPS | placements (cumulative MiB) | pool retained | not pooled per row | |---|---|---|---|---| | on | 3.43 / 3.35 / 3.48 / 4.14 | 0 / 0 / 4 / 0 | 0-18 MiB | 62k-209k buffers (10-27 GB) | | on, `APS5_VRAM_HEADROOM_MIB=1` | 3.81 / 3.82 / 3.83 | 982 / 928 / 350 | 136-402 MiB | 280-338 buffers (0.2-0.4 GB) | | off | 4.02 / 3.14 / 3.60 / 4.05 | 1964 / 4254 / 2038 / 1410 | 149-458 MiB | | - FPS: no difference I can separate from the row spread (3.1-4.1 across the off rows alone). - Placements: with the default headroom the host placements are gone. Without the PR, 1.4-4.3 GB per row land in host memory, almost all of them storage textures (measured with a lab counter in the same scene). On a 16 GB machine heap 1's budget is 7448 MiB and host-pointer imports already hold ~4.7 GB of it, so those placements are what ends a world load with `vkAllocateMemory ... memoryType=0 ... initialResult=-2` (2 of 3 first loads on this box this morning, both before this PR was in). - Cost: in steady state the reported usage sits 3-155 MiB above the target, so the pool keeps nothing for the whole row and every released device buffer is destroyed (62k-209k per row). With a 1 MiB headroom the pool keeps working and drops only ~300 buffers per row, but placements come back (350-982 MiB). A headroom between the two, or a small floor the pool may keep while over the target, would be the next thing to try. AI-assisted: yes (Claude Code)
parl0v commented 2026-10-16 08:37:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by parl0v on 2026-10-16T08:37:07Z.


Follow-up on the headroom, same box and scene (RTX 4060 8 GB, main + #6308 + #5372 + #6490 + this PR, Minecraft Dungeons II first world load + 120 s walk). One batch, arms interleaved so the host load is the same for all of them; GPU busy and idle gaps are per frame over the last 12 windows.

arm walk FPS GPU busy idle gaps placements (cumulative) pool retained not pooled per row
APS5_NO_VRAM_BUDGET=1 3.92 / 3.25 171 / 156 ms 90 / 163 ms 2123 / 1862 MiB 598 / 450 MiB
default (headroom 497 MiB) 4.01 / 4.16 93 / 90 ms 168 / 158 ms 0 / 0 24 / 26 MiB 9075 / 39931 buffers (2.5 / 7.4 GB)
APS5_VRAM_HEADROOM_MIB=128 4.58 / 5.23 103 / 85 ms 115 / 103 ms 512 / 640 MiB 52 / 224 MiB 550 / 192 buffers (0.5 / 0.2 GB)

Two earlier rows at 128 MiB gave 5.42 / 5.74 and two at 256 MiB gave 4.97 / 4.53 (a quieter host, so not comparable to the table above). Over the four 128 MiB rows the mean is 5.24 FPS.

How I read it:

  • Without the PR the placed storage textures are sampled over PCIe: GPU busy per frame is ~165 ms instead of ~90 ms.
  • With the default headroom the placements are gone and GPU busy drops to ~90 ms, but the heap's steady state sits just above the 6691 MiB target, so the pool drops every released device buffer and the per-frame idle gaps go up by about the same amount (allocation churn on the CPU side).
  • At 128 MiB the target is 7061 MiB, usage settles at ~7050 MiB, the pool still drops the excess (a few hundred buffers per row), and only the 4-5 large allocations made during the load end up in host memory. It keeps most of both wins: +37 % over off and +20 % over the default headroom in the interleaved batch.

So on an 8 GB card the default headroom (a sixteenth of the heap, at least 256 MiB) looks too wide for this title. Something like a sixty-fourth of the heap clamped to 64-256 MiB (124 MiB here, 250 MiB on 16 GB) would land where these rows are best. I have only this card and this title, so take it as one data point for where the default should sit, not a tuned value.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6211539451 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4472#issuecomment-6211539451). Originally posted by [parl0v](https://github.com/parl0v) on 2026-10-16T08:37:07Z. --- Follow-up on the headroom, same box and scene (RTX 4060 8 GB, `main` + #6308 + #5372 + #6490 + this PR, Minecraft Dungeons II first world load + 120 s walk). One batch, arms interleaved so the host load is the same for all of them; GPU busy and idle gaps are per frame over the last 12 windows. | arm | walk FPS | GPU busy | idle gaps | placements (cumulative) | pool retained | not pooled per row | |---|---|---|---|---|---|---| | `APS5_NO_VRAM_BUDGET=1` | 3.92 / 3.25 | 171 / 156 ms | 90 / 163 ms | 2123 / 1862 MiB | 598 / 450 MiB | | | default (headroom 497 MiB) | 4.01 / 4.16 | 93 / 90 ms | 168 / 158 ms | 0 / 0 | 24 / 26 MiB | 9075 / 39931 buffers (2.5 / 7.4 GB) | | `APS5_VRAM_HEADROOM_MIB=128` | **4.58 / 5.23** | 103 / 85 ms | 115 / 103 ms | 512 / 640 MiB | 52 / 224 MiB | 550 / 192 buffers (0.5 / 0.2 GB) | Two earlier rows at 128 MiB gave 5.42 / 5.74 and two at 256 MiB gave 4.97 / 4.53 (a quieter host, so not comparable to the table above). Over the four 128 MiB rows the mean is 5.24 FPS. How I read it: - Without the PR the placed storage textures are sampled over PCIe: GPU busy per frame is ~165 ms instead of ~90 ms. - With the default headroom the placements are gone and GPU busy drops to ~90 ms, but the heap's steady state sits just above the 6691 MiB target, so the pool drops every released device buffer and the per-frame idle gaps go up by about the same amount (allocation churn on the CPU side). - At 128 MiB the target is 7061 MiB, usage settles at ~7050 MiB, the pool still drops the excess (a few hundred buffers per row), and only the 4-5 large allocations made during the load end up in host memory. It keeps most of both wins: +37 % over off and +20 % over the default headroom in the interleaved batch. So on an 8 GB card the default headroom (a sixteenth of the heap, at least 256 MiB) looks too wide for this title. Something like a sixty-fourth of the heap clamped to 64-256 MiB (124 MiB here, 250 MiB on 16 GB) would land where these rows are best. I have only this card and this title, so take it as one data point for where the default should sit, not a tuned value. AI-assisted: yes (Claude Code)
parl0v commented 2026-10-16 09:57:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by parl0v on 2026-10-16T09:57:36Z.


Last follow-up from me on the headroom question, with two more variants tried on the same box and scene. All walk FPS rows on main + #6308 + #5372 + #6490 + this PR today, grouped by arm (every row reached the HUD and survived the walk; rows of different batches mix host load, the interleaved batches above are the cleaner comparisons):

arm rows walk FPS, mean rows
APS5_NO_VRAM_BUDGET=1 6 3.66 4.02 3.14 3.60 4.05 3.92 3.25
default (headroom 497 MiB) 8 3.70 3.43 3.35 3.48 4.14 4.01 4.16 3.38 3.69
headroom 1 MiB 3 3.82 3.81 3.82 3.83
headroom 64 MiB 6 4.65 4.97 4.76 4.35 4.22 5.31 4.27
headroom 128 MiB 6 4.97 5.42 5.74 4.58 5.23 4.43 4.42
headroom 192 MiB 2 4.01 4.27 3.76 (25k-68k buffers not pooled per row)
default + pool floor 128 MiB (below) 2 5.12 5.66 4.59
default + pool floor 256 MiB 2 4.93 4.28 5.57

What doesn't work: a trigger that starts dropping only near the budget and then drains down to the target. This title's live footprint (6.9-7.1 GB) sits above the 6691 MiB target, so once it starts it never stops, and it churns like the default (147k-182k buffers per row, 2.48 / 3.09 FPS).

What does: letting the device tier keep a small floor of released buffers while over the target, and destroying only what is beyond it. The churn comes from destroying buffers the title asks for again within milliseconds; once the pool is empty, dropping one more saves nothing. With a 128 MiB floor and the default target the pool holds ~120 MiB, drops 2-9k buffers per row instead of 60-210k, and the walk runs at 5.66 / 4.59 FPS against 3.38 / 3.69 for the default in the same batches. The lab patch I measured (env switch only for the A/B):

         auto& tier = tierFor(allocation.bytes, allocation.properties);
+        static const VkDeviceSize floor = [] {
+            const char* value = std::getenv("APS5_LAB_VRAM_FLOOR_MIB");
+            return value != nullptr ? static_cast<VkDeviceSize>(std::strtoull(value, nullptr, 10)) << 20u : VkDeviceSize{0};
+        }();
+        if (excess != 0 && &tier == &deviceTier && tier.retainedBytes + allocation.allocationBytes <= floor) excess = 0;
         if (excess != 0 && &tier == &deviceTier) {
             auto dropped = allocation.allocationBytes;
-            while (tier.slots != 0 && dropped < excess) {
+            while (tier.slots != 0 && dropped < excess && tier.retainedBytes > floor) {

Either a narrower default headroom or a floor like this gets the ~30-40 % over off that the placements cost on this card; the floor doesn't depend on where a title's footprint sits relative to the target. Happy to rerun whichever you pick.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6212964270 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4472#issuecomment-6212964270). Originally posted by [parl0v](https://github.com/parl0v) on 2026-10-16T09:57:36Z. --- Last follow-up from me on the headroom question, with two more variants tried on the same box and scene. All walk FPS rows on `main` + #6308 + #5372 + #6490 + this PR today, grouped by arm (every row reached the HUD and survived the walk; rows of different batches mix host load, the interleaved batches above are the cleaner comparisons): | arm | rows | walk FPS, mean | rows | |---|---|---|---| | `APS5_NO_VRAM_BUDGET=1` | 6 | 3.66 | 4.02 3.14 3.60 4.05 3.92 3.25 | | default (headroom 497 MiB) | 8 | 3.70 | 3.43 3.35 3.48 4.14 4.01 4.16 3.38 3.69 | | headroom 1 MiB | 3 | 3.82 | 3.81 3.82 3.83 | | headroom 64 MiB | 6 | 4.65 | 4.97 4.76 4.35 4.22 5.31 4.27 | | headroom 128 MiB | 6 | 4.97 | 5.42 5.74 4.58 5.23 4.43 4.42 | | headroom 192 MiB | 2 | 4.01 | 4.27 3.76 (25k-68k buffers not pooled per row) | | default + pool floor 128 MiB (below) | 2 | 5.12 | 5.66 4.59 | | default + pool floor 256 MiB | 2 | 4.93 | 4.28 5.57 | What doesn't work: a trigger that starts dropping only near the budget and then drains down to the target. This title's live footprint (6.9-7.1 GB) sits above the 6691 MiB target, so once it starts it never stops, and it churns like the default (147k-182k buffers per row, 2.48 / 3.09 FPS). What does: letting the device tier keep a small floor of released buffers while over the target, and destroying only what is beyond it. The churn comes from destroying buffers the title asks for again within milliseconds; once the pool is empty, dropping one more saves nothing. With a 128 MiB floor and the default target the pool holds ~120 MiB, drops 2-9k buffers per row instead of 60-210k, and the walk runs at 5.66 / 4.59 FPS against 3.38 / 3.69 for the default in the same batches. The lab patch I measured (env switch only for the A/B): ```diff auto& tier = tierFor(allocation.bytes, allocation.properties); + static const VkDeviceSize floor = [] { + const char* value = std::getenv("APS5_LAB_VRAM_FLOOR_MIB"); + return value != nullptr ? static_cast<VkDeviceSize>(std::strtoull(value, nullptr, 10)) << 20u : VkDeviceSize{0}; + }(); + if (excess != 0 && &tier == &deviceTier && tier.retainedBytes + allocation.allocationBytes <= floor) excess = 0; if (excess != 0 && &tier == &deviceTier) { auto dropped = allocation.allocationBytes; - while (tier.slots != 0 && dropped < excess) { + while (tier.slots != 0 && dropped < excess && tier.retainedBytes > floor) { ``` Either a narrower default headroom or a floor like this gets the ~30-40 % over off that the placements cost on this card; the floor doesn't depend on where a title's footprint sits relative to the target. Happy to rerun whichever you pick. AI-assisted: yes (Claude Code)
AlxcBTW commented 2026-10-16 11:26:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-16T11:26:01Z.


A second machine, and the crash this PR prevents there: RTX 5070 Laptop 8 GB (NVIDIA 617.42), Ryzen AI 9 365, 31 GiB RAM, Windows 11. Minecraft Dungeons II (PPSA16064 01.100.100), world load from an in-world save plus a 180 s walk, automatic storage-cache budget, on AC. Base: main 5d9dcc42d + #6308 + #5372 + #6490 + #6631 + #6632 + #6194 (with the budget revision posted there) + this PR without its test hunk, which conflicts with that base; the code applies cleanly. The same libs serve both arms, and APS5_NO_VRAM_BUDGET=1 turns this PR off.

arm rows device losses storage textures placed in host memory, worst row walk FPS, mean
this PR on 5 0 none 6.60
this PR off 5 1 2048 textures, 8290 MiB 6.69

The device loss is a Windows GPU timeout (TDR). The System log has an nvlddmkm 153 entry, or Windows Error Reporting logs a LiveKernelEvent 141 for the same second. In both device losses of the last two days, the automatic budget had evicted a 256 MiB 3D storage texture (1024x1024x256 R8). With the device-local heap over its budget, it was re-created in host memory, and a compute pass over it then ran past the 2 s limit. Across the earlier rows of that stack, the automatic budget lost the device in 2 of 11 rows and the fixed budget in 0 of 45. Five rows per arm is a small sample. The mechanism fits the counts, though: with this PR the released device buffers stop holding the heap, so those textures stay device-local.

Not run: other GPUs on this stack, Linux.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6214464818 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4472#issuecomment-6214464818). Originally posted by [AlxcBTW](https://github.com/AlxcBTW) on 2026-10-16T11:26:01Z. --- A second machine, and the crash this PR prevents there: RTX 5070 Laptop 8 GB (NVIDIA 617.42), Ryzen AI 9 365, 31 GiB RAM, Windows 11. Minecraft Dungeons II (PPSA16064 01.100.100), world load from an in-world save plus a 180 s walk, automatic storage-cache budget, on AC. Base: `main` 5d9dcc42d + #6308 + #5372 + #6490 + #6631 + #6632 + #6194 (with the budget revision posted there) + this PR without its test hunk, which conflicts with that base; the code applies cleanly. The same libs serve both arms, and `APS5_NO_VRAM_BUDGET=1` turns this PR off. | arm | rows | device losses | storage textures placed in host memory, worst row | walk FPS, mean | |---|---|---|---|---| | this PR on | 5 | 0 | none | 6.60 | | this PR off | 5 | 1 | 2048 textures, 8290 MiB | 6.69 | The device loss is a Windows GPU timeout (TDR). The System log has an nvlddmkm 153 entry, or Windows Error Reporting logs a LiveKernelEvent 141 for the same second. In both device losses of the last two days, the automatic budget had evicted a 256 MiB 3D storage texture (1024x1024x256 R8). With the device-local heap over its budget, it was re-created in host memory, and a compute pass over it then ran past the 2 s limit. Across the earlier rows of that stack, the automatic budget lost the device in 2 of 11 rows and the fixed budget in 0 of 45. Five rows per arm is a small sample. The mechanism fits the counts, though: with this PR the released device buffers stop holding the heap, so those textures stay device-local. Not run: other GPUs on this stack, Linux. AI-assisted: yes
parl0v commented 2026-10-16 11:32:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by parl0v on 2026-10-16T11:32:57Z.


A caveat on my numbers above: every row ran with APS5_TEXTURE_CACHE_MIB=3072, a storage cache budget larger than this 8 GB card can hold next to the rest, so the heap sat over its budget and the device-tier pool was what decided where the overflow went. With the cache left on main's automatic budget the same scene settles at ~6670 MiB of the 7189 MiB budget, nothing is placed in host memory, and this PR drops only ~200 buffers per row; on/off rows there are within the spread (4.78 / 4.94 / 5.59 off, 5.02 / 4.79 on in the same batch). So the effect I measured is for a heap that is already over its budget, as with a forced or oversized cache budget or a bigger title, not for this title at its default settings.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6214572028 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4472#issuecomment-6214572028). Originally posted by [parl0v](https://github.com/parl0v) on 2026-10-16T11:32:57Z. --- A caveat on my numbers above: every row ran with `APS5_TEXTURE_CACHE_MIB=3072`, a storage cache budget larger than this 8 GB card can hold next to the rest, so the heap sat over its budget and the device-tier pool was what decided where the overflow went. With the cache left on `main`'s automatic budget the same scene settles at ~6670 MiB of the 7189 MiB budget, nothing is placed in host memory, and this PR drops only ~200 buffers per row; on/off rows there are within the spread (4.78 / 4.94 / 5.59 off, 5.02 / 4.79 on in the same batch). So the effect I measured is for a heap that is already over its budget, as with a forced or oversized cache budget or a bigger title, not for this title at its default settings. AI-assisted: yes (Claude Code)
CnRJay commented 2026-10-16 21:46:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-16T21:46:29Z.


Thanks for the rows, @parl0v and @AlxcBTW. They confirm the churn I raised in the first review: with the default headroom the pool drops 40–210k buffers per row, and the idle gaps grow by about as much as the GPU busy time shrinks. @parl0v's last variant (a pool floor) is the design I'd ask for here, and I'd rather it replace a tuned headroom than sit beside it.

  • A floor beats any headroom value. The measured optimum moves with the title (1 MiB, 64, 128, 192 MiB all behave differently), and the table shows that a headroom that is slightly too high or too low is worse than no PR (192 MiB: 4.01 FPS, 25–68k buffers per row). A floor doesn't depend on where the footprint sits relative to the target. Pooling is only worth dropping when the pool holds more than the title asks for again within a few frames, and a small floor keeps exactly that.
  • Size it from the title's own demand rather than a constant. A fixed 128 MiB is a number from one card and one game. Keeping the buffers requested in the last N frames (my earlier suggestion) scales with the title and stays small on a title that doesn't churn. If a constant is simpler, make it a fraction of the heap with a sane clamp, as DeviceBudget does for the staging pool.
  • Keep the other two numbers visible. Both the churn count (vkAllocateMemory calls after a dropped Put) and the placements need to be on the [vram] line, so the summary lines of any title show which side it is on.
  • The case this protects. @AlxcBTW's device loss is the real argument for the PR: an evicted 256 MiB 3D storage texture was re-created in host memory and a compute pass over it ran past the TDR limit. That should go into the description with the logs, since it's a crash rather than a few FPS. The caveat in @parl0v's last comment (the effect appears only when the heap is already over budget, and not at default cache settings on this title) belongs there too, so reviewers know which configurations it matters for.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6225304932 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4472#issuecomment-6225304932). Originally posted by [CnRJay](https://github.com/CnRJay) on 2026-10-16T21:46:29Z. --- Thanks for the rows, @parl0v and @AlxcBTW. They confirm the churn I raised in the first review: with the default headroom the pool drops 40–210k buffers per row, and the idle gaps grow by about as much as the GPU busy time shrinks. @parl0v's last variant (a pool floor) is the design I'd ask for here, and I'd rather it replace a tuned headroom than sit beside it. - **A floor beats any headroom value.** The measured optimum moves with the title (1 MiB, 64, 128, 192 MiB all behave differently), and the table shows that a headroom that is slightly too high or too low is worse than no PR (192 MiB: 4.01 FPS, 25–68k buffers per row). A floor doesn't depend on where the footprint sits relative to the target. Pooling is only worth dropping when the pool holds more than the title asks for again within a few frames, and a small floor keeps exactly that. - **Size it from the title's own demand rather than a constant.** A fixed 128 MiB is a number from one card and one game. Keeping the buffers requested in the last N frames (my earlier suggestion) scales with the title and stays small on a title that doesn't churn. If a constant is simpler, make it a fraction of the heap with a sane clamp, as `DeviceBudget` does for the staging pool. - **Keep the other two numbers visible.** Both the churn count (`vkAllocateMemory` calls after a dropped `Put`) and the placements need to be on the `[vram]` line, so the summary lines of any title show which side it is on. - **The case this protects.** @AlxcBTW's device loss is the real argument for the PR: an evicted 256 MiB 3D storage texture was re-created in host memory and a compute pass over it ran past the TDR limit. That should go into the description with the logs, since it's a crash rather than a few FPS. The caveat in @parl0v's last comment (the effect appears only when the heap is already over budget, and not at default cache settings on this title) belongs there too, so reviewers know which configurations it matters for.
parl0v commented 2026-10-16 21:47:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by parl0v on 2026-10-16T21:47:51Z.


@CnRJay agreed on all four points. The fixed 128 MiB was only there to find out whether a floor works at all; it shouldn't ship as a constant.

I'll write the floor sized from demand: the device tier keeps what it handed out over the last N presents (a rolling peak of Get bytes), drops only what sits above that while the heap is over its target, and the headroom goes away. The [vram] line gets the churn count (vkAllocateMemory calls that follow a dropped Put) and the host placements next to the drops. Then I'll rerun the same three cases on my RTX 4060 8 GB: the forced 3072 MiB cache, the automatic budget, and the in-world walk.

@solbjorg1245 how do you want it: I can send it as a commit on top of your branch for you to pull in, or open it as a separate PR that depends on this one. Your call; it's your PR.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6225323696 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4472#issuecomment-6225323696). Originally posted by [parl0v](https://github.com/parl0v) on 2026-10-16T21:47:51Z. --- @CnRJay agreed on all four points. The fixed 128 MiB was only there to find out whether a floor works at all; it shouldn't ship as a constant. I'll write the floor sized from demand: the device tier keeps what it handed out over the last N presents (a rolling peak of `Get` bytes), drops only what sits above that while the heap is over its target, and the headroom goes away. The `[vram]` line gets the churn count (`vkAllocateMemory` calls that follow a dropped `Put`) and the host placements next to the drops. Then I'll rerun the same three cases on my RTX 4060 8 GB: the forced 3072 MiB cache, the automatic budget, and the in-world walk. @solbjorg1245 how do you want it: I can send it as a commit on top of your branch for you to pull in, or open it as a separate PR that depends on this one. Your call; it's your PR. AI-assisted: yes (Claude Code)
oneandonlydean commented 2026-10-16 23:02:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-16T23:02:00Z.


I agree with @CnRJay: a floor sized from what the title asked for over the last few presents, replacing the headroom rather than sitting beside it, with the churn count and host placements on the [vram] line. @solbjorg1245, your call whether @parl0v's change comes in as a commit here or as a PR on top. Please also put @AlxcBTW's device loss in the description with its logs, since that's a crash rather than a few FPS, along with the note that the effect only shows once the heap is over budget. The rebase is only tests/BufferPool.cpp, so it can go in with the floor change.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6226300445 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4472#issuecomment-6226300445). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-16T23:02:00Z. --- I agree with @CnRJay: a floor sized from what the title asked for over the last few presents, replacing the headroom rather than sitting beside it, with the churn count and host placements on the `[vram]` line. @solbjorg1245, your call whether @parl0v's change comes in as a commit here or as a PR on top. Please also put @AlxcBTW's device loss in the description with its logs, since that's a crash rather than a few FPS, along with the note that the effect only shows once the heap is over budget. The rebase is only `tests/BufferPool.cpp`, so it can go in with the floor change.
solbjorg1245 commented 2026-10-16 23:42:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by solbjorg1245 on 2026-10-16T23:42:19Z.


@parl0v Do as commit please.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6226764806 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4472#issuecomment-6226764806). Originally posted by [solbjorg1245](https://github.com/solbjorg1245) on 2026-10-16T23:42:19Z. --- @parl0v Do as commit please.
oneandonlydean commented 2026-10-17 00:41:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T00:41:53Z.


A commit here is fine. What is left: the floor replacing the headroom, the churn count and host placements on the [vram] line, and @AlxcBTW's device loss with its logs in the description. The rebase is only tests/BufferPool.cpp.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6227476393 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4472#issuecomment-6227476393). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-17T00:41:53Z. --- A commit here is fine. What is left: the floor replacing the headroom, the churn count and host placements on the `[vram]` line, and @AlxcBTW's device loss with its logs in the description. The rebase is only `tests/BufferPool.cpp`.
parl0v commented 2026-10-17 03:36:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by parl0v on 2026-10-17T03:36:53Z.


@oneandonlydean @solbjorg1245 the commit is on parl0v:perf/vram-floor: this PR's commit rebased onto current main (bfcf02e3a), then b5da959c9 on top.

  • Floor instead of headroom. The target is the reported budget itself. Over it, the device tier keeps released buffers up to what it handed out (hits and misses) in the last second, in eight 125 ms buckets, capped at a sixteenth of the heap; only what is beyond that is destroyed. APS5_VRAM_HEADROOM_MIB and HeadroomFor are gone, and APS5_VRAM_BUDGET_MIB still caps the budget. The cap is there because a world load hands out over 3 GB per second, and an uncapped floor held 3220 MiB in one of my rows.
  • [vram] line: the floor, the device allocations made while the pool was dropping (the churn), and the host placements. Those are DeviceMemoryType's counters, moved out of function-local statics into HostPlacements().
  • Rebase: tests/BufferPool.cpp merges with main's HostPlacement test on the PR's mock. Since main's DeviceMemoryType places a device buffer in host memory once the heap is over its budget, the budget tests now allocate under the budget and raise the usage before releasing. The integrated test checks !Vram().Enabled() instead of "no budget queries", because DeviceMemoryType queries the budget either way. New tests: the floor keeps what was taken in the last second, and it gives everything back once the window has passed. agc_buffer_pool and agc_device_memory_fallback pass, and check_conventions.py passes.

Lab numbers for the window, RTX 4060 8 GB, Minecraft Dungeons II world load + 120 s walk, forced APS5_TEXTURE_CACHE_MIB=3072, on the older base from my earlier rows, one row per arm (so a direction, not a measurement):

device tier over the target walk FPS buffers dropped pool retained
this PR as it was (headroom 497 MiB) 3.94 238,803 0 MiB
fixed 128 MiB floor 4.39 537 82 MiB
demand floor, 1 s window 5.63 447 106 MiB
demand floor, 3 s window 3.39 270 193 MiB (usage over the budget)

Not done: an in-game run of the commit itself. On current main this world load stops at storing storage image results pending over memory outside the write watch without the guest bytes saved before them is not implemented, with this PR on and with APS5_NO_VRAM_BUDGET=1 alike, so I couldn't get walk rows on that base. @AlxcBTW's device-loss logs for the description are his to attach.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6229124935 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4472#issuecomment-6229124935). Originally posted by [parl0v](https://github.com/parl0v) on 2026-10-17T03:36:53Z. --- @oneandonlydean @solbjorg1245 the commit is on [`parl0v:perf/vram-floor`](https://github.com/parl0v/AnyPS5/tree/perf/vram-floor): this PR's commit rebased onto current `main` (bfcf02e3a), then [b5da959c9](https://github.com/parl0v/AnyPS5/commit/b5da959c9dd682141051adafcce1802150d995d6) on top. - **Floor instead of headroom.** The target is the reported budget itself. Over it, the device tier keeps released buffers up to what it handed out (hits and misses) in the last second, in eight 125 ms buckets, capped at a sixteenth of the heap; only what is beyond that is destroyed. `APS5_VRAM_HEADROOM_MIB` and `HeadroomFor` are gone, and `APS5_VRAM_BUDGET_MIB` still caps the budget. The cap is there because a world load hands out over 3 GB per second, and an uncapped floor held 3220 MiB in one of my rows. - **`[vram]` line:** the floor, the device allocations made while the pool was dropping (the churn), and the host placements. Those are `DeviceMemoryType`'s counters, moved out of function-local statics into `HostPlacements()`. - **Rebase:** `tests/BufferPool.cpp` merges with `main`'s `HostPlacement` test on the PR's mock. Since `main`'s `DeviceMemoryType` places a device buffer in host memory once the heap is over its budget, the budget tests now allocate under the budget and raise the usage before releasing. The integrated test checks `!Vram().Enabled()` instead of "no budget queries", because `DeviceMemoryType` queries the budget either way. New tests: the floor keeps what was taken in the last second, and it gives everything back once the window has passed. `agc_buffer_pool` and `agc_device_memory_fallback` pass, and `check_conventions.py` passes. Lab numbers for the window, RTX 4060 8 GB, Minecraft Dungeons II world load + 120 s walk, forced `APS5_TEXTURE_CACHE_MIB=3072`, on the older base from my earlier rows, one row per arm (so a direction, not a measurement): | device tier over the target | walk FPS | buffers dropped | pool retained | |---|---|---|---| | this PR as it was (headroom 497 MiB) | 3.94 | 238,803 | 0 MiB | | fixed 128 MiB floor | 4.39 | 537 | 82 MiB | | **demand floor, 1 s window** | **5.63** | 447 | 106 MiB | | demand floor, 3 s window | 3.39 | 270 | 193 MiB (usage over the budget) | Not done: an in-game run of the commit itself. On current `main` this world load stops at `storing storage image results pending over memory outside the write watch without the guest bytes saved before them is not implemented`, with this PR on and with `APS5_NO_VRAM_BUDGET=1` alike, so I couldn't get walk rows on that base. @AlxcBTW's device-loss logs for the description are his to attach. AI-assisted: yes (Claude Code)
parl0v commented 2026-10-17 17:00:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by parl0v on 2026-10-17T17:00:30Z.


@solbjorg1245 the PR picked up "needs rebase" again. parl0v:perf/vram-floor is now both commits rebased onto current main (66702f1cf). The only conflict was tests/BufferPool.cpp: main added AllocationFailure.hpp and map counters to the mock next to this PR's budget fields, and I kept both sides. agc_buffer_pool, the two new agc_buffer_pool_small_device_* tests from main and agc_device_memory_fallback pass, and so does check_conventions.py. Resetting your branch to 835062895 clears it.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6237176031 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4472#issuecomment-6237176031). Originally posted by [parl0v](https://github.com/parl0v) on 2026-10-17T17:00:30Z. --- @solbjorg1245 the PR picked up "needs rebase" again. [`parl0v:perf/vram-floor`](https://github.com/parl0v/AnyPS5/tree/perf/vram-floor) is now both commits rebased onto current `main` (66702f1cf). The only conflict was `tests/BufferPool.cpp`: `main` added `AllocationFailure.hpp` and map counters to the mock next to this PR's budget fields, and I kept both sides. `agc_buffer_pool`, the two new `agc_buffer_pool_small_device_*` tests from `main` and `agc_device_memory_fallback` pass, and so does `check_conventions.py`. Resetting your branch to 835062895 clears it. AI-assisted: yes (Claude Code)
oneandonlydean commented 2026-10-17 21:40:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T21:40:33Z.


Thanks @parl0v for the rebase on perf/vram-floor (83506289556). Two things before this can go to CI and the gate runs:

  1. Small-tier puts report VRAM they didn't free. Since #7056, tierFor sends device-local buffers smaller than classLimit to the small tier. In BufferPool::Put, excess is read from vram.Excess() for any device-tiered allocation before the tier is chosen. For a small-tier put the drop branch is skipped, but the last line still calls vram.Released(freed) with whatever the small tier evicted (that can be host-visible buffers). Excess() then reads low until the next budget query. Suggested fix: if (&tier != &deviceTier) excess = 0; right after tierFor(...), plus a test: over budget, a small device-tiered Put that evicts from the small tier must leave Excess() unchanged.

  2. Main has moved again. Against current main, Context.hpp and BufferPool.cpp conflict with the texture-cache reclaim change (cacheReclaim, #6174): both sides add one Context member and one constructor initializer at the same spot. Keeping both should be all it needs. (tests/BufferPool.cpp merges cleanly now.)

Could you push the rebased branch with the fix to this PR (or solbjorg1245 can pull it)? Once the head is on the PR, we'll run full CI on it and then the no-harm and constrained gate runs. The description update with AlxcBTW's device-loss logs and the "only matters once the heap is over budget" note is still needed too.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6241584169 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4472#issuecomment-6241584169). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-17T21:40:33Z. --- Thanks @parl0v for the rebase on `perf/vram-floor` (83506289556). Two things before this can go to CI and the gate runs: 1. **Small-tier puts report VRAM they didn't free.** Since #7056, `tierFor` sends device-local buffers smaller than `classLimit` to the small tier. In `BufferPool::Put`, `excess` is read from `vram.Excess()` for any device-tiered allocation before the tier is chosen. For a small-tier put the drop branch is skipped, but the last line still calls `vram.Released(freed)` with whatever the small tier evicted (that can be host-visible buffers). `Excess()` then reads low until the next budget query. Suggested fix: `if (&tier != &deviceTier) excess = 0;` right after `tierFor(...)`, plus a test: over budget, a small device-tiered Put that evicts from the small tier must leave `Excess()` unchanged. 2. **Main has moved again.** Against current main, `Context.hpp` and `BufferPool.cpp` conflict with the texture-cache reclaim change (`cacheReclaim`, #6174): both sides add one `Context` member and one constructor initializer at the same spot. Keeping both should be all it needs. (`tests/BufferPool.cpp` merges cleanly now.) Could you push the rebased branch with the fix to this PR (or solbjorg1245 can pull it)? Once the head is on the PR, we'll run full CI on it and then the no-harm and constrained gate runs. The description update with AlxcBTW's device-loss logs and the "only matters once the heap is over budget" note is still needed too.
parl0v commented 2026-10-18 02:22:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by parl0v on 2026-10-18T02:22:47Z.


@oneandonlydean both done, on parl0v:perf/vram-floor at 2ac92ca90, rebased onto current main (195d0d08a):

  1. Small-tier puts. Put now clears excess right after tierFor when the buffer isn't going to the device tier, so the small tier's evictions never reach vram.Released. New test VramSmallTierPutKeepsExcess: over the budget, 160 released 512 KiB device buffers overflow the small tier, and Excess() must be the same before and after. Without the fix it fails with 336 -> 320 MiB over; with it, it passes.
  2. Rebase. Context.hpp keeps both cacheReclaim and integratedGpu. The BufferPool constructor initializes cacheReclaim(context.cacheReclaim), vram(context) in declaration order. tests/BufferPool.cpp merged cleanly, as you said.

agc_buffer_pool, agc_buffer_pool_small_device_shared, agc_buffer_pool_small_device_no_staging and agc_device_memory_fallback pass, and so does check_conventions.py. I can't push to solbjorg1245's fork, so @solbjorg1245, resetting upstream/vram-budget-1 to 2ac92ca90 puts it on the PR.

For the description, a section that could go in as is:

When it matters. The pool only drops buffers once the device-local heap is over the budget VK_EXT_memory_budget reports. At default settings Minecraft Dungeons II on an 8 GB card settles below it, and nothing changes. It matters for a heap that is already full: a bigger title, a forced or oversized APS5_TEXTURE_CACHE_MIB, or other processes using VRAM. There, without this PR, the pool's retained buffers push new device allocations into host memory.

The crash it prevents (@AlxcBTW, RTX 5070 Laptop 8 GB, Minecraft Dungeons II world load + walk): with the device-local heap over its budget, the automatic budget evicted a 256 MiB 3D storage texture (1024x1024x256 R8). It was re-created in host memory, and a compute pass over it ran past the 2 s TDR limit (nvlddmkm 153 / LiveKernelEvent 141). Over the earlier rows that stack lost the device in 2 of 11; with this PR, 0 of 5.

@AlxcBTW, the logs themselves are yours to attach.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6244682805 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4472#issuecomment-6244682805). Originally posted by [parl0v](https://github.com/parl0v) on 2026-10-18T02:22:47Z. --- @oneandonlydean both done, on [`parl0v:perf/vram-floor`](https://github.com/parl0v/AnyPS5/tree/perf/vram-floor) at 2ac92ca90, rebased onto current `main` (195d0d08a): 1. **Small-tier puts.** `Put` now clears `excess` right after `tierFor` when the buffer isn't going to the device tier, so the small tier's evictions never reach `vram.Released`. New test `VramSmallTierPutKeepsExcess`: over the budget, 160 released 512 KiB device buffers overflow the small tier, and `Excess()` must be the same before and after. Without the fix it fails with `336 -> 320 MiB over`; with it, it passes. 2. **Rebase.** `Context.hpp` keeps both `cacheReclaim` and `integratedGpu`. The `BufferPool` constructor initializes `cacheReclaim(context.cacheReclaim), vram(context)` in declaration order. `tests/BufferPool.cpp` merged cleanly, as you said. `agc_buffer_pool`, `agc_buffer_pool_small_device_shared`, `agc_buffer_pool_small_device_no_staging` and `agc_device_memory_fallback` pass, and so does `check_conventions.py`. I can't push to solbjorg1245's fork, so @solbjorg1245, resetting `upstream/vram-budget-1` to 2ac92ca90 puts it on the PR. For the description, a section that could go in as is: > **When it matters.** The pool only drops buffers once the device-local heap is over the budget `VK_EXT_memory_budget` reports. At default settings Minecraft Dungeons II on an 8 GB card settles below it, and nothing changes. It matters for a heap that is already full: a bigger title, a forced or oversized `APS5_TEXTURE_CACHE_MIB`, or other processes using VRAM. There, without this PR, the pool's retained buffers push new device allocations into host memory. > > **The crash it prevents** (@AlxcBTW, RTX 5070 Laptop 8 GB, Minecraft Dungeons II world load + walk): with the device-local heap over its budget, the automatic budget evicted a 256 MiB 3D storage texture (1024x1024x256 R8). It was re-created in host memory, and a compute pass over it ran past the 2 s TDR limit (nvlddmkm 153 / LiveKernelEvent 141). Over the earlier rows that stack lost the device in 2 of 11; with this PR, 0 of 5. @AlxcBTW, the logs themselves are yours to attach. AI-assisted: yes (Claude Code)
solbjorg1245 commented 2026-10-18 15:54:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by solbjorg1245 on 2026-10-18T15:54:19Z.


Thanks @parl0v for the floor and the rebase, and @oneandonlydean for putting it on the branch. I've updated the description for the floor and added the when-it-matters note and the crash section. @AlxcBTW, could you attach your device-loss logs when you get a chance?

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6251947356 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4472#issuecomment-6251947356). Originally posted by [solbjorg1245](https://github.com/solbjorg1245) on 2026-10-18T15:54:19Z. --- Thanks @parl0v for the floor and the rebase, and @oneandonlydean for putting it on the branch. I've updated the description for the floor and added the when-it-matters note and the crash section. @AlxcBTW, could you attach your device-loss logs when you get a chance?
fdfawef324 commented 2026-10-18 23:15:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fdfawef324 on 2026-10-18T23:15:59Z.


I am updating #6553 after #5987 merged. Its remaining change checks the reported host-heap budget before a proactive host placement; main's actual-refusal fallback, pool trim and texture-cache reclaim routing are retained.

There is a shared DeviceMemoryType/buffer-pool test area with this PR; both branches also already need resolution against newer main. I propose #6553 first, then this PR can move successful-placement counters into HostPlacements while retaining HostMemoryTypeWithRoom, the host-budget diagnostics, and the separate diagnostic for keeping a device-local allocation when no host heap fits.

The guard's standalone and integrated tests do not establish combined behavior with this PR. Please let me know if the opposite landing order is preferable so we can compose and test it explicitly.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6256388659 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4472#issuecomment-6256388659). Originally posted by [fdfawef324](https://github.com/fdfawef324) on 2026-10-18T23:15:59Z. --- I am updating #6553 after #5987 merged. Its remaining change checks the reported host-heap budget before a proactive host placement; main's actual-refusal fallback, pool trim and texture-cache reclaim routing are retained. There is a shared `DeviceMemoryType`/buffer-pool test area with this PR; both branches also already need resolution against newer main. I propose #6553 first, then this PR can move successful-placement counters into `HostPlacements` while retaining `HostMemoryTypeWithRoom`, the host-budget diagnostics, and the separate diagnostic for keeping a device-local allocation when no host heap fits. The guard's standalone and integrated tests do not establish combined behavior with this PR. Please let me know if the opposite landing order is preferable so we can compose and test it explicitly. AI-assisted: yes
solbjorg1245 commented 2026-10-19 15:32:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by solbjorg1245 on 2026-10-19T15:32:20Z.


Thanks, #6553 first works for me. Once it lands I'll rebase this past it and #5987, keep HostMemoryTypeWithRoom and the host-budget diagnostics, and only move the successful-placement counters into HostPlacements.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6270987140 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4472#issuecomment-6270987140). Originally posted by [solbjorg1245](https://github.com/solbjorg1245) on 2026-10-19T15:32:20Z. --- Thanks, #6553 first works for me. Once it lands I'll rebase this past it and #5987, keep `HostMemoryTypeWithRoom` and the host-budget diagnostics, and only move the successful-placement counters into `HostPlacements`.
eliasbruno124-dev commented 2026-10-20 18:06:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by eliasbruno124-dev on 2026-10-20T18:06:21Z.


I found storage-cache churn below the reported heap budget on a 6 GB NVIDIA GPU. This is coordination evidence for a possible follow-up; it is not a test of #4472.

GTA III, PPSA03527/01.003.000, stationary at the first "Give me Liberty" spawn beside the Kuruma, with HUD/radar visible. RTX 3060 Laptop 6 GB, NVIDIA 617.42, i5-11400H, 32 GB RAM, Windows 26300. Both runs use the same complete runtime, eb210d1e1756 = main 1b08a33b121e + #8527. The same initial pipeline cache and private profile were checked by SHA-256 before the countercheck; 726 pipeline recipes replayed on both runs. No source change or forced texture-cache budget was used.

Stationary diagnostic window Default device pool Existing APS5_STAGING_POOL_MIB=128
Window duration 91.5 s 81.3 s
Reported presents/s, median (range of eight intervals) 1.0 (0.9-1.1) 2.75 (1.8-3.1)
Idle device buffers retained, median 534 MiB 101 MiB
Logical cache-eviction write-back, median per storage interval 9,586.6 MiB 0 MiB
Device-pool hits / misses / evictions between first and last pool rows 4,317 / 0 / 0 0 / 0 / 0
Pipeline-cache hits / misses in the window 96,795 / 0 229,243 / 1

The last default-pool budget report before the window ended was 4,471 MiB used against 5,161 MiB reported, with a 512 MiB storage-cache budget. That is a logged snapshot, not continuous heap telemetry. It does not meet this PR's over-budget predicate. An earlier default-pool run also gave 1.0-1.1 presents/s, but its starting cache differed, so the table uses the subsequent matched-cache control.

These are profiled diagnostic intervals with a renderer readback every 30 presents, not clean performance captures. The write-back figures are logical surface traffic, not measured PCIe bandwidth. The bounded trace covered an earlier loading phase and overflowed event storage; it cannot support a gameplay speed claim. Neither setting is playable, and this does not justify shipping a fixed 128 MiB pool: #1147 documents a title that needs a larger pool.

The result suggests investigating reclamation of cold idle device buffers when the storage cache is actively evicting below the heap budget, while preserving recent buffer demand. I have not changed this PR's target or implemented a competing retention policy. Please flag any existing follow-up that owns this case so the work can stay coordinated.

Prepared with AI assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6297728906 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4472#issuecomment-6297728906). Originally posted by [eliasbruno124-dev](https://github.com/eliasbruno124-dev) on 2026-10-20T18:06:21Z. --- I found storage-cache churn below the reported heap budget on a 6 GB NVIDIA GPU. This is coordination evidence for a possible follow-up; it is not a test of #4472. GTA III, PPSA03527/01.003.000, stationary at the first "Give me Liberty" spawn beside the Kuruma, with HUD/radar visible. RTX 3060 Laptop 6 GB, NVIDIA 617.42, i5-11400H, 32 GB RAM, Windows 26300. Both runs use the same complete runtime, `eb210d1e1756` = main `1b08a33b121e` + #8527. The same initial pipeline cache and private profile were checked by SHA-256 before the countercheck; 726 pipeline recipes replayed on both runs. No source change or forced texture-cache budget was used. | Stationary diagnostic window | Default device pool | Existing `APS5_STAGING_POOL_MIB=128` | |---|---:|---:| | Window duration | 91.5 s | 81.3 s | | Reported presents/s, median (range of eight intervals) | 1.0 (0.9-1.1) | 2.75 (1.8-3.1) | | Idle device buffers retained, median | 534 MiB | 101 MiB | | Logical cache-eviction write-back, median per storage interval | 9,586.6 MiB | 0 MiB | | Device-pool hits / misses / evictions between first and last pool rows | 4,317 / 0 / 0 | 0 / 0 / 0 | | Pipeline-cache hits / misses in the window | 96,795 / 0 | 229,243 / 1 | The last default-pool budget report before the window ended was 4,471 MiB used against 5,161 MiB reported, with a 512 MiB storage-cache budget. That is a logged snapshot, not continuous heap telemetry. It does not meet this PR's over-budget predicate. An earlier default-pool run also gave 1.0-1.1 presents/s, but its starting cache differed, so the table uses the subsequent matched-cache control. These are profiled diagnostic intervals with a renderer readback every 30 presents, not clean performance captures. The write-back figures are logical surface traffic, not measured PCIe bandwidth. The bounded trace covered an earlier loading phase and overflowed event storage; it cannot support a gameplay speed claim. Neither setting is playable, and this does not justify shipping a fixed 128 MiB pool: #1147 documents a title that needs a larger pool. The result suggests investigating reclamation of cold idle device buffers when the storage cache is actively evicting below the heap budget, while preserving recent buffer demand. I have not changed this PR's target or implemented a competing retention policy. Please flag any existing follow-up that owns this case so the work can stay coordinated. Prepared with AI assistance.
solbjorg1245 commented 2026-10-20 18:34:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by solbjorg1245 on 2026-10-20T18:34:44Z.


Thanks for the data. Nothing I have open covers that case: #4472 only stops pooling released buffers once the heap is over budget, so reclaiming cold idle buffers while the storage cache evicts below budget would be a separate follow-up, and I'm not working on one. If you take it on I'll rebase this around it.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6298307877 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4472#issuecomment-6298307877). Originally posted by [solbjorg1245](https://github.com/solbjorg1245) on 2026-10-20T18:34:44Z. --- Thanks for the data. Nothing I have open covers that case: #4472 only stops pooling released buffers once the heap is over budget, so reclaiming cold idle buffers while the storage cache evicts below budget would be a separate follow-up, and I'm not working on one. If you take it on I'll rebase this around it.
MarcZX10 commented 2026-11-23 03:09:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T03:09:53Z.

Review: CHANGES_REQUESTED


Reviewed — changes requested

Changes are required before merge: fix how device allocation releases update the budget accounting.

What I ran

  • Reviewed head c58f968028ccef496eb2270918aac49579780d6d against base main using repo_read.py to inspect the prepared diff and source files.
  • No build or tests were run. The description reports tests on a different revision (85a4d7f8c); those results are author supplied.

Results

Check Result Note
Diff and source review passed Changed code and relevant callers read
Build and tests not run No execution performed

Findings

Blocking

  • core/libs/prx/libSceAgcDriver/Graphics/src/BufferPool.cpp:627 increments the released-byte allowance for every evicted device-tier allocation, including the buffer being returned by the current Put. That allocation has not necessarily been freed: on the ordinary retention path it is inserted into tier.free at lines 623–625, while vram.Released(...) still counts it as released. After usage was sampled, this makes Excess() understate real heap use and can cause later Put calls to retain additional buffers over the target. Count only allocations that are actually destroyed; retained allocations must not reduce the reported usage.

Non-blocking

  • No verified non-blocking findings.

Not verified

  • Build and automated tests were not run. The reported results in the PR description refer to revision 85a4d7f8c, not this reviewed head.
  • Title behavior and the reported GPU crash improvement were not independently verified.
  • Read all changed files listed as reviewed in the manifest: VulkanDevice.cpp, BufferPool.hpp, Context.hpp, VramBudget.hpp, BufferPool.cpp, VramBudget.cpp, PostCompile.cmake, tests/BufferPool.cpp, and docs/dev/ENVIRONMENT.md. No changed files were excluded by the manifest.

To get this to a good state

  • Correct the release accounting so only allocations destroyed by eviction are added to VramBudget::Released, then rerun the buffer-pool budget tests on the updated head.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:6016141625 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4472#pullrequestreview-6016141625). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-23T03:09:53Z. **Review:** CHANGES_REQUESTED --- # Reviewed — changes requested Changes are required before merge: fix how device allocation releases update the budget accounting. ## What I ran - Reviewed head `c58f968028ccef496eb2270918aac49579780d6d` against base `main` using `repo_read.py` to inspect the prepared diff and source files. - No build or tests were run. The description reports tests on a different revision (`85a4d7f8c`); those results are author supplied. ## Results | Check | Result | Note | |---|---|---| | Diff and source review | passed | Changed code and relevant callers read | | Build and tests | not run | No execution performed | ## Findings ### Blocking - `core/libs/prx/libSceAgcDriver/Graphics/src/BufferPool.cpp:627` increments the released-byte allowance for every evicted device-tier allocation, including the buffer being returned by the current `Put`. That allocation has not necessarily been freed: on the ordinary retention path it is inserted into `tier.free` at lines 623–625, while `vram.Released(...)` still counts it as released. After usage was sampled, this makes `Excess()` understate real heap use and can cause later `Put` calls to retain additional buffers over the target. Count only allocations that are actually destroyed; retained allocations must not reduce the reported usage. ### Non-blocking - No verified non-blocking findings. ## Not verified - Build and automated tests were not run. The reported results in the PR description refer to revision `85a4d7f8c`, not this reviewed head. - Title behavior and the reported GPU crash improvement were not independently verified. - Read all changed files listed as reviewed in the manifest: `VulkanDevice.cpp`, `BufferPool.hpp`, `Context.hpp`, `VramBudget.hpp`, `BufferPool.cpp`, `VramBudget.cpp`, `PostCompile.cmake`, `tests/BufferPool.cpp`, and `docs/dev/ENVIRONMENT.md`. No changed files were excluded by the manifest. ## To get this to a good state - Correct the release accounting so only allocations destroyed by eviction are added to `VramBudget::Released`, then rerun the buffer-pool budget tests on the updated head.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/4472:upstream-pr/4472'
git switch 'upstream-pr/4472'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/4472'
git switch 'upstream-pr/4472'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/4472'
git switch 'upstream-pr/4472'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/4472'
git switch 'main'
git merge --squash 'upstream-pr/4472'
git switch 'main'
git merge --ff-only 'upstream-pr/4472'
git switch 'main'
git merge 'upstream-pr/4472'
git push origin 'main'
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!4472
No description provided.