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

Closed
Androtim wants to merge 2 commits from upstream-pr/355 into main
Androtim commented 2026-12-02 15:43:15 +00:00 (Migrated from github.com)

Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-12-02T15:43:15Z.


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)
<!-- greyfinch-sync:Androtim/MiniVI:issue:5609811182 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/355). Originally posted by [Androtim](https://github.com/Androtim) on 2026-12-02T15:43:15Z. --- ## 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 commented 2026-12-02 16:04:17 +00:00 (Migrated from github.com)

Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-12-02T16:04:17Z.


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.
<!-- greyfinch-sync:Androtim/MiniVI:comment:7351389804 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/355#issuecomment-7351389804). Originally posted by [Androtim](https://github.com/Androtim) on 2026-12-02T16:04:17Z. --- 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 commented 2026-12-02 16:06:07 +00:00 (Migrated from github.com)

Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-12-02T16:06:07Z.


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).

<!-- greyfinch-sync:Androtim/MiniVI:comment:7351437399 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/355#issuecomment-7351437399). Originally posted by [Androtim](https://github.com/Androtim) on 2026-12-02T16:06:07Z. --- <!-- 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`)._
Androtim commented 2026-12-02 17:33:13 +00:00 (Migrated from github.com)

Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-12-02T17:33:13Z.


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.

<!-- greyfinch-sync:Androtim/MiniVI:comment:7353416317 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/355#issuecomment-7353416317). Originally posted by [Androtim](https://github.com/Androtim) on 2026-12-02T17:33:13Z. --- 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 commented 2026-12-02 19:37:18 +00:00 (Migrated from github.com)

Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-12-02T19:37:18Z.


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.

<!-- greyfinch-sync:Androtim/MiniVI:comment:7356462590 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/355#issuecomment-7356462590). Originally posted by [Androtim](https://github.com/Androtim) on 2026-12-02T19:37:18Z. --- 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

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