fix(gpu/ahead): replace bump-only CardBumpPool with fence-gated recycling (#282) (#276) #355

Closed
github-bot wants to merge 2 commits from github-bot/gh-355 into main AGit
Owner

@⁠Androtim on GitHub · 2026-12-02 15:43 UTC · original
Androtim:fix/gpu-card-bump-pool-recycling → main · +628 −137 · 2 files · 2 commits · closed without merging

Summary

Fixes P0 finding #2 from #282 (tracking bottleneck backlog #276).

Previously, \CardBumpPool\ in \crates/victory-gpu/src/ahead.rs\ only bumped slot offsets inside 4 MiB \D3D12_HEAP_TYPE_DEFAULT\ heaps and discarded old heaps from \ctive\ once \ctive.len() >= 2. Any single surviving 64 KiB allocation permanently pinned an entire 4 MiB VRAM heap while the remaining 63 slots could never be reused, and concurrent heap creation races could abandon remaining free slots in newly created heaps.

Changes

  • Unified bitset/fence-gated pool (\HeapBlock\ / \HeapPool, \PoolReclaim): Replaced \CardBumpPool\ with the 64-slot bitset pool shared with \SHARED_SMALL_POOL\ / \SHARED_LARGE_POOL, gated card slot retirement on completed GPU submission fences (\queue::queued\ read before \host::submissions().0), and handled out-of-order retirement entries safely.
  • No heap pinning & zero-initialization preserved: \ ake_slot_with\ prefers non-empty blocks (and virgin slots before recycled slots), \CardZeroer\ zeroes recycled default-heap slots on a dedicated COPY queue to preserve \Host::uav_buffer\ zero-initialized semantics, and \ rim_card_pool\ drops excess empty heaps from \head::fill\ and \host::sweep.
  • Serialized heap creation & re-check: \lloc_pooled_card\ serializes fresh heap creation under \CARD_CREATE\ and re-checks \ ake_fenced\ after re-acquiring \CARD_POOL\ before allocating a fresh 4 MiB \ID3D12Heap.

Testing

  • \cargo test -p victory-gpu --lib -j 4 -- --test-threads=1\ (724 passed, 0 failed, 39 ignored; includes \card_pool_fenced_retirement_slot_reuse_and_no_heap_pinning\ and \pooled_shared_and_card_buffers_pass_d3d12_lifecycle_and_zero_on_recycle)
  • \cargo clippy -p victory-gpu --lib --tests -j 4 -- -D warnings\ and --all-features\
  • \cargo test -p xtask -j 4\ (8 policy tests passed)
**@⁠Androtim** on GitHub · 2026-12-02 15:43 UTC · [original](https://github.com/Androtim/MiniVI/pull/355) `Androtim:fix/gpu-card-bump-pool-recycling` → `main` · +628 −137 · 2 files · 2 commits · closed without merging ## Summary Fixes P0 finding #2 from #282 (tracking bottleneck backlog #276). Previously, \CardBumpPool\ in \crates/victory-gpu/src/ahead.rs\ only bumped slot offsets inside 4 MiB \D3D12_HEAP_TYPE_DEFAULT\ heaps and discarded old heaps from \ctive\ once \ctive.len() >= 2\. Any single surviving 64 KiB allocation permanently pinned an entire 4 MiB VRAM heap while the remaining 63 slots could never be reused, and concurrent heap creation races could abandon remaining free slots in newly created heaps. ## Changes - **Unified bitset/fence-gated pool (\HeapBlock\ / \HeapPool\, \PoolReclaim\):** Replaced \CardBumpPool\ with the 64-slot bitset pool shared with \SHARED_SMALL_POOL\ / \SHARED_LARGE_POOL\, gated card slot retirement on completed GPU submission fences (\queue::queued\ read before \host::submissions().0\), and handled out-of-order retirement entries safely. - **No heap pinning & zero-initialization preserved:** \ ake_slot_with\ prefers non-empty blocks (and virgin slots before recycled slots), \CardZeroer\ zeroes recycled default-heap slots on a dedicated COPY queue to preserve \Host::uav_buffer\ zero-initialized semantics, and \ rim_card_pool\ drops excess empty heaps from \head::fill\ and \host::sweep\. - **Serialized heap creation & re-check:** \lloc_pooled_card\ serializes fresh heap creation under \CARD_CREATE\ and re-checks \ ake_fenced\ after re-acquiring \CARD_POOL\ before allocating a fresh 4 MiB \ID3D12Heap\. ## Testing - \cargo test -p victory-gpu --lib -j 4 -- --test-threads=1\ (724 passed, 0 failed, 39 ignored; includes \card_pool_fenced_retirement_slot_reuse_and_no_heap_pinning\ and \pooled_shared_and_card_buffers_pass_d3d12_lifecycle_and_zero_on_recycle\) - \cargo clippy -p victory-gpu --lib --tests -j 4 -- -D warnings\ and \--all-features\ - \cargo test -p xtask -j 4\ (8 policy tests passed)
Replace the bump-only CardBumpPool in ahead.rs with a unified 64-slot bitset and fence-gated retirement pool (HeapBlock/HeapPool), mirroring SharedPool and tracking live placed allocations via PoolReclaim COM private data.

- Retire freed card slots against GPU submission completion fences (reading queue::queued strictly before host::submissions().0) and handle out-of-order retirement safely.
- Prefer non-empty blocks (and virgin slots inside a block) before empty blocks so a single surviving 64 KiB allocation never pins a 4 MiB VRAM heap, and zero recycled card slots on a dedicated COPY queue to preserve Host::uav_buffer zero-initialization semantics.
- Serialize card heap creation via CARD_CREATE and re-check take_fenced after re-acquiring CARD_POOL before creating a fresh 4 MiB heap.
- Trim excess empty card heaps in ahead::fill and host::sweep.
- Add unit tests covering fence-gated slot reuse, out-of-order retirement, multi-slot recycling, and zero heap pinning.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-02 15:44:51 +00:00
Author
Owner

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

Architect Deep Review (#282 P0 #2 — CI 46918042491 GREEN):

The unified 64-slot bitset HeapBlock/HeapPool, fence-gated slot retirement (card_retire_fence() reading queue::queued() before host::submissions().0), CARD_CREATE serialization, and trim_card_pool look clean — one major stall/deadlock issue to fix in CardZeroer::zero (crates/victory-gpu/src/ahead.rs:583) before GPU A/B & merge:

  • CardZeroer::zero calls crate::host::settle() (a full synchronous GPU pipeline drain) plus synchronous COPY-queue WaitForSingleObject(INFINITE) on every recycled needs_zero slot allocation.
  • Because take_fenced(slots, finished) already guarantees retire_fence <= finished (every GPU submission that used that slot has already completed and decayed back to COMMON), calling crate::host::settle() is redundant and will stall the entire frame pipeline whenever alloc_pooled_card recycles a slot (and risks stalling/re-entrancy if triggered from a submitting/recording path when spares run dry).
  • Removing crate::host::settle() from CardZeroer::zero (or verifying whether batching/copy-queue zeroing adds any stall) + running a paired plain---release A/B on main (3efe9073+, ideally on driving-loop.csv to verify 4 MiB card heap count stays bounded with zero FPS regression) is needed before merge.
**@⁠Androtim** on GitHub · 2026-12-02 16:04 UTC · [original](https://github.com/Androtim/MiniVI/pull/355#issuecomment-7351389804) Architect Deep Review (`#282` P0 #2 — CI `46918042491` **GREEN**): The unified 64-slot bitset `HeapBlock`/`HeapPool`, fence-gated slot retirement (`card_retire_fence()` reading `queue::queued()` before `host::submissions().0`), `CARD_CREATE` serialization, and `trim_card_pool` look clean — **one major stall/deadlock issue to fix in `CardZeroer::zero` (`crates/victory-gpu/src/ahead.rs:583`) before GPU A/B & merge:** - `CardZeroer::zero` calls `crate::host::settle()` (a **full synchronous GPU pipeline drain**) plus synchronous COPY-queue `WaitForSingleObject(INFINITE)` on every recycled `needs_zero` slot allocation. - Because `take_fenced(slots, finished)` **already guarantees `retire_fence <= finished`** (every GPU submission that used that slot has already completed and decayed back to `COMMON`), calling `crate::host::settle()` is redundant and will stall the entire frame pipeline whenever `alloc_pooled_card` recycles a slot (and risks stalling/re-entrancy if triggered from a submitting/recording path when spares run dry). - Removing `crate::host::settle()` from `CardZeroer::zero` (or verifying whether batching/copy-queue zeroing adds any stall) + running a paired plain-`--release` A/B on `main` (`3efe9073`+, ideally on `driving-loop.csv` to verify 4 MiB card heap count stays bounded with zero FPS regression) is needed before merge.
Author
Owner

@⁠Androtim on GitHub · 2026-12-02 16:06 UTC · original · edited 2026-12-02 18: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-12-02 16:06 UTC · [original](https://github.com/Androtim/MiniVI/pull/355#issuecomment-7351437399) · edited 2026-12-02 18:02 UTC <!-- minivi-triage v1 head=d31fa431ade2cc5fd7af4f53fe67365488a11c74 verdict=needs-rebase ci=none at=2026-12-02T18:02:48Z --> 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

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

Superseded by #362 (just merged to main with green CI 46932200524, verified plain---release A/B -553 MB 4K 120s peak VRAM / 0 MB over / card_heaps 167 -> 58, visually inspected PNGs, and without CardZeroer::zero() calling host::settle()).

If we want to carry over #355's card_retire_fence = started + queued + bury_lag.max(1) hardening on top of #362's card_reclaim_release, a tiny targeted follow-up PR on main is the cleanest path; otherwise #355 can be closed.

**@⁠Androtim** on GitHub · 2026-12-02 17:33 UTC · [original](https://github.com/Androtim/MiniVI/pull/355#issuecomment-7353416317) Superseded by `#362` (just merged to `main` with green CI `46932200524`, verified plain-`--release` A/B `-553 MB` 4K 120s peak VRAM / `0 MB` over / `card_heaps 167 -> 58`, visually inspected PNGs, and without `CardZeroer::zero()` calling `host::settle()`). If we want to carry over `#355`'s `card_retire_fence = started + queued + bury_lag.max(1)` hardening on top of `#362`'s `card_reclaim_release`, a tiny targeted follow-up PR on `main` is the cleanest path; otherwise `#355` can be closed.
Addresses #282 Pass #2 finding #21 (see #276):
- Expose host::bury_lag() as pub(crate) and include bury_lag.max(1) in card_retire_fence() so thin-mode folded Job::Lists batches and idle or recorded-unsubmitted command lists retain a submission-fence safety margin.
- Gate CARD_POOL slot retirement, room checks, and empty-heap trimming on both fence <= finished and now_ms.saturating_sub(freed_ms) >= REST_MS (500 ms rest window mirroring SharedPool).
- Update and add unit tests covering bury_lag margin calculation and the joint fence + REST_MS retirement gates.
github-bot closed this pull request 2026-12-02 19:40:32 +00:00
Author
Owner

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

Closing as superseded by merged #362 (8ff2a82d), which landed both #282 P0 #1 (slot_evict) and P0 #2 (recycling CardPool without calling host::settle()) with verified A/B VRAM savings (-553 MB 4K peak / 0 MB over). If we later want #355 card_retire_fence hardening on top of #362, a small targeted PR on main is the cleanest path.

**@⁠Androtim** on GitHub · 2026-12-02 19:37 UTC · [original](https://github.com/Androtim/MiniVI/pull/355#issuecomment-7356462590) Closing as superseded by merged #362 (8ff2a82d), which landed both #282 P0 #1 (slot_evict) and P0 #2 (recycling CardPool without calling host::settle()) with verified A/B VRAM savings (-553 MB 4K peak / 0 MB over). If we later want #355 card_retire_fence hardening on top of #362, a small targeted PR on main is the cleanest path.

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