gpu: physical-page transient RT aliasing, lazy depth-UAV twins, and idle RT reclamation #1147

Closed
mikael-jarvinen wants to merge 1 commit from upstream-pr/1147 into main
mikael-jarvinen commented 2026-11-28 14:15:40 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by mikael-jarvinen on 2026-11-28T14:15:40Z.


Summary

Reduces non-texture VRAM consumption on 8–12 GB GPUs by ~509 MB (−355 MB from transient render-target aliasing + ~154 MB from lazy depth-UAV twins and unmapped/idle RT reclamation) with 0 GPU faults and 0 D3D12 errors.

What Changed

  1. Physical-page transient RT/DS/UAV aliasing (crates/victory-gpu/src/alias_rt.rs, inplace.rs, resource.rs, host.rs):
    • Detects transient render targets / depth-stencil / UAV textures whose title virtual addresses are backed by XMemMapPhysicalPages physical sections (inplace::aliased_section_pages).
    • On D3D12 Tier-2 resource heap / tiled-resource hardware (heap_tier >= 2), creates them via CreateReservedResource and maps their 64 KiB tiles synchronously onto lazily allocated 16 MiB D3D12_HEAP_FLAG_NONE chunks via UpdateTileMappings (plus a small private overflow tile pool for minor pitch padding), mirroring the title's physical-page aliasing on the host GPU.
    • Emits D3D12_RESOURCE_BARRIER_TYPE_ALIASING barriers in HostList::transition and HostList::prelude when switching between aliased resources sharing physical backing.
    • Controlled by VICTORY_ALIAS_TARGETS (default ON; set VICTORY_ALIAS_TARGETS=0 to disable and fall back to committed resources).
  2. Lazy depth-UAV color twins (crates/victory-gpu/src/resource.rs, host.rs):
    • Defers twin_texture allocation for depth textures with ALLOW_UNORDERED_ACCESS until the texture is actually bound as a UAV (resource::ensure_twin), avoiding unused color-twin allocations on plain depth draws.
  3. Unmapped & idle RT reclamation (crates/victory-gpu/src/resource.rs):
    • Periodically reclaims host copies of unmapped or 30 s-idle placed render targets inside let_go_idle (every 5 s), and accounts alias_rt::allocated_bytes() in targets_room_kept().

Verification

  • cargo clippy -p victory-gpu --all-targets --locked (0 warnings in touched files)
  • cargo clippy -p victory-gpu --all-targets --all-features --locked (0 warnings in touched files)
  • cargo test -p victory-gpu --lib --locked: 454 passed, 0 failed (36 ignored), including alias_rt::tests::coalesce_runs_merges_contiguous_tile_ranges
  • cargo xtask policy: 295 files ok
  • cargo build --release -p victory: 0 warnings

A/B Benchmark (origin/main 63b902f vs this PR)

Hardware: NVIDIA RTX 3080 10 GB, Windows 11, 1440p DLSS Performance, identical 115 s scripted startup + world run (VICTORY_WARMUP_RESTART=0, VICTORY_POOL_STATS=1).

Metric origin/main (63b902f) This PR (6ba7fa8) Delta
Aliased transient RTs/DSVs/UAVs 0 256 (731 MB virtual → 376 MB physical) −355 MB (~2:1 ratio, 12 fallbacks)
Non-texture VRAM (peak total − pool) 4,688 MB (8,336 − 3,648) 4,179 MB (8,083 − 3,904) −509 MB (−10.9%)
Peak local VRAM in use 8,336 / 8,679 MB (96%) 8,083 / 8,561 MB (pool grew +256 MB into reclaimed headroom) −253 MB
Texture pass lateness (late 5 s windows) 1.6–2.5 fr (12–15 max) 0.4–0.5 fr (1 max) −75% lateness
held back for room (total) 1,263,687 1,019,913 −19.3%
D3D12 errors / GPU faults 0 0 Clean
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5541030712 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1147). Originally posted by [mikael-jarvinen](https://github.com/mikael-jarvinen) on 2026-11-28T14:15:40Z. --- ## Summary Reduces non-texture VRAM consumption on 8–12 GB GPUs by **~509 MB** (`−355 MB` from transient render-target aliasing + `~154 MB` from lazy depth-UAV twins and unmapped/idle RT reclamation) with **0 GPU faults and 0 D3D12 errors**. ### What Changed 1. **Physical-page transient RT/DS/UAV aliasing (`crates/victory-gpu/src/alias_rt.rs`, `inplace.rs`, `resource.rs`, `host.rs`)**: - Detects transient render targets / depth-stencil / UAV textures whose title virtual addresses are backed by `XMemMapPhysicalPages` physical sections (`inplace::aliased_section_pages`). - On D3D12 Tier-2 resource heap / tiled-resource hardware (`heap_tier >= 2`), creates them via `CreateReservedResource` and maps their 64 KiB tiles synchronously onto lazily allocated 16 MiB `D3D12_HEAP_FLAG_NONE` chunks via `UpdateTileMappings` (plus a small private overflow tile pool for minor pitch padding), mirroring the title's physical-page aliasing on the host GPU. - Emits `D3D12_RESOURCE_BARRIER_TYPE_ALIASING` barriers in `HostList::transition` and `HostList::prelude` when switching between aliased resources sharing physical backing. - Controlled by `VICTORY_ALIAS_TARGETS` (default ON; set `VICTORY_ALIAS_TARGETS=0` to disable and fall back to committed resources). 2. **Lazy depth-UAV color twins (`crates/victory-gpu/src/resource.rs`, `host.rs`)**: - Defers `twin_texture` allocation for depth textures with `ALLOW_UNORDERED_ACCESS` until the texture is actually bound as a UAV (`resource::ensure_twin`), avoiding unused color-twin allocations on plain depth draws. 3. **Unmapped & idle RT reclamation (`crates/victory-gpu/src/resource.rs`)**: - Periodically reclaims host copies of unmapped or 30 s-idle placed render targets inside `let_go_idle` (every 5 s), and accounts `alias_rt::allocated_bytes()` in `targets_room_kept()`. ## Verification - `cargo clippy -p victory-gpu --all-targets --locked` (0 warnings in touched files) - `cargo clippy -p victory-gpu --all-targets --all-features --locked` (0 warnings in touched files) - `cargo test -p victory-gpu --lib --locked`: **454 passed, 0 failed** (36 ignored), including `alias_rt::tests::coalesce_runs_merges_contiguous_tile_ranges` - `cargo xtask policy`: **295 files ok** - `cargo build --release -p victory`: **0 warnings** ## A/B Benchmark (`origin/main` `63b902f` vs this PR) Hardware: **NVIDIA RTX 3080 10 GB**, Windows 11, 1440p DLSS Performance, identical 115 s scripted startup + world run (`VICTORY_WARMUP_RESTART=0`, `VICTORY_POOL_STATS=1`). | Metric | `origin/main` (`63b902f`) | This PR (`6ba7fa8`) | Delta | |---|---:|---:|---:| | **Aliased transient RTs/DSVs/UAVs** | 0 | **256** (`731 MB` virtual → `376 MB` physical) | **−355 MB (~2:1 ratio, 12 fallbacks)** | | **Non-texture VRAM (peak total − pool)** | 4,688 MB (`8,336 − 3,648`) | **4,179 MB** (`8,083 − 3,904`) | **−509 MB (−10.9%)** | | **Peak local VRAM in use** | 8,336 / 8,679 MB (96%) | **8,083 / 8,561 MB** *(pool grew +256 MB into reclaimed headroom)* | **−253 MB** | | **Texture pass lateness (late 5 s windows)** | 1.6–2.5 fr (12–15 max) | **0.4–0.5 fr (1 max)** | **−75% lateness** | | **`held back for room` (total)** | 1,263,687 | **1,019,913** | **−19.3%** | | **D3D12 errors / GPU faults** | 0 | **0** | Clean |
rahmondg45 commented 2026-11-28 14:17:53 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by rahmondg45 on 2026-11-28T14:17:53Z.


good work

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7240564617 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1147#issuecomment-7240564617). Originally posted by [rahmondg45](https://github.com/rahmondg45) on 2026-11-28T14:17:53Z. --- good work
mikael-jarvinen commented 2026-11-28 21:45:15 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by mikael-jarvinen on 2026-11-28T21:45:15Z.


Rebased cleanly onto main (923e38c, head 724e51f; 1/1 alias_rt + 29/29 resource::tests pass, 0 new warnings) and re-measured on RTX 3080 10 GB + Ryzen 7 7800X3D (diag build, warm shader cache, 1440p DLSS Performance, FG off, 115 s scripted run):

Metric main (923e38c) This PR (724e51f) Delta
Steady 3D FPS (med / peak) 15.7 / 17.3 (stall to 5.9) 17.8 / 18.7 (0 stalls) +13.4% FPS
GPU busy (%) / idle behind CPU (ms) 66.0% / 21.65 ms 92.0% / 4.55 ms +26.0 pp / −79.0% idle
Submit prep TOTAL 58.50 ms 49.60 ms −8.90 ms (−15.2%)
VRAM in use (DXGI) 8,247 MB 8,005 MB −242 MB (with +187 MB more pool free)
Texture queue weighed VRAM 8,806 MB 8,237 MB −569 MB
Kept for render targets 692 MB 552 MB −140 MB
Unmapped placed copies alive 230–266 MB 106 MB −54%
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7246246846 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1147#issuecomment-7246246846). Originally posted by [mikael-jarvinen](https://github.com/mikael-jarvinen) on 2026-11-28T21:45:15Z. --- Rebased cleanly onto `main` (`923e38c`, head `724e51f`; 1/1 `alias_rt` + 29/29 `resource::tests` pass, 0 new warnings) and re-measured on RTX 3080 10 GB + Ryzen 7 7800X3D (`diag` build, warm shader cache, 1440p DLSS Performance, FG off, 115 s scripted run): | Metric | `main` (`923e38c`) | This PR (`724e51f`) | Delta | |---|---:|---:|---:| | Steady 3D FPS (med / peak) | 15.7 / 17.3 (stall to 5.9) | **17.8 / 18.7 (0 stalls)** | **+13.4% FPS** | | GPU busy (%) / idle behind CPU (ms) | 66.0% / 21.65 ms | **92.0% / 4.55 ms** | **+26.0 pp / −79.0% idle** | | Submit prep TOTAL | 58.50 ms | **49.60 ms** | **−8.90 ms (−15.2%)** | | VRAM in use (DXGI) | 8,247 MB | **8,005 MB** | **−242 MB** (with +187 MB more pool free) | | Texture queue weighed VRAM | 8,806 MB | **8,237 MB** | **−569 MB** | | `Kept for render targets` | 692 MB | **552 MB** | **−140 MB** | | Unmapped placed copies alive | 230–266 MB | **106 MB** | **−54%** |
mikael-jarvinen commented 2026-11-29 08:17:14 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by mikael-jarvinen on 2026-11-29T08:17:14Z.


Note: this PR was merged into main in d6e0670 (so this PR can be closed). Opened follow-up #2042 to fix the missing intra-list aliasing barrier on first aliased RT write and make VICTORY_ALIAS_TARGETS opt-in until DCC/DiscardResource tracking is added.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7253006258 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1147#issuecomment-7253006258). Originally posted by [mikael-jarvinen](https://github.com/mikael-jarvinen) on 2026-11-29T08:17:14Z. --- Note: this PR was merged into `main` in `d6e0670` (so this PR can be closed). Opened follow-up #2042 to fix the missing intra-list aliasing barrier on first aliased RT write and make `VICTORY_ALIAS_TARGETS` opt-in until DCC/`DiscardResource` tracking is added.
trustno1-coder commented 2026-11-29 08:28:10 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by trustno1-coder on 2026-11-29T08:28:10Z.


Thank you! An earlier version of this pull request was merged into main with its original commits and is part of v2026.11.29.01, where you are credited. GitHub does not show it as merged because new commits were pushed here after that merge. It stays open so those newer commits can be looked at next.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7253124045 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1147#issuecomment-7253124045). Originally posted by [trustno1-coder](https://github.com/trustno1-coder) on 2026-11-29T08:28:10Z. --- Thank you! An earlier version of this pull request was merged into main with its original commits and is part of [v2026.11.29.01](https://github.com/trustno1-coder/VIctory-NVIDIA/releases/tag/v2026.11.29.01), where you are credited. GitHub does not show it as merged because new commits were pushed here after that merge. It stays open so those newer commits can be looked at next.
mikael-jarvinen commented 2026-11-29 08:42:11 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by mikael-jarvinen on 2026-11-29T08:42:11Z.


Thanks for merging the earlier commits into v2026.11.29.01! The only remaining commit on this branch (96fb6722) was half-superseded by main's alias_tracker.record_touch, and its other half (making VICTORY_ALIAS_TARGETS opt-in =1 until DiscardResource/DCC clearing is verified) is cleanly rebased onto latest main in #2042. Closing this PR to keep things tidy.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7253276255 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1147#issuecomment-7253276255). Originally posted by [mikael-jarvinen](https://github.com/mikael-jarvinen) on 2026-11-29T08:42:11Z. --- Thanks for merging the earlier commits into v2026.11.29.01! The only remaining commit on this branch (`96fb6722`) was half-superseded by `main`'s `alias_tracker.record_touch`, and its other half (making `VICTORY_ALIAS_TARGETS` opt-in `=1` until `DiscardResource`/DCC clearing is verified) is cleanly rebased onto latest `main` in #2042. Closing this PR to keep things tidy.
AlexeyYuditsky commented 2026-11-29 12:21:18 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by AlexeyYuditsky on 2026-11-29T12:21:18Z.


Because of this PR, ripples started appearing when enabling frame gen 2x and higher.
Скриншот-20261129-151650

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7255751340 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1147#issuecomment-7255751340). Originally posted by [AlexeyYuditsky](https://github.com/AlexeyYuditsky) on 2026-11-29T12:21:18Z. --- Because of this PR, ripples started appearing when enabling frame gen 2x and higher. <img width="2558" height="1433" alt="Скриншот-20261129-151650" src="https://github.com/user-attachments/assets/901ceb8c-1f2f-4667-809c-e3d437ac0ea7" />

Pull request closed

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
trustno1-coder/VIctory-NVIDIA!1147
No description provided.