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

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

@⁠Vladimir-Human on GitHub · 2026-11-26 10:34 UTC · original
Vladimir-Human:perf/vram-tiered-card-eviction → main · +2063 −174 · 7 files · 1 commits · open

Summary

Ports size-tiered card-buffer headroom reservation and fence-safe LRU demotion of cold small (< 1 MiB) card buffers from fxceless/victory-fork#1280 (originally #1163) onto avatarmanz/VIctory-7900XTX, while preserving all existing VIctory-7900XTX card-buffer and queue features.

Motivation

When VICTORY_CARD_BUFFERS_MIN_KB < 1024 (e.g. 64 KiB) is used, a burst of small (< 1 MiB) card buffers can fill VICTORY_CARD_BUFFERS_MB or push DXGI local video memory above the admission threshold before large hot (>= 1 MiB) vertex/storage buffers arrive, forcing large buffers back to host RAM or causing VRAM pressure spikes on 8–12 GB GPUs.

Key Changes

  1. Size-tiered headroom reservation (crates/victory-gpu/src/shadow.rs)
    • When min_bytes < 1 MiB, reserves min(256 MiB, cap / 3) inside VICTORY_CARD_BUFFERS_MB (overridable via VICTORY_CARD_LARGE_RESERVE_MB) exclusively for >= 1 MiB buffers (CardAdmit::ReservedForLarge, tracked by card_reserved_large_rejects).
    • Guards < 1 MiB card admissions at 85% DXGI local video-memory usage without incrementing CARD_REFUSED[1], so card_room_kept() remains intact for >= 1 MiB buffers.
    • Tracks CARD_PRESSURE_RELEASED and subtracts it in card_room_kept_for(...) so DXGI-pressure demotions genuinely release headroom back to resource::room().
  2. Fence-safe LRU demotion of cold < 1 MiB card buffers (crates/victory-gpu/src/shadow.rs, host.rs, host/upq.rs, host/upcheck.rs, tiles.rs, descriptor/host.rs)
    • Demotes cold, fence-completed < 1 MiB card buffers (Arc::strong_count == 1, host::references == 1, pending.is_empty(), last_fence <= completed_fence) back to host RAM in place by reusing card.staging — never evicting >= 1 MiB buffers, in-flight buffers, or descriptor-referenced buffers.
    • Phase 1 (fast, no GPU wait) demotes buffers untouched by GPU work; Phase 2 batches GPU readbacks (DemoteCopy, up to 16 MiB per batch, transient L0 staging dropped immediately after each batch, *slot = None reset on error, Drop closing its Win32 event HANDLE) and merges GPU-written bytes strictly outside card.dirty for bit-exact preservation.
    • Serializes all direct runtime Host::queue operations (ExecuteCommandLists, Signal, Wait, UpdateTileMappings) across Host::submit (late and sync), card_before, card_land (QUEUE_ORDER -> QUEUE_SUBMIT), card_back, demote_readback, upq::send, upcheck::run, and tiles::Tiled via the narrow leaf mutex QUEUE_SUBMIT (host::queue_lock()), always released before any fence wait.
    • Marks submitted shadows via note_submitted_shadows on both submit paths, marks UAV-bound buffers via shadow.note_gpu_written() in descriptor::host::buffer_uav, and re-validates entry.end / buf_len / size / big / existing shadow in lookup() after re-acquiring buffers() across bounded multi-batch demotion (DEMOTE_MAX_PASSES, cap_shortfall.max(dxgi_shortfall)).
    • Emits card_demoted_count, card_demoted_bytes, and card_reserved_large_rejects in the Meter card-buffer log line.
    • Opt-out / tuning env vars: VICTORY_CARD_LARGE_RESERVE_MB, VICTORY_CARD_DEMOTE=0, VICTORY_CARD_PRESSURE_PCT (default 88).
  3. Preserved VIctory-7900XTX behavior
    • Keeps VRAM-scaled default_card_limits_mb / resolve_card_limits / card_limits, the SEEN = 1 GiB cap in card_room_kept(), VICTORY_CARD_ALL=1 PC-RAM two-sided fallback (counted: false, in_pc_ram: true), crate::port::place_for and crate::inplace::place_for, BUFFERS_CHANGED invalidation, and card_before 1-barrier-per-buffer coalescing.

Verification

  • cargo test -p victory-gpu -- --test-threads=1: 376 passed; 0 failed; 34 ignored (includes existing window_tests::card_limits_scale_with_local_vram_budget and all 7 new shadow::vram_tier_tests::*).
  • VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --lib vram_tier_tests -- --test-threads=1: 7 passed; 0 failed (0 D3D12 debug layer errors/warnings on WARP).
  • cargo test -p victory-gpu --features diagnostics --lib vram_tier_tests -- --test-threads=1: 7 passed; 0 failed.
  • cargo test -p victory-gpu --lib tiles -- --test-threads=1: 4 passed; 0 failed; 1 ignored.
  • cargo clippy -p victory-gpu --all-targets -- -A deprecated: 0 warnings in touched files.
  • git diff --check & git merge-tree --write-tree origin/main HEAD: clean.

Credits

Ported from fxceless/victory-fork#1280 (#1163).

**@⁠Vladimir-Human** on GitHub · 2026-11-26 10:34 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/180) `Vladimir-Human:perf/vram-tiered-card-eviction` → `main` · +2063 −174 · 7 files · 1 commits · open ## Summary Ports size-tiered card-buffer headroom reservation and fence-safe LRU demotion of cold small (`< 1 MiB`) card buffers from [`fxceless/victory-fork#1280`](https://github.com/fxceless/victory-fork/pull/1280) (originally [`#1163`](https://github.com/fxceless/victory-fork/pull/1163)) onto `avatarmanz/VIctory-7900XTX`, while preserving all existing `VIctory-7900XTX` card-buffer and queue features. ### Motivation When `VICTORY_CARD_BUFFERS_MIN_KB < 1024` (e.g. `64` KiB) is used, a burst of small (`< 1 MiB`) card buffers can fill `VICTORY_CARD_BUFFERS_MB` or push DXGI local video memory above the admission threshold before large hot (`>= 1 MiB`) vertex/storage buffers arrive, forcing large buffers back to host RAM or causing VRAM pressure spikes on 8–12 GB GPUs. ### Key Changes 1. **Size-tiered headroom reservation (`crates/victory-gpu/src/shadow.rs`)** - When `min_bytes < 1 MiB`, reserves `min(256 MiB, cap / 3)` inside `VICTORY_CARD_BUFFERS_MB` (overridable via `VICTORY_CARD_LARGE_RESERVE_MB`) exclusively for `>= 1 MiB` buffers (`CardAdmit::ReservedForLarge`, tracked by `card_reserved_large_rejects`). - Guards `< 1 MiB` card admissions at `85%` DXGI local video-memory usage without incrementing `CARD_REFUSED[1]`, so `card_room_kept()` remains intact for `>= 1 MiB` buffers. - Tracks `CARD_PRESSURE_RELEASED` and subtracts it in `card_room_kept_for(...)` so DXGI-pressure demotions genuinely release headroom back to `resource::room()`. 2. **Fence-safe LRU demotion of cold `< 1 MiB` card buffers (`crates/victory-gpu/src/shadow.rs`, `host.rs`, `host/upq.rs`, `host/upcheck.rs`, `tiles.rs`, `descriptor/host.rs`)** - Demotes cold, fence-completed `< 1 MiB` card buffers (`Arc::strong_count == 1`, `host::references == 1`, `pending.is_empty()`, `last_fence <= completed_fence`) back to host RAM in place by reusing `card.staging` — never evicting `>= 1 MiB` buffers, in-flight buffers, or descriptor-referenced buffers. - Phase 1 (fast, no GPU wait) demotes buffers untouched by GPU work; Phase 2 batches GPU readbacks (`DemoteCopy`, up to `16 MiB` per batch, transient L0 staging dropped immediately after each batch, `*slot = None` reset on error, `Drop` closing its Win32 event `HANDLE`) and merges GPU-written bytes strictly outside `card.dirty` for bit-exact preservation. - Serializes all direct runtime `Host::queue` operations (`ExecuteCommandLists`, `Signal`, `Wait`, `UpdateTileMappings`) across `Host::submit` (`late` and sync), `card_before`, `card_land` (`QUEUE_ORDER -> QUEUE_SUBMIT`), `card_back`, `demote_readback`, `upq::send`, `upcheck::run`, and `tiles::Tiled` via the narrow leaf mutex `QUEUE_SUBMIT` (`host::queue_lock()`), always released before any fence wait. - Marks submitted shadows via `note_submitted_shadows` on both `submit` paths, marks UAV-bound buffers via `shadow.note_gpu_written()` in `descriptor::host::buffer_uav`, and re-validates `entry.end` / `buf_len` / `size` / `big` / existing shadow in `lookup()` after re-acquiring `buffers()` across bounded multi-batch demotion (`DEMOTE_MAX_PASSES`, `cap_shortfall.max(dxgi_shortfall)`). - Emits `card_demoted_count`, `card_demoted_bytes`, and `card_reserved_large_rejects` in the `Meter` card-buffer log line. - Opt-out / tuning env vars: `VICTORY_CARD_LARGE_RESERVE_MB`, `VICTORY_CARD_DEMOTE=0`, `VICTORY_CARD_PRESSURE_PCT` (default `88`). 3. **Preserved `VIctory-7900XTX` behavior** - Keeps VRAM-scaled `default_card_limits_mb` / `resolve_card_limits` / `card_limits`, the `SEEN = 1 GiB` cap in `card_room_kept()`, `VICTORY_CARD_ALL=1` PC-RAM two-sided fallback (`counted: false, in_pc_ram: true`), `crate::port::place_for` and `crate::inplace::place_for`, `BUFFERS_CHANGED` invalidation, and `card_before` 1-barrier-per-buffer coalescing. ### Verification - `cargo test -p victory-gpu -- --test-threads=1`: **376 passed; 0 failed; 34 ignored** (includes existing `window_tests::card_limits_scale_with_local_vram_budget` and all 7 new `shadow::vram_tier_tests::*`). - `VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --lib vram_tier_tests -- --test-threads=1`: **7 passed; 0 failed** (0 D3D12 debug layer errors/warnings on WARP). - `cargo test -p victory-gpu --features diagnostics --lib vram_tier_tests -- --test-threads=1`: **7 passed; 0 failed**. - `cargo test -p victory-gpu --lib tiles -- --test-threads=1`: **4 passed; 0 failed; 1 ignored**. - `cargo clippy -p victory-gpu --all-targets -- -A deprecated`: **0 warnings** in touched files. - `git diff --check` & `git merge-tree --write-tree origin/main HEAD`: clean. ### Credits Ported from [`fxceless/victory-fork#1280`](https://github.com/fxceless/victory-fork/pull/1280) (`#1163`).
Ported from fxceless/victory-fork#1280 (#1163) while preserving VIctory-7900XTX VRAM-scaled card limits, SEEN 1 GiB card_room_kept cap, VICTORY_CARD_ALL=1 fallback, port/inplace placement, and card_before barrier coalescing.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 11:21:52 +00:00
github-bot force-pushed github-bot/gh-180 from 31991d8b41 to 4cc03c8856 2026-11-27 07:17:56 +00:00 Compare
Author
Owner

@⁠Vladimir-Human on GitHub · 2026-11-27 07:17 UTC · original

Rebased cleanly onto latest main (014d52d) at 4cc03c8:

  • shadow.rs: Resolved the single conflict by preserving upstream BY_ADDRESS_CARD_BYTES and vram_breakdown() alongside CARD_PRESSURE_RELEASED and the tiered admission/demotion state.
  • host.rs (522,026 B < 512 KiB) & host/demote.rs: Extracted DemoteCopy / demote_readback_run / demote_readback_host into crates/victory-gpu/src/host/demote.rs to keep host.rs < 512 KiB, and verified all runtime Host::queue operations hold QUEUE_SUBMIT (queue_lock()).
  • Verification (VICTORY_D3D12_DEBUG=1 VICTORY_REAPER=1): xtask policy 273 files ok; clippy -p victory-gpu --all-targets -- -A deprecated (default & diagnostics) 0 warnings in touched files; default HW shadow:: tiles:: descriptor:: resource:: texture:: 110 passed; 0 failed; 5 ignored; WARP diagnostics vram_tier_tests tiles:: 10 passed; 0 failed; 1 ignored.
**@⁠Vladimir-Human** on GitHub · 2026-11-27 07:17 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/180#issuecomment-7212326750) Rebased cleanly onto latest `main` (`014d52d`) at `4cc03c8`: - **`shadow.rs`:** Resolved the single conflict by preserving upstream `BY_ADDRESS_CARD_BYTES` and `vram_breakdown()` alongside `CARD_PRESSURE_RELEASED` and the tiered admission/demotion state. - **`host.rs` (`522,026 B < 512 KiB`) & `host/demote.rs`:** Extracted `DemoteCopy` / `demote_readback_run` / `demote_readback_host` into `crates/victory-gpu/src/host/demote.rs` to keep `host.rs < 512 KiB`, and verified all runtime `Host::queue` operations hold `QUEUE_SUBMIT` (`queue_lock()`). - **Verification (`VICTORY_D3D12_DEBUG=1 VICTORY_REAPER=1`):** `xtask policy` `273 files ok`; `clippy -p victory-gpu --all-targets -- -A deprecated` (default & `diagnostics`) **0 warnings in touched files**; default HW `shadow:: tiles:: descriptor:: resource:: texture::` **110 passed; 0 failed; 5 ignored**; WARP `diagnostics` `vram_tier_tests tiles::` **10 passed; 0 failed; 1 ignored**.
This pull request can be merged automatically.
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/180/head:github-bot/gh-180'
git switch 'github-bot/gh-180'

Merge

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