victory-gpu/hle: opt-in ReBAR, VRAM LRU, SEC_COMMIT L0 views, RT skin_hair skip & VRAM/L0/RAM leak fixes #3503

Closed
github-bot wants to merge 10 commits from github-bot/gh-3503 into main AGit
Owner

@⁠Rulemore on GitHub · 2026-11-30 00:08 UTC · original
Rulemore:pr/gpu-rebar-vram-leaks → main · +2247 −249 · 16 files · 10 commits · closed without merging

Summary

This PR adds opt-in ReBAR / VRAM LRU / SEC_COMMIT zero-copy L0 / selective RT-skip modes and fixes a set of concrete VRAM, Shared L0, and Host RAM leaks across victory-gpu and victory-hle. All new modes are strictly opt-in behind switches; existing upstream defaults (VICTORY_LAZY_TWINS, VICTORY_SPARE_SCALE, VICTORY_CARD_CPU_HEAP, etc.) are left unchanged.

Part 1 — Opt-In ReBAR, VRAM LRU, SEC_COMMIT L0 & RT Skip Modes

  1. ReBAR (D3D12_HEAP_TYPE_GPU_UPLOAD) Routing (shadow.rs, host.rs, xmem.rs)
    • VICTORY_RO_BAR=1: routes GPU-read-only buffers into GPU_UPLOAD ReBAR memory.
    • VICTORY_CARD_BAR=1: hybrid ReBAR routing for Card buffers overlapping GPU-RO memory (direct BAR writes on 64 KiB-aligned RO pieces, staged RW tail for exact GPU compare hashes).
    • Extends ReBAR routing to RO/WC loose windows (VICTORY_WINDOWS_BAR_MB) and propagates write-combined tracking across xmem placeholder splits and VirtualProtect.
  2. VRAM LRU Promote/Demote with TAKEN_OVER Descriptor Rebinding (shadow.rs, descriptor.rs)
    • Opt-in via VICTORY_CARD_WINDOWS_IDLE_MS and VICTORY_CARD_BUFFERS_IDLE_MS: demotes cold VRAM windows/buffers (>= 1 MiB for buffers under VRAM pressure) back to L0 and promotes hot copies back to VRAM, rebinding stale descriptor slots via descriptor::rebind_taken_over().
  3. Zero-Copy SEC_COMMIT XMem Section Views (xmem.rs, inplace.rs, shadow.rs, draw.rs)
    • VICTORY_XMEM_COMMIT_SECTIONS=1: allocates physical sections in SEC_COMMIT chunks (default 256 MiB via VICTORY_XMEM_CHUNK_MB) and caches OpenExistingHeapFromFileMapping L0 views for zero-copy placement.
  4. Selective Dead RT Pass Skipping (pipeline/make.rs)
    • Adds VICTORY_RT_SKIP_DEAD=no_vbuffer and VICTORY_RT_SKIP_DEAD=skin_hair modes so dead BVH skin/hair builds can be skipped while preserving CS_ScreenProbes_TraceRays and CS_RaytraceVBuffer reflections (no black ponds/glass).

Part 2 — Safe Memory Leak & Non-Release Fixes (Defaults Preserved)

  • resource.rs: Fixed dead NEXT_DEAD_RT_SWEEP condition (!r.host.placed → matches!(r.backing, Backing::Committed(_))) and added Twin Arc::strong_count == 1 + COM references == 1 safety checks.
  • pool.rs: Capped empty blocks in SMALL (<= 64 KiB texture pool) to texture_limit.min(SPARE) and disabled 12-block Ripe pre-allocation on SMALL (saving up to 704 MiB VRAM).
  • shadow.rs:
    • Added idle L0 shadow eviction in BUFFERS during let_go_idle() (guarded by place.is_none() && card.is_none() && !mapped && !written && !has_pending && Arc::strong_count == 1 && references == 1, two-phase read→write lock so BUFFERS_CHANGED only bumps on actual evictions).
    • Added trim_snapshot_pool() to shrink retained POOL snapshots (up to 512 MiB) down to 32 MiB (0 under pressure).
    • Added forced idle pruning of EXACT.map in trim_exact_pool().
    • Added Arc::strong_count guards to demote_idle_card_buffers/promote_hot_buffers, missing self.forward(...) in Shadow::shader_writes(), and any_taken_over() trigger for rebind_taken_over().
  • descriptor.rs, descriptor/host.rs, sampled.rs:
    • Tracked View::Constant slots (HostHeap::constants) so rebind_taken_over() releases TAKEN_OVER shadows pinned in HostHeap::kept.
    • Normalized unused filler words [1] and [13] in Spans::bytes to prevent unbounded HashMap growth from console stack garbage.
    • Added sampled::clear_evicted() (on slot overwrite) and sampled::forget_heap() (on Heap::drop).
  • texture.rs, texture/ahead.rs, host.rs, procmem.rs, xmem.rs, dstorage.rs:
    • Shrunk oversized thread-local READ buffers back to 4 MiB, capped staging idle timeout to 30 s (10 s under pressure) + drained SPARE_LINEAR under pressure, retired outgrown shared_zeros instead of leaking into a Vec, cleared THROUGH in unstage(), cleaned up orphan once staging in ahead::claim, drained SPARE_SHARED + uav_pool in free_all_spares(), ran 10 s SPARE/SPARE_SHARED trim unless VICTORY_ALLOCATOR_TRIM=0, added procmem::section_gone() in xmem::Section::drop, and guarded WALLS_FILES with walls_trace() > 0.

Verification

  • cargo test -p victory-gpu --lib -- --test-threads=1 (including new tests for VICTORY_RO_BAR, VICTORY_CARD_BAR, VRAM LRU, sampled::clear_evicted/forget_heap, and trim_snapshot_pool): 932 passed, 0 failed.
  • cargo test -p victory-hle --lib -- --test-threads=1 xmem::tests dstorage: passed.
  • cargo xtask policy --staged: passed on all modified files.
**@⁠Rulemore** on GitHub · 2026-11-30 00:08 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3503) `Rulemore:pr/gpu-rebar-vram-leaks` → `main` · +2247 −249 · 16 files · 10 commits · closed without merging ## Summary This PR adds opt-in ReBAR / VRAM LRU / `SEC_COMMIT` zero-copy L0 / selective RT-skip modes and fixes a set of concrete VRAM, Shared L0, and Host RAM leaks across `victory-gpu` and `victory-hle`. All new modes are **strictly opt-in** behind switches; existing upstream defaults (`VICTORY_LAZY_TWINS`, `VICTORY_SPARE_SCALE`, `VICTORY_CARD_CPU_HEAP`, etc.) are left unchanged. ### Part 1 — Opt-In ReBAR, VRAM LRU, `SEC_COMMIT` L0 & RT Skip Modes 1. **ReBAR (`D3D12_HEAP_TYPE_GPU_UPLOAD`) Routing (`shadow.rs`, `host.rs`, `xmem.rs`)** - `VICTORY_RO_BAR=1`: routes GPU-read-only buffers into `GPU_UPLOAD` ReBAR memory. - `VICTORY_CARD_BAR=1`: hybrid ReBAR routing for `Card` buffers overlapping GPU-RO memory (direct BAR writes on 64 KiB-aligned RO pieces, staged RW tail for exact GPU compare hashes). - Extends ReBAR routing to RO/WC loose windows (`VICTORY_WINDOWS_BAR_MB`) and propagates write-combined tracking across `xmem` placeholder splits and `VirtualProtect`. 2. **VRAM LRU Promote/Demote with `TAKEN_OVER` Descriptor Rebinding (`shadow.rs`, `descriptor.rs`)** - Opt-in via `VICTORY_CARD_WINDOWS_IDLE_MS` and `VICTORY_CARD_BUFFERS_IDLE_MS`: demotes cold VRAM windows/buffers (`>= 1 MiB` for buffers under VRAM pressure) back to L0 and promotes hot copies back to VRAM, rebinding stale descriptor slots via `descriptor::rebind_taken_over()`. 3. **Zero-Copy `SEC_COMMIT` XMem Section Views (`xmem.rs`, `inplace.rs`, `shadow.rs`, `draw.rs`)** - `VICTORY_XMEM_COMMIT_SECTIONS=1`: allocates physical sections in `SEC_COMMIT` chunks (default 256 MiB via `VICTORY_XMEM_CHUNK_MB`) and caches `OpenExistingHeapFromFileMapping` L0 views for zero-copy placement. 4. **Selective Dead RT Pass Skipping (`pipeline/make.rs`)** - Adds `VICTORY_RT_SKIP_DEAD=no_vbuffer` and `VICTORY_RT_SKIP_DEAD=skin_hair` modes so dead BVH skin/hair builds can be skipped while preserving `CS_ScreenProbes_TraceRays` and `CS_RaytraceVBuffer` reflections (no black ponds/glass). ### Part 2 — Safe Memory Leak & Non-Release Fixes (Defaults Preserved) - **`resource.rs`:** Fixed dead `NEXT_DEAD_RT_SWEEP` condition (`!r.host.placed` → `matches!(r.backing, Backing::Committed(_))`) and added `Twin` `Arc::strong_count == 1` + COM `references == 1` safety checks. - **`pool.rs`:** Capped empty blocks in `SMALL` (`<= 64 KiB` texture pool) to `texture_limit.min(SPARE)` and disabled 12-block `Ripe` pre-allocation on `SMALL` (saving up to 704 MiB VRAM). - **`shadow.rs`:** - Added idle L0 shadow eviction in `BUFFERS` during `let_go_idle()` (guarded by `place.is_none() && card.is_none() && !mapped && !written && !has_pending && Arc::strong_count == 1 && references == 1`, two-phase read→write lock so `BUFFERS_CHANGED` only bumps on actual evictions). - Added `trim_snapshot_pool()` to shrink retained `POOL` snapshots (up to 512 MiB) down to 32 MiB (`0` under pressure). - Added forced idle pruning of `EXACT.map` in `trim_exact_pool()`. - Added `Arc::strong_count` guards to `demote_idle_card_buffers`/`promote_hot_buffers`, missing `self.forward(...)` in `Shadow::shader_writes()`, and `any_taken_over()` trigger for `rebind_taken_over()`. - **`descriptor.rs`, `descriptor/host.rs`, `sampled.rs`:** - Tracked `View::Constant` slots (`HostHeap::constants`) so `rebind_taken_over()` releases `TAKEN_OVER` shadows pinned in `HostHeap::kept`. - Normalized unused filler words `[1]` and `[13]` in `Spans::bytes` to prevent unbounded `HashMap` growth from console stack garbage. - Added `sampled::clear_evicted()` (on slot overwrite) and `sampled::forget_heap()` (on `Heap::drop`). - **`texture.rs`, `texture/ahead.rs`, `host.rs`, `procmem.rs`, `xmem.rs`, `dstorage.rs`:** - Shrunk oversized thread-local `READ` buffers back to 4 MiB, capped staging idle timeout to 30 s (`10 s` under pressure) + drained `SPARE_LINEAR` under pressure, retired outgrown `shared_zeros` instead of leaking into a `Vec`, cleared `THROUGH` in `unstage()`, cleaned up orphan `once` staging in `ahead::claim`, drained `SPARE_SHARED` + `uav_pool` in `free_all_spares()`, ran 10 s `SPARE`/`SPARE_SHARED` trim unless `VICTORY_ALLOCATOR_TRIM=0`, added `procmem::section_gone()` in `xmem::Section::drop`, and guarded `WALLS_FILES` with `walls_trace() > 0`. ### Verification - `cargo test -p victory-gpu --lib -- --test-threads=1` (including new tests for `VICTORY_RO_BAR`, `VICTORY_CARD_BAR`, `VRAM LRU`, `sampled::clear_evicted`/`forget_heap`, and `trim_snapshot_pool`): **932 passed, 0 failed**. - `cargo test -p victory-hle --lib -- --test-threads=1 xmem::tests dstorage`: passed. - `cargo xtask policy --staged`: passed on all modified files.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 00:11:43 +00:00
Author
Owner

@⁠tyr0nsur on GitHub · 2026-11-30 10:31 UTC · original

I tested a pressure-only version of the exact-view sweep on main at 41adb55. The existing sweep drains the recycle pool under pressure. A scene can leave idle entries in EXACT.map too, because lookup pruning requires at least 256 entries and another miss. The forced scan here addresses that. Running it on normal ticks can also move reusable views into quarantine, so I tried keeping normal cache hits and forcing the map sweep only while the existing host-pressure signal is on.

The small companion patch shares the pruning guard and the existing age, Arc and COM checks. It removes eligible views under the lookup lock, then hands them to host::retire after unlocking. The normal submission watermark and deferred release still apply.

On an RTX 4060, a standalone fixture held an idle 16 MiB committed L0 view. With simulated pressure, DXGI non-local usage stayed at 108 MiB on main and fell from 108 to 92 MiB with the patch. The ordinary tick kept the view, and the pressure tick kept a freshly used view, one held by a list reference, and one held by a descriptor reference. The fixture ran with VICTORY_BURY_LAG=0 and no submissions in flight to measure the release. It also passed on WARP. The focused diagnostics suite passed 73 tests.

One-file commit against main

**@⁠tyr0nsur** on GitHub · 2026-11-30 10:31 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3503#issuecomment-7275713971) I tested a pressure-only version of the exact-view sweep on main at `41adb55`. The existing sweep drains the recycle pool under pressure. A scene can leave idle entries in `EXACT.map` too, because lookup pruning requires at least 256 entries and another miss. The forced scan here addresses that. Running it on normal ticks can also move reusable views into quarantine, so I tried keeping normal cache hits and forcing the map sweep only while the existing host-pressure signal is on. The small companion patch shares the pruning guard and the existing age, Arc and COM checks. It removes eligible views under the lookup lock, then hands them to `host::retire` after unlocking. The normal submission watermark and deferred release still apply. On an RTX 4060, a standalone fixture held an idle 16 MiB committed L0 view. With simulated pressure, DXGI non-local usage stayed at 108 MiB on main and fell from 108 to 92 MiB with the patch. The ordinary tick kept the view, and the pressure tick kept a freshly used view, one held by a list reference, and one held by a descriptor reference. The fixture ran with `VICTORY_BURY_LAG=0` and no submissions in flight to measure the release. It also passed on WARP. The focused diagnostics suite passed 73 tests. [One-file commit against main](https://github.com/tyr0nsur/VIctory-NVIDIA/commit/c9868796c72586fdbc6abd38261adf2274cd2571)
Author
Owner

@⁠trustno1-coder on GitHub · 2026-12-01 18:51 UTC · original

Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

**@⁠trustno1-coder** on GitHub · 2026-12-01 18:51 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3503#issuecomment-7321689388) Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.
github-bot closed this pull request 2026-12-01 18:58:26 +00:00

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