perf(victory-gpu): optimize indirect batch table, WriteLog, merge counters, and clamp shaders #10

Manually merged
github merged 1 commit from github-bot/gh-10 into mega-upgrade-v3 2026-12-04 20:20:08 +00:00 AGit
Owner

@⁠MahanYTT on GitHub · 2026-12-04 18:27 UTC · original
MahanYTT:perf/indirect-batch-merge → mega-upgrade-v3 · +595 −155 · 3 files · 1 commits · merged 2026-12-04 20:18 UTC

Summary

Reduces per-execution CPU recording overhead and idle GPU clamp work across ~3,765 indirect executions/frame (victory-ma-play-20261204-165800-18832.log):

Why not root-constant-only merge signatures?

From the frame log (3,765 indirect executions/frame): 2,478 (65.8%) changed non-root-constant bindings, 957 (25.4%) changed kind/pipeline, 267 (7.1%) followed a recording title call, and only 11 (0.29%) changed root constants only (VICTORY_INDIRECT_MERGE=1 is off by default). Adding root-constant-per-record signatures would affect <= 0.29% of executions, whereas the per-execution CPU path in batch.rs, merge.rs, and indirect.rs runs on every execution.

Optimizations

  • crates/victory-gpu/src/indirect/batch.rs:
    • Replaced Table's per-batch Vec<u32> + HashMap<(u32, u32, u32), u32> (two heap allocations + RandomState/SipHash per batch across hundreds of batches/frame) with a 16-entry inline table (INLINE_CAP = 16) that spills lazily to a 512-slot Fibonacci-hashed open-addressing Overflow table with in-place slot replacement on TIMES saturation.
    • Combined the 4 scalar write_volatile stores per new job into a single 16-byte [u32; 4] write_volatile store to write-combined upload memory.
    • Upgraded WriteLog from O(N) linear scans (up to 4,096 ranges) to sorted, coalesced disjoint intervals with O(1) [min_addr, max_end) bounding-box rejection, O(1) tail fast path, and O(log N) binary search in note()/touches().
    • Added group-uniform early-out (first >= count) in batch::SOURCE so idle threadgroups in 256-thread batch dispatches skip LDS writes and both GroupMemoryBarrierWithGroupSync() barriers, plus zero-cost budget fast path and asked > 0 guard for mesh LDS atomics.
  • crates/victory-gpu/src/indirect/merge.rs:
    • Buffered merge::count() in thread-local LocalCounts flushing to COUNTS every 64 calls (and on thread exit via Drop), cutting cross-core atomic RMWs and cache-line bouncing by 64x across multi-threaded command list recording even when VICTORY_INDIRECT_MERGE=1 is off.
    • Marked hot verdict/run helpers #[inline].
  • crates/victory-gpu/src/indirect.rs:
    • Eliminated duplicate validate_layout calls in bound() and bound_ahead() via record_clamp_validated.
    • Fixed sparse indexing in open_batch when a recent buffer has an invalid GPU VA (keeping ids, sources, and source_bufs densely packed).
    • Guarded pre_clamp_barriers against emitting redundant UNORDERED_ACCESS -> UNORDERED_ACCESS transitions and guarded empty barrier slice calls.
    • Added group-uniform early-out (first >= eff_count) and zero-cost budget fast path in SOURCE.

Verification

  • cargo clippy -p victory-gpu --target x86_64-pc-windows-msvc -- -D warnings (default, --tests, and --features diagnostics): 0 warnings, 0 errors.
  • Native rustc --edition=2024 --test on batch + merge unit tests (including new inline/spill/saturation, WriteLog coalescing, and merge::count thread-local flush tests): 18 passed, 0 failed.
**@⁠MahanYTT** on GitHub · 2026-12-04 18:27 UTC · [original](https://github.com/MahanYTT/VIctory-MA/pull/10) `MahanYTT:perf/indirect-batch-merge` → `mega-upgrade-v3` · +595 −155 · 3 files · 1 commits · merged 2026-12-04 20:18 UTC ## Summary Reduces per-execution CPU recording overhead and idle GPU clamp work across ~3,765 indirect executions/frame (`victory-ma-play-20261204-165800-18832.log`): ### Why not root-constant-only merge signatures? From the frame log (`3,765` indirect executions/frame): `2,478` (65.8%) changed non-root-constant bindings, `957` (25.4%) changed kind/pipeline, `267` (7.1%) followed a recording title call, and only `11` (0.29%) changed root constants only (`VICTORY_INDIRECT_MERGE=1` is off by default). Adding root-constant-per-record signatures would affect <= 0.29% of executions, whereas the per-execution CPU path in `batch.rs`, `merge.rs`, and `indirect.rs` runs on every execution. ### Optimizations - **`crates/victory-gpu/src/indirect/batch.rs`**: - Replaced `Table`'s per-batch `Vec<u32>` + `HashMap<(u32, u32, u32), u32>` (two heap allocations + `RandomState`/SipHash per batch across hundreds of batches/frame) with a 16-entry inline table (`INLINE_CAP = 16`) that spills lazily to a 512-slot Fibonacci-hashed open-addressing `Overflow` table with in-place slot replacement on `TIMES` saturation. - Combined the 4 scalar `write_volatile` stores per new job into a single 16-byte `[u32; 4]` `write_volatile` store to write-combined upload memory. - Upgraded `WriteLog` from O(N) linear scans (up to 4,096 ranges) to sorted, coalesced disjoint intervals with O(1) `[min_addr, max_end)` bounding-box rejection, O(1) tail fast path, and O(log N) binary search in `note()`/`touches()`. - Added group-uniform early-out (`first >= count`) in `batch::SOURCE` so idle threadgroups in 256-thread batch dispatches skip LDS writes and both `GroupMemoryBarrierWithGroupSync()` barriers, plus zero-cost budget fast path and `asked > 0` guard for mesh LDS atomics. - **`crates/victory-gpu/src/indirect/merge.rs`**: - Buffered `merge::count()` in thread-local `LocalCounts` flushing to `COUNTS` every 64 calls (and on thread exit via `Drop`), cutting cross-core atomic RMWs and cache-line bouncing by 64x across multi-threaded command list recording even when `VICTORY_INDIRECT_MERGE=1` is off. - Marked hot verdict/run helpers `#[inline]`. - **`crates/victory-gpu/src/indirect.rs`**: - Eliminated duplicate `validate_layout` calls in `bound()` and `bound_ahead()` via `record_clamp_validated`. - Fixed sparse indexing in `open_batch` when a recent buffer has an invalid GPU VA (keeping `ids`, `sources`, and `source_bufs` densely packed). - Guarded `pre_clamp_barriers` against emitting redundant `UNORDERED_ACCESS -> UNORDERED_ACCESS` transitions and guarded empty barrier slice calls. - Added group-uniform early-out (`first >= eff_count`) and zero-cost budget fast path in `SOURCE`. ### Verification - `cargo clippy -p victory-gpu --target x86_64-pc-windows-msvc -- -D warnings` (default, `--tests`, and `--features diagnostics`): 0 warnings, 0 errors. - Native `rustc --edition=2024 --test` on `batch` + `merge` unit tests (including new inline/spill/saturation, `WriteLog` coalescing, and `merge::count` thread-local flush tests): 18 passed, 0 failed.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-04 18:27:23 +00:00
github manually merged commit 4ba58378c8 into mega-upgrade-v3 2026-12-04 20:20:08 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.