GPU: the per-frame eviction pass is counted, and its census reads a flag instead of GetDesc per texture #3252

Open
borosf wants to merge 2 commits from upstream-pr/3254 into main
borosf commented 2026-11-26 14:41:29 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by borosf on 2026-11-26T14:41:29Z.


The per-frame eviction census now costs nothing when nothing is evictable, and reads a flag instead of a COM call per texture when it does run.

What it cost

evict_unused runs once per presented frame and calls candidates(), which locks TEXTURES_AT and walks every title texture there is (~20,000–50,000 in the world), taking each resource's host mutex, cloning the Arc, and calling GetDesc per texture to answer "may this be given up?" — all under the same TEXTURES_AT lock that alias_source needs per texture view per draw, so title threads queue behind it once a frame.

What changes

HostTexture carries an evictable: AtomicBool — fed from title memory (has a MemoryKey, not a render/depth/unordered target) and not written by the host — maintained exactly where its inputs change:

  • set where the key is assigned at creation (and counted in a new EVICTABLE counter),
  • cleared by HostTexture::note_host_written() (the existing deferred host_written store in texture.rs now calls it),
  • cleared in Drop, alongside the existing TEXTURES/TEXTURE_BYTES counter maintenance.

candidates() reads the flag instead of GetDesc, and evict_unused returns immediately when EVICTABLE == 0 — the steady state between shots, and any frame where the host has written everything fed from title memory.

The old evictable(t) helper (the GetDesc-per-texture predicate) is gone; the flag is its memo.

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 — 229 passed, 2 failed, both the known Intel baseline failures pristine main also fails (#1744/#1829). I checked the counts against a main worktree run twice, identical; one earlier run showed a third, shadow::tests::marked_pages_go_back_by_the_bytes_the_gpu_changed, which passes 3/3 in isolation and did not recur in three further full runs — a parallel-run flake, not this change.
  • The eviction tests (evict_among, idle/budget/evict_among-driven cases in resource::tests) pass.
  • rustfmt --edition 2024 --check hunk counts against main: resource.rs 64→63, texture.rs 25→24 (both one fewer).

Synthetic tests only; no game data.

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

<!-- greyfinch-sync:Marvisak/VIctory:issue:5512043051 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3254). Originally posted by [borosf](https://github.com/borosf) on 2026-11-26T14:41:29Z. --- The per-frame eviction census now costs nothing when nothing is evictable, and reads a flag instead of a COM call per texture when it does run. ## What it cost `evict_unused` runs once per presented frame and calls `candidates()`, which locks `TEXTURES_AT` and walks every title texture there is (~20,000–50,000 in the world), taking each resource's `host` mutex, cloning the `Arc`, and calling `GetDesc` per texture to answer "may this be given up?" — all under the same `TEXTURES_AT` lock that `alias_source` needs per texture view per draw, so title threads queue behind it once a frame. ## What changes `HostTexture` carries an `evictable: AtomicBool` — fed from title memory (has a `MemoryKey`, not a render/depth/unordered target) and not written by the host — maintained exactly where its inputs change: - set where the key is assigned at creation (and counted in a new `EVICTABLE` counter), - cleared by `HostTexture::note_host_written()` (the existing deferred `host_written` store in `texture.rs` now calls it), - cleared in `Drop`, alongside the existing `TEXTURES`/`TEXTURE_BYTES` counter maintenance. `candidates()` reads the flag instead of `GetDesc`, and `evict_unused` returns immediately when `EVICTABLE == 0` — the steady state between shots, and any frame where the host has written everything fed from title memory. The old `evictable(t)` helper (the `GetDesc`-per-texture predicate) is gone; the flag is its memo. ## 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` — 229 passed, 2 failed, both the known Intel baseline failures pristine `main` also fails (#1744/#1829). I checked the counts against a `main` worktree run twice, identical; one earlier run showed a third, `shadow::tests::marked_pages_go_back_by_the_bytes_the_gpu_changed`, which passes 3/3 in isolation and did not recur in three further full runs — a parallel-run flake, not this change. - The eviction tests (`evict_among`, idle/budget/`evict_among`-driven cases in `resource::tests`) pass. - `rustfmt --edition 2024 --check` hunk counts against `main`: `resource.rs` 64→63, `texture.rs` 25→24 (both one *fewer*). Synthetic tests only; no game data. Part of the fifteen gaps claimed for this sweep on #1633. AI-assisted.
Dukestar69 commented 2026-11-26 14:48:29 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T14:48:29Z.

Review: APPROVED


Reviewed the diff and verified locally on Windows 11 x64 (RTX 5090):

  • Tracking HostTexture::evictable and the global EVICTABLE counter (incremented in shared_texture, decremented once via swap(false) in
    ote_host_written or Drop) avoids per-texture GetDesc calls during candidates() and skips the per-frame census when EVICTABLE == 0. Confirmed exture::host_writes is the sole mutator of host_written.
  • cargo test -p victory-gpu --lib resource:: -- --test-threads=1 (RTX 5090): 18 passed, 0 failed (including only_textures_fed_from_title_memory_are_given_up and 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).

<!-- greyfinch-sync:Marvisak/VIctory:review:6076146163 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3254#pullrequestreview-6076146163). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T14:48:29Z. **Review:** APPROVED --- Reviewed the diff and verified locally on Windows 11 x64 (RTX 5090): - Tracking HostTexture::evictable and the global EVICTABLE counter (incremented in shared_texture, decremented once via swap(false) in ote_host_written or Drop) avoids per-texture GetDesc calls during candidates() and skips the per-frame census when EVICTABLE == 0. Confirmed exture::host_writes is the sole mutator of host_written. - cargo test -p victory-gpu --lib resource:: -- --test-threads=1 (RTX 5090): 18 passed, 0 failed (including only_textures_fed_from_title_memory_are_given_up and 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).
borosf commented 2026-11-26 15:02:37 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by borosf on 2026-11-26T14:59:14Z.


Thanks — no change needed, head stays 14b3ff6710a9086a33a1e3e0a413a573fccfc480. Your check that texture::host_writes is the sole mutator of host_written matches mine (single store(true) site, now routed through note_host_written). Synthetic tests only; no game data.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7195616849 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3254#issuecomment-7195616849). Originally posted by [borosf](https://github.com/borosf) on 2026-11-26T14:59:14Z. --- Thanks — no change needed, head stays `14b3ff6710a9086a33a1e3e0a413a573fccfc480`. Your check that `texture::host_writes` is the sole mutator of `host_written` matches mine (single `store(true)` site, now routed through `note_host_written`). Synthetic tests only; no game data.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3254:upstream-pr/3254'
git switch 'upstream-pr/3254'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3254'
git switch 'upstream-pr/3254'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3254'
git switch 'upstream-pr/3254'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3254'
git switch 'main'
git merge --squash 'upstream-pr/3254'
git switch 'main'
git merge --ff-only 'upstream-pr/3254'
git switch 'main'
git merge 'upstream-pr/3254'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!3252
No description provided.