GPU: reclaim idle texture staging, command list scratch, and shadow arena buffers #2972
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2972
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@0xKaji on GitHub · 2026-11-26 01:50 UTC · original
0xKaji:perf/reclaim-gpu-buffers→main· +188 −30 · 3 files · 6 commits · openSummary
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).@pickles976 on GitHub · 2026-11-26 03:25 UTC · original
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 #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.
@Marvisak on GitHub · 2026-11-26 05:48 UTC · original
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
GPU: reclaim idle staging, scratch, and arena buffers and evict on system memory pressureto GPU: reclaim idle texture staging, command list scratch, and shadow arena buffers7e769e07e2to5c0ad8e109@fuzeofficlal on GitHub · 2026-11-26 02:01 UTC · original · reviewed
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 ok@kotekompotek on GitHub · 2026-11-26 02:29 UTC · original · reviewed
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.
@0xKaji on GitHub · 2026-11-26 12:21 UTC · original
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.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.