Repository navigation
d3d12: the threads of a frame share its pipeline wait budget and none is left with nothing (D3D12-COLD-START-SKIPS) - #3000
Conversation
… is left with nothing (D3D12-COLD-START-SKIPS) The shared frame budget was a reservation: the first recording thread to wait in a frame took all that was left of it, and every other thread of that frame (and any thread still on an older frame) got nothing, so its draw went out without a wait and was dropped as not made. On first starts (no pipeline book) 400 to 3,600 draws, dispatches and indirect executions a frame were dropped at the arrival in the world, and the character's head, drawn by a pass the title runs once, stayed missing for the run. - The frame's waits are counted once over the threads that wait at the same time: what passed while at least one thread waited. A thread that begins to wait while others do is left what is left at that count, so waits that overlap still cost the frame its budget once; the time a thread records between two waits is not counted; a thread on an older frame joins the current frame's waits and opens no budget of its own (ProjectLeonida#2601). On by default; LEONIDA_PIPELINE_WAIT_DEADLINE=0 reserves the frame's budget as before (no effect with LEONIDA_PIPELINE_WAIT_SHARED=0); LEONIDA_AB can turn it while the title runs. - A pipeline's own budget (LEONIDA_PIPELINE_WAIT_ONCE) is charged the same way, the real time once, not the threads' times added up, whatever the sharing of the frame's budget (LEONIDA_PIPELINE_WAIT_ONCE=0 turns that budget off). - The queue a wait moves its pipeline forward in and the budget a pipeline's waits count against are passed in, so that tests cover them; one line tells the rules in use at the first wait. AI-assisted: Claude Code (Claude Opus 5.5) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The shared deadline can refund time that was actually spent waiting when two waiters report completion in reverse timestamp order. At 7c69bc8 I compiled the PR's FrameWait and Waited unchanged and exercised take/give_back on one frame with a 100 ms budget:
The union is 85 ms in both cases. wait_in samples now before locking the accounting mutex, so A can capture 20 ms, be descheduled, and report after B. Waited::end uses only the timestamp of the caller that decrements waiting to zero. This affects both frame and per-pipeline accounting. For this case, retaining the latest end timestamp across the active group and testing reversed completion order would prevent the 65 ms undercharge. This is a deterministic CPU accounting reproduction; I did not measure its frequency during gameplay. Codex-assisted. |
|
A delayed end report can also count the gap between two disjoint waits. I compiled the exact
Reporting A before B starts gives the expected 90/80/20 ms. The two completion reports in the failing case are already in timestamp order. Testing overlapping waits in reversed completion order therefore covers a different case. The gap is charged because |
|
First-start RUN of head 7c69bc8 merged onto main 913b88b (tree ceaf7f729). RTX 4070 Laptop 8 GB, NVIDIA 621.40, Windows 11, -SeriesS -NoDlss -NoFrameGen, BAR 0, texture budget 1024, fresh data folder with no pipelines (every pipeline compiles on arrival), default switches.
|
|
Red/green RUN on one exe: head 7c69bc8 merged onto main 913b88b (tree ceaf7f729). RTX 4070 Laptop 8 GB, NVIDIA 621.40, Windows 11, -SeriesS -NoDlss -NoFrameGen, BAR 0, texture budget 1024, each run on a fresh data folder with no pipelines, 330 s in the world, pictures looked at (not posted) at +60, +150, +280 and +320 s.
Safe to merge into main? Yes: merge-tree clean on main 7adb42f (main gained #2857, #2852 and #2991 since my test, none touches AI-assisted: Claude Code (oreofr-agent). |
|
Merging (added to the merge queue). Head 7c69bc8 merges cleanly with main 7adb42f. Claim: D3D12-COLD-START-SKIPS (#2570 (comment)). Red/green: oreofr-agent on an RTX 4070 Laptop, same exe, |
|
Thanks @andrew-ai and @merzleckeier: both cases are real. A follow-up pull request reads the clock under the accounting lock and keeps a late end from moving the count back, with both of your schedules as tests (red on this head, green with the change), for the frame's count and for a pipeline's own. Since this one is already in the merge queue, the follow-up will go on top of Separately, the cost OreoFR measured on the 4070 Laptop belongs in the record: while the pipelines compile on a first start, frames are longer than on |
|
Follow-up for the two counting cases above: #3032. It reads the time of each begin and end of a wait under the lock of the count it goes into, and |
Claimed in the coordination issue as: D3D12-COLD-START-SKIPS (#2570 (comment))
What and why
On a first start (a data folder with no pipeline book, so no pipeline is started early) the D3D12 runtime makes each pipeline at its first draw, and a draw waits for it within a budget per frame. That budget, one for all the title's recording threads, was a reservation: the first thread to wait in a frame took all that was left of it, and every other thread recording in that frame, as well as a thread still on an older frame, was left nothing. Their draws went out without a wait and were dropped as not made. At the arrival in the world that was 400 to 3,600 draws, dispatches and indirect executions a frame, and a pass the title runs only once, the one that draws the character's head, was lost for the whole run. A budget of ten minutes a frame (
LEONIDA_PIPELINE_WAIT_MS=600000) still left hundreds a frame dropped, because the other threads still got nothing.This change (
d3d12/crates/leonida-gpu/src/pipeline/make.rs):LEONIDA_PIPELINE_WAIT_DEADLINE=0reserves the frame's budget as before (no effect withLEONIDA_PIPELINE_WAIT_SHARED=0), andLEONIDA_ABcan turn it while the title runs;LEONIDA_PIPELINE_WAIT_ONCE) the same way, the real time once, in every mode:LEONIDA_PIPELINE_WAIT_DEADLINE=0andLEONIDA_PIPELINE_WAIT_SHARED=0bring back only the old sharing of the frame's budget, andLEONIDA_PIPELINE_WAIT_ONCE=0turns a pipeline's own budget off as before. Added up per thread, a pass run once that several threads waited for together ran out of its budget early (13 such pipelines on one first start, some reported two or three times at the same millisecond);d3d12/docs/switches.mdis regenerated (tools/d3d12_switches.py --out, then--check;tests/test_d3d12_switches.pypasses). The rows of this change: the new switch,LEONIDA_PIPELINE_WAIT_SHARED(its sentence now says it brings back only the frame's budget), and the count of files that nameLEONIDA_AB. One row is unrelated:LEONIDA_RENDER_SCALE_MINmoves from the loader's section to the GPU's because the page onmainhad not been regenerated sincehost/menu.rsbegan to read it;--outwrites it whatever the change.Not in this pull request: waiting past the frame's budget for a pipeline never made. In one run it removed the last dropped draws, but at the cost of a 39 s frame, and its cost on a cold start is not measured.
Tested
Image runs (RTX 3090, NVIDIA 621.40, Windows 11; Series S settings, no DLSS, no frame generation, the title's hang watchdog quieted; 420 s each from the same save, each on a fresh data folder; captures kept locally, not published; no frame-time measurement). Two series. The first ran build b02c80796, the first form of this change, which ended a frame's waits at one deadline counted from its first wait. The second ran build c38efe212, the logic of this commit (its later edits are comments, a debug check and where a log line is written), four runs alternating the switch, on and off, on and off; the head was judged on the captures shuffled, before matching them to the switch. NVIDIA's own shader cache, per executable: cold in the first run, filled by the earlier runs for the later ones (same executable, run in the order below).
LEONIDA_PIPELINE_WAIT_DEADLINE=0(the reservation)Second series, build c38efe212 (the final logic), same setup, one executable path for the four runs:
LEONIDA_PIPELINE_WAIT_DEADLINE=0LEONIDA_PIPELINE_WAIT_DEADLINE=0With the reservation the head was missing on every first start: 10 runs of 10 (8 before this change, and the two witnesses of the second series). With this change at its defaults it was drawn in 4 runs of 4 (two of each form). In run F0 the head was missing with few drops, so how many draws are dropped matters less than which: a pass run once. The defect also reproduces on an RTX 4070 Laptop (OreoFR); the fix was not run there.
Limits: four runs with the fix and three witnesses in this executable, on one GPU. A cold start still drops draws (runs 1 and F1: about 10,100 and 10,300), fewer than without (43,600 to 157,000) but not none. Frames of 5 s and more remain on a cold start, and run 1 had more windows with them than the witness: threads now wait where they used to drop. The column "10 s windows" is how the frame lines were read, not a measured frame-time distribution.
Rust, on
7c69bc8b1(this branch, onmainc4ca57615), fromd3d12/:cargo test -p leonida-gpu --lib --locked -- pipeline::make::testscargo test -p leonida-gpu --lockedcargo test -p leonida-gpu --features diagnostics --lockedcargo test --workspace --exclude xtask --locked -- --skip depth_bounds_pipeline_loads_and_filters_drawscargo clippy --workspace --all-targets --lockedmake.rscargo clippy -p leonida-gpu --all-targets --features diagnostics --lockedmake.rsThe two failing workspace tests are both in
leonida-loader, a crate that does not depend onleonida-gpu.loads_binds_and_calls_probefailed in the same way onmainhere (the probe DLL it builds is not found where it looks; this machine builds withCARGO_BUILD_TARGETset).console_insn::tests::a_clzero_loop_becomes_plain_storespassed alone, and in two further runs of the crate's tests (84 of 84).Compared with
mainat the same base one commit earlier (1e3e316c5): 9 more tests in eachleonida-gpusuite and in the workspace, and the same clippy warnings.Red and green. The new API makes the tests fail to compile on
mainitself, so they were run on a seam with no change of behaviour, whose stubs behave asmaindoes; each failed for the reason it states.main's reservation: the second thread to wait in a frame got 0 instead of what was left (400 ms of 500), and so did a thread on an older frame; of two overlapping waits, the second waited 6 µs.They pass with the change. Nine mutations, each built and run on
c38efe212(the same logic as this commit, whose later edits are comments, a debug check and where a log line is written), are each caught by at least one test:python -I scripts/check_no_game_data.pypasses on both changed files.GPUs tested: NVIDIA GeForce RTX 3090, driver 621.40, Windows 11 Pro (build 26300): image runs and the Rust suites.
AI-assisted: yes (Claude Code, Claude Opus 5.5; reviews by two independent Claude Opus 5.5 agents)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (No translator change.)🤖 Generated with Claude Code