GPU: fix VRAM eviction monotonicity, texture-pool fragmentation masking, and sweep spikes #223
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Belobug--VIctory-Belobug-AMD!223
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-223"
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?
@zaixiakongyiji on GitHub · 2026-11-26 03:45 UTC · original
zaixiakongyiji:gpu/rx9070xt-vram-hysteresis→a-publier· +1328 −150 · 3 files · 2 commits · openProblem
On 16 GB cards (e.g. Radeon RX 9070 XT with a 13.6-15.4 GiB DXGI local budget), long sessions (70+ minutes of streaming) hit three interacting VRAM-management failure modes:
>= 93%eviction target,85..90%admit/evict overlap, and pool-fragmentation masking (host.rs,resource.rs):vram_keep, the>= 93%hard tier previously targetedused - share(84)while85%..93%targetedused - share(80), evicting less at 93% than at 92%.room_percent()defaulted to90%while soft eviction started at85%, so the queue kept admitting between 85% and 90% while the sweep tried to evict down to 80%.effective_vram_usagesubtracted all free bytes across non-empty 64 MiB texture-pool blocks without bound. After 70+ minutes, ~1.6 GiB of scattered holes across partially occupied 64 MiB blocks kept computedeffective_usedbelow the soft eviction line (idle_ms = 600_000) even while physicalLOCAL.usedexceeded 90%+ (12,322 / 13,579 MiB), starving buffer allocations and stalling streaming.pool.rs):whole(BLOCK)and returning physical VRAM to WDDM.let_go_idleframe-time spikes & stalehost.usedtimestamps (resource.rs):r.host.usednon-zero, so every subsequent pressuredlet_go_idlepass re-lockedmadeon already-evicted entries across 150k+ resources (10.87 msavg,30.4 msmax per sweep).Changes
crates/victory-gpu/src/host.rs:VRAM_TARGET_HARD_PCTto76%(VRAM_EVICT_SOFT_PCT = 85,VRAM_EVICT_HARD_PCT = 93,VRAM_TARGET_SOFT_PCT = 80,SHORT_MS = 3_000) so eviction targets increase monotonically across85%..=120%, and updatevram_keep's doc comment.vram_keep_with_raw+note_raw_local_vram(wired insweep()andHost::video_memory()) with an86% -> 82%rawLOCAL.usedhysteresis guardrail so fragmented pool holes cannot suppress cold-texture eviction as physical VRAM nears exhaustion.crates/victory-gpu/src/pool.rs:best_fit/pick_candidate) so low-occupancy tail 64 MiB heaps drain towhole(BLOCK).spare_and_fragmented_room()andhas_reusable_hole(size, alignment), drop empty-block retention to0under raw high-VRAM hysteresis, and restrictpool::texture()to zero-WDDM non-empty hole reuse when new WDDM heaps are blocked.crates/victory-gpu/src/resource.rs:DEFAULT_TEXTURE_ROOM_PCTdirectly toVRAM_EVICT_SOFT_PCT(85%) so 5 s eviction toward 80% starts at the exact boundary whereroom()pauses new admission (eliminating both the85..90%admit/evict overlap and any dead band where waiting textures sit below the 5 s eviction threshold).256 MiB(0under raw high pressure) viacompute_vram_pressure/room_allows_with_pool_hole(allowing zero-WDDM hole reuse below 88% raw while deferring standalone committed textures viaHostTextureOutcome::Deferredwithout settingrefused).r.host.usedto0undermade's lock inwant_levelandlet_go_idle, countSWEPT_USon cooldown-skipped looks as well, and bound pressuredlet_go_idlescans to a rolling16,384-entry window,2,048lock checks, and a4 MiBprogress floor before a2,000 mscooldown (10.87 ms -> 2.04 msavg in 154k-texture city streaming).Verification
cargo clippy --workspace --all-targets --locked -- -D warnings: cleancargo clippy --workspace --all-targets --all-features --locked -- -D warnings: cleancargo test -p victory-gpu --locked&cargo test -p victory-gpu --features diagnostics --locked: 453 + 1 passed, 0 failed (9 unit tests coveringvram_keepmonotonicity/hysteresis, zero dead-band admission/eviction handoff,poolbest-fit draining & non-empty hole reuse, 74-minute fragmentation pressure snapshot, eviction safety guardrails, and rolling sweep cooldown).@adrianmjim on GitHub · 2026-11-26 22:41 UTC · original
Checked by reading the code on a-publier
cd8dfc0(head73626bf, change 81ebb7b..73626bf); I did not build or run it.Rebase:
cd8dfc0.host.rsconflicts invram_keepand in its test.resource.rsmerges cleanly.cd8dfc0already moved the same thresholds to 85 / 93, with targets 80 / 84 andSHORT_MS3,000 (host.rs:171-181). The PR's 82 / 90 / 78 / 74 and its test values (5,000 / 1,500 ms, 16 GiB at 90%) would need to be chosen again on top of those numbers.4eb6cfd. None of the merges sincecd8dfc0touchvram_keep,room_percent()orresource.rs, so the numbers below are the same there, and the change conflicts inhost.rsthe same way.Both problems in the description are still there on
cd8dfc0:used - share(80)and 93% and up evictsused - share(84)(host.rs:178-181). At 92% that is 12% of the budget. At 93% it is 9%. The base test asserts this:(3_000, 11 GiB)at 95% (host.rs:11416), less than the 12 GiB at 92%. With a soft target of 80, any hard target above 80 makes the bytes to evict drop at 93%.room_percent()is still 90 (resource.rs:1863-1869) and soft eviction starts at 85 (host.rs:176).room()(resource.rs:1774) andlet_go_idle()(resource.rs:2136-2141) use the same usage figure. So between 85% and 90% the queue keeps admitting while the sweep works down to 80%.vram_keepdoc oncd8dfc0still says 88 % / 85 % (host.rs:161-162). The rebase could update it to the new numbers.Concern with
DEFAULT_TEXTURE_ROOM_PCT = VRAM_EVICT_SOFT_PCT - 2(from reading):vram_keepreturns(600_000, u64::MAX), so the sweep only lets go of copies idle 10 minutes or more.room()is false, new heap textures are refused (draw.rs:2297, 2533-2537). Held levels are not asked for again (texture.rs:782).keep_shownstops (descriptor/host.rs:2363, 3343, 3373).cd8dfc0) says that at 90 about a tenth of the budget stayed unused while thousands of textures waited (runs 170-174), and suggests 94. Going below 90 moves the other way.room()stops admitting.Small things:
assert!(DEFAULT_TEXTURE_ROOM_PCT < crate::host::VRAM_EVICT_SOFT_PCT)(resource.rs:4589 on the PR head) compares two constants. From reading, I expect clippy'sassertions_on_constantsto flag it. I did not run clippy. CI runs clippy with--all-targets -- -D warningson Windows (ci.yml:29, 31), so if it is flagged the Clippy job fails.const { assert!(..) }avoids it, as descriptor/host.rs:61 already does.EMPTY_PRESSURE_SWEEP_COOLDOWN_MS(resource.rs:2018 on the PR head) sits betweenlet_go_idle's doc comment (from 1996) and the function (2042). Rustdoc attaches most of that comment to the const.SWEPT_USis counted (2172). So the sweep counters no longer include those calls.Not checked: build, unit tests and clippy on a rebased branch; in-world behaviour at 12-18 GB VRAM.
GPU: align texture room_percent below vram_keep and fix >=90% eviction targetto GPU: fix VRAM eviction monotonicity, texture-pool fragmentation masking, and sweep spikes73626bfcfdto6be0fe3c72@zaixiakongyiji on GitHub · 2026-11-27 15:13 UTC · original
Rebased onto
a-publier(4eb6cfd), retargeted the base branch fromrx9070xttoa-publier, and addressed every item from @adrianmjim's review (thank you for the detailed catch!):a-publier: Kept85 / 93andSHORT_MS = 3_000, lowered the hard eviction target from84%to76%(VRAM_TARGET_SOFT_PCT = 80,VRAM_TARGET_HARD_PCT = 76) so eviction bytes increase monotonically across the92% -> 93%boundary, and updatedvram_keep's doc comment.room()and 5 s eviction: ChangedDEFAULT_TEXTURE_ROOM_PCTto matchVRAM_EVICT_SOFT_PCT(85%) directly instead ofVRAM_EVICT_SOFT_PCT - 2, so 5 s eviction toward 80% starts at the exact byte boundary whereroom()pauses admission (and kept theruns 170-174note onroom_percent()).SWEPT_USnits: Usedconst { assert!(..) }, keptlet_go_idle's doc comment attached directly tolet_go_idlerather thanEMPTY_PRESSURE_SWEEP_COOLDOWN_MS, and recordedSWEPT_USon cooldown-skippedlet_go_idlecalls too.LOCAL.used86% -> 82%hysteresis (pool.rsbest-fit block clustering +spare_and_fragmented_room()) and bounded rolling16,384-entry sweeps +r.host.used = 0eviction reset (10.87 ms -> 2.04 msavg over 154k textures).@adrianmjim on GitHub · 2026-11-27 15:25 UTC · original
Thanks @zaixiakongyiji. I checked
6be0fe3ona-publier4eb6cfd.What I ran
cargo build -p victory-gpu: OK.cargo clippy -p victory-gpu --all-targets -- -D warnings, with and withoutdiagnostics: clean.I did not run GPU tests or the game.
Earlier points: all addressed.
room()and the 5 s eviction now start at the same 85% line, from the same usage figure.const { assert!(..) }, the rustdoc placement and theSWEPT_UScounting are all in.New code. These come from reading the code, not from runs.
While
RAW_VRAM_HIGHis set, some textures are drawn black, and they can stay black after it clears.resource.rs:3029-3031. A title-filled texture thatpool::texturecan't place returnsDeferred. That means XOR-swizzled, over 64 MiB, or no ripe non-empty block with a hole that fits.hosted()then returnsNonewithout settingrefused.mirrorwrites a typed null SRV into the slot (descriptor/host.rs:3399-3406), so the shader samples zeros.mirrorrecords the slot as made under that key even though the texture wasn't (3398,3412). When the texture is made later, the quick path doesn't remake the slot. It stays null until the title rewrites that descriptor.4eb6cfdthese textures always went on toCreateCommittedResource.Deferred.Under the latch, eviction doesn't see most of what it frees.
4eb6cfdthe sweep subtracted every unheld pool byte, so each released copy loweredused.raw - whole_freeor more (resource.rs:1856-1866,1888-1893). A copy whose release only leaves a hole in a partly used block doesn't move it.mostis about 1,175 MiB. Each 1 s sweep can let go of that much again, up to 2,048 lock checks per sweep. A productive sweep resets the cooldown streak (resource.rs:2383), so cooldown never stops it.The two raw latches use different lines.
raw_vram_high_foruses the margin. For budgets of 8-16 GiB the margin is exactly budget/32, so it turns on at 84.875% and off at 81.875%.vram_keep_with_rawuses a plain 86 / 82.RAW_VRAM_HIGHinvram_keep, or giving the host the same margin, would make them one latch.The 2,048 lock-check cap can starve a window.
by_ageruns oldest first (resource.rs:2521). A texture held by a descriptor slot that the CPU hasn't asked for passes the lock-free checks, then failscom_refs == 1. Itsusedis never refreshed or cleared, so it takes a check again on every pass.4eb6cfdhad no cap.by_age, or not counting checks for textures already known to be held.Smaller:
room()admits whenever raw is under 88% and a hole exists. It ignores the effective figure andVICTORY_TEXTURE_ROOM_PERCENT, so admission and eviction overlap again in that range.host.rs:159says "below this line" where it means "at".else ifatresource.rs:1894can't run:whole == 0is caught by the branch before it.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.