feat(gpu/pool): default-on sparse texture pool drain and compaction #302

Closed
github-bot wants to merge 1 commit from github-bot/gh-302 into main AGit
Owner

@⁠Androtim on GitHub · 2026-12-02 02:02 UTC · original
Androtim:feat/pool-sparse-compaction → main · +600 −35 · 4 files · 1 commits · closed without merging

Summary

Implements default-on sparse 64 MiB texture block drain and compaction (\VICTORY_POOL_COMPACT=0\ kill-switch) to reclaim fragmented VRAM heaps back to D3D12 under pressure and curb Shared GPU spillover, using dynamic budget-reactive headroom across 8 GB to 16 GB+ GPUs.

  • Sparse Pool Compaction Engine (\crates/victory-gpu/src/pool.rs):
    • Replaced separate \LIVE_BLOCKS\ mutex with \Pool::live\ tracking every pooled resource's (block, len)\ and simplified \lock_used_bytes.
    • Added \compact_choice, dynamic \compact_headroom\ (\1–2\ blocks at >= 85–90%\ VRAM pressure or < 768 MiB\ headroom; \512–1024 MiB\ on spacious 16–24+ GiB GPUs), and dynamic \move_budget\ (\32–128 MiB/s).
    • Excluded draining blocks from all allocation paths (\ ake_ripe, \cut_best_ripe, unripe fallback, ahead empty count), bypassed the spare limit in \Pool::reclaim\ to immediately return emptied blocks to D3D12, added 30s give-up / 120s cooldown backoff, and added
      ote_load_burst\ / \call_off_drains\ during streaming bursts.
  • Relocation & Full-Card Safety (\descriptor/host.rs,
    esource.rs, \draw.rs):
    • Added \HostHeap::texture_slots_regrow\ and
      esource::drain_moves\ (moving non-host-written placed textures into \REPLACED\ while descriptor slots keep displaying the valid old copy until the relocated copy uploads and lands).
    • Protected !room\ relocations in \draw::heap_textures\ with \pool::existing_only\ so compacting textures never triggers \Grow::Must\ new-heap allocations while VRAM is full.

Verification

  • \cargo +1.98.1-x86_64-pc-windows-gnu xtask policy\ -> \sset policy: 319 files ok\
  • \cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-gpu --lib --locked pool::\ -> 23 passed, 0 failed, 1 ignored (hardware timing benchmark)
  • \cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --locked --all-targets -- -D warnings\ -> passed
  • \cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --locked --all-targets --features diagnostics -- -D warnings\ -> passed
  • \cargo +1.98.1-x86_64-pc-windows-gnu build --release --bin MiniVI --locked\ + \objdump -p\ -> standard Windows DLLs only.

Paired Plain --release\ 90s A/B Benchmarks (RTX 4060 Ti 8 GB / Series X Parity, vs \main\ \73f4cc8)

  • 4K (-PlayParity -Res 4k):
    • FPS: \5.8 -> 6.6 fps\ (+13.8%, \171.6 -> 151.5 ms/frame, min \4.6 -> 5.8 fps)
    • CPU \preparing: \30.6 -> 22.6 ms\ (-8.0 ms), \copyback: \20.3 -> 13.7 ms\ (-6.6 ms)
    • Residency \mapped(): \5.21 -> 2.56 ms/s\ (\258.2 -> 139.7 ms\ total)
    • Pool:
      ot made\ \4,556 -> 0, \given back\ \
**@⁠Androtim** on GitHub · 2026-12-02 02:02 UTC · [original](https://github.com/Androtim/MiniVI/pull/302) `Androtim:feat/pool-sparse-compaction` → `main` · +600 −35 · 4 files · 1 commits · closed without merging ## Summary Implements default-on sparse 64 MiB texture block drain and compaction (\VICTORY_POOL_COMPACT=0\ kill-switch) to reclaim fragmented VRAM heaps back to D3D12 under pressure and curb Shared GPU spillover, using dynamic budget-reactive headroom across 8 GB to 16 GB+ GPUs. - **Sparse Pool Compaction Engine (\crates/victory-gpu/src/pool.rs\):** - Replaced separate \LIVE_BLOCKS\ mutex with \Pool::live\ tracking every pooled resource's \(block, len)\ and simplified \lock_used_bytes\. - Added \compact_choice\, dynamic \compact_headroom\ (\1–2\ blocks at \>= 85–90%\ VRAM pressure or \< 768 MiB\ headroom; \512–1024 MiB\ on spacious 16–24+ GiB GPUs), and dynamic \move_budget\ (\32–128 MiB/s\). - Excluded draining blocks from all allocation paths (\ ake_ripe\, \cut_best_ripe\, unripe fallback, ahead empty count), bypassed the spare limit in \Pool::reclaim\ to immediately return emptied blocks to D3D12, added 30s give-up / 120s cooldown backoff, and added \ ote_load_burst\ / \call_off_drains\ during streaming bursts. - **Relocation & Full-Card Safety (\descriptor/host.rs\, \ esource.rs\, \draw.rs\):** - Added \HostHeap::texture_slots_regrow\ and \ esource::drain_moves\ (moving non-host-written placed textures into \REPLACED\ while descriptor slots keep displaying the valid old copy until the relocated copy uploads and lands). - Protected \!room\ relocations in \draw::heap_textures\ with \pool::existing_only\ so compacting textures never triggers \Grow::Must\ new-heap allocations while VRAM is full. ## Verification - \cargo +1.98.1-x86_64-pc-windows-gnu xtask policy\ -> \sset policy: 319 files ok\ - \cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-gpu --lib --locked pool::\ -> 23 passed, 0 failed, 1 ignored (hardware timing benchmark) - \cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --locked --all-targets -- -D warnings\ -> passed - \cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --locked --all-targets --features diagnostics -- -D warnings\ -> passed - \cargo +1.98.1-x86_64-pc-windows-gnu build --release --bin MiniVI --locked\ + \objdump -p\ -> standard Windows DLLs only. ### Paired Plain \--release\ 90s A/B Benchmarks (RTX 4060 Ti 8 GB / Series X Parity, vs \main\ \73f4cc8\) - **4K (\-PlayParity -Res 4k\):** - FPS: \5.8 -> 6.6 fps\ (\+13.8%\, \171.6 -> 151.5 ms/frame\, min \4.6 -> 5.8 fps\) - CPU \preparing\: \30.6 -> 22.6 ms\ (\-8.0 ms\), \copyback\: \20.3 -> 13.7 ms\ (\-6.6 ms\) - Residency \mapped()\: \5.21 -> 2.56 ms/s\ (\258.2 -> 139.7 ms\ total) - Pool: \ ot made\ \4,556 -> 0\, \given back\ \
- Enable default-on sparse 64 MiB texture block compaction (VICTORY_POOL_COMPACT=0 opt-out) with dynamic budget-reactive headroom (1-2 blocks under tight >=85-90% VRAM pressure, 512-1024 MiB on 16-24+ GiB GPUs).
- Skip draining blocks during allocation, protect !room relocations with pool::existing_only to prevent Grow::Must allocations while full, pause/cancel drains on streaming load bursts, and immediately return emptied blocks to D3D12.
- Wire descriptor::HostHeap::texture_slots_regrow, resource::drain_moves, and draw::heap_textures pass scheduling.
- Verified with xtask policy, pool:: (23/23), dual clippy, and paired 90s plain --release A/B runs (1440p & 4K) plus diagnostics PNG inspection.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-02 02:06:01 +00:00
Author
Owner

@⁠Androtim on GitHub · 2026-12-02 02:20 UTC · original

Audited full diff (e3065e2a, +600 -35 across 4 files) — architecture and lock discipline look strong:

  • Consolidating LIVE_BLOCKS into Pool::live, dynamic compact_headroom / move_budget (8 GB tight vs 16–24+ GB spacious), VICTORY_POOL_COMPACT=0 kill-switch, burst cancellation (note_load_burst), existing_only protection against Grow::Must, and lock ordering in drain_moves() (draining_textures() + video_memory() before textures()) all look solid.
  • The visible portion of the 4K plain---release A/B is very promising (5.8 -> 6.6 fps +13.8%, preparing 30.6 -> 22.6 ms, copyback 20.3 -> 13.7 ms, mapped() 5.21 -> 2.56 ms/s, not_made 4,556 -> 0).

However, the PR body was truncated right at given back by a PowerShell \0 escape, cutting off required gate fields. Please post a comment (using a single-quoted PowerShell here-string @' ... '@ so backticks and 0 are not escaped) with:

  1. Complete plain---release A/B numbers (4K and 1440p if run): median/min fps, preparing ms, copyback ms, VRAM used_max / budget / over / room_false, pool given_back, final_waiting, untranslated, 0 crashes/DRED, and shared_mb / private_commit_mb / commit_left_mb from the 5 s memory log if available.
  2. --features diagnostics visual verification (luma, near_black, edge_energy, magenta, 0 black/swapped textures during live compaction relocations) and the verification run folder name so we can inspect the PNGs directly before merging.
**@⁠Androtim** on GitHub · 2026-12-02 02:20 UTC · [original](https://github.com/Androtim/MiniVI/pull/302#issuecomment-7332724727) Audited full diff (`e3065e2a`, `+600 -35` across 4 files) — architecture and lock discipline look strong: - Consolidating `LIVE_BLOCKS` into `Pool::live`, dynamic `compact_headroom` / `move_budget` (8 GB tight vs 16–24+ GB spacious), `VICTORY_POOL_COMPACT=0` kill-switch, burst cancellation (`note_load_burst`), `existing_only` protection against `Grow::Must`, and lock ordering in `drain_moves()` (`draining_textures()` + `video_memory()` before `textures()`) all look solid. - The visible portion of the 4K plain-`--release` A/B is very promising (`5.8 -> 6.6 fps` `+13.8%`, `preparing 30.6 -> 22.6 ms`, `copyback 20.3 -> 13.7 ms`, `mapped() 5.21 -> 2.56 ms/s`, `not_made 4,556 -> 0`). However, the PR body was truncated right at `given back` by a PowerShell `\0` escape, cutting off required gate fields. Please post a comment (using a single-quoted PowerShell here-string `@' ... '@` so backticks and `0` are not escaped) with: 1. Complete plain-`--release` A/B numbers (4K and 1440p if run): `median/min fps`, `preparing ms`, `copyback ms`, `VRAM used_max / budget / over / room_false`, `pool given_back`, `final_waiting`, `untranslated`, `0` crashes/DRED, and `shared_mb` / `private_commit_mb` / `commit_left_mb` from the 5 s memory log if available. 2. `--features diagnostics` visual verification (`luma`, `near_black`, `edge_energy`, `magenta`, `0` black/swapped textures during live compaction relocations) and the verification run folder name so we can inspect the PNGs directly before merging.
Author
Owner

@⁠Androtim on GitHub · 2026-12-02 03:04 UTC · original

Automated triage for the maintainers (not an approval).

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

Review Summary

Logic, lock ordering, and safety invariants for default-on sparse texture pool compaction (VICTORY_POOL_COMPACT=0 kill-switch) look solid, and CI is passing. Because this enables live D3D12 placed-texture relocation and heap reclamation by default under VRAM pressure, a local real-GPU smoke test is recommended before merging.

Verified Details

  • Pool compaction & allocation exclusion (crates/victory-gpu/src/pool.rs):
    • Replacing the separate LIVE_BLOCKS mutex with Pool::live under TEXTURES eliminates cross-lock coordination in block_used_bytes and release.
    • Draining blocks are consistently excluded across take_ripe (best_fit, fullest, linear scan, unripe fallback, and ahead empty count), and Pool::reclaim immediately drops emptied draining blocks without counting them against SPARES.
    • note_load_burst / call_off_drains and the 30s give-up / 120s cooldown (DRAIN_GIVE_UP_MS / DRAIN_AGAIN_MS) properly clear self.no_fit so freed holes become allocatable again.
    • Unit tests cover compact_choice, compact_headroom, move_budget, draining exclusion/reclamation, timeout backoff, and burst cancellation.
  • Relocation & full-card safety (crates/victory-gpu/src/resource.rs, crates/victory-gpu/src/draw.rs, crates/victory-gpu/src/descriptor/host.rs):
    • resource::drain_moves fetches pool::draining_textures() before locking textures(), skips twin/tiled/host_wrote textures, and retires old copies into REPLACED so existing descriptor slots stay valid until the relocated copy uploads.
    • In draw::heap_textures, guarding !room relocations (made_copy(...).is_none()) with pool::existing_only prevents relocated copies from triggering Grow::Must new-block allocations while VRAM is full.

Minor Non-Blocking Notes

  • compact_choice (crates/victory-gpu/src/pool.rs): When selecting multiple blocks in a single pass, an earlier candidate's fits check (g.longest >= f.largest) can rely on a block that is subsequently chosen later in the same loop. This is safe (the block will time out after DRAIN_GIVE_UP_MS and back off), though re-checking or reserving the destination's longest would avoid futile drain attempts.
  • Doc comment (crates/victory-gpu/src/resource.rs): The doc comment on drain_moves begins with /// `VICTORY_SLOT_EVICT=1` (`crate::resource::slot_evict`). rather than VICTORY_POOL_COMPACT.
  • Run a VRAM-pressured session (e.g., 8 GB GPU or 4K/high-res streaming scene) with default settings (VICTORY_POOL_COMPACT unset) and confirm:
    1. Compaction telemetry (texture pool compaction) logs emptied > 0 without D3D12 device removal, descriptor corruption, or black/missing textures during relocation.
    2. No new-block growth spikes occur while !room (not made / past stay bounded).
    3. Setting VICTORY_POOL_COMPACT=0 cleanly disables compaction and restores baseline behavior.

Generated with Antigravity CLI (agy).

**@⁠Androtim** on GitHub · 2026-12-02 03:04 UTC · [original](https://github.com/Androtim/MiniVI/pull/302#issuecomment-7333494254) <!-- minivi-triage v1 head=e3065e2ab0b47d056e7bd6c48331ce73c8184a6a verdict=needs-gpu-test ci=passing at=2026-12-02T03:04:33Z --> Automated triage for the maintainers (not an approval). **Verdict:** `needs-gpu-test` · **CI (`check`):** `passing` ### Review Summary Logic, lock ordering, and safety invariants for default-on sparse texture pool compaction (`VICTORY_POOL_COMPACT=0` kill-switch) look solid, and CI is passing. Because this enables live D3D12 placed-texture relocation and heap reclamation by default under VRAM pressure, a local real-GPU smoke test is recommended before merging. ### Verified Details - **Pool compaction & allocation exclusion (`crates/victory-gpu/src/pool.rs`):** - Replacing the separate `LIVE_BLOCKS` mutex with `Pool::live` under `TEXTURES` eliminates cross-lock coordination in `block_used_bytes` and `release`. - Draining blocks are consistently excluded across `take_ripe` (`best_fit`, `fullest`, linear scan, unripe fallback, and `ahead` empty count), and `Pool::reclaim` immediately drops emptied draining blocks without counting them against `SPARES`. - `note_load_burst` / `call_off_drains` and the 30s give-up / 120s cooldown (`DRAIN_GIVE_UP_MS` / `DRAIN_AGAIN_MS`) properly clear `self.no_fit` so freed holes become allocatable again. - Unit tests cover `compact_choice`, `compact_headroom`, `move_budget`, draining exclusion/reclamation, timeout backoff, and burst cancellation. - **Relocation & full-card safety (`crates/victory-gpu/src/resource.rs`, `crates/victory-gpu/src/draw.rs`, `crates/victory-gpu/src/descriptor/host.rs`):** - `resource::drain_moves` fetches `pool::draining_textures()` before locking `textures()`, skips `twin`/`tiled`/`host_wrote` textures, and retires old copies into `REPLACED` so existing descriptor slots stay valid until the relocated copy uploads. - In `draw::heap_textures`, guarding `!room` relocations (`made_copy(...).is_none()`) with `pool::existing_only` prevents relocated copies from triggering `Grow::Must` new-block allocations while VRAM is full. ### Minor Non-Blocking Notes - **`compact_choice` (`crates/victory-gpu/src/pool.rs`):** When selecting multiple blocks in a single pass, an earlier candidate's `fits` check (`g.longest >= f.largest`) can rely on a block that is subsequently chosen later in the same loop. This is safe (the block will time out after `DRAIN_GIVE_UP_MS` and back off), though re-checking or reserving the destination's `longest` would avoid futile drain attempts. - **Doc comment (`crates/victory-gpu/src/resource.rs`):** The doc comment on `drain_moves` begins with ``/// `VICTORY_SLOT_EVICT=1` (`crate::resource::slot_evict`).`` rather than `VICTORY_POOL_COMPACT`. ### Recommended Local GPU Smoke Test - Run a VRAM-pressured session (e.g., 8 GB GPU or 4K/high-res streaming scene) with default settings (`VICTORY_POOL_COMPACT` unset) and confirm: 1. Compaction telemetry (`texture pool compaction`) logs `emptied > 0` without D3D12 device removal, descriptor corruption, or black/missing textures during relocation. 2. No new-block growth spikes occur while `!room` (`not made` / `past` stay bounded). 3. Setting `VICTORY_POOL_COMPACT=0` cleanly disables compaction and restores baseline behavior. --- _Generated with Antigravity CLI (`agy`)._
Author
Owner

@⁠Androtim on GitHub · 2026-12-02 15:03 UTC · original

Holding merge (triage: needs work) per deep static audit routing (#282 comment 7349410307, P1 finding #15): relocated non-level0 textures never update host SRVs, which can double VRAM usage. Please fix and re-run CI + driving-loop.csv A/B before merge.

**@⁠Androtim** on GitHub · 2026-12-02 15:03 UTC · [original](https://github.com/Androtim/MiniVI/pull/302#issuecomment-7349651286) Holding merge (`triage: needs work`) per deep static audit routing (`#282` comment `7349410307`, P1 finding #15): relocated non-`level0` textures never update host SRVs, which can double VRAM usage. Please fix and re-run CI + `driving-loop.csv` A/B before merge.
github-bot closed this pull request 2026-12-02 15:44:52 +00:00
Author
Owner

@⁠Androtim on GitHub · 2026-12-02 15:40 UTC · original

Closing as regressing under the paired plain---release driving-loop.csv A/B gate against main (79b7589).

Even after fixing #282 finding #15 locally (relocated: AtomicBool, unconditional levels_changed_after refresh for relocated copies, draining_plan hole verification before unstaging, existing_only fallback guard, and compact_choice destination pinning), 120s paired driving-loop.csv A/B runs showed significant regressions:

4K DLSS Quality (120s driving-loop.csv, Series X, RTX 4060 Ti 8 GB)

  • FPS / frame time: 5.9 -> 5.3 fps med (168.7 -> 188.1 ms, -0.6 fps, min 5.3 -> 5.0 fps)
  • Breakdown: preparing 20.45 -> 23.2 ms (+2.75 ms), GPU 132.05 -> 139.8 ms (+7.75 ms), copyback 10.65 -> 12.8 ms (+2.15 ms)
  • VRAM: used_max 6776 -> 6931 MB (+155 MB), over=56 -> 204 MB
  • Compaction / streaming: chosen=7, emptied=2, given_up=2, given_back_total=2, moved=9078 (174 MB), slots_due=9005, not_made 16776 -> 3004, final_waiting 9988 -> 15741, 0 crashes/DRED

1440p DLSS Quality (120s driving-loop.csv, Series X, RTX 4060 Ti 8 GB)

  • FPS / frame time: 8.7 -> 8.75 fps med (114.85 -> 114.0 ms), min 4.9 -> 2.2 fps
  • VRAM: used_max 6265 -> 6395 MB (+130 MB), room_false 42.9% -> 60.9%, pool free_mb 298 -> 364 MB
  • Compaction / streaming: chosen=22, emptied=1, given_up=0, given_back_total=1, moved=9485 (337 MB), slots_due=9456, not_made 4865 -> 1885, final_waiting 3140 -> 11248, 0 crashes/DRED

Live-relocating 9,000+ small textures across 64 MiB blocks kept both old (REPLACED) and new copies resident while churning CPU uploads/re-tabling for only 1–2 freed blocks. Moving directly to #282 P0 #1 & #2 (slot_evict idle-threshold deadlock + CardPool free-bitset) instead.

**@⁠Androtim** on GitHub · 2026-12-02 15:40 UTC · [original](https://github.com/Androtim/MiniVI/pull/302#issuecomment-7350741210) Closing as regressing under the paired plain-`--release` `driving-loop.csv` A/B gate against `main` (`79b7589`). Even after fixing `#282` finding `#15` locally (`relocated: AtomicBool`, unconditional `levels_changed_after` refresh for relocated copies, `draining_plan` hole verification before unstaging, `existing_only` fallback guard, and `compact_choice` destination pinning), 120s paired `driving-loop.csv` A/B runs showed significant regressions: ### 4K DLSS Quality (120s `driving-loop.csv`, Series X, RTX 4060 Ti 8 GB) - **FPS / frame time:** `5.9 -> 5.3 fps` med (`168.7 -> 188.1 ms`, `-0.6 fps`, min `5.3 -> 5.0 fps`) - **Breakdown:** preparing `20.45 -> 23.2 ms` (`+2.75 ms`), GPU `132.05 -> 139.8 ms` (`+7.75 ms`), copyback `10.65 -> 12.8 ms` (`+2.15 ms`) - **VRAM:** `used_max 6776 -> 6931 MB` (`+155 MB`), `over=56 -> 204 MB` - **Compaction / streaming:** `chosen=7`, `emptied=2`, `given_up=2`, `given_back_total=2`, `moved=9078` (`174 MB`), `slots_due=9005`, `not_made 16776 -> 3004`, `final_waiting 9988 -> 15741`, `0` crashes/DRED ### 1440p DLSS Quality (120s `driving-loop.csv`, Series X, RTX 4060 Ti 8 GB) - **FPS / frame time:** `8.7 -> 8.75 fps` med (`114.85 -> 114.0 ms`), min `4.9 -> 2.2 fps` - **VRAM:** `used_max 6265 -> 6395 MB` (`+130 MB`), `room_false 42.9% -> 60.9%`, `pool free_mb 298 -> 364 MB` - **Compaction / streaming:** `chosen=22`, `emptied=1`, `given_up=0`, `given_back_total=1`, `moved=9485` (`337 MB`), `slots_due=9456`, `not_made 4865 -> 1885`, `final_waiting 3140 -> 11248`, `0` crashes/DRED Live-relocating 9,000+ small textures across 64 MiB blocks kept both old (`REPLACED`) and new copies resident while churning CPU uploads/re-tabling for only 1–2 freed blocks. Moving directly to `#282` P0 #1 & #2 (`slot_evict` idle-threshold deadlock + `CardPool` free-bitset) instead.

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!302
No description provided.