perf(gpu): optimize card_steps planner, batched fill-to lookup, sorted writer search #1279

Open
qlfu wants to merge 1 commit from upstream-pr/1279 into main
qlfu commented 2026-11-28 16:52:11 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by qlfu on 2026-11-28T16:52:11Z.


Summary

Reduces submitting-thread CPU overhead in crates/victory-gpu/src/host/card_steps.rs (planning steps done on the card):

  1. Fast-path plan() when no Does::Copy exists:
    • Tracks has_copy / has_placed and taken_count during the initial scan so submissions with only Does::Fill skip redundant copy/placement overlap passes.
    • Removes Box<dyn Iterator> heap allocations during level assignment.
  2. Batched FillTo lookups per HostList:
    • Replaces repeated per-fill lock acquisitions/lookups with collect_fill_tos(), gathering each HostList's fill targets in a single pass.
  3. Sorted writers search + fast barrier deduplication + empty-slot skip:
    • Keeps writers sorted and uses partition_point in holder() instead of linear scanning.
    • Deduplicates D3D12 transition barriers with AddressHash.
    • Skips each_under thread-pool dispatch when slot_ops == 0.

Benchmark (GTA VI, 90s steady gameplay, 1440p Series X, DLSS Quality, Ryzen 7 5700X + RTX 4070 Ti 12 GB)

Paired A/B on main (9ce3cf9) with -FrameGen:

Metric (90s median per 5s window unless noted) main (9ce3cf9) pr/card-steps-perf (674d1c5) Delta
Median FPS 15.65 16.30 +4.2%
Mean FPS 16.06 17.10 +6.5%
Max FPS (p90) 21.3 (19.2) 27.3 (20.7) +28.2% (+7.8%)
Frame time (prep / copy back) 63.95 ms (46.95 / 18.4) 61.45 ms (45.55 / 17.7) -3.9%
ASYNC_SUBMIT worked 61.1 ms 58.9 ms -3.6%
Title present-wait 19.7 ms 16.1 ms -18.3%
Gameplay WARN / ERROR count 0 / 0 0 / 0 clean

Verification

  • cargo clippy -p victory-gpu --all-targets --locked and --all-features --locked: 0 warnings/errors in card_steps.rs.
  • cargo test -p victory-gpu --lib --locked -- --test-threads=1 --quiet: 455 passed, 0 failed, 36 ignored.
  • cargo build --release --locked -p victory: exit 0.
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5542479503 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1279). Originally posted by [qlfu](https://github.com/qlfu) on 2026-11-28T16:52:11Z. --- ### Summary Reduces submitting-thread CPU overhead in `crates/victory-gpu/src/host/card_steps.rs` (`planning steps done on the card`): 1. **Fast-path `plan()` when no `Does::Copy` exists**: - Tracks `has_copy` / `has_placed` and `taken_count` during the initial scan so submissions with only `Does::Fill` skip redundant copy/placement overlap passes. - Removes `Box<dyn Iterator>` heap allocations during level assignment. 2. **Batched `FillTo` lookups per `HostList`**: - Replaces repeated per-fill lock acquisitions/lookups with `collect_fill_tos()`, gathering each `HostList`'s fill targets in a single pass. 3. **Sorted `writers` search + fast barrier deduplication + empty-slot skip**: - Keeps `writers` sorted and uses `partition_point` in `holder()` instead of linear scanning. - Deduplicates D3D12 transition barriers with `AddressHash`. - Skips `each_under` thread-pool dispatch when `slot_ops == 0`. ### Benchmark (GTA VI, 90s steady gameplay, 1440p Series X, DLSS Quality, Ryzen 7 5700X + RTX 4070 Ti 12 GB) Paired A/B on `main` (`9ce3cf9`) with `-FrameGen`: | Metric (90s median per 5s window unless noted) | `main` (`9ce3cf9`) | `pr/card-steps-perf` (`674d1c5`) | Delta | |---|---:|---:|---:| | Median FPS | `15.65` | `16.30` | **+4.2%** | | Mean FPS | `16.06` | `17.10` | **+6.5%** | | Max FPS (`p90`) | `21.3` (`19.2`) | `27.3` (`20.7`) | **+28.2%** (**+7.8%**) | | Frame time (`prep` / `copy back`) | `63.95 ms` (`46.95` / `18.4`) | `61.45 ms` (`45.55` / `17.7`) | **-3.9%** | | `ASYNC_SUBMIT` worked | `61.1 ms` | `58.9 ms` | **-3.6%** | | Title `present-wait` | `19.7 ms` | `16.1 ms` | **-18.3%** | | Gameplay `WARN` / `ERROR` count | `0` / `0` | `0` / `0` | clean | ### Verification - `cargo clippy -p victory-gpu --all-targets --locked` and `--all-features --locked`: 0 warnings/errors in `card_steps.rs`. - `cargo test -p victory-gpu --lib --locked -- --test-threads=1 --quiet`: **455 passed, 0 failed, 36 ignored**. - `cargo build --release --locked -p victory`: exit `0`.
Aniseto commented 2026-11-28 19:39:04 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Aniseto on 2026-11-28T19:39:04Z.


Ran the full victory-gpu library suite at 674d1c5 on an NVIDIA Blackwell desktop part with an updated driver.

System

  • GPU: NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, mesh shaders), driver 32.0.16.2140 (621.40)
  • CPU: Intel Core i5-12400F, 64 GB RAM
  • OS: Windows 11 Pro build 26200 x64
  • Toolchain: Rust 1.98.1 (48a229cea 2026-09-01, pinned by rust-toolchain.toml), MSVC 14.44.35207, DXC 1.9.2609.5
  • Build: debug

Results

  • VICTORY_D3D12_ADAPTER=NVIDIA cargo test -p victory-gpu --lib --locked -- --test-threads=1 --quiet: 455 passed, 0 failed, 36 ignored.

What this adds
The count matches the author's run. This covers the faster card-step planner, batched FillTo lookup and sorted writer search. The PR has no comments yet, so this is the first datapoint in the thread and the first from an RTX 5070 Ti on driver 32.0.16.2140. It is a correctness run, not a CPU-time measurement.

Not tested
A retail title, CPU-time or FPS A/B, a paired smoke run, the whole workspace suite, AMD and Intel GPUs, native wave64 hosts, Wine, release profile, game data.

AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - ran the commands above on this machine and wrote this report; no game data was used.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7244703586 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1279#issuecomment-7244703586). Originally posted by [Aniseto](https://github.com/Aniseto) on 2026-11-28T19:39:04Z. --- Ran the full victory-gpu library suite at `674d1c5` on an NVIDIA Blackwell desktop part with an updated driver. **System** - GPU: NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, mesh shaders), driver 32.0.16.2140 (621.40) - CPU: Intel Core i5-12400F, 64 GB RAM - OS: Windows 11 Pro build 26200 x64 - Toolchain: Rust 1.98.1 (48a229cea 2026-09-01, pinned by `rust-toolchain.toml`), MSVC 14.44.35207, DXC 1.9.2609.5 - Build: debug **Results** - `VICTORY_D3D12_ADAPTER=NVIDIA cargo test -p victory-gpu --lib --locked -- --test-threads=1 --quiet`: 455 passed, 0 failed, 36 ignored. **What this adds** The count matches the author's run. This covers the faster card-step planner, batched FillTo lookup and sorted writer search. The PR has no comments yet, so this is the first datapoint in the thread and the first from an RTX 5070 Ti on driver 32.0.16.2140. It is a correctness run, not a CPU-time measurement. **Not tested** A retail title, CPU-time or FPS A/B, a paired smoke run, the whole workspace suite, AMD and Intel GPUs, native wave64 hosts, Wine, release profile, game data. AI-assisted (OpenCode), model: **DeepSeek V4.1 Flash Free** - ran the commands above on this machine and wrote this report; no game data was used.
meonline42 commented 2026-11-29 09:18:04 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by meonline42 on 2026-11-29T09:18:04Z.


Measurements from a Zen 3 + Ampere machine, in case they're useful (stacked builds, so most PRs aren't isolated, see below).

Machine: Ryzen 9 5900X (thermally limited: ~3.7 GHz average, Tctl 80-87 °C), RTX 3090 at 350 W, 64 GB DDR4-3200, Windows 11. Series X profile, 1080p rendered to 1440p, DLSS Performance, FSR 3 frame generation 2x.
Base: main at e1f2eb6, plus a local keyboard-input patch (victory-hle only, nothing in the GPU path).
Method: each build was started unattended from the same save, standing still, and measured for 150 s once the world was drawn. The scene isn't identical between runs (traffic and time of day differ), so I also bucketed the 5-second victory_gpu::host lines by draws per frame.

Build (stacked, each on top of the one above) fps median ms/frame, 6,000-6,999 draws ms/frame, 12,000-12,999 draws
main e1f2eb6 16 57.9 (n=3) -
+ #1403 #1279 #2049 #1937 17 56.8 (n=22) 77.6 (n=4)
+ #1988 with VICTORY_PRESENT_QUEUE=1 18 55.9 (n=24) 75.5 (n=10)
#1403 #1279 #2049 #1937 + #128 (fat LTO), no present queue 18 55.0 (n=26) 74.0 (n=8)
  • Each step moves in the right direction, but the gains (1-2 ms per step, about 5% in total) are close to run-to-run noise on this setup.
  • No crashes or visible problems in any run, but standing still doesn't exercise much.
  • #1937: the launcher here already set VICTORY_SPANS_QUICK=1, so its default flip made no difference in this run.
  • #128: a full release build took 4 min 23 s on the 5900X.
  • On this machine, most of the frame is still preparing: copies of 24-28 ms for 60-70 MB per frame, and the card busy only a few ms. Copy-back dropped from ~13 ms to ~6.5 ms between 923e38c and e1f2eb6.

Posted by Claude Code on behalf of the machine's owner.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7253671241 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1279#issuecomment-7253671241). Originally posted by [meonline42](https://github.com/meonline42) on 2026-11-29T09:18:04Z. --- Measurements from a Zen 3 + Ampere machine, in case they're useful (stacked builds, so most PRs aren't isolated, see below). **Machine:** Ryzen 9 5900X (thermally limited: ~3.7 GHz average, Tctl 80-87 °C), RTX 3090 at 350 W, 64 GB DDR4-3200, Windows 11. Series X profile, 1080p rendered to 1440p, DLSS Performance, FSR 3 frame generation 2x. **Base:** `main` at `e1f2eb6`, plus a local keyboard-input patch (victory-hle only, nothing in the GPU path). **Method:** each build was started unattended from the same save, standing still, and measured for 150 s once the world was drawn. The scene isn't identical between runs (traffic and time of day differ), so I also bucketed the 5-second `victory_gpu::host` lines by draws per frame. | Build (stacked, each on top of the one above) | fps median | ms/frame, 6,000-6,999 draws | ms/frame, 12,000-12,999 draws | |---|---|---|---| | `main` e1f2eb6 | 16 | 57.9 (n=3) | - | | + #1403 #1279 #2049 #1937 | 17 | 56.8 (n=22) | 77.6 (n=4) | | + #1988 with `VICTORY_PRESENT_QUEUE=1` | 18 | 55.9 (n=24) | 75.5 (n=10) | | #1403 #1279 #2049 #1937 + #128 (fat LTO), no present queue | 18 | 55.0 (n=26) | 74.0 (n=8) | - Each step moves in the right direction, but the gains (1-2 ms per step, about 5% in total) are close to run-to-run noise on this setup. - No crashes or visible problems in any run, but standing still doesn't exercise much. - #1937: the launcher here already set `VICTORY_SPANS_QUICK=1`, so its default flip made no difference in this run. - #128: a full release build took 4 min 23 s on the 5900X. - On this machine, most of the frame is still `preparing`: copies of 24-28 ms for 60-70 MB per frame, and the card busy only a few ms. Copy-back dropped from ~13 ms to ~6.5 ms between `923e38c` and `e1f2eb6`. Posted by Claude Code on behalf of the machine's owner.
dyshay commented 2026-11-29 15:40:18 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by dyshay on 2026-11-29T15:40:18Z.


Merged into our fork's integration branch for testing (dyshay/VIctory-NVIDIA, branch janus-prs). I read the full diff first: no network access, process spawning, binaries, build or dependency changes, or game data. It builds with --profile diag --features diagnostics, and the CPU tests of the touched crates pass. Runs on an RTX 4090 are queued (Series X 1440p, and Series S with ray tracing, DLSS Quality). Frame times will follow here.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7258273541 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1279#issuecomment-7258273541). Originally posted by [dyshay](https://github.com/dyshay) on 2026-11-29T15:40:18Z. --- Merged into our fork's integration branch for testing ([dyshay/VIctory-NVIDIA](https://github.com/dyshay/VIctory-NVIDIA/tree/janus-prs), branch `janus-prs`). I read the full diff first: no network access, process spawning, binaries, build or dependency changes, or game data. It builds with `--profile diag --features diagnostics`, and the CPU tests of the touched crates pass. Runs on an RTX 4090 are queued (Series X 1440p, and Series S with ray tracing, DLSS Quality). Frame times will follow here.
DoubleD17 commented 2026-11-30 07:58:23 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by DoubleD17 on 2026-11-30T07:58:23Z.


We ran a test of this PR on current main (41adb551 with this PR merged), on a CPU-bound machine.

We compare only the seconds where the idle camera shows the same lighter views (about 7,500 draws a frame). Its heavier view (about 15,000 draws, half the frame rate) takes 10 to 60 s of each 150 s run, and it moved whole-run means by several ms.

CPU prep (ms/frame) main at that point fps main at that point
round 1 60.0 60.8 15.3 14.3
round 2 64.0 60.0 13.5 15.3
mean difference +1.6 ms −2.4 %

No difference we can measure. The five main runs of the session agreed within 1.3 ms on these seconds. But we also ran main again, built in another folder, eight times: it ranged from 57.5 to 65.5 ms. Its first four runs were 2.4 ms slower than main on average, and the last four 4.2 ms faster. All nine PRs we tested in this session came out 0.4 to 3.9 ms slower than main, and fps moved with it. So we read the difference as a newly built executable, not as this PR.

Picture: 0 defects in 160 frames.

Setup:

  • Ryzen 7 5800X (8 cores, 16 threads), RTX 5070 12 GB (DXGI budget 11,175 MB), 64 GB RAM, Windows 11;
  • Series X, 1440p with DLAA (DLSS at native resolution; corrected, this line said DLSS Performance at first), frame generation and ray tracing off;
  • the PR merged locally onto main 41adb551 (only its own commits on top), against 41adb551 itself;
  • a warm-up run per build, then 150 s runs in two rounds (the second in reverse order), with five main runs spread through the session;
  • every run starts from the same save, restored before each run;
  • CPU prep is the median of the submitting thread's 5 s lines, fps the median of the host's 5 s lines, on the light-view seconds after the first 20 s; each run is compared with main's runs interpolated in time.

Picture check: a burst of 10 captures a second at the end of each run (80 frames), looked at frame by frame.

AI Assisted

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7272336152 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1279#issuecomment-7272336152). Originally posted by [DoubleD17](https://github.com/DoubleD17) on 2026-11-30T07:58:23Z. --- We ran a test of this PR on current main (41adb551 with this PR merged), on a CPU-bound machine. We compare only the seconds where the idle camera shows the same lighter views (about 7,500 draws a frame). Its heavier view (about 15,000 draws, half the frame rate) takes 10 to 60 s of each 150 s run, and it moved whole-run means by several ms. | | CPU prep (ms/frame) | main at that point | fps | main at that point | |---|---|---|---|---| | round 1 | 60.0 | 60.8 | 15.3 | 14.3 | | round 2 | 64.0 | 60.0 | 13.5 | 15.3 | | **mean difference** | **+1.6 ms** | | **−2.4 %** | | No difference we can measure. The five main runs of the session agreed within 1.3 ms on these seconds. But we also ran main again, built in another folder, eight times: it ranged from 57.5 to 65.5 ms. Its first four runs were 2.4 ms slower than main on average, and the last four 4.2 ms faster. All nine PRs we tested in this session came out 0.4 to 3.9 ms slower than main, and fps moved with it. So we read the difference as a newly built executable, not as this PR. **Picture:** 0 defects in 160 frames. **Setup:** - Ryzen 7 5800X (8 cores, 16 threads), RTX 5070 12 GB (DXGI budget 11,175 MB), 64 GB RAM, Windows 11; - Series X, 1440p with DLAA (DLSS at native resolution; corrected, this line said DLSS Performance at first), frame generation and ray tracing off; - the PR merged locally onto main 41adb551 (only its own commits on top), against 41adb551 itself; - a warm-up run per build, then 150 s runs in two rounds (the second in reverse order), with five main runs spread through the session; - every run starts from the same save, restored before each run; - CPU prep is the median of the submitting thread's 5 s lines, fps the median of the host's 5 s lines, on the light-view seconds after the first 20 s; each run is compared with main's runs interpolated in time. Picture check: a burst of 10 captures a second at the end of each run (80 frames), looked at frame by frame. AI Assisted
Cooperos commented 2026-11-30 09:39:20 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Cooperos on 2026-11-30T09:39:20Z.


I tested this changes on the same CPU (Ryzen 7 5700X), 8 GB RTX 3070 Ti,
driver 610.88, Series S profile, 1440p scene 1280x720, DLSS quality, frame
generation off, same save and overlapping routes:

v2026.11.29.05 this PR
median fps 16.3 15.6
slowest 5% 9.9 10.1
under 10 fps 65 s of 1,202 s 69 s of 1,447 s
title waited at presents 15.7 ms 10.5 ms (−33%)
crashes / memory-pressure warnings 0 0
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7274505131 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1279#issuecomment-7274505131). Originally posted by [Cooperos](https://github.com/Cooperos) on 2026-11-30T09:39:20Z. --- I tested this changes on the same CPU (Ryzen 7 5700X), 8 GB RTX 3070 Ti, driver 610.88, Series S profile, 1440p scene 1280x720, DLSS quality, frame generation off, same save and overlapping routes: | | v2026.11.29.05 | this PR | |---|---|---| | median fps | 16.3 | 15.6 | | slowest 5% | 9.9 | 10.1 | | under 10 fps | 65 s of 1,202 s | 69 s of 1,447 s | | title waited at presents | 15.7 ms | **10.5 ms (−33%)** | | crashes / memory-pressure warnings | 0 | 0 |
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/1279:upstream-pr/1279'
git switch 'upstream-pr/1279'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/1279'
git switch 'upstream-pr/1279'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1279'
git switch 'upstream-pr/1279'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1279'
git switch 'main'
git merge --squash 'upstream-pr/1279'
git switch 'main'
git merge --ff-only 'upstream-pr/1279'
git switch 'main'
git merge 'upstream-pr/1279'
git push origin 'main'
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!1279
No description provided.