perf(victory-gpu): virtualize card staging mirror and release texture CPU staging post-upload #392

Merged
Androtim merged 4 commits from upstream-pr/392 into main 2026-12-03 15:15:34 +00:00
Androtim commented 2026-12-03 13:07:48 +00:00 (Migrated from github.com)

Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-12-03T13:07:48Z.


Refs: #276

Summary

Reduces host RAM and Windows virtual commit footprint on 16 GB–32 GB systems without relaxing GPU fence lifetime or readback correctness:

  1. Lazy / virtualized Card::staging CPU mirror (shadow.rs, host/send.rs, host.rs, host/upcheck.rs):

    • Under default send::own() (VICTORY_SEND_OWN != 0) and without VICTORY_UPCOPY_CHECK=1, replaces eager permanent ID3D12Resource upload mirrors (host.shared_buffer_staging) on card-resident buffers (lookup, by_address, by_address_in, loose) with CardCpu::Virtual(CardMirror): an anonymous VirtualAlloc(MEM_RESERVE) reservation committed lazily in 64 KiB (PAGE) chunks only when written/copied.
    • Untouched pages remain uncommitted (MEM_RESERVE only), reading as zero in copy_out / sync_range_to / card_held until first touched, and allocate a D3D12 staging fallback resource lazily (CardMirror::ensure_staging) only when an own.is_none() copy or diagnostic fallback actually requires one (VICTORY_CARD_LAZY_STAGING=0 restores eager allocation).
    • Defers send::take pass_aside trigger until non-zero word transfers are observed (total_words > 0) so pure CopyBufferRegion sends do not unnecessarily force eager ID3D12Resource card staging allocation.
  2. Fence-safe post-upload release of texture CpuStaging and pool::STAGING block sizing (texture.rs, texture/ahead.rs, pool.rs, host.rs, host/prelude.rs, texture_detile_tests.rs):

    • Replaces write-once OnceLock<CpuStaging> in texture::Staging with releasable Mutex<Option<Arc<CpuStaging>>>, reference-counted UploadGuard, and pending_uploads: AtomicU32 tracked across HostList::hold (prelude_uploads, claim_hoisted, direct upload_from) and copy-queue texture::ahead::Jobs.
    • Drops Staging::cpu (returning StagingPiece back to pool::STAGING or freeing dedicated upload buffers and updating STAGED accurately in CpuStaging::drop) immediately when the final in-flight GPU fence retires (HostList::reset() / post-SetEventOnCompletion in ahead::finish) whenever uploaded && !dirty, while lazily re-acquiring and refreshing CpuStaging if title memory changes later.
    • Skips unused CpuStaging allocation for linear movie_plane staging entries.
    • Scales pool::STAGING block size (16 MiB on <= 18 GiB, 32 MiB on <= 32 GiB, 64 MiB above) and idle spare retention via STAGING_SPARES (separate from VRAM TEXTURES spares), packing allocations with fullest: true.

Verification

  • cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-gpu --lib -- --test-threads=1: 844 passed, 0 failed, 39 ignored (matching CI serial execution; includes new tests in shadow::card_staging_tests, pool::tests, and texture_detile_tests).
  • cargo +1.98.1-x86_64-pc-windows-gnu clippy -p victory-gpu --all-targets -- -D warnings: passed with zero warnings.
  • cargo +1.98.1-x86_64-pc-windows-gnu clippy -p victory-gpu --all-targets --all-features -- -D warnings: passed with zero warnings.
  • cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets --locked -- -D warnings: passed with zero warnings.
<!-- greyfinch-sync:Androtim/MiniVI:issue:5627116704 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/392). Originally posted by [Androtim](https://github.com/Androtim) on 2026-12-03T13:07:48Z. --- Refs: #276 ### Summary Reduces host RAM and Windows virtual commit footprint on 16 GB–32 GB systems without relaxing GPU fence lifetime or readback correctness: 1. **Lazy / virtualized `Card::staging` CPU mirror (`shadow.rs`, `host/send.rs`, `host.rs`, `host/upcheck.rs`):** - Under default `send::own()` (`VICTORY_SEND_OWN != 0`) and without `VICTORY_UPCOPY_CHECK=1`, replaces eager permanent `ID3D12Resource` upload mirrors (`host.shared_buffer_staging`) on card-resident buffers (`lookup`, `by_address`, `by_address_in`, `loose`) with `CardCpu::Virtual(CardMirror)`: an anonymous `VirtualAlloc(MEM_RESERVE)` reservation committed lazily in 64 KiB (`PAGE`) chunks only when written/copied. - Untouched pages remain uncommitted (`MEM_RESERVE` only), reading as zero in `copy_out` / `sync_range_to` / `card_held` until first touched, and allocate a D3D12 staging fallback resource lazily (`CardMirror::ensure_staging`) only when an `own.is_none()` copy or diagnostic fallback actually requires one (`VICTORY_CARD_LAZY_STAGING=0` restores eager allocation). - Defers `send::take` `pass_aside` trigger until non-zero word transfers are observed (`total_words > 0`) so pure `CopyBufferRegion` sends do not unnecessarily force eager `ID3D12Resource` card staging allocation. 2. **Fence-safe post-upload release of texture `CpuStaging` and `pool::STAGING` block sizing (`texture.rs`, `texture/ahead.rs`, `pool.rs`, `host.rs`, `host/prelude.rs`, `texture_detile_tests.rs`):** - Replaces write-once `OnceLock<CpuStaging>` in `texture::Staging` with releasable `Mutex<Option<Arc<CpuStaging>>>`, reference-counted `UploadGuard`, and `pending_uploads: AtomicU32` tracked across `HostList::hold` (`prelude_uploads`, `claim_hoisted`, direct `upload_from`) and copy-queue `texture::ahead::Job`s. - Drops `Staging::cpu` (returning `StagingPiece` back to `pool::STAGING` or freeing dedicated upload buffers and updating `STAGED` accurately in `CpuStaging::drop`) immediately when the final in-flight GPU fence retires (`HostList::reset()` / post-`SetEventOnCompletion` in `ahead::finish`) whenever `uploaded && !dirty`, while lazily re-acquiring and refreshing `CpuStaging` if title memory changes later. - Skips unused `CpuStaging` allocation for linear `movie_plane` staging entries. - Scales `pool::STAGING` block size (`16 MiB` on `<= 18 GiB`, `32 MiB` on `<= 32 GiB`, `64 MiB` above) and idle spare retention via `STAGING_SPARES` (separate from VRAM `TEXTURES` spares), packing allocations with `fullest: true`. ### Verification - `cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-gpu --lib -- --test-threads=1`: 844 passed, 0 failed, 39 ignored (matching CI serial execution; includes new tests in `shadow::card_staging_tests`, `pool::tests`, and `texture_detile_tests`). - `cargo +1.98.1-x86_64-pc-windows-gnu clippy -p victory-gpu --all-targets -- -D warnings`: passed with zero warnings. - `cargo +1.98.1-x86_64-pc-windows-gnu clippy -p victory-gpu --all-targets --all-features -- -D warnings`: passed with zero warnings. - `cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets --locked -- -D warnings`: passed with zero warnings.
Androtim commented 2026-12-03 13:33:22 +00:00 (Migrated from github.com)

Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-12-03T13:33:22Z.


Triage (bd171f16, CI check PASS):

  • High-priority Directive #40 Rank 1 & Rank 2 memory work (+1,025/-286 across 9 files: virtualized Card::staging mirror under send::own() + post-upload CpuStaging release).
  • Holding auto-merge for Gate 2 Deep Reasoning Audit (#282) + Gate 3 plain --release A/B (FPS, private_commit_mb, working_set_mb, 0 crashes/DRED) + --features diagnostics visual PNG check.
<!-- greyfinch-sync:Androtim/MiniVI:comment:7379994227 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/392#issuecomment-7379994227). Originally posted by [Androtim](https://github.com/Androtim) on 2026-12-03T13:33:22Z. --- Triage (`bd171f16`, **CI `check` PASS**): - High-priority Directive `#40` Rank 1 & Rank 2 memory work (`+1,025/-286` across 9 files: virtualized `Card::staging` mirror under `send::own()` + post-upload `CpuStaging` release). - Holding auto-merge for **Gate 2 Deep Reasoning Audit (`#282`)** + **Gate 3 plain `--release` A/B** (FPS, `private_commit_mb`, `working_set_mb`, `0` crashes/DRED) + `--features diagnostics` visual PNG check.
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
Androtim/MiniVI!392
No description provided.