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

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

@⁠0xkn0wh3r3 on GitHub · 2026-11-25 23:38 UTC · original
0xkn0wh3r3:gpu/submission-preludes-recorded-in-parallel → main · +294 −6 · 2 files · 2 commits · open

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.
**@⁠0xkn0wh3r3** on GitHub · 2026-11-25 23:38 UTC · [original](https://github.com/Marvisak/VIctory/pull/2908) `0xkn0wh3r3:gpu/submission-preludes-recorded-in-parallel` → `main` · +294 −6 · 2 files · 2 commits · open ## 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.
At a submission each list's prelude (the barriers that bring its
textures to the states its first uses need, and depth twin copies) was
decided and recorded on the submitting thread, list after list.

The prelude is now planned in submission order (plan_prelude: the states
each leaves are those the next starts from) and, for a prelude of
barriers only, recorded apart (record_prelude). With
VICTORY_PARALLEL_PRELUDES=1 (off by default) and four lists or more,
each submitted once, the preludes of barriers are recorded on several
threads when they hold 2,048 barriers in all; fewer, and preludes with
twin copies (which read the states lists before them leave), are
recorded in order as before. Every prelude is recorded before the lists
go to the GPU, in their order.

Eight preludes, release build, Ryzen 9 7900X: of 40 barriers each,
200 us in order and 430 us on threads; of 400, 700 us and 550 us (hence
the threshold).

Test: preludes_planned_in_order_record_on_several_threads (eight lists
moving 400 textures: each planned prelude starts from the states the
list before leaves, replayed in the GPU's order by the debug layer's
rule; recorded on threads, each where its list's prelude goes). The
whole victory-gpu suite also passes with VICTORY_PARALLEL_PRELUDES=1.

From DexNom/VIctory@5f4c3df441
(PlannedPrelude, record_preludes, parallel_preludes), on this tree's
preludes and twins.

Co-authored-by: DexNom <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:17:14 +00:00
The diagnostics copies line timed the state preludes planned and recorded
in each list's turn, but not those recorded after the loop when
VICTORY_PARALLEL_PRELUDES=1, so the two settings could not be compared.
That recording is now timed too, and the line also gives, per frame, the
preludes recorded, the barriers in those of barriers only, and how many
were recorded on threads: "state preludes X ms (N preludes, B barriers,
T on threads)".

Whether a submission's preludes go on threads is now on_threads (four or
more, holding PARALLEL_PRELUDE_BARRIERS in all), and the test
small_submissions_record_their_preludes_in_order keeps eight preludes of
40 barriers each in order and eight of 400 on threads.
Author
Owner

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

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

**@⁠Marvisak** on GitHub · 2026-11-26 02:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/2908#issuecomment-7180699757) <!-- 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)_
Author
Owner

@⁠0xkn0wh3r3 on GitHub · 2026-11-26 07:23 UTC · original

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.

**@⁠0xkn0wh3r3** on GitHub · 2026-11-26 07:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/2908#issuecomment-7185397845) 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 can be merged automatically.
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/2908/head:github-bot/gh-2908'
git switch 'github-bot/gh-2908'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2908'
git switch 'github-bot/gh-2908'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2908'
git switch 'github-bot/gh-2908'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2908'
git switch 'main'
git merge --squash 'github-bot/gh-2908'
git switch 'main'
git merge --ff-only 'github-bot/gh-2908'
git switch 'main'
git merge 'github-bot/gh-2908'
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!2908
No description provided.