GPU: a list's upload fills can be shared among threads (VICTORY_FILL_WORKERS) #2898

Open
0xkn0wh3r3 wants to merge 2 commits from upstream-pr/2900 into main
0xkn0wh3r3 commented 2026-11-25 23:29:16 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by 0xkn0wh3r3 on 2026-11-25T23:29:16Z.


What

At submission, each list copies the title memory its draws read into upload memory (defer_fill: root constant buffers not on 256 bytes, expanded data). It does this one fill at a time on the submitting thread.

With VICTORY_FILL_WORKERS=2…6 (default 1, unchanged), a run of consecutive fills, up to the next step that may write title memory, is shared among that many threads, at least 128 fills each. That happens only when the fills are independent:

  • their destinations rise without overlapping (the upload memory a list hands out in turn);
  • no source reaches into those destinations.

Anything else runs in order. The submitting thread takes one share and waits for the rest before the next step. The helper threads are a small pool started on first use, because spawning threads for each run costs more than the copies.

Measurement

28,279 fills of 448 bytes in runs of 512, the workload DexNom measured. Release build, Windows 11, Ryzen 9 7900X, fill_runs_bench, medians of 10 rounds each:

one thread four threads
pool (this PR) 8.6–9.1 ms 5.9–7.4 ms
threads spawned per run (tried first) ~10 ms ~17 ms

That's a CPU microbenchmark. I haven't measured how many fills a frame of the title makes on this tree, which is why it stays opt-in.

Where it came from

From DexNom's fork, DexNom/VIctory@5f4c3df (Fill, independent_fills, run_fills and their tests; opt-in there too). Here the runs are found at submission instead of being grouped when recorded, and the crate uses its own small pool. Credited with Co-authored-by: DexNom.

Tested

  • host::fill_tests::parallel_fills_copy_what_serial_ones_do: 512 fills of 448 bytes on four threads copy the same bytes as one thread does, from the source as it is when they run.
  • host::fill_tests::dependent_fills_run_in_order: overlapping destinations, and a source that reads another fill's destination, both run in order.
  • host::fill_tests::a_title_copy_ends_a_run_of_fills.
  • cargo test -p victory-gpu: 232 passed both by default and with VICTORY_FILL_WORKERS=4. The 2 known NVIDIA failures are fixed by #2121.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings, with and without --features diagnostics: clean.

Not tested

  • Not run with the title, so there's no frame-time number.

Changes after review

  • 85befef: a share is counted done by a guard that drops after it, including while a panic in it unwinds. Pool threads catch a share's panic and take the next. A share that can't be sent to the pool (no thread left) runs on the submitting thread. New test a_panicking_share_counts_as_done.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6615905092 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2900). Originally posted by [0xkn0wh3r3](https://github.com/0xkn0wh3r3) on 2026-11-25T23:29:16Z. --- ## What At submission, each list copies the title memory its draws read into upload memory (`defer_fill`: root constant buffers not on 256 bytes, expanded data). It does this one fill at a time on the submitting thread. With `VICTORY_FILL_WORKERS=2`…`6` (default `1`, unchanged), a run of consecutive fills, up to the next step that may write title memory, is shared among that many threads, at least 128 fills each. That happens only when the fills are independent: - their destinations rise without overlapping (the upload memory a list hands out in turn); - no source reaches into those destinations. Anything else runs in order. The submitting thread takes one share and waits for the rest before the next step. The helper threads are a small pool started on first use, because spawning threads for each run costs more than the copies. ## Measurement 28,279 fills of 448 bytes in runs of 512, the workload DexNom measured. Release build, Windows 11, Ryzen 9 7900X, `fill_runs_bench`, medians of 10 rounds each: | | one thread | four threads | |---|---:|---:| | pool (this PR) | 8.6–9.1 ms | 5.9–7.4 ms | | threads spawned per run (tried first) | ~10 ms | ~17 ms | That's a CPU microbenchmark. I haven't measured how many fills a frame of the title makes on this tree, which is why it stays opt-in. ## Where it came from From DexNom's fork, [DexNom/VIctory@5f4c3df](https://github.com/DexNom/VIctory/commit/5f4c3df44197eb03b82205d2da871ded8d0ccf16) (`Fill`, `independent_fills`, `run_fills` and their tests; opt-in there too). Here the runs are found at submission instead of being grouped when recorded, and the crate uses its own small pool. Credited with `Co-authored-by: DexNom`. ## Tested - `host::fill_tests::parallel_fills_copy_what_serial_ones_do`: 512 fills of 448 bytes on four threads copy the same bytes as one thread does, from the source as it is when they run. - `host::fill_tests::dependent_fills_run_in_order`: overlapping destinations, and a source that reads another fill's destination, both run in order. - `host::fill_tests::a_title_copy_ends_a_run_of_fills`. - `cargo test -p victory-gpu`: 232 passed both by default and with `VICTORY_FILL_WORKERS=4`. The 2 known NVIDIA failures are fixed by #2121. - `cargo clippy -p victory-gpu --all-targets -- -D warnings`, with and without `--features diagnostics`: clean. ## Not tested - Not run with the title, so there's no frame-time number. ## Changes after review - 85befef: a share is counted done by a guard that drops after it, including while a panic in it unwinds. Pool threads catch a share's panic and take the next. A share that can't be sent to the pool (no thread left) runs on the submitting thread. New test `a_panicking_share_counts_as_done`.
kotekompotek commented 2026-11-26 00:03:08 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T23:37:06Z.

Review: COMMENTED


Sound: consecutive Fill steps are independent by construction (each writes its own upload range), so splitting a run across workers is safe as long as run_fills joins before the next step — the get/while loop structure keeps non-Fill steps sequential. Plays fine with the deferred-copy ordering (late steps run after this loop). LGTM.

<!-- greyfinch-sync:Marvisak/VIctory:review:6066497632 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2900#pullrequestreview-6066497632). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-25T23:37:06Z. **Review:** COMMENTED --- Sound: consecutive Fill steps are independent by construction (each writes its own upload range), so splitting a run across workers is safe as long as run_fills joins before the next step — the get/while loop structure keeps non-Fill steps sequential. Plays fine with the deferred-copy ordering (late steps run after this loop). LGTM.
fuzeofficlal commented 2026-11-26 00:03:08 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T23:43:22Z.

Review: COMMENTED


Verified head 670b1a54 cleanly on origin/main (63bcca43) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + D3D12 WARP + VICTORY_D3D12_DEBUG=1).

Concurrency & Safety Review

  • independent_fills guarantees strictly monotonic, non-overlapping destination ranges in the upload buffer and ensures no src..src+len overlaps [first.dst, end), so parallel copy_mapped(..., false) workers (which only read title memory via ReadProcessMemory and never touch watch::writing) are free of data races, and run_fills completes before any non-Fill step runs.
  • Robustness suggestion: In run_fills, *n -= 1 and done.notify_all() run after chunk.into_iter().for_each(Fill::run) without a Drop guard. While Fill::run shouldn't panic in normal operation, wrapping the decrement + notify in a small RAII Drop guard guarantees the submitting thread cannot deadlock forever on Condvar::wait if a worker ever panics.

Local Verification & Benchmark

  • VICTORY_FILL_WORKERS=4 + VICTORY_D3D12_DEBUG=1 + --features diagnostics:
    • RTX 5090: fill_tests 3/3 (1 ignored), draw::tests 20/20, resource::tests 18/18, host::tests 30/31 (only the pre-existing dynamic_slots_are_held_until_released 1M view cap baseline).
    • WARP: fill_tests 3/3, draw::tests 20/20, host::tests 31/31.
  • --release benchmark (cargo test --release -p victory-gpu fill_runs_bench -- --ignored --nocapture, quiet host):
    • 1 thread(s): median 12.17 ms, best 10.99 ms
    • 4 thread(s): median 10.50 ms, best 6.09 ms (1.80x best speedup, -13.7% median)
  • cargo clippy --locked -p victory-gpu --tests -- -D warnings (default and --features diagnostics) & cargo xtask policy (191 files ok): clean.
<!-- greyfinch-sync:Marvisak/VIctory:review:6066557774 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2900#pullrequestreview-6066557774). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T23:43:22Z. **Review:** COMMENTED --- Verified head `670b1a54` cleanly on `origin/main` (`63bcca43`) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + D3D12 WARP + `VICTORY_D3D12_DEBUG=1`). ### Concurrency & Safety Review - `independent_fills` guarantees strictly monotonic, non-overlapping destination ranges in the upload buffer and ensures no `src..src+len` overlaps `[first.dst, end)`, so parallel `copy_mapped(..., false)` workers (which only read title memory via `ReadProcessMemory` and never touch `watch::writing`) are free of data races, and `run_fills` completes before any non-`Fill` step runs. - **Robustness suggestion**: In `run_fills`, `*n -= 1` and `done.notify_all()` run after `chunk.into_iter().for_each(Fill::run)` without a `Drop` guard. While `Fill::run` shouldn't panic in normal operation, wrapping the decrement + notify in a small RAII `Drop` guard guarantees the submitting thread cannot deadlock forever on `Condvar::wait` if a worker ever panics. ### Local Verification & Benchmark - **`VICTORY_FILL_WORKERS=4` + `VICTORY_D3D12_DEBUG=1` + `--features diagnostics`**: - **RTX 5090**: `fill_tests` **3/3** (1 ignored), `draw::tests` **20/20**, `resource::tests` **18/18**, `host::tests` **30/31** (only the pre-existing `dynamic_slots_are_held_until_released` 1M view cap baseline). - **WARP**: `fill_tests` **3/3**, `draw::tests` **20/20**, `host::tests` **31/31**. - **`--release` benchmark** (`cargo test --release -p victory-gpu fill_runs_bench -- --ignored --nocapture`, quiet host): - `1 thread(s)`: median **12.17 ms**, best **10.99 ms** - `4 thread(s)`: median **10.50 ms**, best **6.09 ms** (**1.80x** best speedup, **-13.7%** median) - `cargo clippy --locked -p victory-gpu --tests -- -D warnings` (default and `--features diagnostics`) & `cargo xtask policy` (`191 files ok`): clean.
Marvisak commented 2026-11-26 03:05:04 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T02:16:22Z.


Automated triage for the maintainers.

Merge candidate (a recommendation to look, not an approval). In host.rs HostList::run_deferred, a run of consecutive Step::Fills can be shared among a small thread pool when VICTORY_FILL_WORKERS is 2–6. The default of 1 keeps today's serial path. I checked that a run stops at the first non-fill step, that independent_fills falls back to in-order copies for overlapping or aliased fills, and that the submitting thread waits for every share, panics included (ShareDone), before the next step. CI check passes. The only evidence is a microbenchmark (about 9 ms down to 6–7 ms) with no frame measurement from the title, which is why it stays opt-in.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7180634052 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2900#issuecomment-7180634052). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T02:16:22Z. --- <!-- victory-triage v1 head=85befefb6ddb2166bb1348ca23681edaec7ddfde verdict=merge-candidate at=2026-11-26T02:16:00Z --> Automated triage for the maintainers. **Merge candidate** (a recommendation to look, not an approval). In `host.rs` `HostList::run_deferred`, a run of consecutive `Step::Fill`s can be shared among a small thread pool when `VICTORY_FILL_WORKERS` is 2–6. The default of 1 keeps today's serial path. I checked that a run stops at the first non-fill step, that `independent_fills` falls back to in-order copies for overlapping or aliased fills, and that the submitting thread waits for every share, panics included (`ShareDone`), before the next step. CI `check` passes. The only evidence is a microbenchmark (about 9 ms down to 6–7 ms) with no frame measurement from the title, which is why it stays opt-in. --- _Generated by [Claude Code](https://claude.ai/code)_
Dukestar69 commented 2026-11-26 04:05:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T03:50:08Z.

Review: APPROVED


Tested merged onto origin/main (63bcca4) on Windows 11 x64:

  • cargo test -p victory-gpu --lib host::fill_tests: 4 passed, 0 failed, 1 ignored (a_title_copy_ends_a_run_of_fills, a_panicking_share_counts_as_done, dependent_fills_run_in_order, parallel_fills_copy_what_serial_ones_do).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6068301360 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2900#pullrequestreview-6068301360). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T03:50:08Z. **Review:** APPROVED --- Tested merged onto `origin/main` (`63bcca4`) on Windows 11 x64: - `cargo test -p victory-gpu --lib host::fill_tests`: **4 passed, 0 failed, 1 ignored** (`a_title_copy_ends_a_run_of_fills`, `a_panicking_share_counts_as_done`, `dependent_fills_run_in_order`, `parallel_fills_copy_what_serial_ones_do`). - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
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/2900:upstream-pr/2900'
git switch 'upstream-pr/2900'

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