perf(host): parallelize HostList prelude recording and skip empty copying map #1397

Open
qlfu wants to merge 1 commit from upstream-pr/1397 into main
qlfu commented 2026-11-28 18:50:21 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by qlfu on 2026-11-28T18:50:21Z.


Summary

Splits HostList::prelude into two phases in crates/victory-gpu/src/host.rs:

  1. HostList::prepare_prelude (serial, in exact submission order): updates twin.behind and copy.state and builds a PreludePlan containing the required barriers, twin copies, and prelude uploads. When syncs and uploads are both empty (the common case), it skips allocating/probing the copying map entirely; otherwise it uses ByCopy<u32> (AddressHash) instead of default SipHash.
  2. HostList::record_prelude / record_preludes (parallel via crate::land::each_under): when a submission has >= 4 non-empty prelude plans across distinct HostLists (guarded by all_unique_ptrs), D3D12 allocator.Reset / list.Reset / ResourceBarrier / CopyTextureRegion / Close recording runs in parallel across each_under workers, and the resulting command lists are assembled into lists and firsts in exact submission order.

Correctness & Safety

  • All texture state transitions (copy.state.swap) and depth-twin behind updates still happen serially in exact runs submission order inside prepare_prelude.
  • All ID3D12Resource pointers embedded in D3D12_RESOURCE_BARRIER structs are kept alive by runs (HostList::states/twins) and PreludePlan (syncs/uploads) across record_preludes.
  • Parallel recording is gated on all_unique_ptrs over job.list so no two workers ever touch the same HostList or D3D12 ID3D12CommandAllocator/ID3D12GraphicsCommandList; duplicate list references fall back sequentially.
  • Added unit test prelude_tests::unique_ptr_check_guards_parallel_prelude_recording.

Verification

  • cargo +1.98.1-x86_64-pc-windows-msvc clippy -p victory-gpu --lib --tests --locked and --all-features: 0 warnings in host.rs.
  • cargo +1.98.1-x86_64-pc-windows-msvc test -p victory-gpu --lib --locked -- --test-threads=1 --quiet: 455 passed, 0 failed, 36 ignored.
  • cargo +1.98.1-x86_64-pc-windows-msvc build --release --locked -p victory: exit 0.

Clean Idle-PC 90s A/B Benchmark (RTX 4070 Ti 12 GB + Ryzen 7 5700X, -FrameGen, vs origin/main)

Metric origin/main This PR Delta
steps - refreshes - copies (prelude/loop) median 5.45 ms 4.10 ms -1.35 ms (-24.8%)
steps - refreshes - copies mean 5.41 ms 4.11 ms -1.30 ms (-24.0%)
in the lists' steps total median 19.50 ms 17.80 ms -1.70 ms (-8.7%)
Submitting thread total (sub_all) median 50.85 ms 48.70 ms -2.15 ms (-4.2%)
Frame time median 53.80 ms 51.60 ms -2.20 ms (-4.1%)
Median FPS 18.60 19.40 +4.3%
GPU busy 71% 74% +3 pp
WARNs / ERRORs 0 / 0 0 / 0 Clean
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5543492051 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1397). Originally posted by [qlfu](https://github.com/qlfu) on 2026-11-28T18:50:21Z. --- ## Summary Splits `HostList::prelude` into two phases in `crates/victory-gpu/src/host.rs`: 1. **`HostList::prepare_prelude` (serial, in exact submission order):** updates `twin.behind` and `copy.state` and builds a `PreludePlan` containing the required barriers, twin copies, and prelude uploads. When `syncs` and `uploads` are both empty (the common case), it skips allocating/probing the `copying` map entirely; otherwise it uses `ByCopy<u32>` (`AddressHash`) instead of default SipHash. 2. **`HostList::record_prelude` / `record_preludes` (parallel via `crate::land::each_under`):** when a submission has `>= 4` non-empty prelude plans across distinct `HostList`s (guarded by `all_unique_ptrs`), D3D12 `allocator.Reset` / `list.Reset` / `ResourceBarrier` / `CopyTextureRegion` / `Close` recording runs in parallel across `each_under` workers, and the resulting command lists are assembled into `lists` and `firsts` in exact submission order. ### Correctness & Safety - All texture state transitions (`copy.state.swap`) and depth-twin `behind` updates still happen serially in exact `runs` submission order inside `prepare_prelude`. - All `ID3D12Resource` pointers embedded in `D3D12_RESOURCE_BARRIER` structs are kept alive by `runs` (`HostList::states`/`twins`) and `PreludePlan` (`syncs`/`uploads`) across `record_preludes`. - Parallel recording is gated on `all_unique_ptrs` over `job.list` so no two workers ever touch the same `HostList` or D3D12 `ID3D12CommandAllocator`/`ID3D12GraphicsCommandList`; duplicate list references fall back sequentially. - Added unit test `prelude_tests::unique_ptr_check_guards_parallel_prelude_recording`. ## Verification - `cargo +1.98.1-x86_64-pc-windows-msvc clippy -p victory-gpu --lib --tests --locked` and `--all-features`: 0 warnings in `host.rs`. - `cargo +1.98.1-x86_64-pc-windows-msvc test -p victory-gpu --lib --locked -- --test-threads=1 --quiet`: **455 passed, 0 failed, 36 ignored**. - `cargo +1.98.1-x86_64-pc-windows-msvc build --release --locked -p victory`: exit `0`. ## Clean Idle-PC 90s A/B Benchmark (RTX 4070 Ti 12 GB + Ryzen 7 5700X, `-FrameGen`, vs `origin/main`) | Metric | `origin/main` | This PR | Delta | |---|---:|---:|---:| | `steps - refreshes - copies` (prelude/loop) median | `5.45 ms` | **`4.10 ms`** | **`-1.35 ms` (`-24.8%`)** | | `steps - refreshes - copies` mean | `5.41 ms` | **`4.11 ms`** | **`-1.30 ms` (`-24.0%`)** | | `in the lists' steps` total median | `19.50 ms` | **`17.80 ms`** | **`-1.70 ms` (`-8.7%`)** | | Submitting thread total (`sub_all`) median | `50.85 ms` | **`48.70 ms`** | **`-2.15 ms` (`-4.2%`)** | | Frame time median | `53.80 ms` | **`51.60 ms`** | **`-2.20 ms` (`-4.1%`)** | | Median FPS | `18.60` | **`19.40`** | **`+4.3%`** | | GPU busy | `71%` | **`74%`** | **`+3 pp`** | | WARNs / ERRORs | `0 / 0` | `0 / 0` | Clean |
qlfu commented 2026-11-29 10:14:28 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by qlfu on 2026-11-29T10:14:28Z.


Rebased onto current main (829188e9): preserved alias_rt::resolve_prelude resource lifetimes inside PreludePlan and barstat::rb barrier accounting. Verified with cargo clippy, prelude + alias_rt unit tests, and a clean 90s gameplay run on 829188e9 (steps_oth 7.95 ms -> 6.25 ms, -1.70 ms/frame).

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7254301873 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1397#issuecomment-7254301873). Originally posted by [qlfu](https://github.com/qlfu) on 2026-11-29T10:14:28Z. --- Rebased onto current `main` (`829188e9`): preserved `alias_rt::resolve_prelude` resource lifetimes inside `PreludePlan` and `barstat::rb` barrier accounting. Verified with `cargo clippy`, `prelude` + `alias_rt` unit tests, and a clean 90s gameplay run on `829188e9` (`steps_oth` `7.95 ms -> 6.25 ms`, `-1.70 ms/frame`).
DoubleD17 commented 2026-11-30 07:58:26 +00:00 (Migrated from github.com)

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


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 62.6 61.0 14.2 14.3
round 2 64.1 59.9 14.1 15.3
mean difference +2.9 ms −4.3 %

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:7272336895 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1397#issuecomment-7272336895). Originally posted by [DoubleD17](https://github.com/DoubleD17) on 2026-11-30T07:58:26Z. --- 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 | 62.6 | 61.0 | 14.2 | 14.3 | | round 2 | 64.1 | 59.9 | 14.1 | 15.3 | | **mean difference** | **+2.9 ms** | | **−4.3 %** | | 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
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/1397:upstream-pr/1397'
git switch 'upstream-pr/1397'

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