gpu: reduce WDDM Commit and SwapDelta peaks on <=32 GiB hosts #172

Closed
github-bot wants to merge 2 commits from gh-pr/172/head into gh-pr/172/base
Owner

@⁠jules-noelaudoux on GitHub · 2026-11-29 23:58 UTC · original
jules-noelaudoux:fix/reduce-commit-memory → main · +1008 −42 · 10 files · 2 commits · closed without merging

Summary

Reduces Windows WDDM Commit, SwapDelta, and host private memory peaks on <= 32 GiB RAM systems without regressing frame times:

  • 16 MiB placed buffer sub-allocator (host/buffers.rs): Consolidates 32 KiB ..= <4 MiB UPLOAD, WRITE_BACK (Shared), DEFAULT (Uav), and GPU_UPLOAD buffers into dedicated 16 MiB ID3D12Heap pools (ALLOW_ONLY_BUFFERS), avoiding Windows 11 + NVIDIA WDDM permanent 32 MiB internal slab retention on small CreateCommittedResource calls and returning empty blocks to Windows commit after a short rest.
  • Graduated commit pressure (residency.rs): Adds commit_pressured() with hysteresis on <= 32 GiB hosts (<= 8 GiB free physical RAM or <= 9 GiB free commit to enter; >= 10 GiB and >= 11 GiB to clear) so trimming engages before heavy pagefile thrashing begins.
  • Tighter buffer/list/staging limits under commit pressure (ahead.rs, host.rs, host/send.rs, list.rs, pool.rs, texture.rs):
    • Scales ahead 64 KiB pre-allocated buffers (512 initial / 256 kept on <= 32 GiB RAM) and truncates under commit_pressured().
    • Adds periodic list::trim_idle() (default 45s / 30s under pressure; VICTORY_LIST_POOL_IDLE_S=0 disables), send::trim_spare() (4 MiB floor on limited RAM), and buffers::trim() in host::sweep(), reduces PRELUDES_KEPT (256 -> 64), and gates ID3D12CommandAllocator replacement behind VICTORY_ALLOCATOR_REPLACE=1 to avoid permanent 1024 MiB WDDM driver arena commit growth.
    • Tightens pool::room() spare staging/texture blocks and texture::let_go_idle() staging idle timeout (<= 1,000 ms) under commit_pressured().
  • VRAM / BAR routing & eviction (shadow.rs, resource.rs):
    • Enables GPU_UPLOAD BAR single-copy paths on <= 32 GiB RAM hosts when supported for >= 4 MiB windows (keeping < 4 MiB in the 16 MiB pool) and write-combined buffers >= 1 MiB (VICTORY_WC_BAR=0|1|2 still overrides), while capping combined WINDOW_CARD_BYTES + WINDOW_MAPPED_BYTES.
    • Adds vram_keep_or_commit() and slot_evict commit-pressure floors in resource.rs (running full vram_keep_or_commit every 8 sweeps under soft commit_pressured() while keeping MiniVI's weighed() real-budget guard).

Rig Specs Tested On

  • CPU: AMD Ryzen 7 5800X (8-Core)
  • GPU & VRAM: NVIDIA GeForce RTX 4080 SUPER (16 GB VRAM)
  • System RAM: 32 GB
  • OS & GPU Driver: Windows 11 Pro (10.0.26300.0), NVIDIA Driver 621.40

Run Settings & Profile

  • Build & Commit SHA: release — MiniVI b46464d (before) vs ported branch (f1b364f, rebased cleanly onto main 271a850 as 13733f1)
  • Console Profile & Internal Resolution / Scale: series-x, 2560x1440 native (--res 1440)
  • Ray Tracing: off
  • Upscaling: off (--dlss off)
  • Frame Generation: off (0)
  • Launcher Command / Preset & Extra VICTORY_* Overrides: victory.exe play <exe> --res 1440 --dlss off (stock play defaults, isolated empty VICTORY_HOME and VICTORY_CACHE_DIR)
  • Scene / Area & Session Length: Cold shader & image cache world load + ~3.3 min session per run (~55s mem-watch window + mem-audit)

Measurements & Verification

Before (b46464d) vs After (f1b364f), cold cache, identical settings:

Metric Before (b46464d) After (this PR) Delta
Base FPS (draws >= 500) 11.1 med (8.7–17.0, p50=89.8 ms) 12.1 med (8.7–16.3, p50=82.8 ms) +9% median
Dense scene (~11.6k–12.4k draws) 9.5–9.7 fps (103.5–105.4 ms) 11.7–12.5 fps (79.8–85.5 ms) +23% to +29%
Commit (mem-audit end) 27,515 MiB 23,848 MiB -3,667 MiB (-3.58 GiB)
Commit (mem-watch end / rate) 27,272 MiB (+732.7 MiB/min) 24,022 MiB (+268.1 MiB/min) -3,250 MiB
WorkingSet (mem-audit end) 21,717 MiB 19,551 MiB -2,166 MiB
SwapDelta (mem-audit end) 5,798 MiB 4,297 MiB -1,501 MiB
Free RAM (mem-watch end) 5,165 MiB 5,748 MiB +583 MiB
Host MEM_PRIVATE 22,491 MiB 18,907 MiB -3,584 MiB
VRAM (nvidia-smi / queue) 13,008 / 16,376 MiB (11,905 MB) 11,642 / 16,376 MiB (10,470 MB) -1,366 MiB
WAIT_RESIDENT (cumulative) 16,800 waits / 2,017.3 ms 2,000 waits / 349.9 ms ~8.4x fewer waits
  • Crashes / DRED Resets: 0 (0 errors, 0 allocation failures)
  • Automated Checks:
    • cargo clippy --workspace --all-targets --locked -- -D warnings
    • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings
    • cargo test --locked -p xtask (6 passed; 0 failed)
    • cargo test -p victory-gpu --lib -- --test-threads=1 (572 passed; 0 failed; 37 ignored)
**@⁠jules-noelaudoux** on GitHub · 2026-11-29 23:58 UTC · [original](https://github.com/Androtim/MiniVI/pull/172) `jules-noelaudoux:fix/reduce-commit-memory` → `main` · +1008 −42 · 10 files · 2 commits · closed without merging ## Summary Reduces Windows WDDM Commit, `SwapDelta`, and host private memory peaks on `<= 32 GiB` RAM systems without regressing frame times: - **16 MiB placed buffer sub-allocator (`host/buffers.rs`):** Consolidates `32 KiB ..= <4 MiB` `UPLOAD`, `WRITE_BACK` (`Shared`), `DEFAULT` (`Uav`), and `GPU_UPLOAD` buffers into dedicated 16 MiB `ID3D12Heap` pools (`ALLOW_ONLY_BUFFERS`), avoiding Windows 11 + NVIDIA WDDM permanent 32 MiB internal slab retention on small `CreateCommittedResource` calls and returning empty blocks to Windows commit after a short rest. - **Graduated commit pressure (`residency.rs`):** Adds `commit_pressured()` with hysteresis on `<= 32 GiB` hosts (`<= 8 GiB` free physical RAM or `<= 9 GiB` free commit to enter; `>= 10 GiB` and `>= 11 GiB` to clear) so trimming engages before heavy pagefile thrashing begins. - **Tighter buffer/list/staging limits under commit pressure (`ahead.rs`, `host.rs`, `host/send.rs`, `list.rs`, `pool.rs`, `texture.rs`):** - Scales `ahead` 64 KiB pre-allocated buffers (`512` initial / `256` kept on `<= 32 GiB` RAM) and truncates under `commit_pressured()`. - Adds periodic `list::trim_idle()` (default `45s` / `30s` under pressure; `VICTORY_LIST_POOL_IDLE_S=0` disables), `send::trim_spare()` (`4 MiB` floor on limited RAM), and `buffers::trim()` in `host::sweep()`, reduces `PRELUDES_KEPT` (`256 -> 64`), and gates `ID3D12CommandAllocator` replacement behind `VICTORY_ALLOCATOR_REPLACE=1` to avoid permanent 1024 MiB WDDM driver arena commit growth. - Tightens `pool::room()` spare staging/texture blocks and `texture::let_go_idle()` staging idle timeout (`<= 1,000 ms`) under `commit_pressured()`. - **VRAM / BAR routing & eviction (`shadow.rs`, `resource.rs`):** - Enables `GPU_UPLOAD` BAR single-copy paths on `<= 32 GiB` RAM hosts when supported for `>= 4 MiB` windows (keeping `< 4 MiB` in the 16 MiB pool) and write-combined buffers `>= 1 MiB` (`VICTORY_WC_BAR=0|1|2` still overrides), while capping combined `WINDOW_CARD_BYTES + WINDOW_MAPPED_BYTES`. - Adds `vram_keep_or_commit()` and `slot_evict` commit-pressure floors in `resource.rs` (running full `vram_keep_or_commit` every 8 sweeps under soft `commit_pressured()` while keeping `MiniVI`'s `weighed()` real-budget guard). ## Rig Specs Tested On - **CPU:** AMD Ryzen 7 5800X (8-Core) - **GPU & VRAM:** NVIDIA GeForce RTX 4080 SUPER (16 GB VRAM) - **System RAM:** 32 GB - **OS & GPU Driver:** Windows 11 Pro (`10.0.26300.0`), NVIDIA Driver `621.40` ## Run Settings & Profile - **Build & Commit SHA:** `release` — `MiniVI` `b46464d` (before) vs ported branch (`f1b364f`, rebased cleanly onto `main` `271a850` as `13733f1`) - **Console Profile & Internal Resolution / Scale:** `series-x`, `2560x1440` native (`--res 1440`) - **Ray Tracing:** `off` - **Upscaling:** `off` (`--dlss off`) - **Frame Generation:** `off` (`0`) - **Launcher Command / Preset & Extra `VICTORY_*` Overrides:** `victory.exe play <exe> --res 1440 --dlss off` (stock `play` defaults, isolated empty `VICTORY_HOME` and `VICTORY_CACHE_DIR`) - **Scene / Area & Session Length:** Cold shader & image cache world load + ~3.3 min session per run (~55s `mem-watch` window + `mem-audit`) ## Measurements & Verification Before (`b46464d`) vs After (`f1b364f`), cold cache, identical settings: | Metric | Before (`b46464d`) | After (this PR) | Delta | |---|---|---|---| | **Base FPS (`draws >= 500`)** | `11.1 med` (`8.7`–`17.0`, `p50=89.8 ms`) | **`12.1 med`** (`8.7`–`16.3`, `p50=82.8 ms`) | **+9% median** | | **Dense scene (~11.6k–12.4k draws)** | `9.5–9.7 fps` (`103.5–105.4 ms`) | **`11.7–12.5 fps`** (`79.8–85.5 ms`) | **+23% to +29%** | | **Commit (`mem-audit` end)** | `27,515 MiB` | **`23,848 MiB`** | **`-3,667 MiB` (-3.58 GiB)** | | **Commit (`mem-watch` end / rate)** | `27,272 MiB` (`+732.7 MiB/min`) | **`24,022 MiB`** (`+268.1 MiB/min`) | **`-3,250 MiB`** | | **WorkingSet (`mem-audit` end)** | `21,717 MiB` | **`19,551 MiB`** | **`-2,166 MiB`** | | **SwapDelta (`mem-audit` end)** | `5,798 MiB` | **`4,297 MiB`** | **`-1,501 MiB`** | | **Free RAM (`mem-watch` end)** | `5,165 MiB` | **`5,748 MiB`** | **`+583 MiB`** | | **Host `MEM_PRIVATE`** | `22,491 MiB` | **`18,907 MiB`** | **`-3,584 MiB`** | | **VRAM (`nvidia-smi` / queue)** | `13,008 / 16,376 MiB` (`11,905 MB`) | **`11,642 / 16,376 MiB`** (`10,470 MB`) | **`-1,366 MiB`** | | **`WAIT_RESIDENT` (cumulative)** | `16,800` waits / `2,017.3 ms` | **`2,000` waits / `349.9 ms`** | **~8.4x fewer waits** | - **Crashes / DRED Resets:** `0` (`0` errors, `0` allocation failures) - **Automated Checks:** - [x] `cargo clippy --workspace --all-targets --locked -- -D warnings` - [x] `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings` - [x] `cargo test --locked -p xtask` (`6 passed; 0 failed`) - [x] `cargo test -p victory-gpu --lib -- --test-threads=1` (`572 passed; 0 failed; 37 ignored`)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 20:15:03 +00:00
github-bot closed this pull request 2026-12-01 20:15:03 +00:00
Author
Owner

@⁠Androtim on GitHub · 2026-11-30 00:04 UTC · original · edited 2026-11-30 15:02 UTC

Automated triage for the maintainers (not an approval).

Verdict: needs-rebase · CI (check): none

This PR no longer merges cleanly into main.

To change the verdict: Rebase onto current main and resolve conflicts; CI and triage will run again automatically.


Generated with Antigravity CLI (agy).

**@⁠Androtim** on GitHub · 2026-11-30 00:04 UTC · [original](https://github.com/Androtim/MiniVI/pull/172#issuecomment-7264945935) · edited 2026-11-30 15:02 UTC <!-- minivi-triage v1 head=31f3546d9f6e6368b1cc9cea0f37e8b4a8eaf58f verdict=needs-rebase ci=none at=2026-11-30T15:02:50Z --> Automated triage for the maintainers (not an approval). **Verdict:** `needs-rebase` · **CI (`check`):** `none` This PR no longer merges cleanly into `main`. **To change the verdict:** Rebase onto current `main` and resolve conflicts; CI and triage will run again automatically. --- _Generated with Antigravity CLI (`agy`)._
Author
Owner

@⁠jules-noelaudoux on GitHub · 2026-11-30 00:19 UTC · original

Thanks for the detailed automated review — all findings have been addressed in the latest commit on fix/reduce-commit-memory:

Changes Made

  1. Zero-initialization semantics on reused placed slices (buffers.rs, host.rs):
    • Added zero_init: bool to HeapPool::take and tracked the monotonically advancing fresh_from watermark on each Block (via Ranges::take_from).
    • Mapped pools (Kind::Shared / Kind::GpuUpload): shared_buffer_with and mapped_card_buffer request zero_init = true and clear reused slices via write_bytes(0, size), while upload_buffer sets zero_init = false.
    • Non-mapped Kind::Uav pools: when zero_init = true (uav_buffer_with with wait_residency), allocations only take from untouched [fresh_from, BLOCK) ranges so callers never inherit stale reused bytes without a zeroing pass.
  2. Release ID3D12Resource before returning slot on Map() failure (buffers.rs):
    • Explicitly called drop(resource) before give(piece, now) so the sub-allocated slot is not marked free while the COM resource still references the placed offset.
  3. Avoid holding HeapPool mutex across CreateHeap (buffers.rs):
    • Moved create_pool_heap() (ID3D12Device::CreateHeap + optional residency wait / persistent Map) outside the kind.pool().lock() critical section, inserting/linking the new block cleanly once reacquired.
  4. Tests & comments (buffers.rs, host.rs):
    • Fixed placed_buffers_work_and_reclaim_on_drop to check host() without silently no-oping, query D3D12_FEATURE_D3D12_OPTIONS16::GPUUploadHeapSupported before exercising Kind::GpuUpload (which WARP may not expose), and verify Kind::Shared reuse zeroing.
    • Added uav_fresh_only_skips_reused_dirty_ranges.
    • Corrected the module header comment (32 KiB ..= < 4 MiB sub-allocation threshold) and documented VICTORY_ALLOCATOR_REPLACE=1 on allocator_trim.

Verification

  • cargo xtask policy --staged: pass
  • cargo test --locked -p xtask: 6 passed, 0 failed
  • cargo clippy --workspace --all-targets --locked -- -D warnings: pass (0 warnings)
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: pass (0 warnings)
  • cargo test -p victory-gpu --lib -- --test-threads=1: 573 passed, 0 failed, 37 ignored (all 3 host::buffers::tests::* tests passed)
  • Release cold-cache smoke test (Xbox Series X, 2560x1440 native, DLSS off): reached world rendering (SCENE >=500 draws: n=23, med=12.0 fps, p50=83.5 ms, draws 2252..13162, WAIT_RESIDENT=2400 / 454.2 ms), MEM_AUDIT WS=20606 MiB, Commit=24587 MiB, SwapDelta=3981 MiB (MEM_WATCH 25.1s: Commit 24852 -> 24745 MiB), 0 errors/crashes.
**@⁠jules-noelaudoux** on GitHub · 2026-11-30 00:19 UTC · [original](https://github.com/Androtim/MiniVI/pull/172#issuecomment-7265163945) Thanks for the detailed automated review — all findings have been addressed in the latest commit on `fix/reduce-commit-memory`: ### Changes Made 1. **Zero-initialization semantics on reused placed slices (`buffers.rs`, `host.rs`)**: - Added `zero_init: bool` to `HeapPool::take` and tracked the monotonically advancing `fresh_from` watermark on each `Block` (via `Ranges::take_from`). - Mapped pools (`Kind::Shared` / `Kind::GpuUpload`): `shared_buffer_with` and `mapped_card_buffer` request `zero_init = true` and clear reused slices via `write_bytes(0, size)`, while `upload_buffer` sets `zero_init = false`. - Non-mapped `Kind::Uav` pools: when `zero_init = true` (`uav_buffer_with` with `wait_residency`), allocations only take from untouched `[fresh_from, BLOCK)` ranges so callers never inherit stale reused bytes without a zeroing pass. 2. **Release `ID3D12Resource` before returning slot on `Map()` failure (`buffers.rs`)**: - Explicitly called `drop(resource)` before `give(piece, now)` so the sub-allocated slot is not marked free while the COM resource still references the placed offset. 3. **Avoid holding `HeapPool` mutex across `CreateHeap` (`buffers.rs`)**: - Moved `create_pool_heap()` (`ID3D12Device::CreateHeap` + optional residency wait / persistent `Map`) outside the `kind.pool().lock()` critical section, inserting/linking the new block cleanly once reacquired. 4. **Tests & comments (`buffers.rs`, `host.rs`)**: - Fixed `placed_buffers_work_and_reclaim_on_drop` to check `host()` without silently no-oping, query `D3D12_FEATURE_D3D12_OPTIONS16::GPUUploadHeapSupported` before exercising `Kind::GpuUpload` (which WARP may not expose), and verify `Kind::Shared` reuse zeroing. - Added `uav_fresh_only_skips_reused_dirty_ranges`. - Corrected the module header comment (`32 KiB ..= < 4 MiB` sub-allocation threshold) and documented `VICTORY_ALLOCATOR_REPLACE=1` on `allocator_trim`. ### Verification - `cargo xtask policy --staged`: pass - `cargo test --locked -p xtask`: 6 passed, 0 failed - `cargo clippy --workspace --all-targets --locked -- -D warnings`: pass (0 warnings) - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: pass (0 warnings) - `cargo test -p victory-gpu --lib -- --test-threads=1`: 573 passed, 0 failed, 37 ignored (all 3 `host::buffers::tests::*` tests passed) - Release cold-cache smoke test (Xbox Series X, 2560x1440 native, DLSS off): reached world rendering (`SCENE >=500 draws: n=23, med=12.0 fps, p50=83.5 ms, draws 2252..13162`, `WAIT_RESIDENT=2400 / 454.2 ms`), `MEM_AUDIT` `WS=20606 MiB`, `Commit=24587 MiB`, `SwapDelta=3981 MiB` (`MEM_WATCH` 25.1s: `Commit 24852 -> 24745 MiB`), 0 errors/crashes.
Author
Owner

@⁠Androtim on GitHub · 2026-12-01 01:38 UTC · original

Closing stale/conflicted backlog PR per #276. Superseded by the active root-architecture replacement pillars with isolated plain --release A/B verification.

**@⁠Androtim** on GitHub · 2026-12-01 01:38 UTC · [original](https://github.com/Androtim/MiniVI/pull/172#issuecomment-7297733750) Closing stale/conflicted backlog PR per #276. Superseded by the active root-architecture replacement pillars with isolated plain --release A/B verification.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Androtim--MiniVI!172
No description provided.