Skip to content

victory-gpu: size-tiered card-buffer headroom and fence-safe LRU demotion - #347

Open
Vladimir-Human wants to merge 1 commit into
LooperSalty:mainfrom
Vladimir-Human:perf/vram-tiered-card-eviction
Open

Vladimir-Human wants to merge 1 commit into
LooperSalty:mainfrom
Vladimir-Human:perf/vram-tiered-card-eviction

Conversation

@Vladimir-Human

Copy link
Copy Markdown

Problem

Ports fxceless/victory-fork#1280 (addressing fxceless/victory-fork#1163 and 8–12 GB VRAM streaming dips):

  • When VICTORY_CARD_BUFFERS_MIN_KB=64 is combined with VICTORY_CARD_BUFFERS_MB=1024 (or smaller caps), thousands of small < 1 MiB buffers fill the flat card-buffer cap first and starve hot >= 1 MiB buffers back to PC RAM.
  • On 8–12 GB GPUs (e.g., RTX 4060/5060 8 GB, RTX 4070 SUPER 12 GB), cold small card buffers stay pinned in VRAM until unregistered and starve streaming texture allocations under DXGI video-memory pressure.

Changes

Preserves all existing AnyXboxX / Neptune features (RwLock BUFFERS + SHAPE/FOUND cache, fold_buffers, transient windowup::Chunk windows, and VICTORY_WINDOW_REBAR) while adding:

  1. Size-tiered headroom reservation (shadow.rs):
    • When VICTORY_CARD_BUFFERS_MIN_KB < 1024, reserves min(256 MiB, cap / 3) (env-tunable via VICTORY_CARD_LARGE_RESERVE_MB; 0 disables) inside VICTORY_CARD_BUFFERS_MB for >= 1 MiB buffers (CardAdmit::ReservedForLarge, incrementing card_reserved_large_rejects).
    • Guards < 1 MiB card admissions above 85% DXGI usage without inflating CARD_REFUSED[1], preserving card_room_kept() for upcoming >= 1 MiB buffers.
  2. Fence-safe LRU < 1 MiB card-buffer demotion (shadow.rs, host.rs, descriptor/host.rs, tiles.rs):
    • Tracks per-shadow LRU (used, access_tick), GPU flight fences (last_fence: AtomicU64, stamped in Host::submit), and UAV/shader write state (Card::gpu_written).
    • Strictly demotes ONLY non-window, non-rebar title buffers with card.staging.is_some() and 0 < card.size < 1 MiB that pass all guards after bumping SHAPE (SeqCst): Arc::strong_count == 1, host::references(&shadow.buffer) == 1, pending.is_empty(), and last_fence <= completed_fence (+ unchanged fence across readback).
    • Triggers on:
      • Hot >= 1 MiB buffer CapFull / DxgiPressure in lookup_tables (exact card_admit_shortfall, skips futile partial demotion, up to 4 bounded 16 MiB batches, re-validates entry.end >= end and recomputes buf_len/size/big after re-acquiring BUFFERS).
      • DXGI local video-memory pressure >= 88% (VICTORY_CARD_PRESSURE_PCT, targeting 84% hysteresis) in Host::sweep, adding freed bytes to CARD_PRESSURE_RELEASED so used + card_room_kept() in resource::room() genuinely drops for streaming textures.
    • Serializes all direct Host::queue operations (ExecuteCommandLists, Signal, UpdateTileMappings) via leaf mutex QUEUE_SUBMIT / host::queue_lock().
    • Uses transient L0 readback staging dropped immediately after each batch (zero pinned idle RAM), resets DemoteCopy on error (closing its Win32 event HANDLE on Drop), and merges every byte outside card.dirty into card.staging before promoting card.staging to shadow.buffer. Opt-out via VICTORY_CARD_DEMOTE=0.
  3. Diagnostics counters (shadow.rs, host.rs):
    • Emits card_demoted_count, card_demoted_bytes, and card_reserved_large_rejects via card_tier_stats() and the periodic card-buffer log line.

Verification

  • VICTORY_D3D12_DEBUG=1 cargo test --manifest-path third_party\victory\Cargo.toml -p victory-gpu vram_tier_tests -- --test-threads=1: 7 passed; 0 failed (0 D3D12 debug errors)
  • cargo test --manifest-path third_party\victory\Cargo.toml -p victory-gpu --features diagnostics --lib vram_tier_tests -- --test-threads=1: 7 passed; 0 failed
  • cargo test --manifest-path third_party\victory\Cargo.toml -p victory-gpu -- shadow --test-threads=1: 40 passed; 0 failed
  • cargo test --manifest-path third_party\victory\Cargo.toml -p victory-gpu -- tiles --test-threads=1: 4 passed; 0 failed; 1 ignored
  • cargo clippy --manifest-path third_party\victory\Cargo.toml -p victory-gpu --all-targets: 0 warnings in added/modified lines
  • cargo run --manifest-path third_party\victory\Cargo.toml -p xtask -- policy: asset policy: 199 files ok

@Skyfrye

Skyfrye commented Nov 26, 2026

Copy link
Copy Markdown

For information: I tried this PR in an integration build on main at 2cc6593 (after #358 and #377), stacked with #354, #345 and my #278, #279, #292, #307, #360-#362, #381 and #382. It no longer applies to main. The conflicts are in what the code does, not just neighbouring lines: host.rs (3: QUEUE_SUBMIT and card_sent_locked around the same Execute/Signal calls #354 changes for its fence stamping), shadow.rs (2: note_access/note_gpu_written next to #377's sanitizer, and the buffer copy's construction). I left it out of that build rather than guess at the merge. A rebase on current main would let it in the next one.

🤖 Generated with Claude Code

@Vladimir-Human
Vladimir-Human force-pushed the perf/vram-tiered-card-eviction branch from 374971e to 00109da Compare November 26, 2026 15:12
@Vladimir-Human

Copy link
Copy Markdown
Author

@Skyfrye Rebased onto current main (26c11d4, post-#358/#377/#367/#383; new head 00109da):

  • shadow.rs: preserved #377 (0b0deab, VICTORY_CLAMP_AFTER_WRITER sanitizer) ahead of note_access()/note_gpu_written() in Shadow::gpu_writes, switched buffer creation to #340's note_carded(&shadow) (Card::me/FLAGGED), and preserved Card::prints alongside the tiered admission / LRU demotion logic.
  • host.rs & tiles.rs: QUEUE_SUBMIT / queue_lock() remains wrapped strictly around direct Host::queue ExecuteCommandLists/Signal/UpdateTileMappings calls (if stacked with #354, fence stamping inside those same ExecuteCommandLists+Signal critical sections can stay inside the existing QUEUE_SUBMIT scope).
  • Verified with cargo xtask policy (214 files ok), cargo clippy -p victory-gpu --lib --tests (0 new warnings), and VICTORY_D3D12_DEBUG=1 victory-gpu --lib (shadow:: 45/45 incl. all vram_tier_tests, tiles:: 3/3; default & diagnostics runs show only the 3 pre-existing main failures in descriptor::host::tests::spans_say_the_next_start_and_the_lowest_level_viewed and indirect::tests::warp_card_*).

…tion

Ports fxceless/victory-fork#1280 (addressing fxceless/victory-fork#1163 and 8-12 GB VRAM starvation) onto AnyXboxX while preserving RwLock BUFFERS/SHAPE/FOUND, fold_buffers, transient windowup chunks, and VICTORY_WINDOW_REBAR:

- Reserves min(256 MiB, cap / 3) (tunable via VICTORY_CARD_LARGE_RESERVE_MB) inside VICTORY_CARD_BUFFERS_MB for >= 1 MiB buffers when VICTORY_CARD_BUFFERS_MIN_KB < 1024, and guards < 1 MiB admissions above 85% DXGI usage without inflating CARD_REFUSED[1].
- Adds fence-safe LRU demotion of cold, fence-completed < 1 MiB card buffers back to host RAM (never touching hot >= 1 MiB buffers, transient/rebar windows, or in-flight/referenced buffers) on large-buffer shortfall (bounded multi-batch, post-reacquire TOCTOU re-validation) and >= 88% DXGI pressure (hysteresis target 84%, surrendering freed bytes via CARD_PRESSURE_RELEASED so resource::room() genuinely gains streaming VRAM headroom).
- Serializes all direct Host::queue operations (ExecuteCommandLists, Signal, UpdateTileMappings) via leaf mutex QUEUE_SUBMIT / host::queue_lock(), uses transient L0 staging dropped after each batch with DemoteCopy reset on error and CloseHandle on drop, preserves all GPU and pending CPU dirty bytes bit-exact, and adds unit + D3D12 WARP tests.
@Vladimir-Human
Vladimir-Human force-pushed the perf/vram-tiered-card-eviction branch from 00109da to 18e7731 Compare November 26, 2026 19:11
@Vladimir-Human

Copy link
Copy Markdown
Author

Rebased onto main (50936c0 -> 18e7731, keeping #429's host::queue_lock() + runs.len() == 1 fast path in tiles.rs).
Verified locally: cargo xtask policy (215 files ok), cargo clippy -p victory-gpu --features diagnostics --all-targets exit 0; tiles:: 7/7 (1 ignored, VICTORY_D3D12_DEBUG unset) and shadow:: 45/45 passed (descriptor:: 30/31 with only upstream spans_say_the_next_start_and_the_lowest_level_viewed failing).

@Vladimir-Human

Copy link
Copy Markdown
Author

Noting that #409 (37d4686) replaced third_party/victory with the combined avatarmanz + cool_fox base, putting this branch in CONFLICTING right after the 50936c0 rebase.
The clean avatarmanz-lineage version is open at avatarmanz/VIctory-7900XTX#180 (and fxceless/victory-fork#1280); happy to re-port onto 37d4686+ once #409 settles if you want it here.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants