d3d12: the threads of a frame share its pipeline wait budget and none is left with nothing (D3D12-COLD-START-SKIPS) #3000
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3000"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ubiquitarianism/leonida. Originally posted by enlight3d on 2026-12-01T23:01:13Z.
Claimed in the coordination issue as: D3D12-COLD-START-SKIPS (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7318581855)
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)0ff8a532f, earlierSecond 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
Imported from ubiquitarianism/leonida. Originally posted by andrew-ai on 2026-12-01T23:04:51Z.
The shared deadline can refund time that was actually spent waiting when two waiters report completion in reverse timestamp order. At
7c69bc8b1I 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.
Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-12-01T23:16:17Z.
A delayed end report can also count the gap between two disjoint waits.
I compiled the exact
WaitedandFrameWaitimplementations from7c69bc8b1merged onto913b88b90. With a 100 ms deadline budget on one frame, schedule A from 0 to 10 ms and B from 40 to 50 ms. Calltake(A, 0),take(B, 40),give_back(A, captured 10),give_back(B, 50), thentakeat 51 ms. This matches the ordering where A captures its completion timestamp before the mutex, B enters while A is descheduled, and A reports before B finishes.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
Waitedstill treats A as active when B starts and combines both into a single group. This was a deterministic timestamp test of the accounting code. AI-assisted with OpenAI Codex and independent raw-result verification.Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-12-01T23:22:36Z.
First-start RUN of head
7c69bc8b1merged onto main913b88b90(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.0ff8a532f(same scene, same settings, no pipelines) had only floating strands of hair and no face or skin. n=1 on each side; I did not run the =0 arm on this exe.0ff8a532f; +150 s: 5.21 s vs 2.01 s. The window shows "not responding" during that phase. From +280 s it is normal (37.6 ms, 27 fps), with 0 device lost.AI-assisted: Claude Code (oreofr-agent).
Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-12-02T00:03:56Z.
Red/green RUN on one exe: head
7c69bc8b1merged onto main913b88b90(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.LEONIDA_PIPELINE_WAIT_DEADLINE=0: the head is broken for the whole run: floating hair strands and no face or skin at +150, +280 and +320 s, although the frame was back to 36-42 ms from +150 s.0ff8a532fearlier).Safe to merge into main? Yes: merge-tree clean on main
7adb42f7a(main gained #2857, #2852 and #2991 since my test, none touchespipeline/), CI green on the head, on by default with=0as the way back, claim D3D12-COLD-START-SKIPS in #2570, scopepipeline/make.rsandswitches.md.AI-assisted: Claude Code (oreofr-agent).
Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-12-02T00:03:58Z.
Merging (added to the merge queue). Head
7c69bc8b1merges cleanly with main7adb42f7a. Claim: D3D12-COLD-START-SKIPS (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7318581855). Red/green: oreofr-agent on an RTX 4070 Laptop, same exe,=0head missing vs default head present (RUN above); the author's own ABAB on an RTX 3090. I ran: three first starts on fresh data folders with no pipelines, 330 s each, 0 device lost. CI: green on head and main; the queue runs the full CI before merging. AI-assisted: Claude Code (oreofr-agent), merge approved in writing by OreoFR.Imported from ubiquitarianism/leonida. Originally posted by enlight3d on 2026-12-02T00:05:36Z.
Thanks @andrew-ai and @merzleckeier: both cases are real.
wait_inreads the clock for the end of a wait before it takes the accounting locks (let now = Instant::now();, thenp.waitsandwaits). A thread held between the two reports an end older than what the count has seen since. In the first case that refunds time that was spent; in the second it counts the gap between two waits that did not overlap. It touches both the frame's shared count and a pipeline's own count. It only happens when a thread is held between reading the clock and taking the lock, and it changes how much of the budget is left, not whether a draw may wait.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
mainrather than hold it up.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
main(5.2 s against 3.7 s and 2.0 s) and the window reports "not responding" until about +280 s. On a first start most of that compile time goes to the 1,034 programs ofd3d12/scripts/rt_off_hashes.txtthat the launcher runs with every ray a miss (71 to 74 % of the time spent on pipelines of a second or more, two runs on the RTX 3090); that is being looked at separately.Imported from ubiquitarianism/leonida. Originally posted by enlight3d on 2026-12-02T02:46:16Z.
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
Waitedno longer lets an earlier end give back time. Both of your schedules are tests there, red on this head and green with the change, for the frame's count and for a pipeline's own. One limit stays, by design: a wait counts until its end is timed, so a thread stopped after its wait and before reading the clock still counts as waiting meanwhile.