feat(gpu/resource,shadow,descriptor): dynamic budget-reactive VRAM reclaim & 4K 8 GiB headroom #291
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: launcher
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
run report
security: hold
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs gpu test
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/Androtim--MiniVI!291
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/291/head"
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?
@Androtim on GitHub · 2026-12-01 16:50 UTC · original
Androtim:fix/dynamic-vram-reclaim-and-4k-headroom→main· +525 −146 · 8 files · 1 commits · merged 2026-12-01 19:10 UTCRoot Cause & Architecture Changes
Fixes #149.
Dynamic Budget-Reactive Eviction & Bindless Slot Parking (descriptor/host.rs, descriptor.rs, draw.rs,
esource.rs)
slot_evictby default (VICTORY_SLOT_EVICT=0kill-switch) so eviction starts strictly from live DXGI budget/usage ratios.stamp == 0) and stale tabled (> 240frames idle) title slots during active reclaim viaTextureQueue::evicted_bindlessparking andslot_evicting()gating ontexture_slots_room.block_used < BLOCK_BYTES / 2) first viaevict_coveringso sparse 64 MiB blocks drain cleanly back to DXGI.textures()andHostHeap::made(whichHostHeap::mirror -> placed_texture -> create_at_addressacquires in the reverse order) by staging candidate gathering, descriptor unmake/re-arm, and resource retire in lock-ordered phases in bothlet_go_idleandslot_evict.evict_unmapped_resource_slots) inlet_go_idlewithout pollutingWAITING.8 GiB Target/Buffer Guard & 4K Headroom (shadow.rs, play.rs, erify-world.ps1)
targets_room_keptunder a 92% ceiling incard_room_for/wc_mapped_foronly when DXGIbudget <= 9 GiB, leaving 16+ GiB GPUs at full unthrottled 97% headroom.4k8 GiB headroom tuning (VICTORY_TEXTURE_ROOM_PERCENT=84,VICTORY_SLOT_EVICT_PERCENT=80,VICTORY_SLOT_EVICT_LOW_PERCENT=74,VICTORY_CARD_BUFFERS_MB=512,VICTORY_CARD_ROOM_FOR_TARGETS_MB=2048) only whenlow_vramis active.Verification
Static Checks & Unit Tests
cargo +1.98.1-x86_64-pc-windows-gnu xtask policy: PASS (318 files ok)cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-gpu --locked descriptor::host:: -- --test-threads=1: PASS (64 passed; 0 failed)cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-gpu --locked resource:: -- --test-threads=1: PASS (35 passed; 0 failed)cargo +1.98.1-x86_64-pc-windows-gnu test -p victory --locked: PASS (40 + 2 passed; 0 failed)clippy --workspace --all-targets --locked -- -D warnings(default and--features diagnostics): PASS (0 warnings)objdump -pon plain--releasebinary: standard Windows DLLs only.Paired Plain
--releaseBenchmarks vsorigin/main(27aa2ae4, RTX 4060 Ti 8 GB, Series X Low-VRAM parity)origin/main(27aa2ae4)e394a7df)6834 / 6722 MB)6113 / 6666 MB)room=false/no_room_so_farunmapped mipsmedianfinal_waiting/preparingExtended Diagnostics Check (90s 1440p -> 4K,
--features diagnostics)world_windows=19,max_draws=14,760,crashes=0,failed=0).used_max = 6269 MBvsbudget_min = 6717 MB->over = 0 MBacross the entire 90s run (30,575 copies / 1,251 MB reclaimed including a 516 MB burst sweep).@Androtim on GitHub · 2026-12-01 17:10 UTC · original
Architect & Strict-Gate Review (
e394a7df): markingtriage: needs work.Bringing
1440p -> 4KVRAM down to6,113 / 6,666 MB(over = 0 MB,room_false = 8.3%) and eliminating thetextures()<->HostHeap::madeAB-BA lock cycle are strong progress on#149, but direct visual PNG inspection and 4K/1440p telemetry caught severe regressions that block merge:--features diagnostics(near_black = 32.84%,lit = 19/24):stamp == 0) / active tabled slots is stripping textures/lighting maps still actively sampled in the live scene.copyback, andmapped()regression:--release4K A/B vs27aa2ae4: median FPS dropped8.2 -> 6.6 fps(-19.5%),GPUtime jumped7.2 -> 97.6 ms, andcopybackregressed10.0 -> 13.5 ms(+3.5 ms).mapped()residency stalls exploded to57.62 ms/world_sec(5,997.6 mstotal,19,800calls), whilepool_given_backstayed0despite1,021 MBfree in the pool (blocks are being emptied/thrashed and re-uploaded rather than cleanly reclaimed without touching active slots).final_waitingregression:--release1440p A/B increasedfinal_waiting1,653 -> 2,512(+859) vs27aa2ae4.To Unblock Merge (and
v2026.12.01.01Release)pool_given_back > 0) so late 4K world PNGs render with zero black silhouettes (near_black < 2%,lit = 24/24).--release60s 4K and 1440p A/B vs updatedmain(post-#289) confirmingover = 0 MB, non-regressing 4K FPS /copyback/mapped(), andfinal_waiting <= main, plus wait forminivi-triagereview.@Androtim on GitHub · 2026-12-01 17:45 UTC · original
Root-Cause Audit (
e394a7df)Both 4K regressions and the 1440p
final_waitingregression trace directly to two distinct, provable mechanisms in PR#291:1. Why
diag-vram-reclaim-4k-90sProduces Pitch-Black Silhouettes (near_black = 32.84%)A 4-step causal chain permanently replaces ~30,000 live scene bindless textures with
NULL(0,0,0,0) SRVs:crates/victory-gpu/src/descriptor/host.rs:3626-3629,crates/victory-gpu/src/resource.rs:3102-3123):tabled_stamp(i) == 0) are sampled directly by shader index from material buffers — never via dynamic table copies — soseen_since(0, cutoff, frame)is alwaysfalse, andr.host.usedis only stamped once at initial upload/creation (hosted()), never updated on shader reads.allow_bindless = true(resource.rs:3123) plus lifting the per-sweep cap tou64::MAXabove 90% (resource.rs:3073) and bypassingidle_msat 88% (resource.rs:3081) causesevict_covering()(resource.rs:2997-3014) to sort by oldestr.host.usedand evict the longest-lived live scene/foreground textures first:diagevicted30,575host copies (1,251 MB) (r3:33,704,1,267 MB), leaving only8,834(706 MB) alive in the entire 4K world (only 654 made again).pool_given_back == 0):crates/victory-gpu/src/pool.rs:604only returns a 64 MiBID3D12Heapto D3D12 whenb.free.whole(BLOCK)(100% empty).diagends with27blocks (1,728 MB),1,021 MBfree (15blocks under 25% full holding just38 MBtotal — ~2.5 MB/block!), andpool_given_back = 0. DXGIusedtherefore never drops (6,222 -> 6,269 MB, ~92% of6,786 MB).lowmark wedgesEVICTING = trueforever (apps/victory/src/play.rs:427-432,resource.rs:3072-3076):2,595 MBrender targets/UAVs +844 MBcard buffers +1,728 MBtexture blocks with 0 returned + D3D12 overhead =~6,100–6,269 MB) sit permanently aboveVICTORY_SLOT_EVICT_LOW_PERCENT = 74(~4,958 MB).SLOT_STATE[0](slot_evicting()) therefore staystrueindefinitely.descriptor/host.rs:1740-1763, 3655-3693,descriptor.rs:1998-2013,draw.rs:3494):texture_slot_evicted_bindless()callsunmake(index)(writing aNULLSRV into the live GPU descriptor heap ->0,0,0,0black) and parksindexinevicted_bindless(NOTWAITING).draw.rs:3494gateshost.texture_slots_room(frame)onif room && !crate::resource::slot_evicting(),TextureQueue::room()is never called onceslot_evicting()wedgestrue. Every evicted live bindless texture stays permanently black.slot_evicting()wedge also caused the 1440pfinal_waitingregression1,653 -> 2,512: 1440p peaked at5,884 / 6,662 MB = 88.3% > 86%with0evictions, wedgedEVICTING = trueabove80%, and blockedtexture_slots_room()for 888 frames despiteroom_false = 0.0%.)#291'sunmapped_pinnedpath atresource.rs:2855-2876/descriptor.rs:2024-2040worked cleanly —diaglogged0 MBof unmapped textures still pinned by descriptor slots. The black silhouettes came 100% fromslot_evictevicting mapped bindless slots.)2. Why 4K GPU Time Exploded
7.2 -> 97.6 msandmapped()Exploded7.6 -> 35–57 ms/sTelemetry proves 93–95% of ReBAR
GPU_UPLOADwrite-combined buffers and ~330 hot card shadow buffers were forced out of local VRAM into system RAM over PCIe:main4K (27aa2ae4)#2911440p#2914K (r3)#2914K (diag)VICTORY_CARD_BUFFERS_MB1024 MiB1024 MiB512 MiB512 MiBVICTORY_CARD_ROOM_FOR_TARGETS_MB512 MiB512 MiB2048 MiB2048 MiBGPU_UPLOADWC buffers (wc_mapped_for)2,898(621.0 MB)2,919(626.4 MB)192(308.9 MB, -93.4%)136(314.5 MB, -95.3%)host copies in card memory)514(1,356 MB)522(1,352 MB)185(844 MB)164(844 MB)7.2 ms0.0 ms97.6 ms(+90.4 ms)94.3 ms(+87.1 ms)waiting for flights0.0 ms0.0 ms108.5 ms~100+ msmapped()rate / total7.6 ms/s(1,851 ms/16,000)7.32 ms/s(1,373 ms/16,800)35.19 ms/s(3,225 ms/16,200)57.62 ms/s(5,998 ms/19,800)apps/victory/src/play.rs:440, 442,scripts/verify-world.ps1:174, 176,crates/victory-gpu/src/shadow.rs:546-588, 3174-3203):CARD_BYTES[0]is shared by bothcard_room_for()(shadow.rs:586) andwc_mapped_for()(shadow.rs:3200) againstmost = VICTORY_CARD_BUFFERS_MB. Cutting it to512 MiBon 4K (plus subtractingtargets_room_kept = 2048 MiBagainst a92%ceiling inshadow.rs:549-562, 3183-3196) hit the512 MiBwall on frame 2268 (the first 3D world frame,314.5 MBWC +197.5 MBcard copies =512 MB).2,706–2,762write-combined geometry/vertex/meshlet/constant buffers (~310 MB) and~330shader buffers (~200 MB) silently fell back (shadow.rs:588, 3198, 3202) to CPUshared_buffers (D3D12_HEAP_TYPE_CUSTOML0 over PCIe).7.2 -> 97.6–122.3 ms, blocking the submitting thread108.5 ms/frameon flights and regressingcopyback(10.0 -> 13.5 ms, as non-carded buffers fall back to CPU scan + wait behind the 97 ms GPU).host::mapped()submits onASIDEcopy queue sharing PCIe/WDDM scheduling with the 97 ms PCIe-saturated GPU, inflating per-call latency from0.09 ms/callto0.81 ms/callin latediag(+4,716 msacross the final5,800calls). (Note: PR#291is also based on27aa2ae4pre-#289; rebasing ontomainc15df49beliminates >95% ofaheadmapped()calls automatically.)3. Minimal, Default-On Architectural Fix Blueprint
main(c15df49b, post-#289) & restore 4K card/ReBAR WC buffer residency:VICTORY_CARD_BUFFERS_MB = 1024on 4K (play.rs:440,verify-world.ps1:174) and remove theSMALL_VRAM_CEILINGtargets_room_keptsubtraction /92%throttle fromshadow.rs:546-562andshadow.rs:3180-3196(reservetargets_room_keptexclusively forresource::room()'s texture queue — never starvewc_mapped_for()). Hot WC geometry/constant buffers cost 10–20× more GPU ms per MiB over PCIe than texture mip streaming.CARD_BYTES[0]ever approachesmost, reserve a dedicated slice (e.g.,640 MiB) or priority for ReBARwc_mapped_for()over large coldcard_room_for()buffers.unmapped_pinnedcleanup (resource.rs:2855-2876,descriptor.rs:2024-2040), but NEVER evict mapped bindless (stamp == 0) textures toNULL:stamp == 0): Keepevict_unmapped_resource_slots()+evict_idle_host_with(..., false)(withseen_mapped/!committed+IDLE_FRAMESage guard), and raise the512-per-sweep cap whenused >= highso scene-out unmaps drain immediately.allow_bindless = false): Keepdescriptor/host.rs:3628's fix (!is_bindless || allow_bindless, dropping the brokentabled_lately(i)240-frame cutoff), and passallow_bindless = falseinslot_evict()(resource.rs:3123). Tabled slots automatically re-upload viaWAITING+HostHeap::mirror_after()if re-bound.evicted_bindless,park_evicted(),texture_slot_evicted_bindless(), and the!slot_evicting()gate indraw.rs:3494.slot_evicthysteresis & caps (resource.rs:3073-3081): Drop theu64::MAXcap lift and88%idle_msbypass, and immediately clearEVICTING = false(SLOT_STATE[0] = 0) whenever a sweep finds0evictable bytes — eliminating both the 1440pfinal_waitingregression and permanently-wedged eviction state.pool_given_back > 0) & shed 8 GiB 4K / 12 GiB FG VRAM safely withoutNULLSRVs:pool.rs:857,resource.rs:2997): Return(block_idx, block_used)frompool::block_used_bytes(), group evictable candidates byblock_idx, and prioritize blocks whereevictable_bytes_in_block == block_usedsopool.rs:604(b.free.whole(BLOCK)) actually frees whole 64 MiBID3D12Heaps back to DXGI instead of leaving 15 Swiss-cheese blocks.NULL): For 8 GiB 4K and 12 GiB long-session FG pressure (used >= 88%after Tier A + Tier B), shed VRAM on large (>= 1–2 MiB) bindless textures by clamping top mip(s) (first_mip += 1) on newly created large bindless textures (and/or atomically swapping cold>= 2 MiBbindless SRVs to a1/4-VRAM lower-mip host copy before retiring the full-res copy). That cuts large bindless texture VRAM by 75% with zeroNULLdescriptors and zero black silhouettes, while leaving 16 GiB+ GPUs (and 8–12 GiB GPUs below 88% budget) 100% untouched at full resolution and zero CPU cost.@Androtim on GitHub · 2026-12-01 18:04 UTC · original · edited 2026-12-01 19:03 UTC
Automated triage for the maintainers (not an approval).
Verdict:
needs-gpu-test· CI (check):passingAutomated PR Review —
needs-gpu-testCI is passing, lock-ordering changes are sound, and the new unit tests cover the core budget/reservation/slot-classification logic. Because this PR enables
VICTORY_SLOT_EVICTby default, addsIDXGIAdapter3::SetVideoMemoryReservation(VICTORY_VRAM_RESERVE), changes VRAM budget guards inshadow.rs/resource.rs, and updates 4K low-VRAM launcher defaults, it warrants a local real-GPU smoke test before merging.What looks good
crates/victory-gpu/src/resource.rs): Stagingslot_evictandlet_go_idle'sunmapped_pinnedpath into lock-ordered phases (droppingtextures()beforedescriptor::*/pool::*calls, re-checkingall.contains(&at)undertextures(), and deferringdescriptor::texture_madeuntil aftertextures()is dropped) cleanly breaks thetextures()<->HostHeap::madeAB-BA cycle.crates/victory-gpu/src/resource.rs,crates/victory-gpu/src/shadow.rs):floor_allows_roomandblock_room_fitsstop the texture floor from bypassing real DXGI headroom (REAL_MARGIN/room_line), andcard_room_for/wc_mapped_forreservetargets_room_keptunder a 92% ceiling only whenbudget <= 9 GiB, leaving >9 GiB GPUs unchanged.crates/victory-gpu/src/residency.rs,crates/victory-gpu/src/host.rs):reserve_vramuses a 64 MiB hysteresis band inreservation_target, logs failures once, and provides aVICTORY_VRAM_RESERVE=0kill-switch.crates/victory-gpu/src/resource.rs):card_accountingnow respectshost.baseso dropped top mips are not miscounted as unmapped.Minor notes / polish
apps/victory/src/play.rs(settings_with_vram, L422-L424) vsscripts/verify-world.ps1(L1772): Whenlow_vram && is_4k && framegen,play.rsunconditionally setsVICTORY_TEXTURE_ROOM_PERCENT=88, overwriting the86set forframegenat L393.verify-world.ps1guards this withif ($is4k -and -not $FrameGen). Considerif is_4k && !framegeninplay.rsfor parity.crates/victory-gpu/src/resource.rs(let_go_idle,unmapped_pinned): Ifevict_idle_host_with(..., false)returnsNonedue to a concurrent use between Phase 2 (evict_unmapped_resource_slots) and Phase 3, the slot has already been unmade without being added toWAITINGor restored. Very narrow window givenmapped_bytes == 0, but worth noting.crates/victory-gpu/src/descriptor/host.rs(slots_showing_from_raws) doc comment lists a 5-tuple(index, raw, evictable, seen_recently, is_bindless)while the function returns a 4-tupleVec<(u32, usize, bool, bool)>.evicted_bindless,slot_evicting(), 90%/88% thresholds, and84/80/74/5124K defaults), whereas the diff keeps live bindless slots protected (allow_bindless = falseinslot_evict), uses 92%/95% thresholds, and sets88/85/78/384/128/2048.Note: This is an automated technical review and does not constitute formal maintainer approval.
Generated with Antigravity CLI (
agy).@Androtim on GitHub · 2026-12-01 18:41 UTC · original
Updated PR #291 on commit
66c855b1(rebased ontomainc15df49b) to address thetriage: needs workreview, eliminate the black-silhouette regression, and achieveover = 0 MBon 8 GiB 4K & 1440p.Root Fixes Applied
allow_bindless = false): Strippedevicted_bindless,park_evicted,texture_slot_evicted_bindless, and theslot_evicting()gate acrossdescriptor/host.rs,descriptor.rs,draw.rs, andresource.rs.let_go_idlenow reclaims slot-pinned copies only whenmapped_bytes == 0across the full mip chain, and retains the AB-BAtextures()<->HostHeap::madelock-order fix.VICTORY_VRAM_RESERVE=0kill-switch): Addedreserve_vram/reservation_targetinresidency.rsand wired intohost.rs(createandsweep) so WDDM prioritizes the active local VRAM working set.texture_floor_bytes+host.base-aware accounting: Addedfloor_allows_roomandblock_room_fitsinresource.rsso the 25% texture floor never bypassesroom_line(budget)for new 64 MiB pool blocks orbudget - REAL_MARGINwhen VRAM is already full (used_maxdropped-627 MBat 4K). Updatedcard_accountingto respecthost.baseinstead of counting already-omitted top mips as unmapped.low_vram && is_4kdefaults inapps/victory/src/play.rsandscripts/verify-world.ps1toVICTORY_CARD_BUFFERS_MB=384,VICTORY_CARD_WINDOWS_MB=128, andVICTORY_CARD_ROOM_FOR_TARGETS_MB=2048(1440p and >=10 GB cards remain untouched).Static & Policy Checks
crates/victory-gpu/src/host.rs:646,836bytes (<= 655,360bytes)cargo +1.98.1-x86_64-pc-windows-gnu xtask policy:318 files ok--locked):victory-gpu --lib resource::(36 passed),descriptor::host::(64 passed),residency::(4 passed),-p victory(40 + 2 passed)clippy --workspace --locked --all-targets -- -D warnings(default +--features diagnostics): 0 warningsobjdump -p: standard Windows DLLs onlyVerified Benchmarks (RTX 4060 Ti 8 GB / Series X / DLSS Quality)
--release(60s,paired-291-final-4k-60svsmainc15df49b):used_max:7,059 -> 6,432 MB(-627 MB),over:275 -> 0 MBFPS:6.6 -> 6.5 fps([PASS] A/B FPS non-regression)preparing:28.5 -> 20.1 ms|copyback:17.4 -> 14.3 ms|mapped_rate:3.06 -> 2.59 ms/suploaded:47,011 -> 61,170|crashes:0--release(60s,paired-291-final-1440p-60svsmainc15df49b):FPS:15.05 -> 15.4 fps(+0.35 fps)used_max:6,406 -> 6,083 MB(-323 MB,over = 0 MB)final_waiting:2,665 -> 2,414(-251)preparing:27.7 -> 27.0 ms|copyback:11.2 -> 10.5 ms|mapped_rate:10.21 -> 7.17 ms/s|crashes:0diag-291-final-4k-90s) + D3D12 Debug Check (bisect-noskip-d3ddebug):crashes = 0,over = 0 MB,failed = 0,near_black:32.84% -> 0.2%,luma = 107.38,lit = 17/24.room=falseuntil tiledlevels_on_demandlands, while 1440p stays atroom_false = 8.3%andfinal_waiting = 2,414.@Androtim on GitHub · 2026-12-01 19:10 UTC · original
Architect & Strict-Gate Review (
66c855b1, CI passing,minivi-triageverified,host.rs = 646,836 <= 655,360bytes,xtask policy318 files ok, zero semantic conflict with#28540567147):All blocking items from the previous review were cleanly resolved — live bindless eviction removed (
allow_bindless = false),textures()<->HostHeap::madeAB-BA deadlock eliminated, dynamic DXGI local VRAM reservation added (VICTORY_VRAM_RESERVE=0kill-switch), and 8 GiB / 4K guards kept strictly budget-reactive (<= 9 GiB/low_vramonly; 16+ GiB cards remain untouched):--release60s A/B vsc15df49b:15.05 -> 15.4 fps(+0.35 fps,mean 13.11 -> 14.25,min 4.5 -> 6.3)mapped():27.7 -> 27.0 ms(-0.7 ms) /11.2 -> 10.5 ms(-0.7 ms) /10.21 -> 7.17 ms/s(-29.8%)6,406 -> 6,083 MB(-323 MB,over = 0 MB),final_waiting2,665 -> 2,414(-251,uploaded +7,448)--release60s A/B vsc15df49b:7,059 -> 6,432 MB(-627 MB,over: 275 -> 0 MB)mapped():28.5 -> 20.1 ms(-8.4 ms) /17.4 -> 14.3 ms(-3.1 ms) /3.06 -> 2.59 ms/s47,011 -> 61,170(+30%),6.6 -> 6.5 fps(parity while eliminating 275 MB overflow)near_blackslashed32.84% -> 0.2%(luma = 107.38,edge_energy = 8.06,magenta = 0.0%),0crashes/DRED,untranslated = 6 -> 6, D3D12 debug-layer check clean. (Note: minor follow-ups fromminivi-triage—if is_4k && !framegenparity inplay.rs,slots_showing_from_rawsdoc comment — can be folded into a future pass.)Squash-merging into
main(will tagv2026.12.01.03oncemainCI passes cleanly).