GPU: evicting given-up textures binary-searches the gone set, and choose skips its sort when nothing is over budget #3250
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!3250
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3250"
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?
@borosf on GitHub · 2026-11-26 14:34 UTC · original
borosf:vibe/evict-probes-once-842ca5→main· +56 −3 · 2 files · 2 commits · openTwo per-pass costs in the eviction path, both pure bookkeeping.
HostHeap::evict— one hash probe per kept slotOnce per pass that gives textures up,
evictwalked every kept slot (~962k of them, 15.4 MB ofKept) and probed aHashSet<usize>with SipHash for each, all under thekeptlock that every draw'smirroralso needs. The gone set is a handful of pointers.Now sorted once per pass; each slot asks
binary_search(2–3 ns) instead of a probe (~15 ns). Signature unchanged, so the one caller (descriptor.rs:274) is untouched.resource::choose— sorting candidates when nothing is over budgetchoosepartitioned out the idle textures, then sorted all remaining candidates by last use before discoveringover == 0. It now returns the idle set before the sort.Verification
cargo clippy -p victory-gpu --all-targets --locked -- -D warnings— clean;--all-featurestoo.cargo test -p victory-gpu --lib --locked --no-fail-fast— 230 passed, 2 failed, both the known Intel baseline failures pristinemainalso fails (#1744/#1829). The eviction tests (evict_among, idle/budget cases inresource::tests) pass.rustfmt --edition 2024 --checkhunk counts againstmain:descriptor/host.rs67→66 (the rewritten filter now conforms, so one fewer hunk),resource.rs64/64.Synthetic tests only; no game data.
Note on the sibling item from the same sweep (the
bindless::forgetfull-map sweep): I am holding that one back until #3213 lands, because it guards exactly theViewed::set/Resource::droprace the sweep's fix touches. Claimed on #1633, not released.Part of the fifteen gaps claimed for this sweep on #1633. AI-assisted.
@AurumCarlos on GitHub · 2026-11-26 14:37 UTC · original · reviewed
Both changes are behaviour-preserving as far as I can see:
choose: onmain, withover == 0after the idle partition, the loop breaks on its first iteration and returnsgoneas is. Returning before the sort gives the sameVecwithout theO(n log n).evict:binary_searchon the sorted pointers answers the same membership question asHashSet::contains, and the filter keeps thek.1.is_none()check first.A few remarks:
1. The sort runs once per heap, not once per pass.
descriptor::evictcallshost.evict(textures)for every shader-visible view heap, so thecollect+sort_unstablehappens once per heap. With a handful of pointers that's negligible, but the comment ("Sorted once … per pass") isn't quite accurate. If you'd rather not change the signature, rewording the comment is enough. Otherwise, sorting indescriptor::evictand passing&[usize]would make it literally once.2. For "a handful", a linear scan may beat both. If the gone set really is a few pointers per pass,
gone.contains(&p)on a tinyVecis a couple of compares with no hashing and no branchy search, and it's simpler. Binary search is the safer choice when the LRU pick frees many textures under budget pressure, so I'd keep it. But the 2–3 ns vs ~15 ns figures read as estimates: if you measured them (and the ~962k-slot walk time before and after, under thekeptlock), putting the numbers in the description would make the win concrete.3. Nit:
let (mut gone, rest) = …followed later bylet mut rest = rest;could just staylet (mut gone, mut rest) = …as onmain, since the early return doesn't needrestto be immutable.mut rest, measured probe costs 5afb3844c8@borosf on GitHub · 2026-11-26 14:45 UTC · original
All three remarks addressed at
5afb3844c88a8597bd525184ae22028da3c7f488:Comment: now says "sorted once per call (per heap per pass)" — you're right that
descriptor::evictcallshost.evictper shader-visible heap, so the collect+sort happens per heap.Measured, not estimated — and the honest number is smaller than my estimate. New ignored test
descriptor::host::tests::an_evict_probe_costswalks a 962,144-slot kept list (a texture slot every 7th, 64 gone pointers) both ways on this B580,--release:So ~1.8 → ~1.1 ns per slot, about 0.65 ms per 962k-slot pass, not the ~15 ms my "~15 ns" estimate implied. Kept binary search as you suggested (it wins, and wins more when the LRU pick frees many textures under budget pressure); the PR body's ns figures should be read as replaced by these.
Nit: back to
let (mut gone, mut rest) = …as on main, early return unchanged.Re-verified locally: clippy clean on both feature sets,
cargo test -p victory-gpu --lib --locked --no-fail-fast229 passed / 2 failed (the known #1744/#1829 Intel baseline failures), rustfmt hunk counts vs main unchanged (descriptor/host.rs67/67,resource.rs64/64). Synthetic tests only; no game data.@Dukestar69 on GitHub · 2026-11-26 15:31 UTC · original · approved these changes
Reviewed the diff and verified locally on Windows 11 x64 (RTX 5090):
goneonce inHostHeap::evictfor binary search over kept slots and skipping the LRU sort inresource::choosewhenover == 0are clean, behavior-preserving optimizations.cargo test -p victory-gpu --lib descriptor::host::tests:: -- --test-threads=1 --skip dynamic_slots_are_held_until_released(RTX 5090): 14 passed, 0 failed, 1 ignored (an_evict_probe_costs).cargo test -p victory-gpu --lib resource::tests:: -- --test-threads=1(RTX 5090): 18 passed, 0 failed (includingidle_textures_go_and_past_the_budget_the_least_recently_used).cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
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.