GPU: a submission's preludes of barriers can be recorded on several threads #2906

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

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


What

At a submission, each list's prelude is decided and recorded on the submitting thread, list after list. The prelude is the barriers that bring the list's textures to the states its first uses need, plus depth-twin copies.

This PR splits that in two:

  • plan_prelude decides the prelude in submission order: the states each list leaves are the ones the next list starts from. A prelude with twin copies is recorded right there, because those copies read the states the lists before it left.
  • record_prelude records a barriers-only prelude: allocator reset, barriers, close. Nothing else.

With VICTORY_PARALLEL_PRELUDES=1 (off by default), a submission of four or more lists, each submitted once, records its barriers-only preludes on several threads (texture::in_parallel) once they hold 2,048 barriers in all (on_threads). Below that, preludes are recorded in order as before, so small submissions take the same path with the switch on or off. Every prelude is recorded before the lists go to the GPU, in their original order.

The diagnostics copies line now counts the state preludes the same way in both settings (it used to leave out the preludes recorded on threads), so the switch can be A/B tested on one build.

Whether it matters: measuring with a title

I can't run the title, so I don't know yet if prelude recording is a noticeable part of the frame. Here's how to find out:

  1. Build the diagnostics build at this PR's head: cargo build --profile diag -p victory --features diagnostics (gives target\diag\victory.exe).
  2. Run the same scene twice with that one build: first without VICTORY_PARALLEL_PRELUDES, then with VICTORY_PARALLEL_PRELUDES=1. Let each run settle for a few report intervals. The report is logged every 5 s.
  3. Compare these two log lines between the runs:
    • The frame line … fps, … ms/frame (… preparing: …): ms/frame and preparing.
    • The copies per frame: line, the part state preludes X ms (N preludes, B barriers, T on threads). All values are per frame. X is the time spent planning and recording preludes. N is the number of preludes recorded. B is the barriers in the barriers-only preludes. T is how many preludes went on threads.

How to read the results:

  • T should be 0 without the switch. If T is also 0 with the switch, no submission reaches the threshold and the switch changes nothing for this scene.
  • If X is a small fraction of preparing without the switch (say well under 1 ms), prelude recording doesn't matter for this title and this PR isn't worth taking.
  • Prelude recording matters if X is a real share of preparing without the switch, and with the switch T > 0, X drops, and ms/frame drops by about as much.

Measurement (recording only, not a frame)

The test's timing loop (VICTORY_PRELUDE_BENCH=1) records eight preludes in order and on threads. Release build, Ryzen 9 7900X, medians. The first rows are from the first version of this PR. The later rows come from a local run with the threshold bypassed, to find where the two cross:

barriers per prelude (8 preludes) in order on threads
40 200 µs 430 µs
400 700 µs 550 µs
40 (second run) 79–88 µs 247–254 µs
128 253–286 µs 309–369 µs
192 393 µs 374 µs
256 368–402 µs 334–352 µs
400 569–938 µs 410–719 µs

They break even at roughly 1,500 barriers in all, so below the 2,048 threshold the preludes stay in order. I haven't measured uneven splits, for example one large prelude next to three tiny ones.

Where it came from

From DexNom's fork, DexNom/VIctory@5f4c3df (PlannedPrelude, record_preludes, parallel_preludes; opt-in there too, and their ordering-test idea). It's built on this tree's preludes and twins. Twin copies stay in order because this tree's Twin::copy takes its transitions while recording. Credited with Co-authored-by: DexNom.

Tested

  • host::tests::preludes_planned_in_order_record_on_several_threads: eight lists each move 400 textures through states of their own. Each planned prelude, replayed in the GPU's order (prelude, then list) by the debug layer's rule (replay), starts from the states the list before left, and the final states match the tracked ones. Recorded on threads (3,200 barriers), each prelude lands where its list's prelude goes.
  • host::tests::small_submissions_record_their_preludes_in_order: eight preludes of 40 barriers stay in order, eight of 400 go on threads, and so do the cases at and around the threshold.
  • cargo test -p victory-gpu --lib host::, by default, with VICTORY_PARALLEL_PRELUDES=1, and with --features diagnostics: everything passes except the known NVIDIA failure dynamic_slots_are_held_until_released. Two other descriptor tests failed once each across repeated runs and passed on rerun: views_bound_while_another_slot_gets_its_texture_do_not_wait and a_slot_rewritten_while_its_view_is_prepared_views_the_new_record. With --features diagnostics, host::present_plane_tests::compositor_failure_presents_primary_in_the_same_frame crashes the test process on the head before this change too, so it was skipped.
  • cargo clippy -p victory-gpu --all-targets, with and without --features diagnostics: clean. cargo xtask policy: ok.

Not tested

  • Not run with the title, so there's no frame-time number. That's what the steps above are for.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6616022827 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2908). Originally posted by [0xkn0wh3r3](https://github.com/0xkn0wh3r3) on 2026-11-25T23:38:15Z. --- ## What At a submission, each list's prelude is decided and recorded on the submitting thread, list after list. The prelude is the barriers that bring the list's textures to the states its first uses need, plus depth-twin copies. This PR splits that in two: - **`plan_prelude`** decides the prelude in submission order: the states each list leaves are the ones the next list starts from. A prelude with twin copies is recorded right there, because those copies read the states the lists before it left. - **`record_prelude`** records a barriers-only prelude: allocator reset, barriers, close. Nothing else. With `VICTORY_PARALLEL_PRELUDES=1` (off by default), a submission of four or more lists, each submitted once, records its barriers-only preludes on several threads (`texture::in_parallel`) once they hold 2,048 barriers in all (`on_threads`). Below that, preludes are recorded in order as before, so small submissions take the same path with the switch on or off. Every prelude is recorded before the lists go to the GPU, in their original order. The diagnostics copies line now counts the state preludes the same way in both settings (it used to leave out the preludes recorded on threads), so the switch can be A/B tested on one build. ## Whether it matters: measuring with a title I can't run the title, so I don't know yet if prelude recording is a noticeable part of the frame. Here's how to find out: 1. Build the diagnostics build at this PR's head: `cargo build --profile diag -p victory --features diagnostics` (gives `target\diag\victory.exe`). 2. Run the same scene twice with that one build: first without `VICTORY_PARALLEL_PRELUDES`, then with `VICTORY_PARALLEL_PRELUDES=1`. Let each run settle for a few report intervals. The report is logged every 5 s. 3. Compare these two log lines between the runs: - The frame line `… fps, … ms/frame (… preparing: …)`: `ms/frame` and `preparing`. - The `copies per frame:` line, the part `state preludes X ms (N preludes, B barriers, T on threads)`. All values are per frame. `X` is the time spent planning and recording preludes. `N` is the number of preludes recorded. `B` is the barriers in the barriers-only preludes. `T` is how many preludes went on threads. How to read the results: - `T` should be 0 without the switch. If `T` is also 0 with the switch, no submission reaches the threshold and the switch changes nothing for this scene. - If `X` is a small fraction of `preparing` without the switch (say well under 1 ms), prelude recording doesn't matter for this title and this PR isn't worth taking. - Prelude recording matters if `X` is a real share of `preparing` without the switch, and with the switch `T > 0`, `X` drops, and `ms/frame` drops by about as much. ## Measurement (recording only, not a frame) The test's timing loop (`VICTORY_PRELUDE_BENCH=1`) records eight preludes in order and on threads. Release build, Ryzen 9 7900X, medians. The first rows are from the first version of this PR. The later rows come from a local run with the threshold bypassed, to find where the two cross: | barriers per prelude (8 preludes) | in order | on threads | |---:|---:|---:| | 40 | 200 µs | 430 µs | | 400 | 700 µs | 550 µs | | 40 (second run) | 79–88 µs | 247–254 µs | | 128 | 253–286 µs | 309–369 µs | | 192 | 393 µs | 374 µs | | 256 | 368–402 µs | 334–352 µs | | 400 | 569–938 µs | 410–719 µs | They break even at roughly 1,500 barriers in all, so below the 2,048 threshold the preludes stay in order. I haven't measured uneven splits, for example one large prelude next to three tiny ones. ## Where it came from From DexNom's fork, [DexNom/VIctory@5f4c3df](https://github.com/DexNom/VIctory/commit/5f4c3df44197eb03b82205d2da871ded8d0ccf16) (`PlannedPrelude`, `record_preludes`, `parallel_preludes`; opt-in there too, and their ordering-test idea). It's built on this tree's preludes and twins. Twin copies stay in order because this tree's `Twin::copy` takes its transitions while recording. Credited with `Co-authored-by: DexNom`. ## Tested - `host::tests::preludes_planned_in_order_record_on_several_threads`: eight lists each move 400 textures through states of their own. Each planned prelude, replayed in the GPU's order (prelude, then list) by the debug layer's rule (`replay`), starts from the states the list before left, and the final states match the tracked ones. Recorded on threads (3,200 barriers), each prelude lands where its list's prelude goes. - `host::tests::small_submissions_record_their_preludes_in_order`: eight preludes of 40 barriers stay in order, eight of 400 go on threads, and so do the cases at and around the threshold. - `cargo test -p victory-gpu --lib host::`, by default, with `VICTORY_PARALLEL_PRELUDES=1`, and with `--features diagnostics`: everything passes except the known NVIDIA failure `dynamic_slots_are_held_until_released`. Two other descriptor tests failed once each across repeated runs and passed on rerun: `views_bound_while_another_slot_gets_its_texture_do_not_wait` and `a_slot_rewritten_while_its_view_is_prepared_views_the_new_record`. With `--features diagnostics`, `host::present_plane_tests::compositor_failure_presents_primary_in_the_same_frame` crashes the test process on the head before this change too, so it was skipped. - `cargo clippy -p victory-gpu --all-targets`, with and without `--features diagnostics`: clean. `cargo xtask policy`: ok. ## Not tested - Not run with the title, so there's no frame-time number. That's what the steps above are for.
kotekompotek commented 2026-11-26 00:03:12 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Scoped review: the ordering-sensitive half stays serial — preludes are planned in submission order, so each list's prelude begins from the states its predecessor leaves; only the recording of barrier commands into separate lists' own prelude lists is parallel, which can't interleave since each writes disjoint memory. The 8-list/400-texture test verifies each barrier lands in its own prelude. Sound split. LGTM.

<!-- greyfinch-sync:Marvisak/VIctory:review:6066644753 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2908#pullrequestreview-6066644753). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-25T23:52:55Z. **Review:** COMMENTED --- Scoped review: the ordering-sensitive half stays serial — preludes are *planned* in submission order, so each list's prelude begins from the states its predecessor leaves; only the recording of barrier commands into separate lists' own prelude lists is parallel, which can't interleave since each writes disjoint memory. The 8-list/400-texture test verifies each barrier lands in its own prelude. Sound split. LGTM.
fuzeofficlal commented 2026-11-26 00:03:12 +00:00 (Migrated from github.com)

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

Review: COMMENTED


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

Concurrency & State-Machine Audit

  • D3D12 allocator/list isolation: Each HostList owns a dedicated prelude: (ID3D12CommandAllocator, ID3D12GraphicsCommandList), and parallel_preludes gates on runs.len() >= 4 plus distinct *const HostList pointers via HashSet while Host::execute holds self.submitted — so no two workers ever share an allocator or command list.
  • Barrier & state ordering: plan_prelude runs serially in submission order, recording twin-copy preludes immediately and advancing copy.state to *last before the next list plans its Before state, while record_preludes(&later) writes into indexed slots so ExecuteCommandLists preserves exact [P0, L0, P1, L1, ...] order. Using crate::texture::in_parallel (std::thread::scope) also avoids any Condvar deadlock if a worker panics.
  • Minor diagnostics nit (non-blocking): Under --features diagnostics, Timed(..., C::PreludeUs) sits inside the for list in runs loop, so when parallel is active it omits the time spent in record_preludes(&later) after the loop.

Local Verification & Benchmark

  • VICTORY_PARALLEL_PRELUDES=1 + VICTORY_D3D12_DEBUG=1 (--features diagnostics):
    • RTX 5090: host::tests / draw::tests / twin::tests / resource::tests (skipping pre-existing 1M cap baseline dynamic_slots_are_held_until_released) 71/71 passed, zero debug-layer errors.
    • WARP: 72/72 passed, zero debug-layer errors.
  • --release microbenchmark (VICTORY_PRELUDE_BENCH=1, 8 lists x 400 textures = 3,200 barriers, 40 alternating rounds):
    • in order: median 301 us vs threads: median 258 us (1.17x / -14.3%).
  • cargo clippy --locked -p victory-gpu --all-targets -- -D warnings (default and --features diagnostics) & cargo xtask policy (191 files ok): clean.
<!-- greyfinch-sync:Marvisak/VIctory:review:6066644966 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2908#pullrequestreview-6066644966). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T23:52:57Z. **Review:** COMMENTED --- Verified head `fe918527` cleanly on `origin/main` (`63bcca43`) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + D3D12 WARP + `VICTORY_D3D12_DEBUG=1` + `VICTORY_PARALLEL_PRELUDES=1`). ### Concurrency & State-Machine Audit - **D3D12 allocator/list isolation**: Each `HostList` owns a dedicated `prelude: (ID3D12CommandAllocator, ID3D12GraphicsCommandList)`, and `parallel_preludes` gates on `runs.len() >= 4` plus distinct `*const HostList` pointers via `HashSet` while `Host::execute` holds `self.submitted` — so no two workers ever share an allocator or command list. - **Barrier & state ordering**: `plan_prelude` runs serially in submission order, recording twin-copy preludes immediately and advancing `copy.state` to `*last` before the next list plans its `Before` state, while `record_preludes(&later)` writes into indexed slots so `ExecuteCommandLists` preserves exact `[P0, L0, P1, L1, ...]` order. Using `crate::texture::in_parallel` (`std::thread::scope`) also avoids any `Condvar` deadlock if a worker panics. - **Minor diagnostics nit (non-blocking)**: Under `--features diagnostics`, `Timed(..., C::PreludeUs)` sits inside the `for list in runs` loop, so when `parallel` is active it omits the time spent in `record_preludes(&later)` after the loop. ### Local Verification & Benchmark - **`VICTORY_PARALLEL_PRELUDES=1` + `VICTORY_D3D12_DEBUG=1` (`--features diagnostics`)**: - **RTX 5090**: `host::tests` / `draw::tests` / `twin::tests` / `resource::tests` (skipping pre-existing 1M cap baseline `dynamic_slots_are_held_until_released`) **71/71 passed**, zero debug-layer errors. - **WARP**: **72/72 passed**, zero debug-layer errors. - **`--release` microbenchmark (`VICTORY_PRELUDE_BENCH=1`, 8 lists x 400 textures = 3,200 barriers, 40 alternating rounds)**: - `in order`: median **301 us** vs `threads`: median **258 us** (**1.17x / -14.3%**). - `cargo clippy --locked -p victory-gpu --all-targets -- -D warnings` (default and `--features diagnostics`) & `cargo xtask policy` (`191 files ok`): clean.
Marvisak commented 2026-11-26 03:05:07 +00:00 (Migrated from github.com)

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


Automated triage for the maintainers.

Needs work. This splits HostList::prelude into plan_prelude/record_prelude in host.rs, so that barrier-only preludes can be recorded on several threads with VICTORY_PARALLEL_PRELUDES=1 (off by default). The planning still runs in submission order, and the test replays the states correctly. CI check passes. The problem is the benefit: by the PR's own numbers in PARALLEL_PRELUDE_BARRIERS, eight preludes of 400 barriers go from 700 µs to 550 µs, and small ones get slower (200 µs vs 430 µs). That is a small, opt-in gain for a restructured submission path. What would change the verdict: a frame-time measurement from the title showing that prelude recording matters (for example the frame report's prelude time with and without the switch).


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7180699757 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2908#issuecomment-7180699757). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T02:19:55Z. --- <!-- victory-triage v1 head=fe918527f0f23b1b73b2b419a05f8eab4bb56d58 verdict=needs-work at=2026-11-26T02:19:48Z --> Automated triage for the maintainers. **Needs work.** This splits `HostList::prelude` into `plan_prelude`/`record_prelude` in `host.rs`, so that barrier-only preludes can be recorded on several threads with `VICTORY_PARALLEL_PRELUDES=1` (off by default). The planning still runs in submission order, and the test replays the states correctly. CI `check` passes. The problem is the benefit: by the PR's own numbers in `PARALLEL_PRELUDE_BARRIERS`, eight preludes of 400 barriers go from 700 µs to 550 µs, and small ones get slower (200 µs vs 430 µs). That is a small, opt-in gain for a restructured submission path. What would change the verdict: a frame-time measurement from the title showing that prelude recording matters (for example the frame report's prelude time with and without the switch). --- _Generated by [Claude Code](https://claude.ai/code)_
0xkn0wh3r3 commented 2026-11-26 08:03:19 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by 0xkn0wh3r3 on 2026-11-26T07:23:07Z.


Thanks. Agreed: without numbers from the title, the gain is unproven. The recording microbenchmark doesn't show that preludes matter in a frame. I can't run the title, so fe19554f makes the A/B possible on one build instead.

The frame report and preludes. The diagnostics copies per frame: line already had state preludes X ms. With the switch on, though, it left out the preludes recorded on threads after the loop (host.rs, Host::execute), so on and off couldn't be compared. Now that recording is timed too. The field reads state preludes X ms (N preludes, B barriers, T on threads), per frame, and is counted the same way in both settings.

Measuring. Build with cargo build --profile diag -p victory --features diagnostics. Run the same scene without VICTORY_PARALLEL_PRELUDES, then with VICTORY_PARALLEL_PRELUDES=1, and compare state preludes X ms and T on threads with preparing and ms/frame on the frame line. Prelude recording matters only if X is a real share of preparing without the switch, and with it T > 0, X drops, and ms/frame drops by about the same. If X is a fraction of a millisecond, or T stays 0, this PR isn't worth taking. These steps are in the PR description.

Small preludes getting slower. The 40-barrier row (200 µs vs 430 µs) was measured with the threshold bypassed. In the PR, eight preludes of 40 barriers (320 in all) stay below PARALLEL_PRELUDE_BARRIERS (2,048) and are recorded in order, the same as with the switch off. The decision is now on_threads, and small_submissions_record_their_preludes_in_order covers it: 8×40 stays in order, 8×400 goes on threads, and so do the cases around the threshold. Rerunning the timing loop on the same CPU at more sizes, they break even at roughly 1,500 barriers (8×192: 393 µs in order, 374 µs on threads), so the threshold sits just above that. I haven't measured uneven splits, such as one large prelude next to three tiny ones. I also took the measurements out of the constant's doc comment; they're in the PR description now.

If anyone can run a title with the diagnostics build, the two copies per frame: lines (switch off and on) plus the frame lines would settle this either way.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7185397845 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2908#issuecomment-7185397845). Originally posted by [0xkn0wh3r3](https://github.com/0xkn0wh3r3) on 2026-11-26T07:23:07Z. --- Thanks. Agreed: without numbers from the title, the gain is unproven. The recording microbenchmark doesn't show that preludes matter in a frame. I can't run the title, so fe19554f makes the A/B possible on one build instead. **The frame report and preludes.** The diagnostics `copies per frame:` line already had `state preludes X ms`. With the switch on, though, it left out the preludes recorded on threads after the loop (`host.rs`, `Host::execute`), so on and off couldn't be compared. Now that recording is timed too. The field reads `state preludes X ms (N preludes, B barriers, T on threads)`, per frame, and is counted the same way in both settings. **Measuring.** Build with `cargo build --profile diag -p victory --features diagnostics`. Run the same scene without `VICTORY_PARALLEL_PRELUDES`, then with `VICTORY_PARALLEL_PRELUDES=1`, and compare `state preludes X ms` and `T on threads` with `preparing` and `ms/frame` on the frame line. Prelude recording matters only if `X` is a real share of `preparing` without the switch, and with it `T > 0`, `X` drops, and `ms/frame` drops by about the same. If `X` is a fraction of a millisecond, or `T` stays 0, this PR isn't worth taking. These steps are in the PR description. **Small preludes getting slower.** The 40-barrier row (200 µs vs 430 µs) was measured with the threshold bypassed. In the PR, eight preludes of 40 barriers (320 in all) stay below `PARALLEL_PRELUDE_BARRIERS` (2,048) and are recorded in order, the same as with the switch off. The decision is now `on_threads`, and `small_submissions_record_their_preludes_in_order` covers it: 8×40 stays in order, 8×400 goes on threads, and so do the cases around the threshold. Rerunning the timing loop on the same CPU at more sizes, they break even at roughly 1,500 barriers (8×192: 393 µs in order, 374 µs on threads), so the threshold sits just above that. I haven't measured uneven splits, such as one large prelude next to three tiny ones. I also took the measurements out of the constant's doc comment; they're in the PR description now. If anyone can run a title with the diagnostics build, the two `copies per frame:` lines (switch off and on) plus the frame lines would settle this either way.
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/2908:upstream-pr/2908'
git switch 'upstream-pr/2908'

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