GPU: evicting given-up textures binary-searches the gone set, and choose skips its sort when nothing is over budget #3248
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/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?
Imported from Marvisak/VIctory. Originally posted by borosf on 2026-11-26T14:34:59Z.
Two 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.
Imported from Marvisak/VIctory. Originally posted by AurumCarlos on 2026-11-26T14:37:53Z.
Review: COMMENTED
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.Imported from Marvisak/VIctory. Originally posted by borosf on 2026-11-26T14:45:48Z.
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.Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T15:31:46Z.
Review: APPROVED
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).
Imported from Marvisak/VIctory. Originally posted by borosf on 2026-11-27T13:20:26Z.
Closing this: the micro-optimisation is real but the code it optimises is being removed by #3456.
The sort/binary-search is behaviour-preserving (best-fit preserved via
partition_pointplusremove(cut-1)), but #3456 rewrites the sameHostHeap::evictloop onto a sparsekeptmap and removes the ~962k-slot walk entirely, which dominates this. Landing both would mean reconciling one function twice for a win that #3456 subsumes.Two smaller reasons not to push it: the sort runs once per heap, not "once per pass" (
descriptor.rs:300-306callsevictper shader-visible heap), and the only test is an#[ignore]d benchmark that re-implements the filter in a closure instead of callingHostHeap::evict, so it pins neither correctness nor the claimed speed.The
choosehalf (resource.rs:1669-1671) is a clean no-op-equivalent and already covered by an existing test; I will re-offer it if #3456 changes shape.Pull request closed