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

Open
github-bot wants to merge 1 commit from github-bot/gh-448 into main AGit
Owner

@⁠Wiktorxd-1 on GitHub · 2026-11-27 22:41 UTC · original
Wiktorxd-1:perf/heap-buffers-sweep → main · +104 −42 · 1 files · 1 commits · open

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.

**@⁠Wiktorxd-1** on GitHub · 2026-11-27 22:41 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/448) `Wiktorxd-1:perf/heap-buffers-sweep` → `main` · +104 −42 · 1 files · 1 commits · open ## 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 22:44:12 +00:00
Author
Owner

@⁠Rafa7046 on GitHub · 2026-11-28 01:28 UTC · original

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.

**@⁠Rafa7046** on GitHub · 2026-11-28 01:28 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/448#issuecomment-7231689832) 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.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/448/head:github-bot/gh-448'
git switch 'github-bot/gh-448'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-448'
git switch 'github-bot/gh-448'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-448'
git switch 'github-bot/gh-448'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-448'
git switch 'main'
git merge --squash 'github-bot/gh-448'
git switch 'main'
git merge --ff-only 'github-bot/gh-448'
git switch 'main'
git merge 'github-bot/gh-448'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.