Skip to content

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

Open
Androtim wants to merge 2 commits into
mainfrom
feat/hw-rt-phase1-arena-pool
Open

Androtim wants to merge 2 commits into
mainfrom
feat/hw-rt-phase1-arena-pool

Conversation

@Androtim

@Androtim Androtim commented Dec 2, 2026

Copy link
Copy Markdown
Owner

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.

Phase 1b — Unified BVH arena pool & VRAM headroom coordination:
- Add `host::reserved` (`reserved_uav_buffer`, `map_buffer_tiles`) to map
  64 MiB BVH arena chunks into a shared 2 GiB reserved raw-UAV buffer
  (`ArenaPool`, `VICTORY_BVH_ONE_ARENA=1`) at descriptor slot 0 (`copy=1`),
  eliminating non-uniform descriptor waterfalls on static/fault BVH reads.
- Propagate `Shadow::card_offset()` through card copies (`host.rs`,
  `host/send.rs`, `host/upcheck.rs`), piece hash passes, and copyback, and
  deduplicate resource state transitions per raw `ID3D12Resource`.
- Add `bring_buf` (single 64 KiB `copy_mapped` per dirty page), dirty-epoch
  `GetWriteWatch` skip (`directory_dirty_frame` / `ArenaChunk::dirty_frame`)
  on untouched static arenas, and zero-hashset `named_in_upload` dedup.
- Coordinate `VICTORY_MEMORY_CARD_MB` with `VICTORY_RT_MEMORY_MB` and
  `memory::most_pages_for` / `card_room_for` (`85%`/`90%`/`97%` VRAM-tier
  ceilings matching `shadow::memory_card_budget`) so 8-12 GB cards recycle
  arena pages cleanly without spilling into shared system RAM or starving
  sparse texture pools.

Adapted from GPL-3.0 upstream `ReTerryDavis/ReVIctory` commit `925ac0a`,
preserving MiniVI's dynamic `fault_order` LRU paging, `release_packed_pages`,
and split read/build fault buffers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant