GPU: the frame's wait for pipelines is one budget for all recording threads #2111

Open
github-bot wants to merge 3 commits from github-bot/gh-2111 into main AGit
Owner

@⁠r4tedx on GitHub · 2026-11-25 05:11 UTC · original
r4tedx:gpu/pipeline-wait-budget → main · +211 −10 · 3 files · 3 commits · open

What is wrong

pipeline/make.rs lets a draw wait for its host pipeline while the title frame has budget left: BUDGET is 500 ms, documented as "waiting allowed per title frame, over all threads". wait did not keep to that. It read what was left of the budget when the wait began and added its own time only when it returned:

let left = BUDGET.saturating_sub(Duration::from_micros(WAITED_US.load(Ordering::Relaxed)));
...
WAITED_US.fetch_add(started.elapsed().as_micros() as u64, Ordering::Relaxed);

The title records its lists on several threads. A thread that begins to wait while another still waits reads a budget nobody has charged yet and gets all of it, from its own start. So the frame can stand still for nearly twice the budget (a thread that begins just before the first one returns), and its threads wait a whole budget each.

These waits are on the recording threads, outside Host::execute, so none of the frame line's times holds them. A frame that stood waiting for pipelines only showed as a longer frame.

What changes

  • The waits of a frame end together (Waits): time counts while at least one thread waits, once however many do, and not between waits. Waits one after the other share what is left, as before. A wait that ends early because its pipeline was made leaves the rest to later waits, as before. A thread still naming the frame before (it read the frame number, then lost the processor) no longer brings a fresh budget back: on main a different frame number reset the count.
  • The frame line prints the time waited per frame: ...; 12.3 ms/frame of draws waiting for pipelines.

A title recording on one thread behaves as on main.

Measured (synthetic, CPU threads only, no GPU and no title)

Four threads call wait 125 ms apart for pipelines that are never made, on the 500 ms budget:

each thread returned at the frame stood still threads waited in all
main (940d32f) 509, 635, 758, 882 ms 882 ms 2,033 ms
this PR 505, 505, 505, 505 ms 505 ms 1,268 ms

How much this is worth in the title depends on how often several recording threads wait in one frame, which I have not measured: the title was not run. The new number on the frame line is there so that a tester's log shows it.

Tests

No GPU needed:

  • waits_of_a_frame_share_its_budget: the accounting on given instants (waits that overlap, waits one after the other, a spent budget, a stale frame number, a frame that begins while a wait is under way, the time taken for the frame line while a wait is under way).
  • a_thread_that_waits_while_another_does_gets_no_budget_of_its_own: four real threads waiting on pipelines never made; every wait is over one budget after the first began.

Both fail on main's algorithm. cargo test -p victory-gpu --features diagnostics with VICTORY_D3D12_WARP=1 (software adapter): 148 passed, 0 failed, 2 ignored. cargo clippy -p victory-gpu --all-targets is clean.

  • #275 changes the same accounting (a packed atomic with a reservation and refund) together with an adaptive 8 ms budget and background library saves; it is older and no longer merges. This PR is only the shared budget and the frame-line number, on current main.
  • The fork fxceless/victory-gta6 diagnosed the same defect in its own tree (it measured 2.5 s of waiting per frame summed over five recording threads). The idea of looking here is theirs; the code is written for main.

AI-assisted (Claude Code). No game data was used.

🤖 Generated with Claude Code

**@⁠r4tedx** on GitHub · 2026-11-25 05:11 UTC · [original](https://github.com/Marvisak/VIctory/pull/2111) `r4tedx:gpu/pipeline-wait-budget` → `main` · +211 −10 · 3 files · 3 commits · open ## What is wrong `pipeline/make.rs` lets a draw wait for its host pipeline while the title frame has budget left: `BUDGET` is 500 ms, documented as "waiting allowed per title frame, over all threads". `wait` did not keep to that. It read what was left of the budget when the wait began and added its own time only when it returned: ```rust let left = BUDGET.saturating_sub(Duration::from_micros(WAITED_US.load(Ordering::Relaxed))); ... WAITED_US.fetch_add(started.elapsed().as_micros() as u64, Ordering::Relaxed); ``` The title records its lists on several threads. A thread that begins to wait while another still waits reads a budget nobody has charged yet and gets all of it, from its own start. So the frame can stand still for nearly twice the budget (a thread that begins just before the first one returns), and its threads wait a whole budget each. These waits are on the recording threads, outside `Host::execute`, so none of the frame line's times holds them. A frame that stood waiting for pipelines only showed as a longer frame. ## What changes - The waits of a frame end together (`Waits`): time counts while at least one thread waits, once however many do, and not between waits. Waits one after the other share what is left, as before. A wait that ends early because its pipeline was made leaves the rest to later waits, as before. A thread still naming the frame before (it read the frame number, then lost the processor) no longer brings a fresh budget back: on `main` a different frame number reset the count. - The frame line prints the time waited per frame: `...; 12.3 ms/frame of draws waiting for pipelines`. A title recording on one thread behaves as on `main`. ## Measured (synthetic, CPU threads only, no GPU and no title) Four threads call `wait` 125 ms apart for pipelines that are never made, on the 500 ms budget: | | each thread returned at | the frame stood still | threads waited in all | |---|---|---|---| | `main` (`940d32f`) | 509, 635, 758, 882 ms | 882 ms | 2,033 ms | | this PR | 505, 505, 505, 505 ms | 505 ms | 1,268 ms | How much this is worth in the title depends on how often several recording threads wait in one frame, which I have not measured: the title was not run. The new number on the frame line is there so that a tester's log shows it. ## Tests No GPU needed: - `waits_of_a_frame_share_its_budget`: the accounting on given instants (waits that overlap, waits one after the other, a spent budget, a stale frame number, a frame that begins while a wait is under way, the time taken for the frame line while a wait is under way). - `a_thread_that_waits_while_another_does_gets_no_budget_of_its_own`: four real threads waiting on pipelines never made; every wait is over one budget after the first began. Both fail on `main`'s algorithm. `cargo test -p victory-gpu --features diagnostics` with `VICTORY_D3D12_WARP=1` (software adapter): 148 passed, 0 failed, 2 ignored. `cargo clippy -p victory-gpu --all-targets` is clean. ## Related - #275 changes the same accounting (a packed atomic with a reservation and refund) together with an adaptive 8 ms budget and background library saves; it is older and no longer merges. This PR is only the shared budget and the frame-line number, on current `main`. - The fork `fxceless/victory-gta6` diagnosed the same defect in its own tree (it measured 2.5 s of waiting per frame summed over five recording threads). The idea of looking here is theirs; the code is written for `main`. AI-assisted (Claude Code). No game data was used. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
`BUDGET` is "waiting allowed per title frame, over all threads", but each
wait took what was left of it when the wait began and counted its own time
only on return. The title records its lists on several threads: a thread
that began to wait while another still waited got the whole budget again,
from its own start. The frame then stood still for up to twice the budget
(a thread that begins just before the first returns), and its threads
waited a budget each.

The waits of a frame now end together (`Waits`): time counts while any
thread waits, once however many do; waits one after the other share what
is left; a thread still naming the frame before brings no budget back.

The frame line prints the time waited: these waits are on the recording
threads, outside the submissions, so they were in none of its times.

Tests, no GPU: waits_of_a_frame_share_its_budget (the accounting, on given
instants) and a_thread_that_waits_while_another_does_gets_no_budget_of_its_own
(four threads waiting on pipelines never made).

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Main's #1320 gave `Pending::new` the diagnostics build's shader hashes to
skip; the test passes none, as the module's other tests do.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:55:10 +00:00
Author
Owner

@⁠upipibi on GitHub · 2026-11-25 05:14 UTC · original

Ran on Windows 11 with an RTX 3070 (Ampere, driver 616.56), debug build, at 0ef11e5. victory-gpu: 143 passed, 2 failed, 2 ignored. The new waits_of_a_frame_share_its_budget and a_thread_that_waits_while_another_does_gets_no_budget_of_its_own pass. The 2 failures are #1744's heap-cap failures on main. Same as main on this hardware.

Overlap, from reading: #275 (open, conflicting with main) fixes the same overshoot in pipeline/make.rs with an atomic reserve-and-refund FrameBudget, so concurrent recording threads can't spend the 500 ms twice. It also changes the wake-ups and the library saves. This PR is the narrow version of that fix.

AI-assisted (Claude Code).

**@⁠upipibi** on GitHub · 2026-11-25 05:14 UTC · [original](https://github.com/Marvisak/VIctory/pull/2111#issuecomment-7153579638) Ran on Windows 11 with an RTX 3070 (Ampere, driver 616.56), debug build, at `0ef11e5`. `victory-gpu`: 143 passed, 2 failed, 2 ignored. The new `waits_of_a_frame_share_its_budget` and `a_thread_that_waits_while_another_does_gets_no_budget_of_its_own` pass. The 2 failures are #1744's heap-cap failures on `main`. Same as `main` on this hardware. Overlap, from reading: #275 (open, conflicting with `main`) fixes the same overshoot in `pipeline/make.rs` with an atomic reserve-and-refund `FrameBudget`, so concurrent recording threads can't spend the 500 ms twice. It also changes the wake-ups and the library saves. This PR is the narrow version of that fix. AI-assisted (Claude Code).
Author
Owner

@⁠r4tedx on GitHub · 2026-11-25 05:52 UTC · original

@⁠catminou4 on slow compiles: the budget is per title frame, as on main; only how the waits of several threads add up changes. A pipeline that takes longer than the budget to compile behaves as before: its draw waits until the frame's budget is spent and is dropped, and the next frame's first wait gets a whole budget again while the worker keeps compiling. What changes is that a second thread beginning to wait during the first's wait no longer gets a budget of its own (synthetic, four threads 125 ms apart on pipelines never made: the frame stood still 882 ms on main, 505 ms here). Covered by waits_of_a_frame_share_its_budget, which includes a spent budget and a frame that begins while a wait is under way.

AI-assisted (Claude Code).

**@⁠r4tedx** on GitHub · 2026-11-25 05:52 UTC · [original](https://github.com/Marvisak/VIctory/pull/2111#issuecomment-7154217152) @⁠catminou4 on slow compiles: the budget is per title frame, as on `main`; only how the waits of several threads add up changes. A pipeline that takes longer than the budget to compile behaves as before: its draw waits until the frame's budget is spent and is dropped, and the next frame's first wait gets a whole budget again while the worker keeps compiling. What changes is that a second thread beginning to wait during the first's wait no longer gets a budget of its own (synthetic, four threads 125 ms apart on pipelines never made: the frame stood still 882 ms on `main`, 505 ms here). Covered by `waits_of_a_frame_share_its_budget`, which includes a spent budget and a frame that begins while a wait is under way. AI-assisted (Claude Code).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 10:42 UTC · original · edited 2026-11-26 03:20 UTC

Automated triage for the maintainers.

Thanks for merging main in. The new head merges cleanly and is reviewed again. The verdict from before the conflict still holds.

In crates/victory-gpu/src/pipeline/make.rs, the new Waits type replaces the per-thread budget read in wait with one budget per frame. That budget counts time while any thread waits and charges overlapping waits only once. A stale frame number no longer resets it. Waits::take feeds the new ms/frame of draws waiting for pipelines figure in Meter (host.rs). Since the rebase, the only change is the three-argument pipeline call in the threaded test. waits_of_a_frame_share_its_budget tests the accounting with fixed instants, which is easy to check by hand.

This overlaps #275, the older and broader fix, which no longer merges. This PR is the narrow fix on current main.

Verdict: merge candidate (a recommendation to look, not an approval). CI: passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 10:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/2111#issuecomment-7160054413) · edited 2026-11-26 03:20 UTC <!-- victory-triage v1 head=eb868bce0eb2ee5d63a6401b9390aebdfe19a3db verdict=merge-candidate at=2026-11-26T03:20:59Z --> Automated triage for the maintainers. Thanks for merging `main` in. The new head merges cleanly and is reviewed again. The verdict from before the conflict still holds. In `crates/victory-gpu/src/pipeline/make.rs`, the new `Waits` type replaces the per-thread budget read in `wait` with one budget per frame. That budget counts time while any thread waits and charges overlapping waits only once. A stale frame number no longer resets it. `Waits::take` feeds the new `ms/frame of draws waiting for pipelines` figure in `Meter` (`host.rs`). Since the rebase, the only change is the three-argument pipeline call in the threaded test. `waits_of_a_frame_share_its_budget` tests the accounting with fixed instants, which is easy to check by hand. This overlaps #275, the older and broader fix, which no longer merges. This PR is the narrow fix on current `main`. **Verdict: merge candidate** (a recommendation to look, not an approval). CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠r4tedx on GitHub · 2026-11-26 02:58 UTC · original

Merged main 842b0cb into the branch (merge a8316c9d, no force-push), head now eb868bce. The follow-up commit makes the staggered-waits test build its pipeline the way main's tests now do (three-argument call). Verified on this head: cargo clippy clean; VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --features diagnostics --lib -- --test-threads=1: 248 passed, 0 failed, 1 ignored. Synthetic tests on WARP only, no title data used.

AI-assisted

**@⁠r4tedx** on GitHub · 2026-11-26 02:58 UTC · [original](https://github.com/Marvisak/VIctory/pull/2111#issuecomment-7181285548) Merged main `842b0cb` into the branch (merge `a8316c9d`, no force-push), head now `eb868bce`. The follow-up commit makes the staggered-waits test build its pipeline the way main's tests now do (three-argument call). Verified on this head: `cargo clippy` clean; `VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --features diagnostics --lib -- --test-threads=1`: 248 passed, 0 failed, 1 ignored. Synthetic tests on WARP only, no title data used. AI-assisted
Author
Owner

@⁠DenRakEiw on GitHub · 2026-11-25 05:18 UTC · original · approved these changes

Verified locally merged onto origin/main (940d32f, Windows 11 x64, Rust 1.98.1 MSVC):

  • cargo test -p victory-gpu --lib pipeline:: — 17 passed, 0 failed
  • cargo clippy -p victory-gpu --all-targets — 0 warnings
  • cargo xtask policy — ok (183 files ok)

Clean shared per-frame pipeline wait budget across recording threads. Looks good.

AI-assisted (Gemini 4 Neon).

**@⁠DenRakEiw** on GitHub · 2026-11-25 05:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/2111#pullrequestreview-6052218563) · **approved these changes** Verified locally merged onto `origin/main` (`940d32f`, Windows 11 x64, Rust 1.98.1 MSVC): - `cargo test -p victory-gpu --lib pipeline::` — **17 passed, 0 failed** - `cargo clippy -p victory-gpu --all-targets` — 0 warnings - `cargo xtask policy` — ok (`183 files ok`) Clean shared per-frame pipeline wait budget across recording threads. Looks good. AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠catminou4 on GitHub · 2026-11-25 05:48 UTC · original · reviewed

Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.

Frame's pipeline wait is one budget for all requests — replaces per-request waits; check the budget arithmetic against slow pipeline compiles.

**@⁠catminou4** on GitHub · 2026-11-25 05:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/2111#pullrequestreview-6052483508) · **reviewed** Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff. Frame's pipeline wait is one budget for all requests — replaces per-request waits; check the budget arithmetic against slow pipeline compiles.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 15:22 UTC · original · approved these changes

Reviewed host.rs, pipeline.rs, and pipeline/make.rs at eb868bce merged onto origin/main (63bcca43) and verified on RTX 5090 and WARP (VICTORY_D3D12_WARP=1) with VICTORY_D3D12_DEBUG=1.

Concurrency & accounting audit

  • Waits (crates/victory-gpu/src/pipeline/make.rs:188,223,239,253) replaces the racy per-thread budget read with a shared mutex-protected frame deadline (s.since + budget.saturating_sub(s.used)): overlapping recording threads share one deadline and charge wall time once, stale frame numbers (frame < s.frame) cannot reset the budget, take(now) advances s.since and s.used together so active wait deadlines stay invariant, and saturating_sub / saturating_duration_since avoid underflow.
  • wait_within (pipeline/make.rs:337) uses an RAII Under guard so end() always runs even on unwind. pipeline::take_waited_ms (pipeline.rs:268) is gated #[cfg(windows)] and wired into Meter at host.rs:3077.

Verification

  • cargo run -p xtask -- policy: 191 files ok.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings (default and --all-features): clean.
  • pipeline:: host:: with VICTORY_D3D12_DEBUG=1: 55/55 passed on RTX 5090 (skipping dynamic_slots_are_held_until_released) and 59/59 passed on WARP (--features diagnostics, skipping the pre-existing main compositor_failure_presents_primary_in_the_same_frame Debug Layer mismatch), including waits_of_a_frame_share_its_budget (pipeline/make.rs:495) and a_thread_that_waits_while_another_does_gets_no_budget_of_its_own (pipeline/make.rs:548).
**@⁠fuzeofficlal** on GitHub · 2026-11-26 15:22 UTC · [original](https://github.com/Marvisak/VIctory/pull/2111#pullrequestreview-6076684333) · **approved these changes** Reviewed `host.rs`, `pipeline.rs`, and `pipeline/make.rs` at `eb868bce` merged onto `origin/main` (`63bcca43`) and verified on RTX 5090 and WARP (`VICTORY_D3D12_WARP=1`) with `VICTORY_D3D12_DEBUG=1`. ### Concurrency & accounting audit - `Waits` (`crates/victory-gpu/src/pipeline/make.rs:188,223,239,253`) replaces the racy per-thread budget read with a shared mutex-protected frame deadline (`s.since + budget.saturating_sub(s.used)`): overlapping recording threads share one deadline and charge wall time once, stale frame numbers (`frame < s.frame`) cannot reset the budget, `take(now)` advances `s.since` and `s.used` together so active wait deadlines stay invariant, and `saturating_sub` / `saturating_duration_since` avoid underflow. - `wait_within` (`pipeline/make.rs:337`) uses an RAII `Under` guard so `end()` always runs even on unwind. `pipeline::take_waited_ms` (`pipeline.rs:268`) is gated `#[cfg(windows)]` and wired into `Meter` at `host.rs:3077`. ### Verification - `cargo run -p xtask -- policy`: 191 files ok. - `cargo clippy -p victory-gpu --all-targets -- -D warnings` (default and `--all-features`): clean. - `pipeline:: host::` with `VICTORY_D3D12_DEBUG=1`: **55/55 passed** on RTX 5090 (skipping `dynamic_slots_are_held_until_released`) and **59/59 passed** on WARP (`--features diagnostics`, skipping the pre-existing `main` `compositor_failure_presents_primary_in_the_same_frame` Debug Layer mismatch), including `waits_of_a_frame_share_its_budget` (`pipeline/make.rs:495`) and `a_thread_that_waits_while_another_does_gets_no_budget_of_its_own` (`pipeline/make.rs:548`).
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/2111/head:github-bot/gh-2111'
git switch 'github-bot/gh-2111'

Merge

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