GPU: parallelize host-copy refreshes on multicore systems #38

Open
github-bot wants to merge 2 commits from github-bot/gh-38 into main AGit
Owner

@⁠space-de on GitHub · 2026-11-24 20:46 UTC · original
space-de:perf/adaptive-wide-refresh → main · +37 −3 · 2 files · 2 commits · open

Summary

  • Automatically parallelize independent host-copy refreshes when the system reports at least four logical CPUs.
  • Preserve VICTORY_WIDE_REFRESH=0 as an opt-out and =1 as an override; flushes still need at least four independent copies before using the worker pool.
  • This targets the serial CPU memory reads the code measures at roughly 45–50 ms per frame. It should reduce CPU preparation time on multicore systems; no in-game FPS result is claimed here.

Validation

  • cargo test --workspace --no-fail-fast --quiet — passed (497 passed, 7 ignored).
  • cargo clippy --workspace -- -D warnings — passed.
  • cargo clippy --workspace --all-features -- -D warnings — passed.
  • The workspace formatter check reports existing formatting differences in unrelated files; the changed host.rs lines had no formatter diff.

The existing setting was opt-in and no open PR was found changing its default.

**@⁠space-de** on GitHub · 2026-11-24 20:46 UTC · [original](https://github.com/fxceless/victory-fork/pull/38) `space-de:perf/adaptive-wide-refresh` → `main` · +37 −3 · 2 files · 2 commits · open ## Summary - Automatically parallelize independent host-copy refreshes when the system reports at least four logical CPUs. - Preserve `VICTORY_WIDE_REFRESH=0` as an opt-out and `=1` as an override; flushes still need at least four independent copies before using the worker pool. - This targets the serial CPU memory reads the code measures at roughly 45–50 ms per frame. It should reduce CPU preparation time on multicore systems; no in-game FPS result is claimed here. ## Validation - `cargo test --workspace --no-fail-fast --quiet` — passed (497 passed, 7 ignored). - `cargo clippy --workspace -- -D warnings` — passed. - `cargo clippy --workspace --all-features -- -D warnings` — passed. - The workspace formatter check reports existing formatting differences in unrelated files; the changed `host.rs` lines had no formatter diff. The existing setting was opt-in and no open PR was found changing its default.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:35:01 +00:00
github-bot referenced this pull request from a commit 2026-11-26 03:40:07 +00:00
Author
Owner

@⁠ryotdev on GitHub · 2026-11-24 21:05 UTC · original

I found a race in the copy timer this change enables by default. On 05ee438, each parallel refresh adds its worker time to PREPARING[0]. After joining, the submission reads the total and subtracts the excess over wall time. The presenter can reset the counter with swap(0) between that last read and subtraction. Subtracting 300 µs from the reset counter leaves 18446744073709551316 µs for the next sample. This affects the reported “copies” time used to judge the speedup. Batch::flush · Presenter counter reset

I tested a small fix on Windows. Let Batch::update return its elapsed µs and keep recording bytes and per-range diagnostics there. The serial callers add the returned time as before. For the parallel path, add the wall time once after wide_run joins. This removes the read/subtract correction entirely.

In a CPU-only test using the PR's Batch::flush and four synthetic 4 KiB copies, a second thread sampled after three workers finished and before the batch joined. It saw 6,975 µs of worker time on this head and 0 µs with the fix. The fixed batch published 5,303 µs on return and counted all 16,384 bytes. The one-to-three-copy serial cases and flush_one also passed. This was an AI-assisted accounting test, with no game data or FPS measurement.

**@⁠ryotdev** on GitHub · 2026-11-24 21:05 UTC · [original](https://github.com/fxceless/victory-fork/pull/38#issuecomment-7144459600) I found a race in the copy timer this change enables by default. On `05ee438`, each parallel refresh adds its worker time to `PREPARING[0]`. After joining, the submission reads the total and subtracts the excess over wall time. The presenter can reset the counter with `swap(0)` between that last read and subtraction. Subtracting 300 µs from the reset counter leaves `18446744073709551316` µs for the next sample. This affects the reported “copies” time used to judge the speedup. [Batch::flush](https://github.com/fxceless/victory-fork/blob/05ee4387065d782c4cec6c8ff22d484da5e09894/crates/victory-gpu/src/host.rs#L5299-L5307) · [Presenter counter reset](https://github.com/fxceless/victory-fork/blob/05ee4387065d782c4cec6c8ff22d484da5e09894/crates/victory-gpu/src/host.rs#L5696-L5699) I tested a small fix on Windows. Let `Batch::update` return its elapsed µs and keep recording bytes and per-range diagnostics there. The serial callers add the returned time as before. For the parallel path, add the wall time once after `wide_run` joins. This removes the read/subtract correction entirely. In a CPU-only test using the PR's `Batch::flush` and four synthetic 4 KiB copies, a second thread sampled after three workers finished and before the batch joined. It saw 6,975 µs of worker time on this head and 0 µs with the fix. The fixed batch published 5,303 µs on return and counted all 16,384 bytes. The one-to-three-copy serial cases and `flush_one` also passed. This was an AI-assisted accounting test, with no game data or FPS measurement.
Author
Owner

@⁠rocobalt1 on GitHub · 2026-11-24 22:44 UTC · original

Measured on Windows with the same build this PR was measured on (this tree plus the shader PRs; the only difference between the two runs below is this merge).

Setup: RTX 4060 Ti 8 GB, Ryzen 9 5900X, Windows 11; --console series-x, VICTORY_DISPLAY_MODE=1920x1080, VICTORY_SHADER_LOOP_LIMIT=256, VICTORY_NO_WATCHDOG=1, fresh data dir per run, 3 - 4 minutes each, frames with more than 800 draws only. TdrDelay=60, so both columns are upper bounds.

without this PR with this PR
copies, median 94.6 ms 81.5 ms
copies, min 48.9 ms 17.3 ms
copies, max 154.2 ms 96.6 ms
frame, median 1 036 ms 767 ms
shader refusals 4 4
device removal no no

The frame median moved too, but I would not claim it for this PR: the two runs saw different amounts of streaming (10 against 15 world frames), and the copy lane is the only thing measured identically in both. The part that is clean is the tail - the worst copies halve - which is what I would expect from refreshing across threads rather than one after another.

No game data; counts only.

**@⁠rocobalt1** on GitHub · 2026-11-24 22:44 UTC · [original](https://github.com/fxceless/victory-fork/pull/38#issuecomment-7146588314) Measured on Windows with the same build this PR was measured on (this tree plus the shader PRs; the only difference between the two runs below is this merge). **Setup:** RTX 4060 Ti 8 GB, Ryzen 9 5900X, Windows 11; `--console series-x`, `VICTORY_DISPLAY_MODE=1920x1080`, `VICTORY_SHADER_LOOP_LIMIT=256`, `VICTORY_NO_WATCHDOG=1`, fresh data dir per run, 3 - 4 minutes each, frames with more than 800 draws only. `TdrDelay=60`, so both columns are upper bounds. | | without this PR | **with this PR** | |---|---:|---:| | copies, median | 94.6 ms | **81.5 ms** | | copies, min | 48.9 ms | **17.3 ms** | | copies, max | 154.2 ms | **96.6 ms** | | frame, median | 1 036 ms | 767 ms | | shader refusals | 4 | 4 | | device removal | no | no | The frame median moved too, but I would not claim it for this PR: the two runs saw different amounts of streaming (10 against 15 world frames), and the copy lane is the only thing measured identically in both. The part that is clean is the tail - the worst copies halve - which is what I would expect from refreshing across threads rather than one after another. No game data; counts only.
Author
Owner

@⁠iurysf on GitHub · 2026-11-24 23:25 UTC · original

One more data point, on an RTX 4070 12 GB (Ryzen 7 5800X3D, 32 GB, Windows 11), same executable for both runs (4e17478 + #63 + #71 + #147, the watchdog hooks of #28 and a local profiling commit that is off unless asked for), only VICTORY_WIDE_REFRESH differing. VICTORY_RELAY=2, VICTORY_PIPELINE_WAIT_MS=24, VICTORY_CARD_BUFFERS_MIN_MB=1, VICTORY_CARD_BUFFERS_MB=2048, VICTORY_CARD_REHASH_RUNS=1, VICTORY_WIDE_BACK=1, VICTORY_WIDE_MERGE=1, VICTORY_LATE_WAIT_LISTS=256, no DRED, warm shader cache and pipeline library.

Measured over a settled window of the prologue's first scene: 12 statistics lines (about 60 s) starting at the first of three lines with the heap-buffer pass under 100 ms and at least 3,000 draws a frame, so the texture streaming of the first minute in the world is left out.

per frame, median off VICTORY_WIDE_REFRESH=1
frame 220.8 ms 195.1 ms
last 30 s of the window 224.1 ms 191.0 ms
copies 71.8 ms 58.2 ms
copying back 75.4 ms 57.8 ms
on the GPU 59.2 ms 60.8 ms
draws 4,979 4,977

No device removal, and the world's picture is there in both. One run each, the second after the first (its cache one run warmer), so the ranges overlap (198.8–303.0 against 175.7–232.0); I did not run the reverse order. The frame time here comes from the frame line, not from the "copies" counter, so the timer race @⁠ryotdev describes does not touch the first two rows; it may touch the "copies" row.

AI-assisted.

**@⁠iurysf** on GitHub · 2026-11-24 23:25 UTC · [original](https://github.com/fxceless/victory-fork/pull/38#issuecomment-7147392193) One more data point, on an RTX 4070 12 GB (Ryzen 7 5800X3D, 32 GB, Windows 11), same executable for both runs (`4e17478` + #63 + #71 + #147, the watchdog hooks of #28 and a local profiling commit that is off unless asked for), only `VICTORY_WIDE_REFRESH` differing. `VICTORY_RELAY=2`, `VICTORY_PIPELINE_WAIT_MS=24`, `VICTORY_CARD_BUFFERS_MIN_MB=1`, `VICTORY_CARD_BUFFERS_MB=2048`, `VICTORY_CARD_REHASH_RUNS=1`, `VICTORY_WIDE_BACK=1`, `VICTORY_WIDE_MERGE=1`, `VICTORY_LATE_WAIT_LISTS=256`, no DRED, warm shader cache and pipeline library. Measured over a settled window of the prologue's first scene: 12 statistics lines (about 60 s) starting at the first of three lines with the heap-buffer pass under 100 ms and at least 3,000 draws a frame, so the texture streaming of the first minute in the world is left out. | per frame, median | off | `VICTORY_WIDE_REFRESH=1` | |---|---:|---:| | frame | 220.8 ms | **195.1 ms** | | last 30 s of the window | 224.1 ms | 191.0 ms | | copies | 71.8 ms | 58.2 ms | | copying back | 75.4 ms | 57.8 ms | | on the GPU | 59.2 ms | 60.8 ms | | draws | 4,979 | 4,977 | No device removal, and the world's picture is there in both. One run each, the second after the first (its cache one run warmer), so the ranges overlap (198.8–303.0 against 175.7–232.0); I did not run the reverse order. The frame time here comes from the frame line, not from the "copies" counter, so the timer race @⁠ryotdev describes does not touch the first two rows; it may touch the "copies" row. AI-assisted.
Author
Owner

@⁠iurysf on GitHub · 2026-11-24 23:53 UTC · original

A correction to my numbers above. Two runs with identical settings turned out to differ by 20–25 ms here (the driver is still compiling new pipelines in the "settled" window), so one run per setting could not resolve a gain of this size, and the −25.7 ms I reported was mostly that.

Measured again inside one run: once the world settles, VICTORY_WIDE_REFRESH is switched off (A) and on (B) every 4 statistics lines (about 20 s), the first line of each block is dropped, and each B block is compared with the mean of its neighbouring A blocks. Same scene, cache and machine state for both arms. RTX 4070, same recipe as above, plus #154, #255 and #270 in the build.

per frame, median A (off) B (on)
frame 177.6 ms 168.1 ms
copies 46.7 ms 43.9 ms
heap-buffer pass 35.9 ms 14.8 ms
on the GPU 56.0 ms 62.6 ms

Paired B − A: median −7.0 ms over 4 pairs (+0.4, −6.2, −7.8, −13.1); the sign agrees in 3 of 4. Blocks in order: A176 B179 A182 B170 A171 B166 A177 B164.

So on this machine the change helps by roughly 7 ms a frame, not 26. Small, consistent in sign, 4 pairs in one run.

AI-assisted.

**@⁠iurysf** on GitHub · 2026-11-24 23:53 UTC · [original](https://github.com/fxceless/victory-fork/pull/38#issuecomment-7147899596) A correction to my numbers above. Two runs with identical settings turned out to differ by 20–25 ms here (the driver is still compiling new pipelines in the "settled" window), so one run per setting could not resolve a gain of this size, and the −25.7 ms I reported was mostly that. Measured again inside one run: once the world settles, `VICTORY_WIDE_REFRESH` is switched off (A) and on (B) every 4 statistics lines (about 20 s), the first line of each block is dropped, and each B block is compared with the mean of its neighbouring A blocks. Same scene, cache and machine state for both arms. RTX 4070, same recipe as above, plus #154, #255 and #270 in the build. | per frame, median | A (off) | B (on) | |---|---:|---:| | frame | 177.6 ms | 168.1 ms | | copies | 46.7 ms | 43.9 ms | | heap-buffer pass | 35.9 ms | 14.8 ms | | on the GPU | 56.0 ms | 62.6 ms | Paired B − A: median **−7.0 ms** over 4 pairs (+0.4, −6.2, −7.8, −13.1); the sign agrees in 3 of 4. Blocks in order: A176 B179 A182 B170 A171 B166 A177 B164. So on this machine the change helps by roughly 7 ms a frame, not 26. Small, consistent in sign, 4 pairs in one run. AI-assisted.
Author
Owner

@⁠YeokiNoewChi on GitHub · 2026-11-25 00:37 UTC · original

RTX 3070 Ti 8 GB, Ryzen 5 5600X (6 cores, 12 threads), Windows 11, Series X profile, fork main 4e17478 plus several open PRs. VICTORY_WIDE_REFRESH=1 (the switch this PR turns on by default) makes geometry go missing in the prologue: from the barracks doorway the yard's inmates and picnic tables are not drawn and a wall beside the door shows sky. Restarting the same build and warm cache with only that switch removed brings them all back (checked by eye, same camera position). Frame time is about the same either way on this 6-core CPU (Ryzen 5 5600X), so on this machine the parallel refresh costs picture and gains nothing measurable.

AI-assisted (Claude Code).

**@⁠YeokiNoewChi** on GitHub · 2026-11-25 00:37 UTC · [original](https://github.com/fxceless/victory-fork/pull/38#issuecomment-7148705073) RTX 3070 Ti 8 GB, Ryzen 5 5600X (6 cores, 12 threads), Windows 11, Series X profile, fork `main` 4e17478 plus several open PRs. `VICTORY_WIDE_REFRESH=1` (the switch this PR turns on by default) makes geometry go missing in the prologue: from the barracks doorway the yard's inmates and picnic tables are not drawn and a wall beside the door shows sky. Restarting the same build and warm cache with only that switch removed brings them all back (checked by eye, same camera position). Frame time is about the same either way on this 6-core CPU (Ryzen 5 5600X), so on this machine the parallel refresh costs picture and gains nothing measurable. AI-assisted (Claude Code).
Author
Owner

@⁠AimLogin on GitHub · 2026-11-25 04:31 UTC · original

I tested this PR independently using a synthetic buffer-refresh benchmark and also integrated it locally with #220.

Hardware:

  • AMD Ryzen 7 7800X3D
  • NVIDIA RTX 4060 Ti 16 GB
  • 32 GB RAM
  • Windows 11

Synthetic benchmark with 64 buffer copies and approximately 67 MB of data:

  • Baseline: 17.8 ms
  • Parallel refresh: 5.9 ms
  • Approximately 3x faster
  • Output bytes remained identical

The combined build with #220 compiled successfully and passed all 516 tests.

One remaining concern is contention within the memory-management and write-watch paths under concurrent workloads. Our synthetic benchmark does not fully reproduce those conditions.

Nevertheless, the measured reduction in CPU-side refresh time is encouraging. No isolated end-to-end FPS improvement has been established yet.

**@⁠AimLogin** on GitHub · 2026-11-25 04:31 UTC · [original](https://github.com/fxceless/victory-fork/pull/38#issuecomment-7152923431) I tested this PR independently using a synthetic buffer-refresh benchmark and also integrated it locally with #220. Hardware: - AMD Ryzen 7 7800X3D - NVIDIA RTX 4060 Ti 16 GB - 32 GB RAM - Windows 11 Synthetic benchmark with 64 buffer copies and approximately 67 MB of data: - Baseline: 17.8 ms - Parallel refresh: 5.9 ms - Approximately 3x faster - Output bytes remained identical The combined build with #220 compiled successfully and passed all 516 tests. One remaining concern is contention within the memory-management and write-watch paths under concurrent workloads. Our synthetic benchmark does not fully reproduce those conditions. Nevertheless, the measured reduction in CPU-side refresh time is encouraging. No isolated end-to-end FPS improvement has been established yet.
Author
Owner

@⁠gmankab on GitHub · 2026-11-26 13:30 UTC · original

I tested a Linux native port of the worker approach on Fedora 45 and an RX 6800. Five interleaved process runs, each sampling 21 warm flushes of the same eight D3D12 mappings, measured 5.97 → 3.86 ms at 44 MiB and 69.90 → 31.92 µs at 512 KiB. The fixture checked all bytes and the gaps between disjoint refreshes, including across the title-write barrier.

The Linux native switch stays opt-in given the earlier geometry report here. These results measure the copy path. Gameplay and the picture still need a matched comparison. Linux native port and test

**@⁠gmankab** on GitHub · 2026-11-26 13:30 UTC · [original](https://github.com/fxceless/victory-fork/pull/38#issuecomment-7193435089) I tested a Linux native port of the worker approach on Fedora 45 and an RX 6800. Five interleaved process runs, each sampling 21 warm flushes of the same eight D3D12 mappings, measured 5.97 → 3.86 ms at 44 MiB and 69.90 → 31.92 µs at 512 KiB. The fixture checked all bytes and the gaps between disjoint refreshes, including across the title-write barrier. The Linux native switch stays opt-in given the earlier geometry report here. These results measure the copy path. Gameplay and the picture still need a matched comparison. [Linux native port and test](https://github.com/spidercraft/VIctory/pull/30)
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/host.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

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