Repository navigation
Conversation
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 the heap is. Near the budget VK_EXT_memory_budget reports, that retained memory pushes the process over it, and past the budget an allocation can still succeed while the OS pages device memory, so the out-of-memory trim in AllocateMemory comes late or never. VramBudget reads the budget and usage of the largest device-local heap at most every 100 ms; its target is the budget less a headroom (a sixteenth of the heap, 256 MiB to 1 GiB), never below a quarter of the heap or 1 GiB, whichever is smaller. While the usage, less what the pool released since the read, is over the target, Put destroys a released device-tier buffer instead of retaining it, together with the least recently used retained device buffers until the excess is covered. Without the extension, on an integrated GPU (Context::integratedGpu) or with APS5_NO_VRAM_BUDGET=1 the pool behaves as before. APS5_VRAM_BUDGET_MIB caps the budget and APS5_VRAM_HEADROOM_MIB sets the headroom. A [vram] line is printed at the first read and, with APS5_PROFILE_DRAW, every 10 s after the [bufferpool] line. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VFVE5WbaUJ2vyj8NAW44CS
…eadroom Over the VRAM target the device tier destroyed every released buffer, so a title whose working set sits just above the target re-allocated the buffers it asks for again within milliseconds (40k-210k drops per 120 s walk in Minecraft Dungeons II on an 8 GB card), and the headroom that decided where that started had a different best value per title. The target is now the reported budget itself, and the device tier keeps released buffers up to what it handed out (hits and misses) in the last second, in eight buckets of 125 ms, at most a sixteenth of the heap (a load hands out gigabytes per second); only what is beyond that floor is destroyed. A title that does not churn has a small floor and gives back everything else. APS5_VRAM_HEADROOM_MIB and VramBudget::HeadroomFor are gone; APS5_VRAM_BUDGET_MIB still caps the budget. The [vram] line also reports the floor, the device-tier allocations made while the pool was dropping (the churn the drops cause), and the device-local allocations DeviceMemoryType placed in host memory, now counted in HostPlacements() instead of function-local statics. The budget tests now take their buffers under the budget and raise the usage before releasing them: on current main DeviceMemoryType places a device buffer in host memory once the heap is over its budget, so a buffer allocated there never reaches the device pool. A Put whose buffer lands in another tier no longer counts as device memory released: since small device-local buffers go to the small tier, Put read the excess for them too and reported whatever the small tier evicted (possibly host-visible buffers) through VramBudget::Released, so Excess() read low until the next budget query.
…et read Main's pool now keeps released image memory in the device tier and reads the heap budget itself (at most every 100 ms) to drop that image memory over the budget, frees idle device buffers under storage cache pressure, and trims the pool before an allocation retry. The VRAM budget had its own reader and only knew about the buffers its own Put destroyed. VramBudget no longer queries the driver: the pool's heap budget read feeds it, so a device buffer Put and an image Put within 100 ms share one vkGetPhysicalDeviceMemoryProperties2 call, and the read happens under the pool mutex like the image path's. Every device-tier free the pool makes between two reads is counted as released, so Excess() stays right until the next read: Put's evictions, the image path's drops and evictions, ReclaimIdleDevice and trim(). The bytes are counted under the pool mutex before the memory is destroyed, so a read that lands in between can only see the memory still in use, never count it twice. Over the target, Put gives back retained image memory before the buffers the demand floor keeps (main already drops it over the reported budget, and image takes are not demand), and the floor compares against the buffers alone. The refused-allocation host fallback in AllocateMemory now counts in HostPlacements() too, so the [vram] line reports both placement paths. APS5_NO_VRAM_BUDGET and APS5_VRAM_BUDGET_MIB are documented in ENVIRONMENT.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NWqixRjxAxzP2dBDkLsjZ6
|
This pull request is labeled |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_budgetreports, 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 orDeviceMemoryTypeplaces it in host memory, so the out-of-memory trim inBufferPool::AllocateMemorycomes 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 onevkGetPhysicalDeviceMemoryProperties2call.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 aPutthat lands in another tier is not counted as device memory released.Putevictions, image memory dropped or evicted inPutImageMemory,ReclaimIdleDeviceunder storage cache pressure, andtrim()before an allocation retry. The bytes are counted under the pool mutex before the memory is destroyed, soExcess()never counts a free twice.Context::integratedGpu, set from the device type: there the device-local heap is a carve-out the driver spills into system memory) and withAPS5_NO_VRAM_BUDGET=1.APS5_VRAM_BUDGET_MIBcaps the budget, which lets a large card behave like a smaller one. Both are indocs/dev/ENVIRONMENT.md.[vram]line is printed once, at the first read: the heap, its budget and usage. WithAPS5_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 byDeviceMemoryTypeand by the refused-allocation fallback inAllocateMemory(counted inHostPlacements()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_budgetreports. 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 oversizedAPS5_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 andagc_driver_pooled_buffer_rangepass;python tools/check_conventions.py --base origin/mainpasses.agc_buffer_poolbudget tests (mock device, no GPU needed):Putthat evicts from the small tier leavesExcess()unchanged;Puttrims the oldest retained buffers;ReclaimIdleDevicelowerExcess()by their size;Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
https://claude.ai/code/session_01VFVE5WbaUJ2vyj8NAW44CS