perf(gpu): optimize land dirty-page scan, job/note batching, and texback readback throughput #15

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

@⁠MahanYTT on GitHub · 2026-12-04 18:51 UTC · original
MahanYTT:perf/land-relay-readback → mega-upgrade-v3 · +931 −113 · 3 files · 1 commits · merged 2026-12-04 20:18 UTC

Summary

Optimizes relay landing piece merging, dirty-page scanning, readback/list cleanup, and texture readback throughput based on victory-ma-play-20261204-165800-18832.log (227 pieces (207 dirty), 1,549 pages -> 731 dirty, read-backs and lists 0.78 ms, merging 0.57 ms / 1.07 ms all threads).

crates/victory-gpu/src/land.rs

  • AVX2 128 B/iter dirty-page scan & prefix/suffix trim (first_diff_offset, diff_bounds): Skips safecopy::merge entirely on clean 4 KiB pages (~53% of landed pages) and trims clean 32-byte prefixes and suffixes on dirty 32-byte-aligned pages before merging. Replaces [bool; 17] with a u32 bitmask on the direct path and avoids calling watch::changes() on the beside path.
  • Job-local PieceStats & O(N log N) Notes::flush / pre-sized Notes::flush_all: Accumulates per-piece STATS/PUT counters locally inside Notes and flushes once per landing instead of ~2,200 cross-core atomic RMWs/frame. Replaces quadratic O(B * L) self.landed scanning with in-place collapse_landed + binary search, and pre-allocates flush_all buffers.
  • Adaptive jobs() scaling & in-place ordered(): Scales job chunk targets down to BLOCK (64 KiB) for mid-size landings (~516 KiB/landing) so all worker threads stay utilized instead of only 2 jobs leaving threads idle. Uses chunk_by_mut + in-place sort_unstable_by_key in ordered() to eliminate per-block to_vec() heap allocations.
  • Lock-free Pool::running_now spin & allocation-free Had: Polls AtomicUsize in spin_for instead of contending on state.try_lock(). Replaces per-fetch HashMap in Had with recycled sorted Vecs + binary search.

crates/victory-gpu/src/texback.rs

  • Default-on VICTORY_TEXBACK_FULL_OVERWRITE + zero-scratch linear fast path: Skips redundant full-texture reads of old title bytes on addressable single-subresource full overwrites (retaining per-page safecopy hole probing; =0 opts out), and copies tightly packed Swizzle::LINEAR full overwrites straight from the mapped readback buffer.
  • O(1) bucketed ReadBackPool with oldest-first cap eviction: Replaces linear rposition+remove with 28 power-of-two buckets for O(1) LIFO reuse; evicts oldest idle buffers on cap pressure rather than destroying newly-active buffers; skips pool locking when most == 0.
  • Zero-alloc SIMD VICTORY_TEXBACK_SAME diff & immediate TICKETS pruning: Reuses thread-local TILED_PREV scratch with AVX2 diff_bytes_range, prunes invalidated tickets immediately, and resets TRACKING when empty.

Verification

  • cargo clippy -p victory-gpu --target x86_64-pc-windows-gnu -- -D warnings: pass (0 warnings)
  • cargo clippy -p victory-gpu --tests --target x86_64-pc-windows-gnu -- -D warnings: pass (0 warnings)
  • Native x86_64 AVX2 unit test harness (rustc --edition=2024 --test -O): 6/6 passed (AVX2 detected: true).
**@⁠MahanYTT** on GitHub · 2026-12-04 18:51 UTC · [original](https://github.com/MahanYTT/VIctory-MA/pull/15) `MahanYTT:perf/land-relay-readback` → `mega-upgrade-v3` · +931 −113 · 3 files · 1 commits · merged 2026-12-04 20:18 UTC ## Summary Optimizes relay landing piece merging, dirty-page scanning, readback/list cleanup, and texture readback throughput based on `victory-ma-play-20261204-165800-18832.log` (`227 pieces (207 dirty), 1,549 pages -> 731 dirty`, `read-backs and lists 0.78 ms`, `merging 0.57 ms / 1.07 ms all threads`). ### `crates/victory-gpu/src/land.rs` - **AVX2 128 B/iter dirty-page scan & prefix/suffix trim (`first_diff_offset`, `diff_bounds`)**: Skips `safecopy::merge` entirely on clean 4 KiB pages (~53% of landed pages) and trims clean 32-byte prefixes and suffixes on dirty 32-byte-aligned pages before merging. Replaces `[bool; 17]` with a `u32` bitmask on the direct path and avoids calling `watch::changes()` on the beside path. - **Job-local `PieceStats` & O(N log N) `Notes::flush` / pre-sized `Notes::flush_all`**: Accumulates per-piece `STATS`/`PUT` counters locally inside `Notes` and flushes once per landing instead of ~2,200 cross-core atomic RMWs/frame. Replaces quadratic `O(B * L)` `self.landed` scanning with in-place `collapse_landed` + binary search, and pre-allocates `flush_all` buffers. - **Adaptive `jobs()` scaling & in-place `ordered()`**: Scales job chunk targets down to `BLOCK` (64 KiB) for mid-size landings (~516 KiB/landing) so all worker threads stay utilized instead of only 2 jobs leaving threads idle. Uses `chunk_by_mut` + in-place `sort_unstable_by_key` in `ordered()` to eliminate per-block `to_vec()` heap allocations. - **Lock-free `Pool::running_now` spin & allocation-free `Had`**: Polls `AtomicUsize` in `spin_for` instead of contending on `state.try_lock()`. Replaces per-fetch `HashMap` in `Had` with recycled sorted `Vec`s + binary search. ### `crates/victory-gpu/src/texback.rs` - **Default-on `VICTORY_TEXBACK_FULL_OVERWRITE` + zero-scratch linear fast path**: Skips redundant full-texture reads of old title bytes on addressable single-subresource full overwrites (retaining per-page `safecopy` hole probing; `=0` opts out), and copies tightly packed `Swizzle::LINEAR` full overwrites straight from the mapped readback buffer. - **O(1) bucketed `ReadBackPool` with oldest-first cap eviction**: Replaces linear `rposition`+`remove` with 28 power-of-two buckets for O(1) LIFO reuse; evicts oldest idle buffers on cap pressure rather than destroying newly-active buffers; skips pool locking when `most == 0`. - **Zero-alloc SIMD `VICTORY_TEXBACK_SAME` diff & immediate `TICKETS` pruning**: Reuses thread-local `TILED_PREV` scratch with AVX2 `diff_bytes_range`, prunes invalidated tickets immediately, and resets `TRACKING` when empty. ## Verification - `cargo clippy -p victory-gpu --target x86_64-pc-windows-gnu -- -D warnings`: **pass (0 warnings)** - `cargo clippy -p victory-gpu --tests --target x86_64-pc-windows-gnu -- -D warnings`: **pass (0 warnings)** - Native x86_64 AVX2 unit test harness (`rustc --edition=2024 --test -O`): **6/6 passed** (`AVX2 detected: true`).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-04 18:55:02 +00:00
github manually merged commit 4ba58378c8 into mega-upgrade-v3 2026-12-04 20:20:18 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.