draw: pack active HeapRanges densely and cut heap_buffer_pass overhead #448

Merged
Wiktorxd-1 merged 2 commits from upstream-pr/448 into main 2026-11-28 19:39:39 +00:00
Wiktorxd-1 commented 2026-11-27 22:41:25 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Wiktorxd-1 on 2026-11-27T22:41:25Z.


What this fixes

In live gameplay logs, heap_buffer_pass (crates/victory-gpu/src/draw.rs) took ~18.6 ms/frame on the aside thread while holding host.buffer_sweep:

  1. HeapRanges<T> stored a sparse Vec<Option<(T, u64, u64)>> indexed up to the highest buffer slot (~737k entries). Every frame, ranges.ranges() walked all ~737k entries (with ~72k–83k active) to build spans, and forget_part stepped through 32-byte Option slots.
  2. each_view called crate::descriptor::host::device_removed() (GetDeviceRemovedReason() COM query) on every 256-slot chunk.
  3. spans started at capacity 0, cloned Arc<Shadow> a second time into found, and allocated/swapped next_unwatched = HashMap::new() every frame even when VICTORY_UNWATCHED_FRAMES == 1 (the default).

The commits

  1. Pack active HeapRanges densely and cut heap_buffer_pass overhead.
    • HeapRanges<T> now keeps a compact index: Vec<u32> (u32::MAX = empty, 4 bytes/slot) and a tightly packed dense: Vec<(u32, (T, u64, u64))> of active slots only, so ranges() iterates contiguous active entries without scanning hundreds of thousands of None slots.
    • Moved device_removed() out of the per-chunk each_view closure to once after each_view.
    • Pre-sized spans to last_spans, consumed spans directly into found without extra Arc clones, and skipped next_unwatched allocation when every <= 1.

Tests

  • cargo test --locked -p victory-gpu --lib draw (11 passed; 0 failed; 3 ignored, including every_slot_is_looked_at_again_in_a_round)
  • cargo build --release --locked -p victory (succeeded)
  • Launched target\release\victory.exe via scripts\play-nvidia.ps1 (35s, ALIVE_AFTER_35S=True, crashes.log=False).

Setup

NVIDIA GeForce RTX 5070, driver 621.14.0, Windows 11 (10.0.26300). Series S profile, DLSS Performance, Frame Generation 6x. My own dump: <game dir>. No game files are attached or quoted.

This change and its testing were done with an AI assistant (Antigravity), and I checked the results on my machine.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5534024954 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/448). Originally posted by [Wiktorxd-1](https://github.com/Wiktorxd-1) on 2026-11-27T22:41:25Z. --- ## What this fixes In live gameplay logs, `heap_buffer_pass` (`crates/victory-gpu/src/draw.rs`) took ~18.6 ms/frame on the aside thread while holding `host.buffer_sweep`: 1. `HeapRanges<T>` stored a sparse `Vec<Option<(T, u64, u64)>>` indexed up to the highest buffer slot (~737k entries). Every frame, `ranges.ranges()` walked all ~737k entries (with ~72k–83k active) to build `spans`, and `forget_part` stepped through 32-byte `Option` slots. 2. `each_view` called `crate::descriptor::host::device_removed()` (`GetDeviceRemovedReason()` COM query) on every 256-slot chunk. 3. `spans` started at capacity 0, cloned `Arc<Shadow>` a second time into `found`, and allocated/swapped `next_unwatched = HashMap::new()` every frame even when `VICTORY_UNWATCHED_FRAMES == 1` (the default). ## The commits 1. **Pack active `HeapRanges` densely and cut `heap_buffer_pass` overhead.** - `HeapRanges<T>` now keeps a compact `index: Vec<u32>` (`u32::MAX` = empty, 4 bytes/slot) and a tightly packed `dense: Vec<(u32, (T, u64, u64))>` of active slots only, so `ranges()` iterates contiguous active entries without scanning hundreds of thousands of `None` slots. - Moved `device_removed()` out of the per-chunk `each_view` closure to once after `each_view`. - Pre-sized `spans` to `last_spans`, consumed `spans` directly into `found` without extra `Arc` clones, and skipped `next_unwatched` allocation when `every <= 1`. ## Tests - `cargo test --locked -p victory-gpu --lib draw` (`11 passed; 0 failed; 3 ignored`, including `every_slot_is_looked_at_again_in_a_round`) - `cargo build --release --locked -p victory` (succeeded) - Launched `target\release\victory.exe` via `scripts\play-nvidia.ps1` (`35s`, `ALIVE_AFTER_35S=True`, `crashes.log=False`). ## Setup NVIDIA GeForce RTX 5070, driver `621.14.0`, Windows 11 (`10.0.26300`). Series S profile, DLSS Performance, Frame Generation 6x. My own dump: `<game dir>`. No game files are attached or quoted. This change and its testing were done with an AI assistant (Antigravity), and I checked the results on my machine.
Rafa7046 commented 2026-11-28 01:28:24 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Rafa7046 on 2026-11-28T01:28:24Z.


Measured on an RTX 5080 16 GB + Ryzen 9 9950X3D (Series X, 1440p, DLSS Performance, frame generation off, diagnostics build on 64d4931 with only this PR applied, pipelines made ahead with victory warm), same stretch each run: Lucia's arrest cutscenes, then Jason on the boat and a minute standing still.

Cutscenes, fps (median) Boat, fps preparing in the cutscenes
main, run 1 37.4 35.8 19.6 ms
main, run 2 35.0 34.7 21.4 ms
with #448 35.4 35.9 21.8 ms

Two runs of plain main differ by about 2.4 fps, so this is within the run-to-run spread on this machine: no measurable change in frame rate here, and no new warnings, faults or crashes in the log. On this card the frame is set by the submitting thread (about 21 ms of a 28 ms frame), which is probably why a saving of this size does not show.

Same machine and scene with and without the title's ray tracing: #535.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7231689832 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/448#issuecomment-7231689832). Originally posted by [Rafa7046](https://github.com/Rafa7046) on 2026-11-28T01:28:24Z. --- Measured on an RTX 5080 16 GB + Ryzen 9 9950X3D (Series X, 1440p, DLSS Performance, frame generation off, diagnostics build on `64d4931` with only this PR applied, pipelines made ahead with `victory warm`), same stretch each run: Lucia's arrest cutscenes, then Jason on the boat and a minute standing still. | | Cutscenes, fps (median) | Boat, fps | `preparing` in the cutscenes | |---|---|---|---| | `main`, run 1 | 37.4 | 35.8 | 19.6 ms | | `main`, run 2 | 35.0 | 34.7 | 21.4 ms | | **with #448** | **35.4** | **35.9** | **21.8 ms** | Two runs of plain `main` differ by about 2.4 fps, so this is within the run-to-run spread on this machine: no measurable change in frame rate here, and no new warnings, faults or crashes in the log. On this card the frame is set by the submitting thread (about 21 ms of a 28 ms frame), which is probably why a saving of this size does not show. Same machine and scene with and without the title's ray tracing: #535.
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
trustno1-coder/VIctory-NVIDIA!448
No description provided.