Skip to content

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

Open
r4tedx wants to merge 3 commits into
Marvisak:mainfrom
r4tedx:gpu/pipeline-wait-budget
Open

r4tedx wants to merge 3 commits into
Marvisak:mainfrom
r4tedx:gpu/pipeline-wait-budget

Conversation

@r4tedx

@r4tedx r4tedx commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

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.

Related

  • GPU: atomic adaptive PSO wait budget and non-blocking pipeline library saves #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

…hreads

`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 <noreply@anthropic.com>
@upipibi

upipibi commented Nov 25, 2026

Copy link
Copy Markdown

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).

@DenRakEiw DenRakEiw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@r4tedx

r4tedx commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

@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).

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

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

r4tedx and others added 2 commits November 26, 2026 04:49
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s do

Main's Marvisak#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 <noreply@anthropic.com>
@r4tedx

r4tedx commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

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

@fuzeofficlal fuzeofficlal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants