Repository navigation
gpu: fence-safe LRU texture eviction and budget-aware mip clamping - #1289
Vladimir-Human wants to merge 3 commits into
Conversation
|
A/B on the RTX 3080 (same build as our #1279 test + #1287/#1002/#1279, boat mission, ~3 min standing): the room problem goes away ( |
|
Follow-up, same build and checkpoint with |
… clamping Ports fxceless/victory-fork#1289 onto VIctory-7900XTX while preserving held_only / HostTexture::base, sharded Made/quick/kept heaps, pool::texture_room(), bury_lag(), and texstore: 1. Fence-safe 2-pass LRU texture eviction (VICTORY_TEXTURE_LRU_EVICT, default on; =0 disables): - Tracks last_used_frame, last_fence_value, and idempotent counted: AtomicBool (HostTexture::uncount()) stamped in Host::submit alongside atomic Host::last_signalled. - Evicts cold, fence-completed (last_fence_value <= completed_fence, Arc::strong_count == 1, COM references == 1) title-filled (fills && !host_wrote) textures under budget pressure (room(), hosted() proactive + OOM retry, evict_if_pressured() under Host::submitted when !behind after joining victory-heap-sync via needs_submit_maintenance()). - Adds HostHeap::evict_kept / descriptor::evict_kept_resources unmaking cold title slots and untaken dynamic slots (clearing quick & made before slot.take(), dropping duplicate COM refs outside locks while Hosted::made retains ref avatarmanz#1 so Pass 2's host::retire handles final destruction, preserving 240-frame TextureQueue::hold_evicted cooldown across texture_slots_room without resurrecting evicted View::Shader textures in make_waiting()). - Adds fence completion check, out-of-lock take_staged, and synchronous host.uncount() to let_go_idle(). 2. Budget-aware mip-tail clamping (VICTORY_TEXTURE_AUTO_MIP_CLAMP, default off; 1/auto clamps <=2048 on <=12 GiB and <=1024 on <=8 GiB or >=85% pressure; numeric >=4 sets explicit max dim): - Composes cleanly with held_only (base = held_base.max(clamp)), fixes ResourceDesc::from_level to use mip_count(self), keeps want_level from thrashing past clamped_mip, upgrades SRV shifting (adjust_srv_for_base_mip) for both Texture2D and Texture2DArray, validates Staging (serial, on_demand, level0, mips, host_width, host_height) without downgrading or missing BC tail/NPOT footprints, and wires ensure_unclamped + ABA-safe PendingUnclamp deferred SRV rebinding on explicit GPU copies/resolves. 3. Tightened VRAM pressure policy: - Tightens host::vram_keep curve (<78% -> 600s, 78..85% -> 30s toward 75%, 85..90% -> 3s toward 82%, >=90% -> 1s toward 82%). - Gates default descriptor::host::keep_shown() on side-effect-free room_raw_lately() so replaced stale textures stop pinning descriptor COM refs under VRAM pressure while preserving explicit VICTORY_KEEP_SHOWN overrides and Kin::Same. # Conflicts: # crates/victory-gpu/src/host.rs
…RY_TEXTURE_LRU_HEAP_EVICT=1 HostList::stamp_textures only stamps textures tracked in HostList::states (barriers), not bindless textures bound once into shader-visible HostHeap::kept and read continuously by shaders. Passing �llow_heap_unmake: true by default in �vict_if_pressured could unmake live shader-visible HostHeap SRVs onto the 240-frame cooldown under VRAM pressure. - Add lru_heap_evict_enabled() gated strictly on opt-in VICTORY_TEXTURE_LRU_HEAP_EVICT=1 (default off) and pass it as �llow_heap_unmake across both passes of �vict_if_pressured(), so default LRU eviction (VICTORY_TEXTURE_LRU_EVICT=1) only reclaims fence-completed idle textures with eferences == 1. - Gate NEED_HEAP_EVICT reads and writes on lru_heap_evict_enabled() and gate hosted()'s proactive eviction pass on lru_evict_enabled(). - Add default_lru_eviction_preserves_live_host_heap_textures_until_opt_in covering �vict_if_pressured() under default off and opt-in =1. Source: fxceless/victory-fork#1289 (4c18c9e)
|
Thanks a ton @Garu667 for running both A/B captures and isolating Root Cause
Fix (
|
4c18c9e to
16a6f8e
Compare
|
Retest of 16a6f8e on the RTX 3080 ( |
Prevent VRAM exhaustion and black texture surfaces on 8-12 GB cards when
title-filled textures accumulate in card memory and descriptor heaps:
1. Fence-safe LRU texture eviction under DXGI budget pressure
(`VICTORY_TEXTURE_LRU_EVICT`, default on, `=0` disables):
- Track `last_used_frame` and `last_fence_value` on `HostTexture`,
stamped at submission in `Host::submit` alongside atomic
`Host::last_signalled`.
- Evict least-recently-used title-filled (`fills && !host_wrote`)
textures in two TOCTOU-safe passes once `last_fence_value <=
completed_fence`, `Arc::strong_count == 1`, and COM `references == 1`,
respecting a 1,000 ms / 2-frame idle guard and dropping staging/COM
objects strictly outside locks.
- Under `Host::submitted` when no submissions are in flight, unmake
cold shader-visible title slots and untaken dynamic table slots via
`descriptor::evict_kept_resources` / `HostHeap::evict_kept` (with
`made_now` cleared first, 240-frame re-queue cooldown preserved
across `texture_slots_room`, and no premature resurrection in
`make_waiting`), transparently re-uploading from host console memory
if sampled again later.
2. Budget-aware mip-tail clamping (`VICTORY_TEXTURE_AUTO_MIP_CLAMP`,
default off; `1`/`auto` clamps <= 2048 on <= 12 GiB budgets and
<= 1024 on <= 8 GiB budgets or >= 85% pressure; numeric >= 4 sets an
explicit max dimension):
- Keep title-facing `ResourceDesc`, `footprint()`, and console layouts
unchanged; clamp only eligible single-slice non-MSAA read-only 2D
host D3D12 textures (`mip_levels > 1`, `base <= first_tail_mip`,
BC 4x4 block alignment enforced).
- Offset console mip detiling in `Staging::detile`, validate cached
`Staging` dimensions/mip counts, shift SRV `MostDetailedMip`,
`MipLevels`, and `ResourceMinLODClamp` for `Texture2D`/`Texture2DArray`,
and upgrade cleanly via `ensure_unclamped` + deferred SRV rebinding
on explicit GPU copies/resolves.
…U_HEAP_EVICT=1 `HostList::stamp_textures` only stamps textures tracked in `HostList::states` (barriers), not bindless textures bound once into shader-visible `HostHeap::kept` and read continuously by shaders. Enabling `allow_heap_unmake: true` by default in `evict_if_pressured` evicted live shader-visible `HostHeap` SRVs onto the 240-frame cooldown under VRAM pressure. - Add `lru_heap_evict_enabled()` gated strictly on opt-in `VICTORY_TEXTURE_LRU_HEAP_EVICT=1` (default off) and pass it as `allow_heap_unmake` in `evict_if_pressured()`, so default LRU eviction (`VICTORY_TEXTURE_LRU_EVICT=1`) only reclaims fence-completed idle textures with `references == 1` (never pinned in a live `HostHeap`). - Gate `NEED_HEAP_EVICT` reads and writes on `lru_heap_evict_enabled()` and gate `hosted()`'s proactive eviction pass on `lru_evict_enabled()`. - Call `host.uncount()` synchronously in `flush_unclamped_rebinds()` and drain `VICTORY_REAPER=1` via `flush_reaper_for_test()` in unit tests. - Add `default_lru_eviction_preserves_live_host_heap_textures_until_opt_in` covering `evict_if_pressured()` under default off and opt-in `=1`.
16a6f8e to
42fdddc
Compare
…RY_TEXTURE_LRU_HEAP_EVICT=1 HostList::stamp_textures only stamps textures tracked in HostList::states (barriers), not bindless textures bound once into shader-visible HostHeap::kept and read continuously by shaders. Passing �llow_heap_unmake: true by default in �vict_if_pressured could unmake live shader-visible HostHeap SRVs onto the 240-frame cooldown under VRAM pressure. - Add lru_heap_evict_enabled() gated strictly on opt-in VICTORY_TEXTURE_LRU_HEAP_EVICT=1 (default off) and pass it as �llow_heap_unmake across both passes of �vict_if_pressured(), so default LRU eviction (VICTORY_TEXTURE_LRU_EVICT=1) only reclaims fence-completed idle textures with eferences == 1. - Gate NEED_HEAP_EVICT reads and writes on lru_heap_evict_enabled() and gate hosted()'s proactive eviction pass on lru_evict_enabled(). - Add default_lru_eviction_preserves_live_host_heap_textures_until_opt_in covering �vict_if_pressured() under default off and opt-in =1. Source: fxceless/victory-fork#1289 (4c18c9e)
|
Updated 1. Tier 2 (default ON, zero-corruption superseded-view yield)When 2. Tier 3 (opt-in
|
…RY_TEXTURE_LRU_HEAP_EVICT=1 HostList::stamp_textures only stamps textures tracked in HostList::states (barriers), not bindless textures bound once into shader-visible HostHeap::kept and read continuously by shaders. Passing �llow_heap_unmake: true by default in �vict_if_pressured could unmake live shader-visible HostHeap SRVs onto the 240-frame cooldown under VRAM pressure. - Add lru_heap_evict_enabled() gated strictly on opt-in VICTORY_TEXTURE_LRU_HEAP_EVICT=1 (default off) and pass it as �llow_heap_unmake across both passes of �vict_if_pressured(), so default LRU eviction (VICTORY_TEXTURE_LRU_EVICT=1) only reclaims fence-completed idle textures with eferences == 1. - Gate NEED_HEAP_EVICT reads and writes on lru_heap_evict_enabled() and gate hosted()'s proactive eviction pass on lru_evict_enabled(). - Add default_lru_eviction_preserves_live_host_heap_textures_until_opt_in covering �vict_if_pressured() under default off and opt-in =1. Source: fxceless/victory-fork#1289 (4c18c9e)
Summary
Addresses VRAM exhaustion ("no room on the card" -> refused texture uploads and black surfaces, plus streaming frame-time spikes) on 8–12 GB VRAM GPUs without overlapping #45 (
draw.rsis untouched):Fence-safe LRU placed/committed texture eviction under DXGI budget pressure (
VICTORY_TEXTURE_LRU_EVICT, default on;=0disables):last_used_frameandlast_fence_valueonHostTexture, stamped beforeExecuteCommandListsinHost::submitalongsideHost::last_signalled.evict_lru_textures_with) over title-filled (fills && !host_wrote) textures when hitting the VRAM budget cap or OOM, requiringlast_fence_value <= completed_fence,Arc::strong_count == 1, COMreferences == 1(by default never pinned in any live shader-visibleHostHeap::keptslot), and a 1,000 ms / 2-frame idle window. All staging and COM references are released outside locks, andHOST_TEXTURES/KINDS/MIP_CLAMP_STATSupdate synchronously even underVICTORY_REAPER=1.VICTORY_TEXTURE_LRU_HEAP_EVICT=1, default off so bindless textures bound once into shader-visibleHostHeapslots and read continuously by shaders are never evicted by default): underHost::submittedwhen no GPU submissions are in flight (evict_if_pressured), safely unmakes cold shader-visible title heap slots and untaken dynamic descriptor-table slots (descriptor::evict_kept_resources/HostHeap::evict_kept), preserving a 240-frame anti-thrash cooldown acrosstexture_slots_roomand transparently re-creating + re-uploading from host console memory if drawn again later.Budget-aware mip-tail clamping (
VICTORY_TEXTURE_AUTO_MIP_CLAMP, default off — unchanged unless enabled):VICTORY_TEXTURE_AUTO_MIP_CLAMP=1(auto): clamps eligible large mip-chained read-only 2D textures to<= 2048on8 GiB < budget <= 12 GiB(< 85%pressure) and<= 1024onbudget <= 8 GiBor>= 85%effective budget pressure (leaving> 12 GiBcards with headroom unclamped). Passing an explicit dimension (>= 4, e.g.1024or2048) enforces that cap directly.ResourceDesc,footprint(), and console layouts; clamps only the host D3D12 texture (mip_levels > 1,depth_or_array_size == 1,sample_count <= 1, single-plane non-XOR layout,base <= first_tail_mip, and BC4x4block alignment).Staging::detilebybase_mip, validates cachedStagingshape across upgrades, adjusts explicitTexture2D/Texture2DArraySRVMostDetailedMip/MipLevels/ResourceMinLODClamp, and upgrades cleanly viaensure_unclamped(with deferred SRV rebinding inHost::submit) if touched by an explicit GPU copy or resolve.Verification
cargo clippy -p victory-gpu --all-targets -- -D warnings -A deprecated(default &--features diagnostics): 0 warningscargo test -p victory-gpu --lib -- --test-threads=1: 225 passed, 0 failedcargo test -p victory-gpu --features diagnostics --lib -- --test-threads=1: 244 passed, 0 failedVICTORY_D3D12_DEBUG=1+VICTORY_D3D12_WARP=1+VICTORY_REAPER=1unit & GPU tests covering:VICTORY_TEXTURE_LRU_HEAP_EVICToff (allow_heap_unmake: false): older fence-completed bindless textures held in a live shader-visibleHostHeap(references >= 2) are never unmade or evicted under VRAM pressure (evict_if_pressured), while unreferenced (references == 1) fence-completed idle textures evict cleanlyVICTORY_TEXTURE_LRU_HEAP_EVICT=1(allow_heap_unmake: true) unmakes coldHostHeapand untaken dynamic table slots under budget cap, respects the 240-frame cooldown acrosstexture_slots_room, does not resurrect inmake_waiting(), and transparently detiles/re-uploads updated host bytes on reuse>= 19 MiBmeasuredGetResourceAllocationInfosavings per texture), upload the exact clamped console mips, and upgrade + rebind SRVs cleanly onensure_unclampedcargo run -p xtask -- policy --staged: passed