GPU: reclaim idle texture staging, command list scratch, and shadow arena buffers #2970
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2972"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by 0xKaji on 2026-11-26T01:50:02Z.
Summary
texture.rs): trimChunks::allafter an idle window of 64 submissions down to the recent peak (with a 2-chunk / 64 MiB warm floor) instead of retaining up to 16 chunks (512 MiB) permanently.shadow.rs): keySlice::chunkby stable chunk ID and release empty chunks past 1 standard spare (and any empty oversized chunk) inArena::give_back.host.rs): trim idleHostList::scratchchunks after 64 resets (keeping 1 spare) and shrink oversized clearedstates/twins/notes/targetscollections (capacity > 256→shrink_to(64)).resource.rs): triggerevict_unusedwhen GPU shared system memory (system_budget) exceedsBUDGET_HIGH, not only when local VRAM does.Testing
cargo xwin check --tests --profile diag -p victory-gpu --features diagnostics --target x86_64-pc-windows-msvc --lockedpasses cleanly.staging_chunks_trim_after_idle_window,scratch_chunks_trim_after_idle_window,eviction_over_triggers_on_system_memory_pressure,arena_runs_are_aligned_to_their_elements_and_join_again) pass under Wine (RTX 3060).Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T02:01:12Z.
Review: COMMENTED
Reviewed and verified against
main(63bcca43) on Windows 11 (RTX 5090 + WARP,VICTORY_D3D12_DEBUG=1) — clean and ready to merge:ArenaChunk::idprevents slice index invalidation whenArena::give_backretains active chunks; cloned COMID3D12Resourcehandles held byShadowand retiredHostHeap::keptentries keep GPU-referenced buffers alive until completion;texture::recycleruns underHost::executepost-wait andHostList::resetruns only on idle lists.DXGI_MEMORY_SEGMENT_GROUP_NON_LOCALfromhost::video_memory()to evict idle host textures LRU when shared GPU memory exceeds the 90% budget threshold.7e769e07resolves the twoclippy::manual-clampwarnings inhost.rs:988andtexture.rs:208.Local verification:
victory-gpu(host::tests::,resource::tests::,shadow::,texture::,watch::,draw::tests::withVICTORY_D3D12_DEBUG=1, tested at6451ee8cplus verified 2-lineclampcommit7e769e07): 98/98 passed on both RTX 5090 and WARP (excluding the pre-existing NVIDIA 1M view-heap baseline test), including the 3 new reclamation tests and expandedarena_runs_are_aligned_to_their_elements_and_join_againcargo xtask policy: 191 files okImported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-26T02:29:50Z.
Review: COMMENTED
Verified: the peak-window trimming is right on both allocators — excess above the cap still trims immediately, and the window-end keep is clamped to [spare, cap] of the observed peak. The Slice chunk->id change is a latent correctness fix too: give_back after retain's index shift would have freed into the wrong chunk. Arena retain drops oversized empties outright and keeps one spare standard chunk. eviction_over's max() of local/system excess correctly extends pressure detection to shared memory.
Imported from Marvisak/VIctory. Originally posted by pickles976 on 2026-11-26T03:25:53Z.
Wine 11.0 / vkd3d-proton 3.2.0, physical RTX 4060 Laptop GPU (8 GiB), 16 GiB system RAM: I verified exact head
7e769e07e274with four focused Windows-target tests: the two idle chunk trim fixtures 2/2, shared-system-memory eviction policy 1/1, and shadow arena coalescing/release 1/1 with a required real NVIDIA host. All passed. The diagnostic logs are local (verify-pr2972-updated-wine-{chunks-trim,memory-eviction,rtx4060-arena}.log); the temporary required-host assertion was restored.A separately guarded title load on that same head reached picker/loading art, not a controllable world. In the extended scheduled 130 s run, the external guard stopped at t=86.25 s when global
MemAvailablefell from 13,297 to 1,979 MiB, below the 2,048 MiB safety floor; scope used 7,450 MiB, anon 2,787 MiB, GPU peaked at 3,113 MiB, exit 137 from the guard. The earlier 95 s run started with different available RAM and timed out while above its floor, so these trials do not establish improvement or regression versus base. No title crash or world-frame failure is attributed to this PR.This PR is useful bounded reclamation, but it is not an application-wide host RAM cap: the texture eviction runs once per presented frame and idle trimming after 64 submissions may not fire during a stalled load. A distinct opt-in cooperative loading/admission budget with explicit no-progress handling is requested in https://github.com/Marvisak/VIctory/issues/3012. If adding allocation-time pressure handling here, please preserve pinned/live data and never wait while holding host queue locks. No safety guard was disabled and no gameplay/FPS claim is made.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T05:48:02Z.
Automated triage for the maintainers.
Needs work. The idle trimming looks sound.
texture::recycle/trim_targetandHostList::reset/trim_scratchrun when nothing is executing. Arena chunks dropped inshadow::Arena::give_backstay alive as long as any slice holds itsbufferclone, and slices now use stable chunk ids, so removing a chunk no longer shifts indices. The part that needs changing isresource::evict_unused/eviction_over:host::video_memory()'s second entry isDXGI_MEMORY_SEGMENT_GROUP_NON_LOCAL. On a discrete GPU, the host texturesevictgives up live in local video memory, so evicting them hardly lowers non-local usage. Non-local usage is mostly upload heaps and shadow copies. Once it is overBUDGET_HIGH, every presented frame would askchoosefor the sameoverbytes and evict textures again, which can turn into make/evict churn without relieving the pressure. Please either limit this to adapters where it helps (UMA, where local is the system memory anyway) or show measurements (non-local usage and textures evicted per frame) from a run where it fires.eviction_over_triggers_on_system_memory_pressureonly checks the arithmetic. It can't show that eviction reduces the memory being measured.give_backnow walks every chunk withretainon each return, and these come by the hundred per frame. Cheap for a few chunks, but checking only the chunk just given back would do.The tester's run above didn't establish a memory improvement or a regression. If the eviction-trigger change were split out, the chunk and collection trimming could be judged on its own. Before/after RSS at the same point would help it too.
CI: passing.
Generated by Claude Code
[PR #2972] GPU: reclaim idle staging, scratch, and arena buffers and evict on system memory pressureto [PR #2972] GPU: reclaim idle texture staging, command list scratch, and shadow arena buffersImported from Marvisak/VIctory. Originally posted by 0xKaji on 2026-11-26T12:21:24Z.
Addressed all triage points:
resource::evict_unused/eviction_overchange from this PR as suggested, so it is strictly focused on bounded idle buffer/collection reclamation (zero risk of discrete-GPU texture make/evict churn).shadow::Arena::give_back: now only checks for release when the returned chunk itself becomes empty (free.get(&0) == Some(&size)), avoiding walking/retaining all chunks on every return.mainvs combined branch): menu FPS remained 30.0 fps (33.3 ms/frame);system memorydropped 1,427 -> 1,407 MB in menus and 6,622 -> 6,466 MB working set at world load start.Imported from Marvisak/VIctory. Originally posted by Desamodeth on 2026-11-26T20:39:05Z.
Review: COMMENTED
The
statesshrink inHostList::resetreclaims memory after a burst, but also shrinks a map that the next recording immediately refills. On5c0ad8e1the steady-list threshold showed up between 224 and 225 distinct textures.Same Windows x64 process, Ryzen 7 9800X3D, Rust 1.98.1 MSVC release. One synthetic list, 192 record/reset cycles, one state insertion per texture and a second transition for every fourth texture. Median µs per complete cycle; allocation counts cover all 192 cycles, including the initial fill.
63bcca43The memory win is real: after one 4,096-texture recording followed by 16-texture recordings, main kept 204,816 bytes of map storage. The PR kept 3,216 bytes immediately. The local variant reached the same 3,216 bytes on reset 128. It tracks the maximum map length over each 64-reset window; after clearing, it calls
shrink_to(peak.max(64))only at the window boundary when capacity is over 256 and the peak used at most half of it. The first window still included the spike. A list that stops resetting will retain the larger map under that policy.I'd consider using recent occupancy for this map if busy lists commonly pass the threshold. Reversing the timing order reproduced the 225-texture result (6.20 / 8.36 / 6.19 µs). This isolates the source
trackand state-map reset bodies with synthetic Arc-backed host textures; first/last state and release of the list's references were checked. Allocator-requested map bytes were counted in a separate build. No GPU, title run or process RSS measurement. Coordination. AI-assisted with Codex.Imported from Marvisak/VIctory. Originally posted by 0xKaji on 2026-11-27T11:21:10Z.
Thanks @Desamodeth for the benchmark! Updated
HostList::statesinHostList::resetto track the peak occupancy over a 64-reset window and onlyshrink_to(peak.max(64))at the window boundary whencapacity > 256andpeak.max(64) * 2 <= capacity, keeping steady busy lists allocation-free while still reclaiming spike capacity. Addedstate_map_trims_after_idle_windowto cover both cases.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.