victory-gpu: size-tiered card-buffer headroom and fence-safe LRU demotion (#1163) #1280

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

@⁠Vladimir-Human on GitHub · 2026-11-26 10:04 UTC · original
Vladimir-Human:perf/vram-tiered-card-eviction → main · +2069 −149 · 4 files · 1 commits · open

Problem

Closes / addresses #1163 and 8–12 GB VRAM starvation:

  • When VICTORY_CARD_BUFFERS_MIN_KB=64 is combined with VICTORY_CARD_BUFFERS_MB=1024 (or smaller caps such as 512 MiB), thousands of small < 1 MiB buffers fill the flat card-buffer cap first and starve hot >= 1 MiB buffers back to PC RAM (100–122.6 MB/frame CPU compare and severe GPU slowdown).
  • On 8–12 GB GPUs, once cold small buffers occupy VRAM, they remain pinned on the card until unregistered, starving streaming allocations under DXGI video-memory pressure.

Changes

  1. Size-tiered headroom reservation (crates/victory-gpu/src/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 so small-buffer floods cap at cap - reserve (CardAdmit::ReservedForLarge).
    • Guards < 1 MiB card admissions above 85% DXGI local video memory without inflating CARD_REFUSED[1], keeping card_room_kept() intact for upcoming >= 1 MiB buffers.
  2. Fence-safe LRU card-buffer demotion (crates/victory-gpu/src/shadow.rs, host.rs, descriptor/host.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).
    • Safely demotes cold, fence-completed < 1 MiB card buffers back to host RAM (never touching hot >= 1 MiB buffers) when:
      • a >= 1 MiB buffer hits CapFull or DxgiPressure (computes exact shortfall, skips futile partial demotion, runs up to 4 bounded 16 MiB batches, and re-validates entry after re-acquiring BUFFERS), or
      • DXGI local video-memory usage reaches >= 88% (VICTORY_CARD_PRESSURE_PCT, targeting 84% hysteresis) in Host::sweep, recording freed bytes in CARD_PRESSURE_RELEASED so used + card_room_kept() in resource::room() genuinely drops for texture streaming.
    • Strictly verifies Arc::strong_count == 1, host::references(&shadow.buffer) == 1, pending.is_empty(), and last_fence <= completed_fence (+ unchanged fence across readback) after tables_changed().
    • Preserves exact bytes by reading back VRAM via Host::demote_readback (serialized by a narrow leaf QUEUE_SUBMIT mutex, using transient L0 staging dropped immediately after readback, with DemoteCopy reset and Win32 event CloseHandle on drop) and merging all bytes 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

  • Added 7 unit + self-contained D3D12 WARP tests (shadow::vram_tier_tests::*):
    • small_buffer_flood_cannot_starve_large_buffers_with_tiered_reserve
    • dxgi_pressure_target_reclaims_headroom_on_8gb_and_12gb_cards
    • card_room_kept_and_admit_shortfall_preserve_vram_accounting_invariants
    • warp_small_buffer_flood_reserves_headroom_and_demotes_for_large_buffers
    • warp_demotion_preserves_exact_bytes_across_gpu_writes_and_cpu_dirty_ranges
    • warp_demotion_never_evicts_inflight_or_referenced_card_buffers
    • warp_dxgi_8gb_and_12gb_pressure_demotes_cold_small_and_keeps_hot_large
  • VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu vram_tier_tests -- --test-threads=1: 7 passed; 0 failed (0 D3D12 debug errors)
  • cargo test -p victory-gpu -- --test-threads=1: 219 passed; 0 failed; 6 ignored
  • cargo test -p victory-gpu --all-features -- --test-threads=1: 237 passed; 0 failed; 7 ignored
  • cargo clippy -p victory-gpu --all-targets -- -D warnings -A deprecated & --all-features: 0 warnings/errors in modified files (3 pre-existing AtomicU32::fetch_update deprecations in untouched object.rs)
  • cargo run -p xtask -- policy: asset policy: 220 files ok
**@⁠Vladimir-Human** on GitHub · 2026-11-26 10:04 UTC · [original](https://github.com/fxceless/victory-fork/pull/1280) `Vladimir-Human:perf/vram-tiered-card-eviction` → `main` · +2069 −149 · 4 files · 1 commits · open ### Problem Closes / addresses #1163 and 8–12 GB VRAM starvation: - When `VICTORY_CARD_BUFFERS_MIN_KB=64` is combined with `VICTORY_CARD_BUFFERS_MB=1024` (or smaller caps such as `512` MiB), thousands of small `< 1 MiB` buffers fill the flat card-buffer cap first and starve hot `>= 1 MiB` buffers back to PC RAM (`100–122.6 MB/frame` CPU compare and severe GPU slowdown). - On 8–12 GB GPUs, once cold small buffers occupy VRAM, they remain pinned on the card until unregistered, starving streaming allocations under DXGI video-memory pressure. ### Changes 1. **Size-tiered headroom reservation (`crates/victory-gpu/src/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 so small-buffer floods cap at `cap - reserve` (`CardAdmit::ReservedForLarge`). - Guards `< 1 MiB` card admissions above `85%` DXGI local video memory without inflating `CARD_REFUSED[1]`, keeping `card_room_kept()` intact for upcoming `>= 1 MiB` buffers. 2. **Fence-safe LRU card-buffer demotion (`crates/victory-gpu/src/shadow.rs`, `host.rs`, `descriptor/host.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`). - Safely demotes cold, fence-completed `< 1 MiB` card buffers back to host RAM (never touching hot `>= 1 MiB` buffers) when: - a `>= 1 MiB` buffer hits `CapFull` or `DxgiPressure` (computes exact shortfall, skips futile partial demotion, runs up to 4 bounded 16 MiB batches, and re-validates `entry` after re-acquiring `BUFFERS`), or - DXGI local video-memory usage reaches `>= 88%` (`VICTORY_CARD_PRESSURE_PCT`, targeting `84%` hysteresis) in `Host::sweep`, recording freed bytes in `CARD_PRESSURE_RELEASED` so `used + card_room_kept()` in `resource::room()` genuinely drops for texture streaming. - Strictly verifies `Arc::strong_count == 1`, `host::references(&shadow.buffer) == 1`, `pending.is_empty()`, and `last_fence <= completed_fence` (+ unchanged fence across readback) after `tables_changed()`. - Preserves exact bytes by reading back VRAM via `Host::demote_readback` (serialized by a narrow leaf `QUEUE_SUBMIT` mutex, using transient L0 staging dropped immediately after readback, with `DemoteCopy` reset and Win32 event `CloseHandle` on drop) and merging all bytes 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 - Added 7 unit + self-contained D3D12 WARP tests (`shadow::vram_tier_tests::*`): - `small_buffer_flood_cannot_starve_large_buffers_with_tiered_reserve` - `dxgi_pressure_target_reclaims_headroom_on_8gb_and_12gb_cards` - `card_room_kept_and_admit_shortfall_preserve_vram_accounting_invariants` - `warp_small_buffer_flood_reserves_headroom_and_demotes_for_large_buffers` - `warp_demotion_preserves_exact_bytes_across_gpu_writes_and_cpu_dirty_ranges` - `warp_demotion_never_evicts_inflight_or_referenced_card_buffers` - `warp_dxgi_8gb_and_12gb_pressure_demotes_cold_small_and_keeps_hot_large` - `VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu vram_tier_tests -- --test-threads=1`: **7 passed; 0 failed** (0 D3D12 debug errors) - `cargo test -p victory-gpu -- --test-threads=1`: **219 passed; 0 failed; 6 ignored** - `cargo test -p victory-gpu --all-features -- --test-threads=1`: **237 passed; 0 failed; 7 ignored** - `cargo clippy -p victory-gpu --all-targets -- -D warnings -A deprecated` & `--all-features`: **0 warnings/errors** in modified files (3 pre-existing `AtomicU32::fetch_update` deprecations in untouched `object.rs`) - `cargo run -p xtask -- policy`: `asset policy: 220 files ok`
Addresses #1163 and 8-12 GB VRAM starvation:
- 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 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() gains streaming VRAM headroom).
- Serializes all direct Host::queue operations (ExecuteCommandLists, Signal, UpdateTileMappings via host::queue_lock() in strict Tiled::given -> QUEUE_SUBMIT leaf order) against concurrent card-demotion readbacks, 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, emits card_demoted_count / card_demoted_bytes / card_reserved_large_rejects diagnostics, and adds unit + D3D12 WARP tests.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 11:19:44 +00:00
Author
Owner

@⁠Vladimir-Human on GitHub · 2026-11-26 11:01 UTC · original

Rebased cleanly onto latest main (06702fe, commit 9418259) and added one safety hardening fix:

  • tiles.rs UpdateTileMappings serialization: exposed host::queue_lock() (narrow leaf mutex QUEUE_SUBMIT, strict Tiled::given -> QUEUE_SUBMIT ordering) and held it around queue.UpdateTileMappings(...) in Tiled::give_locked so every direct Host::queue operation (ExecuteCommandLists, Signal, Wait, UpdateTileMappings) is serialized against concurrent card-demotion readbacks.

Re-verified on 06702fe

  • cargo run -p xtask -- policy: asset policy: 220 files ok
  • cargo clippy -p victory-gpu --all-targets -- -D warnings -A deprecated (default & --all-features): 0 warnings
  • VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --lib vram_tier_tests -- --test-threads=1: 7 passed; 0 failed (0 D3D12 debug errors)
  • cargo test -p victory-gpu -- tiles --test-threads=1: 4 passed; 0 failed; 1 ignored
  • cargo test -p victory-gpu -- --test-threads=1: 220 passed; 0 failed; 6 ignored
  • cargo test -p victory-gpu --all-features -- --test-threads=1: 239 passed; 0 failed; 7 ignored
**@⁠Vladimir-Human** on GitHub · 2026-11-26 11:01 UTC · [original](https://github.com/fxceless/victory-fork/pull/1280#issuecomment-7190154813) Rebased cleanly onto latest `main` (`06702fe`, commit `9418259`) and added one safety hardening fix: - **`tiles.rs` `UpdateTileMappings` serialization:** exposed `host::queue_lock()` (narrow leaf mutex `QUEUE_SUBMIT`, strict `Tiled::given -> QUEUE_SUBMIT` ordering) and held it around `queue.UpdateTileMappings(...)` in `Tiled::give_locked` so every direct `Host::queue` operation (`ExecuteCommandLists`, `Signal`, `Wait`, `UpdateTileMappings`) is serialized against concurrent card-demotion readbacks. ### Re-verified on `06702fe` - `cargo run -p xtask -- policy`: `asset policy: 220 files ok` - `cargo clippy -p victory-gpu --all-targets -- -D warnings -A deprecated` (default & `--all-features`): 0 warnings - `VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --lib vram_tier_tests -- --test-threads=1`: **7 passed; 0 failed** (0 D3D12 debug errors) - `cargo test -p victory-gpu -- tiles --test-threads=1`: **4 passed; 0 failed; 1 ignored** - `cargo test -p victory-gpu -- --test-threads=1`: **220 passed; 0 failed; 6 ignored** - `cargo test -p victory-gpu --all-features -- --test-threads=1`: **239 passed; 0 failed; 7 ignored**
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/1280/head:github-bot/gh-1280'
git switch 'github-bot/gh-1280'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1280'
git switch 'github-bot/gh-1280'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1280'
git switch 'github-bot/gh-1280'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1280'
git switch 'main'
git merge --squash 'github-bot/gh-1280'
git switch 'main'
git merge --ff-only 'github-bot/gh-1280'
git switch 'main'
git merge 'github-bot/gh-1280'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.