GPU: committed host textures past the budget are evicted and kept, no… #2872

Open
github-bot wants to merge 1 commit from github-bot/gh-2872 into main AGit
Owner

@⁠mitaka1959 on GitHub · 2026-11-25 22:51 UTC · original
mitaka1959:claude/compassionate-cerf-n9485q → main · +1205 −96 · 7 files · 1 commits · open

Past the card's budget the eviction pass gave up (destroyed) the least recently used host textures fed from title memory, and their next use made them again from title memory, detiled and uploaded. A committed one is now evicted instead (ID3D12Device::Evict): its contents and GPU address stay, and its next use only makes it resident again. Textures in heaps of textures cannot be evicted on their own (residency is the heap's) and are given up as before, as are idle textures (two minutes and 300 frames unused).

No GPU work reaches an evicted texture. The textures a submission's lists name are made resident before they run. The pass leaves the heap slots viewing a texture null before it evicts it, a use makes a texture resident before a view of it is made, and a slot made while a pass picked or evicted its texture is checked once it holds it. If the device refuses to make textures resident, others are evicted first; refused again, the run ends instead of faulting the GPU. Each texture's residency changes together with its device call, under one lock, so the device's count stays 1 or 0.

The policy (which textures go, the budget marks, the address-space check) lives in residency.rs with tests that need no GPU, among them every order of passes and uses; GPU tests cover an eviction, a use, a list recorded before the eviction and a heap slot. The first eviction of a run logs the card's use before and after, and if evicting did not lower it, textures are given up from then on. Diagnostics builds take VICTORY_VRAM_BUDGET_MB (a smaller budget) and VICTORY_GIVE_UP_TEXTURES (the old behaviour, for comparing runs).

**@⁠mitaka1959** on GitHub · 2026-11-25 22:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/2872) `mitaka1959:claude/compassionate-cerf-n9485q` → `main` · +1205 −96 · 7 files · 1 commits · open Past the card's budget the eviction pass gave up (destroyed) the least recently used host textures fed from title memory, and their next use made them again from title memory, detiled and uploaded. A committed one is now evicted instead (ID3D12Device::Evict): its contents and GPU address stay, and its next use only makes it resident again. Textures in heaps of textures cannot be evicted on their own (residency is the heap's) and are given up as before, as are idle textures (two minutes and 300 frames unused). No GPU work reaches an evicted texture. The textures a submission's lists name are made resident before they run. The pass leaves the heap slots viewing a texture null before it evicts it, a use makes a texture resident before a view of it is made, and a slot made while a pass picked or evicted its texture is checked once it holds it. If the device refuses to make textures resident, others are evicted first; refused again, the run ends instead of faulting the GPU. Each texture's residency changes together with its device call, under one lock, so the device's count stays 1 or 0. The policy (which textures go, the budget marks, the address-space check) lives in residency.rs with tests that need no GPU, among them every order of passes and uses; GPU tests cover an eviction, a use, a list recorded before the eviction and a heap slot. The first eviction of a run logs the card's use before and after, and if evicting did not lower it, textures are given up from then on. Diagnostics builds take VICTORY_VRAM_BUDGET_MB (a smaller budget) and VICTORY_GIVE_UP_TEXTURES (the old behaviour, for comparing runs).
Past the card's budget the eviction pass gave up (destroyed) the least
recently used host textures fed from title memory, and their next use
made them again from title memory, detiled and uploaded. A committed one
is now evicted instead (ID3D12Device::Evict): its contents and GPU
address stay, and its next use only makes it resident again. Textures in
heaps of textures cannot be evicted on their own (residency is the
heap's) and are given up as before, as are idle textures (two minutes
and 300 frames unused).

No GPU work reaches an evicted texture. The textures a submission's
lists name are made resident before they run. The pass leaves the heap
slots viewing a texture null before it evicts it, a use makes a texture
resident before a view of it is made, and a slot made while a pass
picked or evicted its texture is checked once it holds it. If the device
refuses to make textures resident, others are evicted first; refused
again, the run ends instead of faulting the GPU. Each texture's residency
changes together with its device call, under one lock, so the device's
count stays 1 or 0.

The policy (which textures go, the budget marks, the address-space
check) lives in residency.rs with tests that need no GPU, among them
every order of passes and uses; GPU tests cover an eviction, a use, a
list recorded before the eviction and a heap slot. The first eviction of
a run logs the card's use before and after, and if evicting did not
lower it, textures are given up from then on. Diagnostics builds take
VICTORY_VRAM_BUDGET_MB (a smaller budget) and VICTORY_GIVE_UP_TEXTURES
(the old behaviour, for comparing runs).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01GgVYzJwCz6RmvFNMHeHDWR
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:16:24 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 04:25 UTC · original

Automated triage for the maintainers.

Needs work. This evicts committed host textures past the budget (ID3D12Device::Evict) instead of destroying them, and makes them resident again on next use (residency.rs, Resource::host, HostHeap::check_resident, Host::execute). The design holds together on paper, but it changes GPU resource lifetime and needs evidence from hardware: a title run with VICTORY_VRAM_BUDGET_MB low enough to force evictions, showing the eviction lines, per-frame evict/resident counts, no device removal, and fewer remade textures than with VICTORY_GIVE_UP_TEXTURES=1. Please also say whether GPU work outside Host::execute's lists (copy-queue uploads, present blits) can name a texture when it is evicted, and whether video_memory() right after Evict reliably shows the drop.

CI: passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-26 04:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/2872#issuecomment-7182583489) <!-- victory-triage v1 head=f5497882ca4eef652b1a943258bfbc990882afb2 verdict=needs-work at=2026-11-26T04:25:25Z --> Automated triage for the maintainers. **Needs work.** This evicts committed host textures past the budget (`ID3D12Device::Evict`) instead of destroying them, and makes them resident again on next use (`residency.rs`, `Resource::host`, `HostHeap::check_resident`, `Host::execute`). The design holds together on paper, but it changes GPU resource lifetime and needs evidence from hardware: a title run with `VICTORY_VRAM_BUDGET_MB` low enough to force evictions, showing the eviction lines, per-frame evict/resident counts, no device removal, and fewer remade textures than with `VICTORY_GIVE_UP_TEXTURES=1`. Please also say whether GPU work outside `Host::execute`'s lists (copy-queue uploads, present blits) can name a texture when it is evicted, and whether `video_memory()` right after `Evict` reliably shows the drop. CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 22:53 UTC · original · reviewed

The budget plumbing checks out: check_resident fires exactly where a slot starts holding a texture, the evict-vs-give-up split is env-gated with documented semantics (evicted-and-kept default, given-up under VICTORY_GIVE_UP_TEXTURES), and the README entries match the implementation. Coherent with the #2870 series. LGTM.

**@⁠kotekompotek** on GitHub · 2026-11-25 22:53 UTC · [original](https://github.com/Marvisak/VIctory/pull/2872#pullrequestreview-6066088893) · **reviewed** The budget plumbing checks out: check_resident fires exactly where a slot starts holding a texture, the evict-vs-give-up split is env-gated with documented semantics (evicted-and-kept default, given-up under VICTORY_GIVE_UP_TEXTURES), and the README entries match the implementation. Coherent with the #2870 series. LGTM.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 23:37 UTC · original · reviewed

Verified head f5497882 cleanly merged onto origin/main (63bcca43) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + D3D12 WARP + VICTORY_D3D12_DEBUG=1).

Architecture & Concurrency Audit

  • State machine & D3D12 residency count: Transitions among RESIDENT(0) <-> PICKED(1) -> EVICTED(2) happen under residency::LOCK paired with Evict/MakeResident, keeping device residency counts strictly in {0, 1} (well covered by the exhaustive interleaving test residency_counts_stay_one_or_zero_in_every_order).
  • In-flight & bindless safety: resource::evict_unused() runs under Host::execute's submitted lock after prior GPU work is idle; previously recorded lists referencing evicted textures are made resident by residency::before_running(runs) before ExecuteCommandLists (with make_room retry + host::fail guard); and descriptor::evict clears shader-visible heap slots to null prior to device.Evict so bindless shaders cannot touch evicted resources.
  • Lock ordering: Acyclic — descriptor releases kept and may acquire residency::LOCK under made, while residency calls descriptor::evict and resource::make_room only after releasing residency::LOCK.
  • Minor observation (non-blocking): The one-shot FIRST effectiveness check in residency::evict permanently sets INEFFECTIVE = true if system-wide video_memory() drops by less than bytes / 4 across the first Evict. Concurrent VRAM allocations by another process during that window could trigger a false-positive permanent fallback to drop-on-evict.

Local Verification (VICTORY_D3D12_DEBUG=1)

  • RTX 5090: residency:: 13/13, resource::tests 17/17, descriptor::tests 7/7, draw::tests 20/20, host::tests 30/31 (only the pre-existing dynamic_slots_are_held_until_released 1M view cap baseline).
  • WARP: residency:: 13/13, resource::tests 17/17, host::tests 31/31.
  • cargo clippy --locked -p victory-gpu --all-targets -- -D warnings (default and --features diagnostics) & cargo xtask policy (192 files ok): clean.

Solid design and verification.

**@⁠fuzeofficlal** on GitHub · 2026-11-25 23:37 UTC · [original](https://github.com/Marvisak/VIctory/pull/2872#pullrequestreview-6066499104) · **reviewed** Verified head `f5497882` cleanly merged onto `origin/main` (`63bcca43`) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + D3D12 WARP + `VICTORY_D3D12_DEBUG=1`). ### Architecture & Concurrency Audit - **State machine & D3D12 residency count**: Transitions among `RESIDENT(0) <-> PICKED(1) -> EVICTED(2)` happen under `residency::LOCK` paired with `Evict`/`MakeResident`, keeping device residency counts strictly in `{0, 1}` (well covered by the exhaustive interleaving test `residency_counts_stay_one_or_zero_in_every_order`). - **In-flight & bindless safety**: `resource::evict_unused()` runs under `Host::execute`'s `submitted` lock after prior GPU work is idle; previously recorded lists referencing evicted textures are made resident by `residency::before_running(runs)` before `ExecuteCommandLists` (with `make_room` retry + `host::fail` guard); and `descriptor::evict` clears shader-visible heap slots to null prior to `device.Evict` so bindless shaders cannot touch evicted resources. - **Lock ordering**: Acyclic — `descriptor` releases `kept` and may acquire `residency::LOCK` under `made`, while `residency` calls `descriptor::evict` and `resource::make_room` only after releasing `residency::LOCK`. - **Minor observation (non-blocking)**: The one-shot `FIRST` effectiveness check in `residency::evict` permanently sets `INEFFECTIVE = true` if system-wide `video_memory()` drops by less than `bytes / 4` across the first `Evict`. Concurrent VRAM allocations by another process during that window could trigger a false-positive permanent fallback to drop-on-evict. ### Local Verification (`VICTORY_D3D12_DEBUG=1`) - **RTX 5090**: `residency::` **13/13**, `resource::tests` **17/17**, `descriptor::tests` **7/7**, `draw::tests` **20/20**, `host::tests` **30/31** (only the pre-existing `dynamic_slots_are_held_until_released` 1M view cap baseline). - **WARP**: `residency::` **13/13**, `resource::tests` **17/17**, `host::tests` **31/31**. - `cargo clippy --locked -p victory-gpu --all-targets -- -D warnings` (default and `--features diagnostics`) & `cargo xtask policy` (`192 files ok`): clean. Solid design and verification.
Author
Owner

@⁠potatoe0100 on GitHub · 2026-11-26 14:21 UTC · original

Tested f5497882 merged onto main (63bcca4) on an RTX 4060 8 GB (driver 621.14, Windows 11, Resizable BAR on), which is the kind of card this is for.

  • cargo test -p victory-gpu --lib: 241 passed, 2 failed. The 2 are the known NVIDIA heap-cap failures that main also has on this card (dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views). All 13 residency:: tests pass, including the three device tests.
  • On the triage question about video_memory() after Evict: I wrote a throwaway probe (not part of this PR) that makes 4 x 256 MB default-heap buffers, then evicts them and makes them resident again. Local CurrentUsage went 12 to 1086 MB after creating them, fell straight back to 12 MB on the very next QueryVideoMemoryInfo after Evict (same again 200 ms later), and went back to 1086 MB after MakeResident. So on this NVIDIA driver the drop shows at once. The local budget on this card is 7,537 MB.
  • On GPU work outside Host::execute: queue.rs present gets its planes through resource::host_resource, so Resource::host calls make_resident there. But if that MakeResident is refused, nothing else catches it. present records and runs its own copy list, so before_running never sees those planes, and the blit would read an evicted texture. A make_room and retry there (or not evicting a texture presented in the last few frames) would cover it.

AI-assisted (Claude).

**@⁠potatoe0100** on GitHub · 2026-11-26 14:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/2872#issuecomment-7194693795) Tested `f5497882` merged onto `main` (`63bcca4`) on an RTX 4060 8 GB (driver 621.14, Windows 11, Resizable BAR on), which is the kind of card this is for. - `cargo test -p victory-gpu --lib`: 241 passed, 2 failed. The 2 are the known NVIDIA heap-cap failures that `main` also has on this card (`dynamic_slots_are_held_until_released`, `lists_share_a_table_and_copies_keep_their_views`). All 13 `residency::` tests pass, including the three device tests. - On the triage question about `video_memory()` after `Evict`: I wrote a throwaway probe (not part of this PR) that makes 4 x 256 MB default-heap buffers, then evicts them and makes them resident again. Local `CurrentUsage` went 12 to 1086 MB after creating them, fell straight back to 12 MB on the very next `QueryVideoMemoryInfo` after `Evict` (same again 200 ms later), and went back to 1086 MB after `MakeResident`. So on this NVIDIA driver the drop shows at once. The local budget on this card is 7,537 MB. - On GPU work outside `Host::execute`: `queue.rs` `present` gets its planes through `resource::host_resource`, so `Resource::host` calls `make_resident` there. But if that `MakeResident` is refused, nothing else catches it. `present` records and runs its own copy list, so `before_running` never sees those planes, and the blit would read an evicted texture. A `make_room` and retry there (or not evicting a texture presented in the last few frames) would cover it. AI-assisted (Claude).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
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/2872/head:github-bot/gh-2872'
git switch 'github-bot/gh-2872'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2872'
git switch 'github-bot/gh-2872'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2872'
git switch 'github-bot/gh-2872'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2872'
git switch 'main'
git merge --squash 'github-bot/gh-2872'
git switch 'main'
git merge --ff-only 'github-bot/gh-2872'
git switch 'main'
git merge 'github-bot/gh-2872'
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!2872
No description provided.