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

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

@⁠0xkn0wh3r3 on GitHub · 2026-11-25 23:29 UTC · original
0xkn0wh3r3:gpu/upload-fills-in-parallel → main · +294 −2 · 1 files · 2 commits · open

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.
**@⁠0xkn0wh3r3** on GitHub · 2026-11-25 23:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/2900) `0xkn0wh3r3:gpu/upload-fills-in-parallel` → `main` · +294 −2 · 1 files · 2 commits · open ## 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`.
At submission a list copies the title memory its draws read from upload
memory (root constant buffers off 256 bytes, expanded data) one fill at
a time on the submitting thread.

With VICTORY_FILL_WORKERS=2..6 (1, as before, by default) a run of
consecutive fills (up to the next step, which may write title memory)
is shared among that many threads, at least 128 fills each, when the
fills are independent: destinations that rise without overlapping (the
upload memory a list hands out in turn) and no source reaching into
them. Others run in order. The submitting thread takes a share and
waits for the rest before the next step. The threads are a small pool
started on first use: threads spawned for each run cost more than the
copies.

28,279 fills of 448 bytes in runs of 512 (DexNom's measurement), release
build, Windows 11, Ryzen 9 7900X: one thread median 8.6-9.1 ms, four with
the pool 5.9-7.4 ms (four spawned per run: 17 ms).

Tests: parallel_fills_copy_what_serial_ones_do,
dependent_fills_run_in_order, a_title_copy_ends_a_run_of_fills;
fill_runs_bench (ignored). The whole victory-gpu suite also passes with
VICTORY_FILL_WORKERS=4.

From DexNom/VIctory@5f4c3df441 (Fill,
independent_fills, run_fills and their tests), with the runs found at
submission instead of grouped when recorded, and a pool of this crate's
own.

Co-authored-by: DexNom <[email protected]>
Review: the submitting thread waits until every share of a fill run is
done, counted after the share's copies, so a share that panicked would
have left it waiting for good, and the pool thread it ran on was gone.

A share is now counted done by a guard that drops after it, or while a
panic in it unwinds; the pool threads catch a share's panic and take the
next; a share the pool cannot be sent (no thread left) is done on the
submitting thread.

Test: a_panicking_share_counts_as_done.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:17:03 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 02:16 UTC · original

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

**@⁠Marvisak** on GitHub · 2026-11-26 02:16 UTC · [original](https://github.com/Marvisak/VIctory/pull/2900#issuecomment-7180634052) <!-- 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)_
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/2900/head:github-bot/gh-2900'
git switch 'github-bot/gh-2900'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2900'
git switch 'github-bot/gh-2900'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2900'
git switch 'github-bot/gh-2900'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2900'
git switch 'main'
git merge --squash 'github-bot/gh-2900'
git switch 'main'
git merge --ff-only 'github-bot/gh-2900'
git switch 'main'
git merge 'github-bot/gh-2900'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2900
No description provided.