perf(victory-gpu): eliminate no-op refresh flushes, offload post-send list reset, and coalesce MakeResident waits #16

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

@⁠MahanYTT on GitHub · 2026-12-04 18:54 UTC · original
MahanYTT:perf/host-noop-refreshes → mega-upgrade-v3 · +468 −115 · 1 files · 1 commits · merged 2026-12-04 20:18 UTC

Summary

Addresses three submitting-thread and allocation-path bottlenecks observed in victory-ma-play-20261204-165800-18832.log (RTX 5070 Ti 16 GB, 1440p DLSS Quality + FG 2x), modifying only crates/victory-gpu/src/host.rs:

  1. Early no-op refresh filtering & zero-alloc bitmask sifting (refreshes 3.6 ms in 28 flushes of 13,977, 12,995 no-op / 93%):

    • Snapshots watch::ahead once per kept submission (Batch::begin_kept_snap / reused from refresh_front_spans) and filters known no-ops directly in Batch::add() before hashing into index, cloning Arc<Shadow>, or queuing into refreshes.
    • Caches verified clean ranges in Batch::clean (invalidated on title_written, flush_one, and Step::Run / ask_once_end, never bridging disjoint gaps via merge_clean_span) and skips redundant re-filtering in Batch::flush_all() when all_filtered holds.
    • Replaces per-flush Vec<AtomicBool> allocations in sift_indexed_with and sift_spans_with with a reusable cache-line-padded Vec<KeepWord> (#[repr(align(64))]) 64-bit mask (64x fewer atomic stores, zero false sharing, single-branch skip for all-zero 64-item chunks).
  2. Offload post-send flight/list reset off the submitting thread (1.9 ms/frame in AFTER_SEND):

    • Tracks whether victory-late-wait (late_helper) started (HELPER_RUNNING).
    • In Host::send_late(), avoids synchronously running land() and bury() on the submitting thread when late_helper is running (poking late_helper under the existing LINE lock when landed.len() > bury_lag()), falling back to synchronous execution only if the helper thread failed to start.
  3. Coalesce MakeResident mapping waits (VICTORY_WAIT_RESIDENT) (20,000 times, only 17 coalesced, 1,798.2 ms):

    • Adds MappedBarrier::mark_needed, has_pending, and flush_pending.
    • Defers mapped() copy-queue fence waits until settle() runs before writing a shader-visible descriptor heap slot (VICTORY_DEFER_MAPPED=0 restores immediate per-allocation waits), coalescing sequential allocations into a single GPU round-trip while preserving WDDM paging-queue ordering for lists submitted after MakeResident.

Verification

  • cargo clippy --lib --tests -p victory-gpu --target x86_64-pc-windows-msvc -- -D warnings: 0 warnings, 0 errors
  • Unit tests (rustc --edition 2024 --test): 4 passed, 0 failed
    • mapped_barrier_defers_and_coalesces_sequential_allocations
    • sync_land_after_send_only_when_not_apart_and_no_helper
    • merge_clean_span_never_bridges_unchecked_gaps
    • compact_by_bitmask_skips_zero_chunks_and_preserves_order
**@⁠MahanYTT** on GitHub · 2026-12-04 18:54 UTC · [original](https://github.com/MahanYTT/VIctory-MA/pull/16) `MahanYTT:perf/host-noop-refreshes` → `mega-upgrade-v3` · +468 −115 · 1 files · 1 commits · merged 2026-12-04 20:18 UTC ## Summary Addresses three submitting-thread and allocation-path bottlenecks observed in `victory-ma-play-20261204-165800-18832.log` (RTX 5070 Ti 16 GB, 1440p DLSS Quality + FG 2x), modifying only `crates/victory-gpu/src/host.rs`: 1. **Early no-op refresh filtering & zero-alloc bitmask sifting** (`refreshes 3.6 ms in 28 flushes of 13,977, 12,995 no-op / 93%`): - Snapshots `watch::ahead` once per kept submission (`Batch::begin_kept_snap` / reused from `refresh_front_spans`) and filters known no-ops directly in `Batch::add()` before hashing into `index`, cloning `Arc<Shadow>`, or queuing into `refreshes`. - Caches verified clean ranges in `Batch::clean` (invalidated on `title_written`, `flush_one`, and `Step::Run` / `ask_once_end`, never bridging disjoint gaps via `merge_clean_span`) and skips redundant re-filtering in `Batch::flush_all()` when `all_filtered` holds. - Replaces per-flush `Vec<AtomicBool>` allocations in `sift_indexed_with` and `sift_spans_with` with a reusable cache-line-padded `Vec<KeepWord>` (`#[repr(align(64))]`) 64-bit mask (64x fewer atomic stores, zero false sharing, single-branch skip for all-zero 64-item chunks). 2. **Offload post-send flight/list reset off the submitting thread** (`1.9 ms/frame` in `AFTER_SEND`): - Tracks whether `victory-late-wait` (`late_helper`) started (`HELPER_RUNNING`). - In `Host::send_late()`, avoids synchronously running `land()` and `bury()` on the submitting thread when `late_helper` is running (poking `late_helper` under the existing `LINE` lock when `landed.len() > bury_lag()`), falling back to synchronous execution only if the helper thread failed to start. 3. **Coalesce `MakeResident` mapping waits (`VICTORY_WAIT_RESIDENT`)** (`20,000 times, only 17 coalesced, 1,798.2 ms`): - Adds `MappedBarrier::mark_needed`, `has_pending`, and `flush_pending`. - Defers `mapped()` copy-queue fence waits until `settle()` runs before writing a shader-visible descriptor heap slot (`VICTORY_DEFER_MAPPED=0` restores immediate per-allocation waits), coalescing sequential allocations into a single GPU round-trip while preserving WDDM paging-queue ordering for lists submitted after `MakeResident`. ## Verification - `cargo clippy --lib --tests -p victory-gpu --target x86_64-pc-windows-msvc -- -D warnings`: **0 warnings, 0 errors** - Unit tests (`rustc --edition 2024 --test`): **4 passed, 0 failed** - `mapped_barrier_defers_and_coalesces_sequential_allocations` - `sync_land_after_send_only_when_not_apart_and_no_helper` - `merge_clean_span_never_bridges_unchecked_gaps` - `compact_by_bitmask_skips_zero_chunks_and_preserves_order`
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-04 18:55:08 +00:00
github manually merged commit 4ba58378c8 into mega-upgrade-v3 2026-12-04 20:20:17 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.