d3d12-gpu: first-use report for host pipelines - warmed/loaded/made and the first caller's wait (#3103) #3490

Code

Clone this repository

Checkout

From your project repository, check out a new branch and test the changes.

git fetch -u  "d3d12/pipeline-first-use:KelboLive-d3d12/pipeline-first-use"
git switch "KelboLive-d3d12/pipeline-first-use"
Open
leonida/mandy
KelboLive wants to merge 1 commit from KelboLive/mandy:d3d12/pipeline-first-use into main

This pull request can be merged automatically.

Conversation
Reviewers 0 approvals
  • No reviewers
Details
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'd3d12/pipeline-first-use:KelboLive-d3d12/pipeline-first-use'
git switch 'KelboLive-d3d12/pipeline-first-use'
First-time contributor

What/why

#3103 asks for exactly this: for each host pipeline, was its key in the warm-up snapshot, did the runtime load it from the library or compile it, and how long did the first caller wait. The number the issue is missing is the one behind "522 pipelines still made during play": in-play (new/made).

Diagnostics only, off by default: LEONIDA_PIPELINE_FIRST_USE=1.

What it prints

One line per pipeline at first use (capped at 4096; counts continue past the cap):

pipeline first use: 0123456789ab graphics new made waited 12.3 ms

kind is graphics, compute, mesh or other; the class is warmed|new (key in early-pipelines.txt or not) crossed with loaded|made|refused.

One summary, at a clean end or on a device loss:

pipeline first use summary: warmed/loaded 1200 warmed/made 5 warmed/refused 0 new/loaded 0 new/made 0 new/refused 0;
  1205 total, waited 123.4 ms, worst 12.3 ms; in-play (new/made) 0; 0 not logged

in-play (new/made) is the count to compare with 0 on a warmed cache. warmed/made means the key was in the snapshot but the library did not serve it; new/loaded means the library had a pipeline the snapshot lacked; new/made are the true in-play compiles.

How it is measured

  • The key is Pending::key, the title pipeline key - the same string early-pipelines.txt, known-pipelines.bin and leonida warm use. (library::name is a different host-description hash and is never written to that file.)
  • First caller's wait is first request -> usable, stamped once on the first ready/masked_for (or a builder request) and completed when the build ends; a timed-out wait is reported as the time before the draw fell back. Later retries cannot overwrite it.
  • loaded vs made comes from library::pipeline: Load*PipelineState success raises LOADED, the Create*PipelineState fallback raises MADE. A mesh_compute build records the graphics PSO that is drawn, not the auxiliary compute one.
  • The snapshot is read once at cache setup, before any worker can rewrite early-pipelines.txt, so a cold run cannot classify its own new keys as warmed.
  • Exactly once per key: the existing used swap, a print swap and a report dedupe by key.
  • Off: one cached bool at the first use; no allocation or lock on the draw path. Pending::new still constructs four atomics, nothing else.

Tests

10 device-free tests in pipeline/first_use/tests.rs: classifier cross (warmed/new x loaded/made/refused), Source round trip (the test that catches swapped discriminants), once-per-key, first-wait-wins, exact line format, cap-stops-lines-not-counts, snapshot filter (32 lowercase hex, CRLF, non-hex, short key), summary counts including in-play (new/made).

Red evidence: reverting only the source logic makes the_classifier_crosses..., a_key_is_counted_once, the_cap_stops_lines_but_not_the_counts fail; reverting only Source to the old implicit discriminants makes a_source_reads_back_as_itself fail with left: Refused, right: Loaded.

800 serial tests, clippy -D warnings, switches --check, no-game-data and diff clean.

Not verified here

The live load-vs-compile wiring and the real first-caller timings need a D3D12 device and the title. This machine has no game run, so the PR stops at the instrument.

Run request (for whoever can run it)

  1. leonida warm (or warm --used) against your cache, then play ~10 minutes of driving with LEONIDA_PIPELINE_FIRST_USE=1.
  2. Paste the pipeline first use summary: line and the slowest pipeline first use: rows (keys are hashes, no game data).

That tells us whether the in-play compiles are new keys (variant/area), warmed keys the library missed, or driver-cache losses - which fixes to build next. A warmed loaded waited 0.x ms-only report with in-play 0 means the cache is doing its job.

Item: D3D12-PIPELINE-FIRST-USE (part 1), claimed in #3312. Depends on: none. Related: #3489 (part 2, library restart proof).
AI-assisted: DeepSeek V4.1 Flash (OpenCode); a read-only reviewer audited the diff twice.

## What/why #3103 asks for exactly this: for each host pipeline, was its key in the warm-up snapshot, did the runtime load it from the library or compile it, and **how long did the first caller wait**. The number the issue is missing is the one behind "522 pipelines still made during play": `in-play (new/made)`. Diagnostics only, **off by default**: `LEONIDA_PIPELINE_FIRST_USE=1`. ## What it prints One line per pipeline at first use (capped at 4096; counts continue past the cap): ```text pipeline first use: 0123456789ab graphics new made waited 12.3 ms ``` `kind` is `graphics`, `compute`, `mesh` or `other`; the class is `warmed|new` (key in `early-pipelines.txt` or not) crossed with `loaded|made|refused`. One summary, at a clean end **or on a device loss**: ```text pipeline first use summary: warmed/loaded 1200 warmed/made 5 warmed/refused 0 new/loaded 0 new/made 0 new/refused 0; 1205 total, waited 123.4 ms, worst 12.3 ms; in-play (new/made) 0; 0 not logged ``` `in-play (new/made)` is the count to compare with 0 on a warmed cache. `warmed/made` means the key was in the snapshot but the library did not serve it; `new/loaded` means the library had a pipeline the snapshot lacked; `new/made` are the true in-play compiles. ## How it is measured - The key is `Pending::key`, the title pipeline key - the same string `early-pipelines.txt`, `known-pipelines.bin` and `leonida warm` use. (`library::name` is a different host-description hash and is never written to that file.) - **First caller's wait** is first request -> usable, stamped once on the first `ready`/`masked_for` (or a builder request) and completed when the build ends; a timed-out wait is reported as the time before the draw fell back. Later retries cannot overwrite it. - `loaded` vs `made` comes from `library::pipeline`: `Load*PipelineState` success raises `LOADED`, the `Create*PipelineState` fallback raises `MADE`. A `mesh_compute` build records the graphics PSO that is drawn, not the auxiliary compute one. - The snapshot is read **once at cache setup**, before any worker can rewrite `early-pipelines.txt`, so a cold run cannot classify its own new keys as warmed. - Exactly once per key: the existing `used` swap, a print swap and a report dedupe by key. - Off: one cached bool at the first use; no allocation or lock on the draw path. `Pending::new` still constructs four atomics, nothing else. ## Tests 10 device-free tests in `pipeline/first_use/tests.rs`: classifier cross (warmed/new x loaded/made/refused), `Source` round trip (the test that catches swapped discriminants), once-per-key, first-wait-wins, exact line format, cap-stops-lines-not-counts, snapshot filter (32 lowercase hex, CRLF, non-hex, short key), summary counts including `in-play (new/made)`. **Red evidence:** reverting only the source logic makes `the_classifier_crosses...`, `a_key_is_counted_once`, `the_cap_stops_lines_but_not_the_counts` fail; reverting only `Source` to the old implicit discriminants makes `a_source_reads_back_as_itself` fail with `left: Refused, right: Loaded`. **800 serial tests**, clippy `-D warnings`, switches `--check`, no-game-data and diff clean. ## Not verified here The live load-vs-compile wiring and the real first-caller timings need a D3D12 device and the title. This machine has no game run, so the PR stops at the instrument. ## Run request (for whoever can run it) 1. `leonida warm` (or `warm --used`) against your cache, then play ~10 minutes of driving with `LEONIDA_PIPELINE_FIRST_USE=1`. 2. Paste the `pipeline first use summary:` line and the slowest `pipeline first use:` rows (keys are hashes, no game data). That tells us whether the in-play compiles are **new keys** (variant/area), **warmed keys the library missed**, or **driver-cache losses** - which fixes to build next. A `warmed loaded waited 0.x ms`-only report with `in-play 0` means the cache is doing its job. Item: D3D12-PIPELINE-FIRST-USE (part 1), claimed in #3312. Depends on: none. Related: #3489 (part 2, library restart proof). AI-assisted: DeepSeek V4.1 Flash (OpenCode); a read-only reviewer audited the diff twice.
Log each host pipeline's first use once: the title pipeline key's first 12 hex digits, its kind, whether its key was in early-pipelines.txt (warmed/new), whether this run loaded it from the library or compiled it (a refusal too), and the first caller's wait. A summary counts each class, the total and worst wait, and the new/made pipelines compiled in play (the number that should be zero on a warmed cache).

The snapshot is keyed by the title pipeline key (Pending::key): library::note_used writes it to early-pipelines.txt and leonida warm matches it against known::keys. library::name is a different string (the host library name) and is not used for the lookup. The snapshot is primed when the cache folder is set, before a save can rewrite it.

Off by default; the draw path pays one cached bool, and the existing wait accounting supplies the wait. The summary is written at a clean end and, non-blocking, on a device loss.
KelboLive force-pushed d3d12/pipeline-first-use from f3a39d3ad7 to e5beee018f 2026-12-04 20:53:12 +00:00 Compare
Author
First-time contributor

Replayed onto main 0036195a7 (head e5beee018). No conflicts. 800 passed, 0 failed, 60 ignored; switch page ok.

Replayed onto `main` `0036195a7` (head `e5beee018`). No conflicts. 800 passed, 0 failed, 60 ignored; switch page ok.
KelboLive force-pushed d3d12/pipeline-first-use from e5beee018f to e7f0b52fd0 2026-12-04 23:20:32 +00:00 Compare
Author
First-time contributor

Replayed onto main f4b0404e9 (head e7f0b52fd). No conflicts; switch page ok. 800 passed, 0 failed, 60 ignored.

Replayed onto `main` `f4b0404e9` (head `e7f0b52fd`). No conflicts; switch page ok. 800 passed, 0 failed, 60 ignored.
Contributor

Five synthetic tests passed for the first-use report. The generated rows exercise all six combinations of warmed/new and loaded/made/refused. The fixture includes a warmed pipeline that is made again and a new pipeline that loads. Omitting the new/made row with not logged = 1 retains its class in the summary.

The checker rejects a relabeled row, an inconsistent total, a missing warm-up snapshot, or conflicting summaries. A native library restart and a held compile remain separate producer tests. Native library restart #3489

AI-assisted.

Five synthetic tests passed for the first-use report. The generated rows exercise all six combinations of `warmed/new` and `loaded/made/refused`. The fixture includes a warmed pipeline that is made again and a new pipeline that loads. Omitting the `new/made` row with `not logged = 1` retains its class in the summary. The checker rejects a relabeled row, an inconsistent total, a missing warm-up snapshot, or conflicting summaries. A native library restart and a held compile remain separate producer tests. [Native library restart #3489](https://git.leonida.now/leonida/mandy/pulls/3489) AI-assisted.
KelboLive force-pushed d3d12/pipeline-first-use from e7f0b52fd0 to 122d1e03f5 2026-12-05 05:34:54 +00:00 Compare
Author
First-time contributor

Replayed onto main 93b9d90a2 (head 122d1e03f). No conflicts. 800 passed, 0 failed, 60 ignored.

Replayed onto `main` `93b9d90a2` (head `122d1e03f`). No conflicts. 800 passed, 0 failed, 60 ignored.
KelboLive force-pushed d3d12/pipeline-first-use from 122d1e03f5 to 077a4c87d5 2026-12-05 08:44:33 +00:00 Compare
Author
First-time contributor

Replayed onto main c5355dd25 (head 077a4c87d). No conflicts. 801 passed, 0 failed, 60 ignored.

Replayed onto `main` `c5355dd25` (head `077a4c87d`). No conflicts. 801 passed, 0 failed, 60 ignored.
KelboLive force-pushed d3d12/pipeline-first-use from 077a4c87d5 to 439a848f1d 2026-12-05 08:53:32 +00:00 Compare
Author
First-time contributor

Replayed onto main e1b0248c1 (head 439a848f1). No conflicts. 801 passed, 0 failed, 60 ignored.

Replayed onto `main` `e1b0248c1` (head `439a848f1`). No conflicts. 801 passed, 0 failed, 60 ignored.
KelboLive force-pushed d3d12/pipeline-first-use from 439a848f1d to 26ac259772 2026-12-05 09:59:48 +00:00 Compare
Author
First-time contributor

Replayed onto main d99bb4d7a (head 26ac25977). No conflicts. 804 passed, 0 failed, 60 ignored.

Replayed onto `main` `d99bb4d7a` (head `26ac25977`). No conflicts. 804 passed, 0 failed, 60 ignored.
Sign in to join this conversation.
No description provided.