perf(gpu): unify BVH arena pool and coordinate VRAM budget (#339) #342

Merged
Androtim merged 3 commits from upstream-pr/342 into main 2026-12-02 17:06:03 +00:00
Androtim commented 2026-12-02 14:20:19 +00:00 (Migrated from github.com)

Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-12-02T14:20:19Z.


Part of #339 (Phase 1 — Unified BVH Arena Pool & VRAM Budget Coordination).

Summary

Adapts GPL-3.0 upstream ReTerryDavis/ReVIctory commit 925ac0a cleanly to MiniVI's newer sparse-VRAM and LRU fault-paging architecture, while coordinating VICTORY_MEMORY_CARD_MB with VICTORY_RT_MEMORY_MB and pool.rs headroom tiers:

  • Unified Reserved BVH Arena Pool (host/reserved.rs, shadow.rs, memory.rs):
    • Maps 64 MiB BVH arena chunks as tiles into a shared 2 GiB reserved raw-UAV buffer (ArenaPool, VICTORY_BVH_ONE_ARENA=1 default) occupying descriptor slot 0 (copy == 1).
    • Adds Shadow::card_offset() / by_address_in and propagates offsets across card copies, CopyBufferRegion, compute root UAV scatter (send.rs), piece-hash passes (host.rs), copyback, and diagnostics (host/upcheck.rs), deduplicating transitions per underlying ID3D12Resource.
    • Preserves MiniVI's dynamic fault_order / give_back() LRU page eviction (keeping SLOT_FAULTS active for camera traversal), release_packed_pages (tracking chunk free_pages), FAILED guard in another(), and split reader/builder fault buffer offsets.
  • CPU / Upload Reductions (memory.rs):
    • Tracks per-chunk dirty_frame, directory_dirty_frame, and dirty_epoch to skip redundant GetWriteWatch scans on cold static BVH chunks in bring_up.
    • Uses a reusable 64 KiB bring_buf (1 copy_mapped per page vs 16) and avoids per-dispatch HashSet allocations in named_in_upload.
  • VRAM Budget Coordination (shadow.rs, memory.rs):
    • Aligns memory::card_room_for (85% on <= 9 GiB, 90% on <= 12 GiB, 97% on > 12 GiB) with shadow::memory_card_budget so fault paging recycles old pages instead of allocating 64 MiB PC-RAM shared_buffers past 85%.
    • Preserves GPU VRAM tier ceilings (85%/90%/97%) even when VICTORY_MEMORY_CARD_MB overrides the cap so texture pools on 8–12 GB cards do not starve into WDDM paging.
    • Bounds memory::most_pages_for by VICTORY_MEMORY_CARD_MB (when >= 64 MiB) so RT arenas stay within the card copy cap rather than spilling over PCIe.

Verification

  • cargo +1.98.1-x86_64-pc-windows-gnu xtask policy --staged passed (325 files ok).
  • cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets -- -D warnings and --all-features passed.
  • CPU-only unit tests passed (memory::tests: 8/8 matching CPU filters including rt_memory_caps_scale_with_vram_and_override, rt_fault_budget_and_card_room_scale_with_vram, replacing_packed_structure_keeps_overlapping_pages_and_frees_solo_tail; shadow::hash_pool_tests::memory_card_budget_keeps_tier_ceiling_with_override: passed).
  • Note: Live D3D12 reserved_arena_pool_maps_chunks_and_copies_roundtrip test skipped locally because another engine process (victory.exe) owns the shared GPU; full suite runs on PR CI.
<!-- greyfinch-sync:Androtim/MiniVI:issue:5608313517 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/342). Originally posted by [Androtim](https://github.com/Androtim) on 2026-12-02T14:20:19Z. --- Part of #339 (Phase 1 — Unified BVH Arena Pool & VRAM Budget Coordination). ### Summary Adapts GPL-3.0 upstream `ReTerryDavis/ReVIctory` commit `925ac0a` cleanly to MiniVI's newer sparse-VRAM and LRU fault-paging architecture, while coordinating `VICTORY_MEMORY_CARD_MB` with `VICTORY_RT_MEMORY_MB` and `pool.rs` headroom tiers: - **Unified Reserved BVH Arena Pool (`host/reserved.rs`, `shadow.rs`, `memory.rs`):** - Maps 64 MiB BVH arena chunks as tiles into a shared 2 GiB reserved raw-UAV buffer (`ArenaPool`, `VICTORY_BVH_ONE_ARENA=1` default) occupying descriptor slot `0` (`copy == 1`). - Adds `Shadow::card_offset()` / `by_address_in` and propagates offsets across card copies, `CopyBufferRegion`, compute root UAV scatter (`send.rs`), piece-hash passes (`host.rs`), copyback, and diagnostics (`host/upcheck.rs`), deduplicating transitions per underlying `ID3D12Resource`. - Preserves `MiniVI`'s dynamic `fault_order` / `give_back()` LRU page eviction (keeping `SLOT_FAULTS` active for camera traversal), `release_packed_pages` (tracking chunk `free_pages`), `FAILED` guard in `another()`, and split reader/builder fault buffer offsets. - **CPU / Upload Reductions (`memory.rs`):** - Tracks per-chunk `dirty_frame`, `directory_dirty_frame`, and `dirty_epoch` to skip redundant `GetWriteWatch` scans on cold static BVH chunks in `bring_up`. - Uses a reusable 64 KiB `bring_buf` (1 `copy_mapped` per page vs 16) and avoids per-dispatch `HashSet` allocations in `named_in_upload`. - **VRAM Budget Coordination (`shadow.rs`, `memory.rs`):** - Aligns `memory::card_room_for` (`85%` on `<= 9 GiB`, `90%` on `<= 12 GiB`, `97%` on `> 12 GiB`) with `shadow::memory_card_budget` so fault paging recycles old pages instead of allocating 64 MiB PC-RAM `shared_buffer`s past 85%. - Preserves GPU VRAM tier ceilings (`85%`/`90%`/`97%`) even when `VICTORY_MEMORY_CARD_MB` overrides the cap so texture pools on 8–12 GB cards do not starve into WDDM paging. - Bounds `memory::most_pages_for` by `VICTORY_MEMORY_CARD_MB` (when `>= 64` MiB) so RT arenas stay within the card copy cap rather than spilling over PCIe. ### Verification - `cargo +1.98.1-x86_64-pc-windows-gnu xtask policy --staged` passed (`325 files ok`). - `cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets -- -D warnings` and `--all-features` passed. - CPU-only unit tests passed (`memory::tests`: 8/8 matching CPU filters including `rt_memory_caps_scale_with_vram_and_override`, `rt_fault_budget_and_card_room_scale_with_vram`, `replacing_packed_structure_keeps_overlapping_pages_and_frees_solo_tail`; `shadow::hash_pool_tests::memory_card_budget_keeps_tier_ceiling_with_override`: passed). - *Note:* Live D3D12 `reserved_arena_pool_maps_chunks_and_copies_roundtrip` test skipped locally because another engine process (`victory.exe`) owns the shared GPU; full suite runs on PR CI.
Androtim commented 2026-12-02 15:04:07 +00:00 (Migrated from github.com)

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


Holding merge (triage: needs work) per deep static audit routing (#282 comment 7349410307, P0/P1 findings #13, #14, #16, #17 routed to #339). Please resolve the flagged findings, re-verify CI, and run a paired plain---release RT-off A/B + --features diagnostics PNG check before merge.

<!-- greyfinch-sync:Androtim/MiniVI:comment:7349656125 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/342#issuecomment-7349656125). Originally posted by [Androtim](https://github.com/Androtim) on 2026-12-02T15:04:07Z. --- Holding merge (`triage: needs work`) per deep static audit routing (`#282` comment `7349410307`, P0/P1 findings #13, #14, #16, #17 routed to `#339`). Please resolve the flagged findings, re-verify CI, and run a paired plain-`--release` RT-off A/B + `--features diagnostics` PNG check before merge.
Androtim commented 2026-12-02 15:06:26 +00:00 (Migrated from github.com)

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


Automated triage for the maintainers (not an approval).

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

Review Summary

Solid implementation adapting a unified 2 GiB reserved BVH arena pool (VICTORY_BVH_ONE_ARENA=1) to MiniVI's sparse-VRAM / LRU fault-paging architecture, with consistent Shadow::card_offset() propagation and coordinated VRAM budget ceilings. CI is passing and no blocking logic or safety defects were found, but the new D3D12 tiled-resource path and VRAM budget changes warrant a local real-GPU smoke test before merging.

Verified Details

  • Reserved arena pool & tile mapping (crates/victory-gpu/src/host/reserved.rs, crates/victory-gpu/src/shadow.rs, crates/victory-gpu/src/memory.rs):
    • Host::reserved_uav_buffer checks TiledResourcesTier before creating a 2 GiB D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS reserved buffer (ArenaPool 0 at descriptor slot 0 / copy == 1).
    • Host::map_buffer_tiles maps 64 MiB default heaps via a dedicated D3D12_COMMAND_LIST_TYPE_COPY queue, synchronizes via fence wait, and defensively unmaps (D3D12_TILE_RANGE_FLAG_NULL) + retires the heap on signal/wait failure.
    • shadow::by_address_in rolls back BY_ADDRESS_USED on staging or tile-mapping failure and falls back cleanly to standalone shadow::by_address in Memory::another.
  • Offset propagation & barrier deduplication (host.rs, host/send.rs, host/upcheck.rs):
    • Shadow::card_offset() is applied consistently across Host::card_sync, Host::card_compare (batched and unbatched), Host::relay_fetch, Own::record (CopyBufferRegion + root UAV), upcheck::record/look, and Memory::dump.
    • Own::record and upcheck::record deduplicate transition barriers by raw ID3D12Resource pointer (as_raw()), matching Host::card_sync.
  • Submit-time refresh epochs & CPU overhead (host.rs, memory.rs):
    • dirty_epoch / refreshed_epoch tracking on directory and ArenaChunk with SubmitRefreshScope / submit_refresh / Batch::add_fresh ensures submit-time land_and_refresh writes invalidate pre-scanned Batch::ahead state and cannot drop delayed refreshes.
    • bring_buf (single 64 KiB copy_mapped per page) and named_in_upload (Vec sort/dedup instead of HashSet) are clean.
  • VRAM budget alignment (memory.rs, shadow.rs):
    • memory::card_room_for (85% / 90% / 97%) now matches shadow::memory_card_budget, VICTORY_MEMORY_CARD_MB no longer relaxes the GPU tier ceiling, and memory::most_pages_for is bounded by VICTORY_MEMORY_CARD_MB when >= 64 MiB.

Non-blocking Notes

  • host/reserved.rs uses a blocking null-handle ID3D12Fence::SetEventOnCompletion(value, HANDLE::default()) on TILE_QUEUE; valid in D3D12, worth confirming during the real-GPU smoke test (especially if also tested under Wine/vkd3d-proton).
  • reserved_arena_pool_maps_chunks_and_copies_roundtrip was skipped locally by the author due to GPU contention; run it on a real GPU as part of verification.

Next Step

Run a local real-GPU test (unit test + short title run with RT/BVH active) before merging.


Generated with Antigravity CLI (agy).

<!-- greyfinch-sync:Androtim/MiniVI:comment:7349730583 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/342#issuecomment-7349730583). Originally posted by [Androtim](https://github.com/Androtim) on 2026-12-02T15:06:26Z. --- <!-- minivi-triage v1 head=f204e9cb1f5dc6c5a04c891499935bcc1400520e verdict=needs-gpu-test ci=passing at=2026-12-02T17:09:40Z --> Automated triage for the maintainers (not an approval). **Verdict:** `needs-gpu-test` · **CI (`check`):** `passing` ### Review Summary Solid implementation adapting a unified 2 GiB reserved BVH arena pool (`VICTORY_BVH_ONE_ARENA=1`) to MiniVI's sparse-VRAM / LRU fault-paging architecture, with consistent `Shadow::card_offset()` propagation and coordinated VRAM budget ceilings. CI is passing and no blocking logic or safety defects were found, but the new D3D12 tiled-resource path and VRAM budget changes warrant a local real-GPU smoke test before merging. ### Verified Details - **Reserved arena pool & tile mapping (`crates/victory-gpu/src/host/reserved.rs`, `crates/victory-gpu/src/shadow.rs`, `crates/victory-gpu/src/memory.rs`)**: - `Host::reserved_uav_buffer` checks `TiledResourcesTier` before creating a 2 GiB `D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS` reserved buffer (`ArenaPool 0` at descriptor slot `0` / `copy == 1`). - `Host::map_buffer_tiles` maps 64 MiB default heaps via a dedicated `D3D12_COMMAND_LIST_TYPE_COPY` queue, synchronizes via fence wait, and defensively unmaps (`D3D12_TILE_RANGE_FLAG_NULL`) + retires the heap on signal/wait failure. - `shadow::by_address_in` rolls back `BY_ADDRESS_USED` on staging or tile-mapping failure and falls back cleanly to standalone `shadow::by_address` in `Memory::another`. - **Offset propagation & barrier deduplication (`host.rs`, `host/send.rs`, `host/upcheck.rs`)**: - `Shadow::card_offset()` is applied consistently across `Host::card_sync`, `Host::card_compare` (batched and unbatched), `Host::relay_fetch`, `Own::record` (`CopyBufferRegion` + root UAV), `upcheck::record`/`look`, and `Memory::dump`. - `Own::record` and `upcheck::record` deduplicate transition barriers by raw `ID3D12Resource` pointer (`as_raw()`), matching `Host::card_sync`. - **Submit-time refresh epochs & CPU overhead (`host.rs`, `memory.rs`)**: - `dirty_epoch` / `refreshed_epoch` tracking on `directory` and `ArenaChunk` with `SubmitRefreshScope` / `submit_refresh` / `Batch::add_fresh` ensures submit-time `land_and_refresh` writes invalidate pre-scanned `Batch::ahead` state and cannot drop delayed refreshes. - `bring_buf` (single 64 KiB `copy_mapped` per page) and `named_in_upload` (`Vec` sort/dedup instead of `HashSet`) are clean. - **VRAM budget alignment (`memory.rs`, `shadow.rs`)**: - `memory::card_room_for` (`85%` / `90%` / `97%`) now matches `shadow::memory_card_budget`, `VICTORY_MEMORY_CARD_MB` no longer relaxes the GPU tier ceiling, and `memory::most_pages_for` is bounded by `VICTORY_MEMORY_CARD_MB` when `>= 64` MiB. ### Non-blocking Notes - `host/reserved.rs` uses a blocking null-handle `ID3D12Fence::SetEventOnCompletion(value, HANDLE::default())` on `TILE_QUEUE`; valid in D3D12, worth confirming during the real-GPU smoke test (especially if also tested under Wine/vkd3d-proton). - `reserved_arena_pool_maps_chunks_and_copies_roundtrip` was skipped locally by the author due to GPU contention; run it on a real GPU as part of verification. ### Next Step Run a local real-GPU test (unit test + short title run with RT/BVH active) before merging. --- _Generated with Antigravity CLI (`agy`)._
Androtim commented 2026-12-02 16:23:03 +00:00 (Migrated from github.com)

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


Rebased onto \main\ (\3efe907) and resolved #282\ P0 findings #13 & #14:

  • Finding #13 (\shadow.rs, \host/reserved.rs): \y_address_in\ now allocates \shared_buffer_staging(len)\ before \map_buffer_tiles, and \map_buffer_tiles\ unmaps tiles (\D3D12_TILE_RANGE_FLAG_NULL, signaled on \TILE_QUEUE) and retires the heap via \host::retire\ on any post-\UpdateTileMappings\ fence/signal error.
  • Finding #14 (\memory.rs, \host.rs): Replaced the \DIRTY_WINDOW\ / \ ree_pages > 0\ heuristic with monotonic (dirty_epoch, refreshed_epoch)\ pairs on \ArenaChunk\ and \directory\ (advancing
    efreshed_epoch\ via \ etch_max\ only inside submitted \defer_host\ callbacks / active \Batch\ refreshes, never at recording time), and wired submit-time \land_and_refresh\ -> \host::submit_refresh\ -> \Batch::add_fresh\ (clearing any stale \atch.ahead\ entry) so \directory\ and every chunk touched or allocated during \land\ always refresh before GPU execution.

Verified (\VICTORY_D3D12_WARP=1): \memory::tests\ (\10 passed; 0 failed), \shadow::window_tests\ (\10 passed; 0 failed), \host::\ (\193 passed; 0 failed; 17 pre-existing ignored), workspace \clippy --all-targets\ (normal & --all-features), and \xtask policy --staged\ (\4 files ok). Ready for CI and maintainer GPU check.

<!-- greyfinch-sync:Androtim/MiniVI:comment:7351863529 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/342#issuecomment-7351863529). Originally posted by [Androtim](https://github.com/Androtim) on 2026-12-02T16:23:03Z. --- Rebased onto \main\ (\3efe907\) and resolved \#282\ P0 findings #13 & #14: - **Finding #13 (\shadow.rs\, \host/reserved.rs\):** \y_address_in\ now allocates \shared_buffer_staging(len)\ before \map_buffer_tiles\, and \map_buffer_tiles\ unmaps tiles (\D3D12_TILE_RANGE_FLAG_NULL\, signaled on \TILE_QUEUE\) and retires the heap via \host::retire\ on any post-\UpdateTileMappings\ fence/signal error. - **Finding #14 (\memory.rs\, \host.rs\):** Replaced the \DIRTY_WINDOW\ / \ ree_pages > 0\ heuristic with monotonic \(dirty_epoch, refreshed_epoch)\ pairs on \ArenaChunk\ and \directory\ (advancing \ efreshed_epoch\ via \ etch_max\ only inside submitted \defer_host\ callbacks / active \Batch\ refreshes, never at recording time), and wired submit-time \land_and_refresh\ -> \host::submit_refresh\ -> \Batch::add_fresh\ (clearing any stale \atch.ahead\ entry) so \directory\ and every chunk touched or allocated during \land\ always refresh before GPU execution. Verified (\VICTORY_D3D12_WARP=1\): \memory::tests\ (\10 passed; 0 failed\), \shadow::window_tests\ (\10 passed; 0 failed\), \host::\ (\193 passed; 0 failed\; 17 pre-existing ignored), workspace \clippy --all-targets\ (normal & \--all-features\), and \xtask policy --staged\ (\4 files ok\). Ready for CI and maintainer GPU check.
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!342
No description provided.