Repository navigation
d3d12: time each begin and end of a pipeline wait under its count's lock (D3D12-COLD-START-SKIPS follow-up) - #3032
Merged
Conversation
…ock (D3D12-COLD-START-SKIPS follow-up) After a wait, wait_in read the clock once, before taking the lock of the frame's count and that of the pipeline's own count, and told both ends that time. A thread stopped between the read and the lock had its end told after events with later times, and Waited took the order it was told as the order of the times (review of pull request 3000): - andrew-ai: A waits 0-20 ms, B 10-85 ms; with A's end told after B's, a wait at 86 ms was left 80 ms of 100 instead of 15, and a pipeline both waited for was charged 20 ms instead of 85; - merzleckeier: A waits 0-10 ms, B 40-50; with A's end, read at 10, told after B began, B was left 60 ms instead of 90, the frame had 50 left instead of 80, and the pipeline was charged 50 instead of 20. Each begin and end is now timed under the lock of the count it goes into, through a seam (trait Waiting: the clock and the wait; Real in the title), so a count is told them in the order of their times. Waited keeps the latest time it has seen and takes an older one as that: an end gives back nothing, a begin counts nothing twice. The frame's end is timed right after the pipeline's, before the log lines. A wait still counts until its end is timed: a thread stopped after its wait and before it reads the time counts as waiting meanwhile (test a_wait_counts_until_its_end_is_timed). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Collaborator
|
RUN - #3032 head
Safe to merge into main? Yes.
AI-assisted (Claude Code, Claude Opus 5.5). |
Collaborator
|
Merging. Head AI-assisted (Claude Code, Claude Opus 5.5). |
OreoFR
removed their request for review
December 2, 2026 03:43
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Claimed in the coordination issue as: D3D12-COLD-START-SKIPS (#2570 (comment)). 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