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

Open
mitaka1959 wants to merge 1 commit from upstream-pr/2872 into main
mitaka1959 commented 2026-11-25 22:51:02 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mitaka1959 on 2026-11-25T22:51:02Z.


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).

<!-- greyfinch-sync:Marvisak/VIctory:issue:6615369322 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2872). Originally posted by [mitaka1959](https://github.com/mitaka1959) on 2026-11-25T22:51:02Z. --- 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).
kotekompotek commented 2026-11-25 23:05:53 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T22:53:13Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:Marvisak/VIctory:review:6066088893 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2872#pullrequestreview-6066088893). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-25T22:53:13Z. **Review:** COMMENTED --- 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.
fuzeofficlal commented 2026-11-26 00:02:55 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T23:37:15Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:Marvisak/VIctory:review:6066499104 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2872#pullrequestreview-6066499104). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T23:37:15Z. **Review:** COMMENTED --- 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.
Marvisak commented 2026-11-26 05:04:09 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T04:25:31Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7182583489 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2872#issuecomment-7182583489). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T04:25:31Z. --- <!-- 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)_
potatoe0100 commented 2026-11-26 15:02:29 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by potatoe0100 on 2026-11-26T14:21:26Z.


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).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7194693795 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2872#issuecomment-7194693795). Originally posted by [potatoe0100](https://github.com/potatoe0100) on 2026-11-26T14:21:26Z. --- 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 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/2872:upstream-pr/2872'
git switch 'upstream-pr/2872'

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/2872'
git switch 'upstream-pr/2872'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2872'
git switch 'upstream-pr/2872'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2872'
git switch 'main'
git merge --squash 'upstream-pr/2872'
git switch 'main'
git merge --ff-only 'upstream-pr/2872'
git switch 'main'
git merge 'upstream-pr/2872'
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!2870
No description provided.