Iter 24: GPU texture detiling and adaptive ring trim (VICTORY_GPU_DETILE) #9

Merged
Androtim merged 1 commit from upstream-pr/9 into main 2026-11-28 18:44:09 +00:00
Androtim commented 2026-11-28 02:27:13 +00:00 (Migrated from github.com)

Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-11-28T02:27:13Z.


Summary

Ports skornuta/victory-memory-stack GPU texture detiling (0001 + 0003: VICTORY_GPU_DETILE=1) and adaptive detile ring trimming (0014 + 0015: VICTORY_GPU_DETILE_TRIM) onto MiniVI, adapted for MiniVI's HostTexture (level0 / copy.base), PreludeUpload (VICTORY_PRELUDE_UPLOADS=1), texture/ahead.rs (VICTORY_UPLOAD_AHEAD=1), pool::StagingPiece, and 8 GiB VRAM rigs:

  • Opt-in GPU Detiling (VICTORY_GPU_DETILE=1, off by default): Avoids per-texture persistent upload staging buffers by staging raw title bytes into a bounded 256 MiB upload ring (VICTORY_GPU_DETILE_RAW_MB), running a compute detile shader (Layout::copy_table) into a bounded card ring (VICTORY_GPU_DETILE_OUT_MB: defaults to 128 MiB on <= 9 GiB VRAM cards, 192 MiB on larger cards, with <= 85% VRAM budget halving down to 32 MiB), and falling back immediately to lazy CpuStaging if a ring or table buffer is full or a subresource table is unaligned.
  • Idle Ring Trimming (VICTORY_GPU_DETILE_TRIM, defaults ON when VICTORY_GPU_DETILE=1; 0 disables): Shrinks idle rings to VICTORY_GPU_DETILE_SMALL_MB (64 MiB each) after VICTORY_GPU_DETILE_TRIM_S (20s) with no bursts and grows back on demand (retrying in 10s if VRAM budget temporarily lacks room without lowering the full target size).
  • MiniVI Compatibility: Preserves CPU detile path identically when VICTORY_GPU_DETILE is unset; disables texture/ahead.rs copy-queue uploads cleanly when GPU detiling is active; keeps PR #1 (fn record_upload) completely untouched.

Changes

  • crates/victory-formats/src/texture.rs: Added CopyRun, CopyRow, CopyTable, Layout::copy_table, and 4 comprehensive unit tests (copy_tables_detile_as_the_walk_does, copy_tables_check_as_the_walk_does, copy_table_alignment, copy_table_sizes).
  • crates/victory-gpu/src/detile.rs: Added GPU detile rings, Arena fence-tracked allocator, table packer/cache, compute shader (DETILE), verification readback (VICTORY_GPU_DETILE_VERIFY), adaptive ring trim (fit), and WARP + table parity tests.
  • crates/victory-gpu/src/texture_detile_tests.rs: Added WARP tests verifying CPU fallback upon ring full (warp_a_full_ring_after_the_staging_buffer_went_detiles_on_the_cpu) and subresource footprint bounds (warp_every_part_of_a_staging_layout_fits_its_slices).
  • crates/victory-gpu/src/{lib,host,host/card_steps,texture,texture/ahead}.rs: Wired Step::GpuTexture, pre_list / sent / completed hooks, CpuStaging lazy OnceLock, and upload_on_card.

Rig Specs Tested On

  • CPU: Intel Core i7-13700F (13th Gen)
  • GPU & VRAM: NVIDIA GeForce RTX 4060 Ti (8 GiB VRAM)
  • System RAM: 32 GiB (33,304,932 KiB)
  • OS & GPU Driver: Windows 11 Home 10.0.26300 / NVIDIA Driver 32.0.16.2124

Run Settings & Profile

  • Build & Commit SHA: diag & release (RUSTFLAGS='-C link-self-contained=yes') @ branch feat/iter24-gpu-texture-detile-and-trim
  • Console Profile & Internal Resolution / Scale: series-s (unattended launch smoke tests)
  • Ray Tracing: Standard preset (VICTORY_EARLY_DEPTH=1)
  • Upscaling: DLSS quality (VICTORY_DLSS=1, VICTORY_DLSS_MODE=quality, Streamline loaded)
  • Frame Generation: off
  • Launcher Command / Preset & Extra VICTORY_* Overrides:
    • Smoke Test 1: Standard preset (VICTORY_GPU_DETILE off)
    • Smoke Test 2: Standard preset + VICTORY_GPU_DETILE=1 VICTORY_GPU_DETILE_VERIFY=10 VICTORY_GPU_DETILE_TRIM=1
    • (Note: unattended menu/intro smoke tests only; interactive open-world gameplay with VICTORY_GPU_DETILE=1 has not yet been playtested.)
  • Scene / Area & Session Length: Two unattended ~30–38s smoke tests (3 active telemetry windows each, 11 draws/frame).

Measurements & Verification

  • Base FPS (without Frame Gen): 30.0 fps (33.3 ms/frame) in both Smoke Test 1 (CPU default) and Smoke Test 2 (VICTORY_GPU_DETILE=1) with 0 dropped
  • Frame-Gen FPS (if enabled): N/A (off)
  • VRAM / RAM Usage: VICTORY_GPU_DETILE=1: textures are detiled on the card raw_mb=256 out_mb=128 table_mb=32 verify=10 trim=true; 637 indexed textures (195 MB) uploaded in Smoke Test 2 cleanly (0 verify mismatches)
  • Crashes / DRED Resets: 0 (6/7 [PASS] on both smoke tests — sole failing check is the pre-existing unmerged-PR#1 wave64 shader 926c46bab3b86bd6; standalone diag & release non_system_mingw_dlls=0)
  • Automated Checks:
    • cargo +1.98.1-x86_64-pc-windows-gnu run -p xtask -- policy (296 files ok)
    • cargo +1.98.1-x86_64-pc-windows-gnu test -p xtask (6 passed; 0 failed)
    • cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets -- -D warnings (0 warnings)
    • cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets --features diagnostics -- -D warnings (0 warnings)
    • cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-formats (46 passed; 0 failed; 5 ignored, including all 4 copy_table* tests)
    • cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-gpu -- --test-threads=1 (455 passed; 0 failed; 36 ignored, including all detile::tests::* and texture::detile_fallback_tests::*)
<!-- greyfinch-sync:Androtim/MiniVI:issue:5535803901 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/9). Originally posted by [Androtim](https://github.com/Androtim) on 2026-11-28T02:27:13Z. --- ## Summary Ports `skornuta/victory-memory-stack` GPU texture detiling (`0001` + `0003`: `VICTORY_GPU_DETILE=1`) and adaptive detile ring trimming (`0014` + `0015`: `VICTORY_GPU_DETILE_TRIM`) onto `MiniVI`, adapted for MiniVI's `HostTexture` (`level0` / `copy.base`), `PreludeUpload` (`VICTORY_PRELUDE_UPLOADS=1`), `texture/ahead.rs` (`VICTORY_UPLOAD_AHEAD=1`), `pool::StagingPiece`, and 8 GiB VRAM rigs: - **Opt-in GPU Detiling (`VICTORY_GPU_DETILE=1`, off by default):** Avoids per-texture persistent upload staging buffers by staging raw title bytes into a bounded 256 MiB upload ring (`VICTORY_GPU_DETILE_RAW_MB`), running a compute detile shader (`Layout::copy_table`) into a bounded card ring (`VICTORY_GPU_DETILE_OUT_MB`: defaults to **128 MiB** on `<= 9 GiB` VRAM cards, **192 MiB** on larger cards, with `<= 85%` VRAM budget halving down to 32 MiB), and falling back immediately to lazy `CpuStaging` if a ring or table buffer is full or a subresource table is unaligned. - **Idle Ring Trimming (`VICTORY_GPU_DETILE_TRIM`, defaults ON when `VICTORY_GPU_DETILE=1`; `0` disables):** Shrinks idle rings to `VICTORY_GPU_DETILE_SMALL_MB` (`64 MiB` each) after `VICTORY_GPU_DETILE_TRIM_S` (`20s`) with no bursts and grows back on demand (retrying in 10s if VRAM budget temporarily lacks room without lowering the full target size). - **MiniVI Compatibility:** Preserves CPU detile path identically when `VICTORY_GPU_DETILE` is unset; disables `texture/ahead.rs` copy-queue uploads cleanly when GPU detiling is active; keeps PR #1 (`fn record_upload`) completely untouched. ### Changes - `crates/victory-formats/src/texture.rs`: Added `CopyRun`, `CopyRow`, `CopyTable`, `Layout::copy_table`, and 4 comprehensive unit tests (`copy_tables_detile_as_the_walk_does`, `copy_tables_check_as_the_walk_does`, `copy_table_alignment`, `copy_table_sizes`). - `crates/victory-gpu/src/detile.rs`: Added GPU detile rings, `Arena` fence-tracked allocator, table packer/cache, compute shader (`DETILE`), verification readback (`VICTORY_GPU_DETILE_VERIFY`), adaptive ring trim (`fit`), and WARP + table parity tests. - `crates/victory-gpu/src/texture_detile_tests.rs`: Added WARP tests verifying CPU fallback upon ring full (`warp_a_full_ring_after_the_staging_buffer_went_detiles_on_the_cpu`) and subresource footprint bounds (`warp_every_part_of_a_staging_layout_fits_its_slices`). - `crates/victory-gpu/src/{lib,host,host/card_steps,texture,texture/ahead}.rs`: Wired `Step::GpuTexture`, `pre_list` / `sent` / `completed` hooks, `CpuStaging` lazy `OnceLock`, and `upload_on_card`. ## Rig Specs Tested On - **CPU:** Intel Core i7-13700F (13th Gen) - **GPU & VRAM:** NVIDIA GeForce RTX 4060 Ti (8 GiB VRAM) - **System RAM:** 32 GiB (`33,304,932` KiB) - **OS & GPU Driver:** Windows 11 Home `10.0.26300` / NVIDIA Driver `32.0.16.2124` ## Run Settings & Profile - **Build & Commit SHA:** `diag` & `release` (`RUSTFLAGS='-C link-self-contained=yes'`) @ branch `feat/iter24-gpu-texture-detile-and-trim` - **Console Profile & Internal Resolution / Scale:** `series-s` (unattended launch smoke tests) - **Ray Tracing:** Standard preset (`VICTORY_EARLY_DEPTH=1`) - **Upscaling:** `DLSS quality` (`VICTORY_DLSS=1`, `VICTORY_DLSS_MODE=quality`, `Streamline` loaded) - **Frame Generation:** `off` - **Launcher Command / Preset & Extra `VICTORY_*` Overrides:** - Smoke Test 1: Standard preset (`VICTORY_GPU_DETILE` off) - Smoke Test 2: Standard preset + `VICTORY_GPU_DETILE=1 VICTORY_GPU_DETILE_VERIFY=10 VICTORY_GPU_DETILE_TRIM=1` - *(Note: unattended menu/intro smoke tests only; interactive open-world gameplay with `VICTORY_GPU_DETILE=1` has not yet been playtested.)* - **Scene / Area & Session Length:** Two unattended ~30–38s smoke tests (3 active telemetry windows each, `11 draws/frame`). ## Measurements & Verification - **Base FPS (without Frame Gen):** `30.0 fps` (`33.3 ms/frame`) in both Smoke Test 1 (CPU default) and Smoke Test 2 (`VICTORY_GPU_DETILE=1`) with `0 dropped` - **Frame-Gen FPS (if enabled):** N/A (`off`) - **VRAM / RAM Usage:** `VICTORY_GPU_DETILE=1: textures are detiled on the card raw_mb=256 out_mb=128 table_mb=32 verify=10 trim=true`; `637` indexed textures (`195 MB`) uploaded in Smoke Test 2 cleanly (`0` verify mismatches) - **Crashes / DRED Resets:** `0` (`6/7 [PASS]` on both smoke tests — sole failing check is the pre-existing unmerged-PR#1 wave64 shader `926c46bab3b86bd6`; standalone `diag` & `release` `non_system_mingw_dlls=0`) - **Automated Checks:** - [x] `cargo +1.98.1-x86_64-pc-windows-gnu run -p xtask -- policy` (`296 files ok`) - [x] `cargo +1.98.1-x86_64-pc-windows-gnu test -p xtask` (`6 passed; 0 failed`) - [x] `cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets -- -D warnings` (`0 warnings`) - [x] `cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets --features diagnostics -- -D warnings` (`0 warnings`) - [x] `cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-formats` (`46 passed; 0 failed; 5 ignored`, including all 4 `copy_table*` tests) - [x] `cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-gpu -- --test-threads=1` (`455 passed; 0 failed; 36 ignored`, including all `detile::tests::*` and `texture::detile_fallback_tests::*`)
Androtim commented 2026-11-28 02:33:03 +00:00 (Migrated from github.com)

Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-11-28T02:33:03Z.


Verification complete for PR #9 (98c18e7):

  • GitHub Actions CI (46098145900): success (Clippy, Clippy diagnostics, Tests)
  • Standalone diag &
    elease binaries (RUSTFLAGS='-C link-self-contained=yes'):
    on_system_mingw_dlls=0 on both
  • Local tests: xtask policy (296 files ok), xtask test (6 passed), ictory-formats (46 passed, including all 4 copy_table* tests), ictory-gpu (455 passed; 0 failed, including all detile::tests::* and exture::detile_fallback_tests::*), both clippy passes (
<!-- greyfinch-sync:Androtim/MiniVI:comment:7232438283 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/9#issuecomment-7232438283). Originally posted by [Androtim](https://github.com/Androtim) on 2026-11-28T02:33:03Z. --- Verification complete for PR #9 (98c18e7): - GitHub Actions CI (46098145900): **success** (Clippy, Clippy diagnostics, Tests) - Standalone diag & elease binaries (RUSTFLAGS='-C link-self-contained=yes'): on_system_mingw_dlls=0 on both - Local tests: xtask policy (296 files ok), xtask test (6 passed), ictory-formats (46 passed, including all 4 copy_table* tests), ictory-gpu (455 passed; 0 failed, including all detile::tests::* and exture::detile_fallback_tests::*), both clippy passes (
Androtim commented 2026-11-28 03:04:04 +00:00 (Migrated from github.com)

Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-11-28T03:04:04Z.


Automated triage for the maintainers (not an approval).

Verdict: needs-gpu-test · CI (check): passing

Technical Review

CI is passing, and the implementation of opt-in GPU texture detiling (VICTORY_GPU_DETILE=1) and adaptive ring trimming (VICTORY_GPU_DETILE_TRIM) looks solid and well-scoped.

Verified Strengths

  • victory-formats (crates/victory-formats/src/texture.rs): Layout::copy_table and CopyTable::{aligned, apply} mirror Layout::detile's validation (mip/slice bounds, 3D slice checks, addressable() guard, pitch overflow checks) and are validated against Layout::detile across >1,000 layout/pitch combinations in copy_tables_detile_as_the_walk_does.
  • Bounds & Fallback Safety (crates/victory-gpu/src/detile.rs, crates/victory-gpu/src/texture.rs):
    • pack() enforces 4-byte alignment and u32 offset bounds; part() validates shift + table.tiled_end <= raw_len and table.linear_end <= bytes; the DETILE compute shader re-checks raw_len and out_len per 32-bit word.
    • route() and Staging::ensure_cpu cleanly fall back to a lazily allocated CpuStaging (OnceLock) on any refusal (Unaligned, Tables, RawFull, OutFull, TooBig, etc.) while keeping STAGED / LET_GO byte accounting balanced in Staging::drop and let_go_idle.
    • When VICTORY_GPU_DETILE is unset, staging() eagerly allocates CpuStaging as before and texture/ahead.rs remains unaffected.
  • Lifetime & Synchronization (crates/victory-gpu/src/detile.rs, crates/victory-gpu/src/host.rs):
    • fit() only resizes/retires the rings when raw_arena.used() == 0 && out_arena.used() == 0 and all recorded pre-lists/jobs/checks have completed on the GPU fence, preventing out_buffer() from being swapped while any recorded Upload or in-flight CopyTextureRegion references it.
    • host.rs inserts detile::pre_list() at index 0 and shifts firsts[1..] (keeping firsts[0] == 0 so VICTORY_GPU_TIMING still executes the detile pre-list ahead of runs[0]), and notifies detile::sent(*submitted) on both late and synchronous submission paths.
    • Step::GpuTexture is wired into blocked_by (host.rs) and does_of (host/card_steps.rs) identically to Step::Texture.

Why Local Real-GPU Testing Is Needed

Although unit tests, WARP tests, and unattended menu/intro smoke tests passed, this PR introduces a new D3D12 compute shader (DETILE), host submission pre-list injection (pre_list / sent), VRAM-budgeted ring allocation (make_rings), and dynamic ring trimming (fit). As noted in the PR description, interactive open-world gameplay with VICTORY_GPU_DETILE=1 (streaming bursts, ring pressure/fallback, and 20s idle trim/regrow transitions) has not yet been playtested on real GPU hardware.


Generated with Antigravity CLI (agy).

<!-- greyfinch-sync:Androtim/MiniVI:comment:7232772441 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/9#issuecomment-7232772441). Originally posted by [Androtim](https://github.com/Androtim) on 2026-11-28T03:04:04Z. --- <!-- minivi-triage v1 head=98c18e7c885ea14f2998e3a8d5c39f171123b690 verdict=needs-gpu-test ci=passing at=2026-11-28T03:04:31Z --> Automated triage for the maintainers (not an approval). **Verdict:** `needs-gpu-test` · **CI (`check`):** `passing` ### Technical Review CI is passing, and the implementation of opt-in GPU texture detiling (`VICTORY_GPU_DETILE=1`) and adaptive ring trimming (`VICTORY_GPU_DETILE_TRIM`) looks solid and well-scoped. #### Verified Strengths - **`victory-formats` (`crates/victory-formats/src/texture.rs`)**: `Layout::copy_table` and `CopyTable::{aligned, apply}` mirror `Layout::detile`'s validation (mip/slice bounds, 3D slice checks, `addressable()` guard, pitch overflow checks) and are validated against `Layout::detile` across >1,000 layout/pitch combinations in `copy_tables_detile_as_the_walk_does`. - **Bounds & Fallback Safety (`crates/victory-gpu/src/detile.rs`, `crates/victory-gpu/src/texture.rs`)**: - `pack()` enforces 4-byte alignment and `u32` offset bounds; `part()` validates `shift + table.tiled_end <= raw_len` and `table.linear_end <= bytes`; the `DETILE` compute shader re-checks `raw_len` and `out_len` per 32-bit word. - `route()` and `Staging::ensure_cpu` cleanly fall back to a lazily allocated `CpuStaging` (`OnceLock`) on any refusal (`Unaligned`, `Tables`, `RawFull`, `OutFull`, `TooBig`, etc.) while keeping `STAGED` / `LET_GO` byte accounting balanced in `Staging::drop` and `let_go_idle`. - When `VICTORY_GPU_DETILE` is unset, `staging()` eagerly allocates `CpuStaging` as before and `texture/ahead.rs` remains unaffected. - **Lifetime & Synchronization (`crates/victory-gpu/src/detile.rs`, `crates/victory-gpu/src/host.rs`)**: - `fit()` only resizes/retires the rings when `raw_arena.used() == 0 && out_arena.used() == 0` and all recorded pre-lists/jobs/checks have completed on the GPU fence, preventing `out_buffer()` from being swapped while any recorded `Upload` or in-flight `CopyTextureRegion` references it. - `host.rs` inserts `detile::pre_list()` at index `0` and shifts `firsts[1..]` (keeping `firsts[0] == 0` so `VICTORY_GPU_TIMING` still executes the detile pre-list ahead of `runs[0]`), and notifies `detile::sent(*submitted)` on both `late` and synchronous submission paths. - `Step::GpuTexture` is wired into `blocked_by` (`host.rs`) and `does_of` (`host/card_steps.rs`) identically to `Step::Texture`. #### Why Local Real-GPU Testing Is Needed Although unit tests, WARP tests, and unattended menu/intro smoke tests passed, this PR introduces a new D3D12 compute shader (`DETILE`), host submission pre-list injection (`pre_list` / `sent`), VRAM-budgeted ring allocation (`make_rings`), and dynamic ring trimming (`fit`). As noted in the PR description, interactive open-world gameplay with `VICTORY_GPU_DETILE=1` (streaming bursts, ring pressure/fallback, and 20s idle trim/regrow transitions) has not yet been playtested on real GPU hardware. --- _Generated with Antigravity CLI (`agy`)._
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!9
No description provided.