d3d12: time each begin and end of a pipeline wait under its count's lock (D3D12-COLD-START-SKIPS follow-up) #3032
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3032"
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-02T02:46:03Z.
Claimed in the coordination issue as: D3D12-COLD-START-SKIPS (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7318581855). A follow-up of #3000, for the counting defect its two reviewers found.
What and why
#3000 counts the pipeline waits of a frame's recording threads once (what passed while at least one of them waited) and charges a pipeline's own budget (
LEONIDA_PIPELINE_WAIT_ONCE) the same way:Waitedind3d12/crates/leonida-gpu/src/pipeline/make.rs. andrew-ai and merzleckeier showed, in review, that the count could come out wrong. After a wait,wait_inread the clock once, before it took the lock of the frame's count and that of the pipeline's, and gave both counts that time. A thread stopped between the reading and the lock had its end recorded after events with later times, andWaitedtook the order it was given the events in as the order of their times:This change (
d3d12/crates/leonida-gpu/src/pipeline/make.rsonly):takeandgive_back, the pipeline's forbeginandend. A count then gets its events in the order of their times. The clock and the wait reach the code ofwait_inthrough a small seam (trait Waiting; in the title,RealisInstant::nowanduntil_made), so that tests can script both;Waitedkeep the latest time it has seen and take an earlier one as that time: an end gives back nothing already counted, and a begin counts nothing twice. With the times read under the lock and a monotonic clock this never happens, so it is a guard. andrew-ai's case is fixed by either part, merzleckeier's only by reading under the lock;What it does not change: a wait counts until its end is timed. A thread stopped after its wait and before it reads the time still counts as waiting meanwhile. In merzleckeier's case with A stopped there, B is still left 60 ms and the frame is charged 50 (test
a_wait_counts_until_its_end_is_timed). The count cannot know an end before the thread gives it, and B's 90 ms would need that. The reading of what is left of a pipeline's own budget (billed) still happens before its lock. It changes no count; a thread stopped there can be left more than its pipeline's remaining budget, by the length of the stop.The switches are those of #3000, unchanged (
LEONIDA_PIPELINE_WAIT_DEADLINE,LEONIDA_PIPELINE_WAIT_SHARED,LEONIDA_PIPELINE_WAIT_ONCE,LEONIDA_AB).d3d12/docs/switches.mdneeds no change:python -I tools/d3d12_switches.py --check d3d12/docs/switches.mdpasses, and--outwrites the same page (no comment that names a switch changed).Tested
The reviewers' cases, red then green. The tests were first run on a seam with no change of behaviour (the clock and the wait passed in, the times read where they were, on the head of #3000), where each failed for the reason it states, then with the change. On this commit, bringing the original counting back fails the same tests with the same numbers (first mutation below).
an_older_end_gives_back_nothing_to_the_framean_older_end_gives_back_nothing_to_the_pipelinean_older_end_gives_back_nothingWaiteditselfan_end_told_late_gives_back_nothing_to_the_framewait_in, two threadsan_end_told_late_gives_back_nothing_to_the_pipelinean_end_timed_before_a_begin_is_counted_before_it_in_the_framewait_inan_end_timed_before_a_begin_is_counted_before_it_in_the_pipelinean_older_begin_counts_no_time_twiceThe two-thread tests run the real code of the wait with a scripted clock. Thread A is stopped once, just after it reads the time of the end under test (as the system may stop a thread anywhere), until the test lets it go; if A holds the lock B waits for, it goes on alone after half a second. With the time read before the lock, as before, the stop let B in between the reading and the count. With the time read under the lock, B waits behind A. With only the guard on
Waited(the times still read before the locks), andrew-ai's tests pass and merzleckeier's two still fail with (60, 50).Two tests were added after review:
an_end_older_than_a_begin_gives_back_nothing(it catches a guard that does not remember the times of begins) anda_wait_counts_until_its_end_is_timed(the limit above, pinned).Rust, on
4b735e555(this branch, onmaind741a9f8f, which has #3000), fromd3d12/, all with--target x86_64-pc-windows-msvc:cargo test -p leonida-gpu --lib --locked -- pipeline::make::testscargo test -p leonida-gpu --lockedcargo test -p leonida-gpu --features diagnostics --lockedcargo clippy -p leonida-gpu --all-targets --lockedhost.rs; none inmake.rscargo clippy -p leonida-gpu --all-targets --features diagnostics --lockedmake.rsThe change adds 10 tests, all in
pipeline::make::tests(21 onmain).Mutations, each applied alone to this commit with the make tests then run; each is caught:
an_end_older_than_a_begin_gives_back_nothing).Not caught, and the same counts either way: the time of
takeor of the pipeline'sbeginread before its lock (the guard on begins keeps the count right; a stop there can only leave the wait more time), andbilledread under its lock.python -I scripts/check_no_game_data.pypasses on the changed file and on this text.GPUs tested: NVIDIA GeForce RTX 3090, driver 621.40, Windows 11 Pro (build 26300): the Rust suites. No game run of this change yet.
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 OreoFR on 2026-12-02T03:15:50Z.
RUN - #3032 head
4b735e555merged intomain393901a5b, RTX 4070 Laptop 8 GB, NVIDIA 621.40, Windows 11 (Verified by OreoFR)cargo test -p leonida-gpu --features diagnostics -- pipeline::makeon the merged tree: 31 passed, 0 failed (the 10 new wait-accounting tests included). PR CI 6/6 green.-SeriesS -NoDlss -NoFrameGen, BAR 0, texture budget 1024, standing, 330 s): the head is drawn at arrival (checked on local captures at +60/+150/+280/+320 s, not posted). The first-start frames are long while pipelines compile (0 fps at +60/+150 s), then 25-27 fps from +280 s. 0 device lost, 0 panics.LEONIDA_PIPELINE_WAIT_DEADLINE=0).Safe to merge into main? Yes.
git merge-tree --write-treeonto currentmain2172c1502: clean (main moved only in docs since393901a5b; nod3d12/code change).4b735e555: all green. Main's last CI / D3D12 runtime / No Game Data: green.LEONIDA_PIPELINE_WAIT_DEADLINE=0still restores the old behaviour.d3d12/crates/leonida-gpu/src/pipeline/make.rs(117 lines of code, 372 of tests).AI-assisted (Claude Code, Claude Opus 5.5).
Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-12-02T03:16:12Z.
Merging. Head
4b735e555, main2172c1502, through the merge queue, with OreoFR's OK (maintainer). Claim D3D12-COLD-START-SKIPS (#2570). Verified on an RTX 4070 Laptop 8 GB / 621.40: tests 31/31 on the merged tree, first start with no pipelines draws the head, 330 s, 0 device lost: https://github.com/ProjectLeonida/mandy/pull/3032#issuecomment-7333706341AI-assisted (Claude Code, Claude Opus 5.5).