GPU: evict cold unpinned textures under DXGI local VRAM budget pressure #2878

Closed
mitaka1959 wants to merge 3 commits from upstream-pr/2880 into main
mitaka1959 commented 2026-11-25 22:59:32 +00:00 (Migrated from github.com)

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


What

When the card goes over budget, the eviction pass used to give up (destroy) the least recently used host textures fed from title memory. At their next use they were made again from title memory: detiled and uploaded again.

Now a committed texture past the budget is evicted with ID3D12Device::Evict and kept. Its contents and GPU address stay. Its next use only calls MakeResident: a copy back if the system paged it out, nothing otherwise. Large textures, the most expensive to rebuild, are the committed ones.

Unchanged:

  • Textures in heaps of textures (placement.rs) are given up as before. D3D12 changes residency only for heaps and committed resources, not for single placed resources.
  • Idle textures (two minutes and 300 frames unused) are still given up.
  • The budget marks (90 % / 85 %) and the LRU order are the same.

How no GPU work reaches an evicted texture

  • Lists: before a submission runs, the evicted textures its lists name (HostList states) are made resident in one call (residency::before_running).
  • Heap slots (shaders pick views from the heap themselves):
    • The pass leaves every slot viewing a texture null before it evicts it, as giving up already did.
    • A use (Resource::host) makes the texture resident before a view of it is made.
    • A slot made while a pass picked or evicted its texture is checked once it holds it (HostHeap::check_resident, in mirror and make_at). That covers descriptor-array entries a list never names.
  • No room: if the device refuses MakeResident, other textures are evicted first, least recently used and none the submission uses, then it asks once more. Refused again, the run ends with a crash report instead of a GPU fault.
  • Device count: each texture's residency changes together with its device call under one lock, so the D3D12 residency count stays 1 or 0.
  • Self-check: the first eviction of a run logs the card's use before and after. If evicting did not lower it, textures are given up from then on, as before. Eviction is also off where the GPU's address space per process is not much larger than the budget (MakeResident docs).

Code

  • New crates/victory-gpu/src/residency.rs:
    • Pure policy: plan replaces resource::choose. Also the budget marks, the budget override and the address-space check.
    • The residency state machine.
    • The D3D12 calls.
  • resource.rs:
    • HostTexture gains a residency field.
    • evict_among runs one walk of the heaps for textures given up and evicted together.
    • give_up is split; its giving-up part is now let_go.
    • New make_room for the refusal path.
  • host.rs: before_running is called in execute before ExecuteCommandLists.
  • Logs: a line beside the frame-rate report, only when evictions happened.
  • Diagnostics builds:
    • VICTORY_VRAM_BUDGET_MB=<n>: a smaller budget, to simulate a smaller card on a larger one.
    • VICTORY_GIVE_UP_TEXTURES=1: the old behaviour, for A/B runs.
    • Both are added to the README's debugging table.

Not included, possible follow-ups:

  • Evicting whole heaps of textures whose textures all went cold. Most streamed textures live there.
  • Evicting host-written textures, which today can never be let go of.

Testing

  • cargo clippy --workspace --all-targets with and without --all-features, -D warnings, for x86_64-pc-windows-msvc: clean.
  • cargo xtask policy: ok.
  • Policy tests that need no GPU (residency::tests, 10): pass. Among them:
    • Every order of two eviction passes and two uses, with every device refusal. It checks that the residency count stays 1 or 0 and that each step does its part.
    • The old choose test, ported to plan.
    • Seven bugs planted on purpose were each caught.
  • GPU tests (residency::device_tests: an eviction and a use, a list recorded before the eviction, a heap slot) and a run in the world: TODO before merge (cargo test -p victory-gpu --lib residency).
  • Suggested run: a diagnostics build into the world with VICTORY_VRAM_BUDGET_MB=8192, checking the first host textures evicted past the budget line and the evicted / made-resident-again counts, compared with VICTORY_GIVE_UP_TEXTURES=1.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6615487697 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2880). Originally posted by [mitaka1959](https://github.com/mitaka1959) on 2026-11-25T22:59:32Z. --- ## What When the card goes over budget, the eviction pass used to give up (destroy) the least recently used host textures fed from title memory. At their next use they were made again from title memory: detiled and uploaded again. Now a **committed** texture past the budget is evicted with `ID3D12Device::Evict` and kept. Its contents and GPU address stay. Its next use only calls `MakeResident`: a copy back if the system paged it out, nothing otherwise. Large textures, the most expensive to rebuild, are the committed ones. Unchanged: - Textures in heaps of textures (`placement.rs`) are given up as before. D3D12 changes residency only for heaps and committed resources, not for single placed resources. - Idle textures (two minutes and 300 frames unused) are still given up. - The budget marks (90 % / 85 %) and the LRU order are the same. ## How no GPU work reaches an evicted texture - **Lists:** before a submission runs, the evicted textures its lists name (`HostList` states) are made resident in one call (`residency::before_running`). - **Heap slots** (shaders pick views from the heap themselves): - The pass leaves every slot viewing a texture null before it evicts it, as giving up already did. - A use (`Resource::host`) makes the texture resident before a view of it is made. - A slot made while a pass picked or evicted its texture is checked once it holds it (`HostHeap::check_resident`, in `mirror` and `make_at`). That covers descriptor-array entries a list never names. - **No room:** if the device refuses `MakeResident`, other textures are evicted first, least recently used and none the submission uses, then it asks once more. Refused again, the run ends with a crash report instead of a GPU fault. - **Device count:** each texture's residency changes together with its device call under one lock, so the D3D12 residency count stays 1 or 0. - **Self-check:** the first eviction of a run logs the card's use before and after. If evicting did not lower it, textures are given up from then on, as before. Eviction is also off where the GPU's address space per process is not much larger than the budget (`MakeResident` docs). ## Code - **New `crates/victory-gpu/src/residency.rs`:** - Pure policy: `plan` replaces `resource::choose`. Also the budget marks, the budget override and the address-space check. - The residency state machine. - The D3D12 calls. - **`resource.rs`:** - `HostTexture` gains a `residency` field. - `evict_among` runs one walk of the heaps for textures given up and evicted together. - `give_up` is split; its giving-up part is now `let_go`. - New `make_room` for the refusal path. - **`host.rs`:** `before_running` is called in `execute` before `ExecuteCommandLists`. - **Logs:** a line beside the frame-rate report, only when evictions happened. - **Diagnostics builds:** - `VICTORY_VRAM_BUDGET_MB=<n>`: a smaller budget, to simulate a smaller card on a larger one. - `VICTORY_GIVE_UP_TEXTURES=1`: the old behaviour, for A/B runs. - Both are added to the README's debugging table. Not included, possible follow-ups: - Evicting whole heaps of textures whose textures all went cold. Most streamed textures live there. - Evicting host-written textures, which today can never be let go of. ## Testing - `cargo clippy --workspace --all-targets` with and without `--all-features`, `-D warnings`, for `x86_64-pc-windows-msvc`: clean. - `cargo xtask policy`: ok. - Policy tests that need no GPU (`residency::tests`, 10): pass. Among them: - Every order of two eviction passes and two uses, with every device refusal. It checks that the residency count stays 1 or 0 and that each step does its part. - The old `choose` test, ported to `plan`. - Seven bugs planted on purpose were each caught. - GPU tests (`residency::device_tests`: an eviction and a use, a list recorded before the eviction, a heap slot) and a run in the world: **TODO before merge** (`cargo test -p victory-gpu --lib residency`). - Suggested run: a diagnostics build into the world with `VICTORY_VRAM_BUDGET_MB=8192`, checking the `first host textures evicted past the budget` line and the evicted / made-resident-again counts, compared with `VICTORY_GIVE_UP_TEXTURES=1`.
upstream-sync closed this pull request 2026-11-25 23:05:55 +00:00

Pull request closed

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!2878
No description provided.