perf(gpu/hwrt): incremental BLAS remap table, pooled staging, IB validation cache, and feedback throttling (Wave 10A) #427

Merged
Androtim merged 4 commits from upstream-pr/427 into main 2026-12-04 09:19:22 +00:00
Androtim commented 2026-12-04 08:14:13 +00:00 (Migrated from github.com)

Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-12-04T08:14:13Z.


Summary

Implements Wave 10A HW-RT CPU preparation optimizations across crates/victory-gpu/src/hwrt.rs, crates/victory-gpu/src/hwrt/budget.rs, and crates/victory-gpu/src/hwrt/decoders.rs to eliminate submission-thread stalls and redundant CPU/GPU prep overhead during BLAS and TLAS builds.

Changes

  1. Incremental GPU-Resident BLAS Remap Table, Exact Version Invalidation & CoW BlasRefs

    • Removed premature as_map_version bumps from record-time alloc_or_reuse_as, record-time execute_copy, and TLAS-only show / show_copy updates (the remap table only depends on shown BLASes, queue.waiting, and lru.evicted).
    • Added BlasHashTable with O(1) in-place upserts and circular backshift deletion (< 64-probe invariant preserved, matching REMAP_HLSL binary layout 100% identically) and eliminated the duplicate known: HashSet<u64> allocation in table_entries.
    • Added capacity hysteresis (choose_table_cap) and a persistent GPU-resident DEFAULT remap buffer (GpuBlasTable) updated by PATCH_TABLE_HLSL (mode 0: 16-byte no-op header, mode 1: dirty-slot scatter patch, mode 2: full copy on initial sync / capacity change / burst overflow), removing per-TLAS 0.5–2 MiB write-combined memcpys on the submission thread.
    • Replaced flat Vec<Arc<HostAs>> + Vec<u64> table snapshots with copy-on-write 256-slot ChunkedRefs (BlasRefs) so incremental TLAS updates share untouched chunks without re-cloning all live Arc<HostAs> entries.
  2. Pooled BLAS Staging & Decoder Scratch Reuse

    • Replaced list.plane_upload(exact_len, (0, 0), ...) in flush_blas_waves with list.scratch_held(len) + immediate copy on the recording worker thread (stage.clear() retaining capacity), eliminating exact-size SPARE.take misses, CreateCommittedResource storms, and submit-thread WC copies.
    • Reused bounded thread-local scratch buffers and direct slice writes in decode_title_quant24_vb and decode_title_meshlet_ib, hoisting the quant24 component swizzle out of the per-vertex loop.
  3. BLAS Refit Fast-Path, Epoch-Gated validated_ibs Cache, Arc<OwnedBuild> & Feedback/Stats Throttling

    • Gated validated_ibs on (shadow_id, !gpu_written, watch::writes_since) epoch so all builds, refits, and rehydrates can safely hit the cache without serving stale data when an index buffer is modified, using a reusable thread-local scan buffer.
    • Skipped clamp_ib dispatch and work allocation whenever every scanned index is strictly < eff_vc and the shadow is not GPU-written (preserving GeomKey consistency across builds and refits).
    • Stored HostAs::geom_keys as Arc<[GeomKey]> and added zero-allocation geom_keys_match on refits.
    • Wrapped OwnedBuild in Arc<OwnedBuild> across recording, backlog, and BlasLru (recipes/evicted), normalizing lazily only when materializing an evicted rebuild (take_wanted / take_evicted).
    • Enabled cached_meshlet_ib for is_rehydrate == true builds.
    • Guarded g_used.Store in REMAP_HLSL with if (stamp != 0u) and throttled TLAS LRU Feedback readbacks (should_sample_feedback: every 8 frames at >=70% VRAM budget or with evicted BLASes, every 16 frames when idle, disabled when budget is 0), switched BlasLru::wanted from Vec to HashSet<u64>, gated pool.stats readback copies to logging cadence (should_read_stats), and separated tlas_pool from as_pool so BLAS eviction does not drain warm TLAS buffers.

Verification

  • cargo test -p victory-gpu --lib hwrt -- --skip postbuild_uav_shader --test-threads=1 — 51 passed, 0 failed (including new unit tests for BlasHashTable wrap-around backshift fuzzing, choose_table_cap hysteresis, CachedBlasTableGeneric CoW chunks & patch encoding, DirtyBlas overflow, ValidatedIb epoch gating & should_skip_clamp_ib, geom_keys_match, PATCH_TABLE_HLSL / REMAP_HLSL compilation, should_sample_feedback / should_read_stats, marked_chunked, and BlasLru Arc sharing).
  • cargo clippy --workspace --all-targets -- -D warnings — passed.
  • cargo clippy --workspace --all-targets --all-features -- -D warnings — passed.
  • cargo xtask policy — passed (365 files ok).
<!-- greyfinch-sync:Androtim/MiniVI:issue:5642874790 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/427). Originally posted by [Androtim](https://github.com/Androtim) on 2026-12-04T08:14:13Z. --- ## Summary Implements **Wave 10A** HW-RT CPU preparation optimizations across `crates/victory-gpu/src/hwrt.rs`, `crates/victory-gpu/src/hwrt/budget.rs`, and `crates/victory-gpu/src/hwrt/decoders.rs` to eliminate submission-thread stalls and redundant CPU/GPU prep overhead during BLAS and TLAS builds. ### Changes 1. **Incremental GPU-Resident BLAS Remap Table, Exact Version Invalidation & CoW `BlasRefs`** - Removed premature `as_map_version` bumps from record-time `alloc_or_reuse_as`, record-time `execute_copy`, and TLAS-only `show` / `show_copy` updates (the remap table only depends on `shown` BLASes, `queue.waiting`, and `lru.evicted`). - Added `BlasHashTable` with O(1) in-place upserts and circular backshift deletion (`< 64`-probe invariant preserved, matching `REMAP_HLSL` binary layout 100% identically) and eliminated the duplicate `known: HashSet<u64>` allocation in `table_entries`. - Added capacity hysteresis (`choose_table_cap`) and a persistent GPU-resident `DEFAULT` remap buffer (`GpuBlasTable`) updated by `PATCH_TABLE_HLSL` (`mode 0`: 16-byte no-op header, `mode 1`: dirty-slot scatter patch, `mode 2`: full copy on initial sync / capacity change / burst overflow), removing per-TLAS 0.5–2 MiB write-combined `memcpy`s on the submission thread. - Replaced flat `Vec<Arc<HostAs>>` + `Vec<u64>` table snapshots with copy-on-write 256-slot `ChunkedRefs` (`BlasRefs`) so incremental TLAS updates share untouched chunks without re-cloning all live `Arc<HostAs>` entries. 2. **Pooled BLAS Staging & Decoder Scratch Reuse** - Replaced `list.plane_upload(exact_len, (0, 0), ...)` in `flush_blas_waves` with `list.scratch_held(len)` + immediate copy on the recording worker thread (`stage.clear()` retaining capacity), eliminating exact-size `SPARE.take` misses, `CreateCommittedResource` storms, and submit-thread WC copies. - Reused bounded thread-local scratch buffers and direct slice writes in `decode_title_quant24_vb` and `decode_title_meshlet_ib`, hoisting the quant24 component swizzle out of the per-vertex loop. 3. **BLAS Refit Fast-Path, Epoch-Gated `validated_ibs` Cache, `Arc<OwnedBuild>` & Feedback/Stats Throttling** - Gated `validated_ibs` on `(shadow_id, !gpu_written, watch::writes_since)` epoch so all builds, refits, and rehydrates can safely hit the cache without serving stale data when an index buffer is modified, using a reusable thread-local scan buffer. - Skipped `clamp_ib` dispatch and `work` allocation whenever every scanned index is strictly `< eff_vc` and the shadow is not GPU-written (preserving `GeomKey` consistency across builds and refits). - Stored `HostAs::geom_keys` as `Arc<[GeomKey]>` and added zero-allocation `geom_keys_match` on refits. - Wrapped `OwnedBuild` in `Arc<OwnedBuild>` across recording, backlog, and `BlasLru` (`recipes`/`evicted`), normalizing lazily only when materializing an evicted rebuild (`take_wanted` / `take_evicted`). - Enabled `cached_meshlet_ib` for `is_rehydrate == true` builds. - Guarded `g_used.Store` in `REMAP_HLSL` with `if (stamp != 0u)` and throttled TLAS LRU `Feedback` readbacks (`should_sample_feedback`: every 8 frames at >=70% VRAM budget or with evicted BLASes, every 16 frames when idle, disabled when budget is 0), switched `BlasLru::wanted` from `Vec` to `HashSet<u64>`, gated `pool.stats` readback copies to logging cadence (`should_read_stats`), and separated `tlas_pool` from `as_pool` so BLAS eviction does not drain warm TLAS buffers. ### Verification - `cargo test -p victory-gpu --lib hwrt -- --skip postbuild_uav_shader --test-threads=1` — 51 passed, 0 failed (including new unit tests for `BlasHashTable` wrap-around backshift fuzzing, `choose_table_cap` hysteresis, `CachedBlasTableGeneric` CoW chunks & patch encoding, `DirtyBlas` overflow, `ValidatedIb` epoch gating & `should_skip_clamp_ib`, `geom_keys_match`, `PATCH_TABLE_HLSL` / `REMAP_HLSL` compilation, `should_sample_feedback` / `should_read_stats`, `marked_chunked`, and `BlasLru` `Arc` sharing). - `cargo clippy --workspace --all-targets -- -D warnings` — passed. - `cargo clippy --workspace --all-targets --all-features -- -D warnings` — passed. - `cargo xtask policy` — passed (`365 files ok`).
Androtim commented 2026-12-04 08:32:08 +00:00 (Migrated from github.com)

Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-12-04T08:32:08Z.


Triage (48235827, CI check PASS, MERGEABLE):

  • Strong Wave 10A HW-RT CPU-prep architecture (+1,903/-477 across hwrt.rs, hwrt/budget.rs, hwrt/decoders.rs, zero new toggles), however Gate 2 Adversarial Audit (#282 comment 7405972309) flagged 2 [P0] + 2 [P1] merge blockers (including persistent GpuBlasTable desync / GPU UAF if alloc_or_reuse_as fails after list.plane_upload).
  • Marked triage: needs work pending fixes + Gate 2 clean re-audit + Gate 3 VICTORY_HW_RT=1 verification.
<!-- greyfinch-sync:Androtim/MiniVI:comment:7406063035 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/427#issuecomment-7406063035). Originally posted by [Androtim](https://github.com/Androtim) on 2026-12-04T08:32:08Z. --- Triage (`48235827`, CI `check` PASS, `MERGEABLE`): - Strong Wave 10A HW-RT CPU-prep architecture (`+1,903/-477` across `hwrt.rs`, `hwrt/budget.rs`, `hwrt/decoders.rs`, zero new toggles), **however Gate 2 Adversarial Audit (`#282` comment `7405972309`) flagged `2 [P0]` + `2 [P1]` merge blockers** (including persistent `GpuBlasTable` desync / GPU UAF if `alloc_or_reuse_as` fails after `list.plane_upload`). - Marked `triage: needs work` pending fixes + Gate 2 clean re-audit + Gate 3 `VICTORY_HW_RT=1` verification.
Androtim commented 2026-12-04 09:01:55 +00:00 (Migrated from github.com)

Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-12-04T09:01:55Z.


Updated triage (00fb5f86, rebased onto 25d75651, CI IN_PROGRESS, MERGEABLE):

  • Gate 2 Pure-Reasoning Re-Audit (#282 comment 7406514018): VERIFIED CLEAN (0 P0, 0 P1) — all 4 prior findings resolved cleanly.
  • Swapped label triage: needs work -> triage: needs gpu test — awaiting CI check PASS + Gate 3 VICTORY_HW_RT=1 GPU verification before merging.
<!-- greyfinch-sync:Androtim/MiniVI:comment:7406743780 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/427#issuecomment-7406743780). Originally posted by [Androtim](https://github.com/Androtim) on 2026-12-04T09:01:55Z. --- Updated triage (`00fb5f86`, rebased onto `25d75651`, CI `IN_PROGRESS`, `MERGEABLE`): - **Gate 2 Pure-Reasoning Re-Audit (`#282` comment `7406514018`):** `VERIFIED CLEAN (0 P0, 0 P1)` — all 4 prior findings resolved cleanly. - Swapped label `triage: needs work` -> `triage: needs gpu test` — awaiting CI `check` PASS + Gate 3 `VICTORY_HW_RT=1` GPU verification before merging.
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!427
No description provided.