[PR #2] Perf Phase 7: BlockRuns absent/protect coalescing, lazy HeapCache shrink, O(N) TextureQueue #1

Open
opened 2026-11-26 20:06:21 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/4ld0-vito/victory-gta6/pull/2
Author: @4ld0-vito
Created: 11/24/2026
Status: 🔄 Open

Base: work ← Head: perf/phase-7-guards-heap


📝 Commits (2)

  • 0d0bc22 Phase 7 perf: BlockRuns absent + coalesced protect + hot-block hysteresis, lazy HeapCache shrink, O(N) TextureQueue
  • 335192f Phase 7b perf: opt-in VICTORY_GUARD_HOT, batched card_before barriers, reuse merge scratch

📊 Changes

5 files changed (+368 additions, -124 deletions)

View changed files

📝 crates/victory-gpu/src/descriptor/host.rs (+77 -22)
📝 crates/victory-gpu/src/draw.rs (+39 -22)
📝 crates/victory-gpu/src/host.rs (+38 -40)
📝 crates/victory-gpu/src/shadow.rs (+14 -10)
📝 crates/victory-gpu/src/watch.rs (+200 -30)

📄 Description

Summary

Phase 7 CPU optimizations on perf/phase-7-guards-heap (0d0bc22, branched from work):

  • crates/victory-gpu/src/watch.rs:
    • Replaced Guards::absent: BTreeSet<usize> with interval-merging BlockRuns and per-frame absent_checked caching (!cfg!(test) && frame > 0), plus clearing in title_memory_remapped.
    • Added VirtualQuery-guided span coalescing in protect() when a multi-block VirtualProtect fails across view boundaries/holes (recording only wholly uncommitted blocks into absent).
    • Added per-frame hot-block hysteresis (VICTORY_GUARD_HOT, toggleable with =0) leaving blocks faulted >= 2x in one frame writable until the next frame.
    • Added unit test coalesced_protect_and_hot_block_hysteresis.
  • crates/victory-gpu/src/draw.rs:
    • Added refcounts, needs_shrink, and last_rebuild_frame to HeapCache in State::heap_buffers so slot changes only delete a shadow when refcount reaches 0 and defer shrink rebuilds to every 64 frames.
  • crates/victory-gpu/src/descriptor/host.rs & draw.rs:
    • Unified TextureQueue::due + census into single-pass TextureQueue::due_with_census, using select_nth_unstable_by (O(N) selection instead of O(N log N) full sort), and lowered heap_textures batch limit 4096 -> 512.

Verification & Benchmarks (Xbox Series X profile, RTX 4070 12 GB, 32 GB RAM)

  • cargo test -p victory-gpu: 115 passed, 0 failed, 1 ignored
  • cargo build --release: succeeded with 0 errors
  • speed16_p7_1080p (210 s, VICTORY_DISPLAY_MODE=1920x1080, HEAP_TEX_MS=2):
    • 0 errors, peak 21.7 GB RAM, total process CPU 1497 s.
    • Peak: 14.5 fps (69.0 ms/frame at 580 draws, 13.9 fps at 568 draws) vs 13.3 fps in speed14_p6_1080p.
    • heap buffers improved from 16–47 ms (speed14) down to 10.1–16.0 ms on steady frames.
    • Key finding / regression from VICTORY_GUARD_HOT=1: Leaving hot 64 KiB blocks writable across all ~63 submissions/frame caused copied MB to double from 118–147 MB (speed14) to 197–338 MB (copies 57–89 ms), offsetting the guard savings on heavy 3k–4.5k draw frames (4.1–7.3 fps, GPU busy 68–69%).
  • speed17_p7_720p (180 s, VICTORY_DISPLAY_MODE=1280x720, HEAP_TEX_MS=2):
    • 0 errors, peak 21.6 GB RAM, CPU 864 s; world 4.4–11.9 fps (preparing 72–129 ms, copies 45–83 ms / 150–280 MB, copying back 40–73 ms, GPU busy 58–69%). Shows resolution is no longer the primary cap until CPU preparing (~90–120 ms), copying back (~60–75 ms), and GPU barrier/clamp overhead drop substantially.

Next (Phase 8 candidates)

  • Set VICTORY_GUARD_HOT default OFF (keep the BlockRuns absent + coalesced protect() + HeapCache + TextureQueue wins without the VICTORY_GUARD_HOT copy-MB inflation).
  • Diagnose post-Phase-6 CPU/GPU breakdown (diag build) and attack the true ~100 ms preparing + ~70 ms copying back + ~58–69% GPU pipeline/barrier stalls.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/4ld0-vito/victory-gta6/pull/2 **Author:** [@4ld0-vito](https://github.com/4ld0-vito) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `work` ← **Head:** `perf/phase-7-guards-heap` --- ### 📝 Commits (2) - [`0d0bc22`](https://github.com/4ld0-vito/victory-gta6/commit/0d0bc22c3b2c528d78beac17a6caaa10e299def0) Phase 7 perf: BlockRuns absent + coalesced protect + hot-block hysteresis, lazy HeapCache shrink, O(N) TextureQueue - [`335192f`](https://github.com/4ld0-vito/victory-gta6/commit/335192f552aa4ba6c88d3ac87f49fc63a819ea80) Phase 7b perf: opt-in VICTORY_GUARD_HOT, batched card_before barriers, reuse merge scratch ### 📊 Changes **5 files changed** (+368 additions, -124 deletions) <details> <summary>View changed files</summary> 📝 `crates/victory-gpu/src/descriptor/host.rs` (+77 -22) 📝 `crates/victory-gpu/src/draw.rs` (+39 -22) 📝 `crates/victory-gpu/src/host.rs` (+38 -40) 📝 `crates/victory-gpu/src/shadow.rs` (+14 -10) 📝 `crates/victory-gpu/src/watch.rs` (+200 -30) </details> ### 📄 Description ## Summary Phase 7 CPU optimizations on `perf/phase-7-guards-heap` (`0d0bc22`, branched from `work`): - **`crates/victory-gpu/src/watch.rs`**: - Replaced `Guards::absent: BTreeSet<usize>` with interval-merging `BlockRuns` and per-frame `absent_checked` caching (`!cfg!(test) && frame > 0`), plus clearing in `title_memory_remapped`. - Added `VirtualQuery`-guided span coalescing in `protect()` when a multi-block `VirtualProtect` fails across view boundaries/holes (recording only wholly uncommitted blocks into `absent`). - Added per-frame hot-block hysteresis (`VICTORY_GUARD_HOT`, toggleable with `=0`) leaving blocks faulted >= 2x in one frame writable until the next frame. - Added unit test `coalesced_protect_and_hot_block_hysteresis`. - **`crates/victory-gpu/src/draw.rs`**: - Added `refcounts`, `needs_shrink`, and `last_rebuild_frame` to `HeapCache` in `State::heap_buffers` so slot changes only delete a shadow when refcount reaches 0 and defer shrink rebuilds to every 64 frames. - **`crates/victory-gpu/src/descriptor/host.rs` & `draw.rs`**: - Unified `TextureQueue::due` + `census` into single-pass `TextureQueue::due_with_census`, using `select_nth_unstable_by` (O(N) selection instead of O(N log N) full sort), and lowered `heap_textures` batch limit `4096 -> 512`. ## Verification & Benchmarks (Xbox Series X profile, RTX 4070 12 GB, 32 GB RAM) - `cargo test -p victory-gpu`: **115 passed, 0 failed, 1 ignored** - `cargo build --release`: succeeded with 0 errors - **`speed16_p7_1080p`** (210 s, `VICTORY_DISPLAY_MODE=1920x1080`, `HEAP_TEX_MS=2`): - **0 errors**, peak 21.7 GB RAM, total process CPU 1497 s. - Peak: **14.5 fps** (`69.0 ms/frame` at 580 draws, `13.9 fps` at 568 draws) vs `13.3 fps` in `speed14_p6_1080p`. - `heap buffers` improved from `16–47 ms` (`speed14`) down to **`10.1–16.0 ms`** on steady frames. - **Key finding / regression from `VICTORY_GUARD_HOT=1`:** Leaving hot 64 KiB blocks writable across all ~63 submissions/frame caused copied MB to double from `118–147 MB` (`speed14`) to **`197–338 MB`** (`copies 57–89 ms`), offsetting the guard savings on heavy 3k–4.5k draw frames (`4.1–7.3 fps`, GPU busy `68–69%`). - **`speed17_p7_720p`** (180 s, `VICTORY_DISPLAY_MODE=1280x720`, `HEAP_TEX_MS=2`): - **0 errors**, peak 21.6 GB RAM, CPU 864 s; world 4.4–11.9 fps (`preparing` 72–129 ms, `copies` 45–83 ms / 150–280 MB, `copying back` 40–73 ms, GPU busy `58–69%`). Shows resolution is no longer the primary cap until CPU `preparing` (~90–120 ms), `copying back` (~60–75 ms), and GPU barrier/clamp overhead drop substantially. ## Next (Phase 8 candidates) - Set `VICTORY_GUARD_HOT` default OFF (keep the `BlockRuns` `absent` + coalesced `protect()` + `HeapCache` + `TextureQueue` wins without the `VICTORY_GUARD_HOT` copy-MB inflation). - Diagnose post-Phase-6 CPU/GPU breakdown (`diag` build) and attack the true ~100 ms `preparing` + ~70 ms `copying back` + ~58–69% GPU pipeline/barrier stalls. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
4ld0/victory-gta6#1
No description provided.