GPU: a list's upload fills can be shared among threads (VICTORY_FILL_WORKERS) #2898
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2900"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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(default1, 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: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: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_fillsand 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 withCo-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 withVICTORY_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
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 testa_panicking_share_counts_as_done.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.
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T23:43:22Z.
Review: COMMENTED
Verified head
670b1a54cleanly onorigin/main(63bcca43) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + D3D12 WARP +VICTORY_D3D12_DEBUG=1).Concurrency & Safety Review
independent_fillsguarantees strictly monotonic, non-overlapping destination ranges in the upload buffer and ensures nosrc..src+lenoverlaps[first.dst, end), so parallelcopy_mapped(..., false)workers (which only read title memory viaReadProcessMemoryand never touchwatch::writing) are free of data races, andrun_fillscompletes before any non-Fillstep runs.run_fills,*n -= 1anddone.notify_all()run afterchunk.into_iter().for_each(Fill::run)without aDropguard. WhileFill::runshouldn't panic in normal operation, wrapping the decrement + notify in a small RAIIDropguard guarantees the submitting thread cannot deadlock forever onCondvar::waitif a worker ever panics.Local Verification & Benchmark
VICTORY_FILL_WORKERS=4+VICTORY_D3D12_DEBUG=1+--features diagnostics:fill_tests3/3 (1 ignored),draw::tests20/20,resource::tests18/18,host::tests30/31 (only the pre-existingdynamic_slots_are_held_until_released1M view cap baseline).fill_tests3/3,draw::tests20/20,host::tests31/31.--releasebenchmark (cargo test --release -p victory-gpu fill_runs_bench -- --ignored --nocapture, quiet host):1 thread(s): median 12.17 ms, best 10.99 ms4 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.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.rsHostList::run_deferred, a run of consecutiveStep::Fills can be shared among a small thread pool whenVICTORY_FILL_WORKERSis 2–6. The default of 1 keeps today's serial path. I checked that a run stops at the first non-fill step, thatindependent_fillsfalls 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. CIcheckpasses. 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
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).
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.