GPU: evicting given-up textures binary-searches the gone set, and choose skips its sort when nothing is over budget #3250

Open
github-bot wants to merge 2 commits from github-bot/gh-3250 into main AGit
Owner

@⁠borosf on GitHub · 2026-11-26 14:34 UTC · original
borosf:vibe/evict-probes-once-842ca5 → main · +56 −3 · 2 files · 2 commits · open

Two per-pass costs in the eviction path, both pure bookkeeping.

HostHeap::evict — one hash probe per kept slot

Once per pass that gives textures up, evict walked every kept slot (~962k of them, 15.4 MB of Kept) and probed a HashSet<usize> with SipHash for each, all under the kept lock that every draw's mirror also 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 budget

choose partitioned out the idle textures, then sorted all remaining candidates by last use before discovering over == 0. It now returns the idle set before the sort.

Verification

  • cargo clippy -p victory-gpu --all-targets --locked -- -D warnings — clean; --all-features too.
  • cargo test -p victory-gpu --lib --locked --no-fail-fast — 230 passed, 2 failed, both the known Intel baseline failures pristine main also fails (#1744/#1829). The eviction tests (evict_among, idle/budget cases in resource::tests) pass.
  • rustfmt --edition 2024 --check hunk counts against main: descriptor/host.rs 67→66 (the rewritten filter now conforms, so one fewer hunk), resource.rs 64/64.

Synthetic tests only; no game data.

Note on the sibling item from the same sweep (the bindless::forget full-map sweep): I am holding that one back until #3213 lands, because it guards exactly the Viewed::set / Resource::drop race the sweep's fix touches. Claimed on #1633, not released.

Part of the fifteen gaps claimed for this sweep on #1633. AI-assisted.

**@⁠borosf** on GitHub · 2026-11-26 14:34 UTC · [original](https://github.com/Marvisak/VIctory/pull/3250) `borosf:vibe/evict-probes-once-842ca5` → `main` · +56 −3 · 2 files · 2 commits · open Two per-pass costs in the eviction path, both pure bookkeeping. ## `HostHeap::evict` — one hash probe per kept slot Once per pass that gives textures up, `evict` walked every kept slot (~962k of them, 15.4 MB of `Kept`) and probed a `HashSet<usize>` with SipHash for each, all under the `kept` lock that every draw's `mirror` also 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 budget `choose` partitioned out the idle textures, then sorted *all* remaining candidates by last use before discovering `over == 0`. It now returns the idle set before the sort. ## Verification - `cargo clippy -p victory-gpu --all-targets --locked -- -D warnings` — clean; `--all-features` too. - `cargo test -p victory-gpu --lib --locked --no-fail-fast` — 230 passed, 2 failed, both the known Intel baseline failures pristine `main` also fails (#1744/#1829). The eviction tests (`evict_among`, idle/budget cases in `resource::tests`) pass. - `rustfmt --edition 2024 --check` hunk counts against `main`: `descriptor/host.rs` 67→66 (the rewritten filter now conforms, so one fewer hunk), `resource.rs` 64/64. Synthetic tests only; no game data. Note on the sibling item from the same sweep (the `bindless::forget` full-map sweep): I am holding that one back until #3213 lands, because it guards exactly the `Viewed::set` / `Resource::drop` race the sweep's fix touches. Claimed on #1633, not released. Part of the fifteen gaps claimed for this sweep on #1633. AI-assisted.
`HostHeap::evict` walked every kept slot (~962k) with a SipHash probe per
slot against the given-up set, under the `kept` lock that every draw's
mirror also takes, once per pass that gives textures up.

The set is sorted once per pass and each slot asks a binary search instead.
`resource::choose` sorted every remaining candidate by last use even when
nothing was over the memory budget, which the idle pass alone had already
covered; it returns before the sort now.

Verification: `cargo clippy -p victory-gpu --all-targets --locked -- -D
warnings` and `--all-features` both clean; `cargo test -p victory-gpu --lib
--locked --no-fail-fast` 230 passed, 2 failed — both the known Intel
baseline failures pristine main also fails (#1744/#1829), including the
eviction tests (`evict_among` and friends). `rustfmt --edition 2024
--check` hunks against main: descriptor/host.rs 67->66 (one fewer, the
rewritten line now conforms), resource.rs 64/64.

Synthetic tests only; no game data.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 14:39:03 +00:00
Author
Owner

@⁠AurumCarlos on GitHub · 2026-11-26 14:37 UTC · original · reviewed

Both changes are behaviour-preserving as far as I can see:

  • choose: on main, with over == 0 after the idle partition, the loop breaks on its first iteration and returns gone as is. Returning before the sort gives the same Vec without the O(n log n).
  • evict: binary_search on the sorted pointers answers the same membership question as HashSet::contains, and the filter keeps the k.1.is_none() check first.

A few remarks:

1. The sort runs once per heap, not once per pass. descriptor::evict calls host.evict(textures) for every shader-visible view heap, so the collect + sort_unstable happens 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 in descriptor::evict and 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 tiny Vec is 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 the kept lock), putting the numbers in the description would make the win concrete.

3. Nit: let (mut gone, rest) = … followed later by let mut rest = rest; could just stay let (mut gone, mut rest) = … as on main, since the early return doesn't need rest to be immutable.

**@⁠AurumCarlos** on GitHub · 2026-11-26 14:37 UTC · [original](https://github.com/Marvisak/VIctory/pull/3250#pullrequestreview-6075967818) · **reviewed** Both changes are behaviour-preserving as far as I can see: - **`choose`**: on `main`, with `over == 0` after the idle partition, the loop breaks on its first iteration and returns `gone` as is. Returning before the sort gives the same `Vec` without the `O(n log n)`. - **`evict`**: `binary_search` on the sorted pointers answers the same membership question as `HashSet::contains`, and the filter keeps the `k.1.is_none()` check first. A few remarks: **1. The sort runs once per heap, not once per pass.** `descriptor::evict` calls `host.evict(textures)` for every shader-visible view heap, so the `collect` + `sort_unstable` happens 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 in `descriptor::evict` and 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 tiny `Vec` is 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 the `kept` lock), putting the numbers in the description would make the win concrete. **3. Nit**: `let (mut gone, rest) = …` followed later by `let mut rest = rest;` could just stay `let (mut gone, mut rest) = …` as on `main`, since the early return doesn't need `rest` to be immutable.
Review remarks on #3250: the sort runs once per evict call (per heap per
pass), not once per pass, so the comment now says so; `choose` keeps
`let (mut gone, mut rest)` as on main; and the probe costs are measured
rather than estimated, in the new ignored test
`descriptor::host::tests::an_evict_probe_costs`.

Synthetic tests only; no game data.
Author
Owner

@⁠borosf on GitHub · 2026-11-26 14:45 UTC · original

All three remarks addressed at 5afb3844c88a8597bd525184ae22028da3c7f488:

  1. Comment: now says "sorted once per call (per heap per pass)" — you're right that descriptor::evict calls host.evict per shader-visible heap, so the collect+sort happens per heap.

  2. Measured, not estimated — and the honest number is smaller than my estimate. New ignored test descriptor::host::tests::an_evict_probe_costs walks a 962,144-slot kept list (a texture slot every 7th, 64 gone pointers) both ways on this B580, --release:

    cargo test --release -p victory-gpu --lib --locked -- --exact --ignored --nocapture \
      descriptor::host::tests::an_evict_probe_costs
    
    962144 kept slots: SipHash probe 1.7437ms (1.8 ns/slot), binary search 1.0934ms (1.1 ns/slot), 10 hits
    

    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.

  3. 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-fast 229 passed / 2 failed (the known #1744/#1829 Intel baseline failures), rustfmt hunk counts vs main unchanged (descriptor/host.rs 67/67, resource.rs 64/64). Synthetic tests only; no game data.

**@⁠borosf** on GitHub · 2026-11-26 14:45 UTC · [original](https://github.com/Marvisak/VIctory/pull/3250#issuecomment-7195290067) All three remarks addressed at `5afb3844c88a8597bd525184ae22028da3c7f488`: 1. **Comment**: now says "sorted once per call (per heap per pass)" — you're right that `descriptor::evict` calls `host.evict` per shader-visible heap, so the collect+sort happens per heap. 2. **Measured, not estimated** — and the honest number is smaller than my estimate. New ignored test `descriptor::host::tests::an_evict_probe_costs` walks a 962,144-slot kept list (a texture slot every 7th, 64 gone pointers) both ways on this B580, `--release`: ``` cargo test --release -p victory-gpu --lib --locked -- --exact --ignored --nocapture \ descriptor::host::tests::an_evict_probe_costs 962144 kept slots: SipHash probe 1.7437ms (1.8 ns/slot), binary search 1.0934ms (1.1 ns/slot), 10 hits ``` 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. 3. **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-fast` 229 passed / 2 failed (the known #1744/#1829 Intel baseline failures), rustfmt hunk counts vs main unchanged (`descriptor/host.rs` 67/67, `resource.rs` 64/64). Synthetic tests only; no game data.
Author
Owner

@⁠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):

  • Sorting gone once in HostHeap::evict for binary search over kept slots and skipping the LRU sort in resource::choose when over == 0 are 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 (including idle_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).

**@⁠Dukestar69** on GitHub · 2026-11-26 15:31 UTC · [original](https://github.com/Marvisak/VIctory/pull/3250#pullrequestreview-6076806335) · **approved these changes** Reviewed the diff and verified locally on Windows 11 x64 (RTX 5090): - Sorting `gone` once in `HostHeap::evict` for binary search over kept slots and skipping the LRU sort in `resource::choose` when `over == 0` are 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 (including `idle_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).
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/3250/head:github-bot/gh-3250'
git switch 'github-bot/gh-3250'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3250'
git switch 'github-bot/gh-3250'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3250'
git switch 'github-bot/gh-3250'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3250'
git switch 'main'
git merge --squash 'github-bot/gh-3250'
git switch 'main'
git merge --ff-only 'github-bot/gh-3250'
git switch 'main'
git merge 'github-bot/gh-3250'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!3250
No description provided.