Skip to content

d3d12: warm-up creates no longer hold the compile gate (RT-COMPILE-GATE-WARMUP-FREE) - #2275

Open
Tyrannys wants to merge 7 commits into
ProjectLeonida:mainfrom
Tyrannys:claude/compile-gate-warmup-free
Open

Tyrannys wants to merge 7 commits into
ProjectLeonida:mainfrom
Tyrannys:claude/compile-gate-warmup-free

Conversation

@Tyrannys

@Tyrannys Tyrannys commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: RT-COMPILE-GATE-WARMUP-FREE (claim)

Depends on: nothing. #2233 has landed on main, so this PR now depends on nothing else.

main is merged in (e1bf0b8), with #2233 and the adaptive compile gate (#2412, #2462). After lixonik's review, a speculative create (compute warm-up; graphics/mesh prewarm of #2260) passes the gate without holding submissions only if it is a compute create and the gate is adaptive (SubmitMutex::warmup_passes), and not where the adaptive verdict says the driver holds submissions. With classic (forced or chosen by auto), with LEONIDA_COMPILE_GATE=1, and for graphics/mesh prewarms, it holds the gate as a demanded create does; LEONIDA_COMPILE_GATE_WARMUPS=0 opts compute warm-ups in with every gate, =1 makes all hold.

What and why

The compile gate (SubmitMutex::CompileTurn, runtime/src/vulkan_device_fault.h) keeps a queue submission out of the driver while any pipeline create is in it. That covers warm-ups too, which nobody is waiting for. HasiKe's cold boots on an RTX 2070 SUPER (#2233) show the cost:

  • With the gate on, the title demanded about 6 builds in 300 s. About 290 s of serial warm-ups ran meanwhile, and the title crawled at about 1 submission a second.
  • With LEONIDA_COMPILE_GATE=0 it ran at about 100 frames a second.

MoonEyes measured the same in #1608 (07:32): 142 s of submission waits behind warm-ups, and game state 3 reached with the gate off. The gate must stay for demanded creates (the device losses it was added for), so this narrows it to them:

  • Submissions wait only for demanded creates. A create made by a compile worker's speculative job passes the gate as speculative (a warm-up, a prewarm from runtime: prewarm graphics pipelines in recorded order on the compile pool (RT-PIPELINE-PREWARM-ORDER phase 2) #2260, or the checkpoint). The worker sets the thread-local compile_job_speculative for the length of such a job, and DriverTurn passes it to CompileTurn. enter_submit waits only for the demanded creates in the driver. A warm-up's pipeline is simply not ready yet: a draw or dispatch that needs it builds it or waits for it, as before.
  • The creates beside a submission stay bounded:
    • A warm-up still never enters the driver while a submission is in it or waiting at the gate. A submission that is already waiting therefore keeps new warm-ups out.
    • At most LEONIDA_COMPILE_GATE_WARMUP_MAX warm-ups (default 1) are in the driver at once.
    • With d3d12: a pool of compile workers for the pipeline compiler (RT-ASYNC-COMPILE-POOL) #2233's pool there is at most one warm-up anyway, and none starts while a demanded build is queued or running. So while the title submits, the driver sees the demanded builds plus at most one warm-up.
  • Switches:
    • LEONIDA_COMPILE_GATE_WARMUPS=1 makes warm-ups hold the gate again, the behaviour before.
    • LEONIDA_COMPILE_GATE=0 still turns the whole gate off, unchanged.
  • Demanded builds on the title's thread (synchronous mode) and on the pool are unchanged: they hold the gate as before.

Risk, and why it is opt-out rather than opt-in: a submission can now be in the driver while one warm-up create runs. That is the case the gate was first added for (NVIDIA 630.20, a submission behind a long warm-up create lost the device). HasiKe has since corrected their own report: their TDR with the gate off at 249.7 s matches fiestorra's world-load GPU hang, which happens with no pipeline build at all, and says nothing about parallel creates. So no current measurement shows a create beside a submission losing the device. This pull request keeps that overlap to one warm-up at a time. HasiKe offered to run it on their card; the result decides whether the default stays.

Tested

  • submit_mutex_test (CPU), new case warmups_do_not_hold_the_gate:

    • a submission passes while a warm-up is in the driver (under 50 ms);
    • with a warm-up and a demanded create in the driver, the submission waits for the demanded one and not for the warm-up;
    • with max 1 and 2, four warm-ups never have more than max in the driver at once, and a demanded create does not wait for them;
    • a warm-up does not enter while a submission is in the driver;
    • with warm-ups held (LEONIDA_COMPILE_GATE_WARMUPS=1), a submission waits for a warm-up as before;
    • the settings parse.

    The earlier gate cases (a submission waits for a create, a create waits behind a waiting submission, creates share the gate) still pass.

  • d3d12_compile_pool_test, new case: a warm-up's and the checkpoint's jobs run with compile_job_speculative set, a demanded job without, also on a worker that ran a warm-up before (one worker and three).

  • Each gate rule was broken by hand in turn (4 mutants: warm-ups hold submissions, the policy ignored, no cap, a warm-up entering during a submission), and submit_mutex_test failed for every one.

  • With the change, these pass (15 of 15): submit_mutex, d3d12_compile_pool, d3d12_compile_teardown (pool and one worker), big_compile_gate, d3d12_big_compute (all 7 settings), d3d12_m4_compute, d3d12_pipeline_workers and d3d12_pipeline_workers_eager. A boot was running on this machine, so the full suite was not run.

  • python -I tests/test_docs_env_vars.py, tests/test_docs_repo_paths.py, scripts/check_no_game_data.py on the changed files: pass.

Not tested here: a real boot. A cold boot on HasiKe's card, and ours, with the gate on is the measurement that matters (submissions a second while warm-ups run, and whether the device stays).

GPUs tested: profile M: NVIDIA GeForce RTX 4070 SUPER, 12 GB, desktop, driver 621.01, Windows 11

AI-assisted: yes (Claude Code)

Checklist

  • Based on current main and merges cleanly.
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)

🤖 Generated with Claude Code

…TE-WARMUP-FREE)

A queue submission waited at the compile gate for every pipeline create in
the driver, warm-ups included. On a cold boot (HasiKe, RTX 2070 SUPER, ubiquitarianism#2233)
the title crawled at about one submission a second behind 290 s of serial
warm-ups; with the gate off it ran at about 100 frames a second.

A compile worker now marks its speculative jobs (warm-ups, prewarms, the
checkpoint) with the thread-local compile_job_speculative, and DriverTurn
passes that to SubmitMutex::CompileTurn. A submission waits only for the
demanded creates in the driver. A warm-up still never enters while a
submission is in the driver or waiting at the gate, and at most
LEONIDA_COMPILE_GATE_WARMUP_MAX (default 1) warm-ups are in the driver at
once, so the creates beside a submission stay bounded.
LEONIDA_COMPILE_GATE_WARMUPS=1 restores the old behaviour;
LEONIDA_COMPILE_GATE=0 still turns the gate off.

Tests: submit_mutex_test gets warmups_do_not_hold_the_gate (a submission
passes a warm-up, still waits for a demanded create, the warm-up cap, no
warm-up during a submission, the old policy, the settings);
d3d12_compile_pool_test checks which jobs run as speculative.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Tyrannys

Copy link
Copy Markdown
Contributor Author

One boot with this PR and the compile gate on: RTX 4070 SUPER (12 GB), NVIDIA 621.01, Windows 11, 64 GB. Counts only.

Tree: main a73a57e + #1851 #1905 #1957 #1886 #1894 #1914 #1882 #2195 #2113 #1592 #2097 + #2233 #2179 #2228, #2260 at 6f2b52e, and this PR (all clean merges). Recipe: async pipelines, prewarm from the previous run's order log (846 graphics pipelines planned), a local skip list of the 1,009 ray-hit shading programs, LEONIDA_RT_AS=off, LEONIDA_DEVICE_FAULT=0, the watchdog kicked, LEONIDA_ARENA_MB=1536, LEONIDA_TITLE_WINDOWS_MB=1024, warm offline, heavy and journal caches. LEONIDA_COMPILE_GATE unset (on), LEONIDA_COMPILE_GATE_WARMUP_MAX default.

F3 (gate on, before #2233/#2275, my #1608 runs) F6 (gate off) F7 (gate on + this PR)
game state 3 at 260 s 110 s 95 s
submissions during the load (60-100 s) - - 27-36/s, 13-18 frames/s
gate waits by a submission - - 41, 909 ms in all, longest 117 ms
end title crash at 1,093 s title crash at 1,544 s device lost at 270 s (vkQueueWaitIdle), then exit 0xC0000005 at 291 s
  • With the gate on, the load is now as fast as with it off. Submissions waited less than 1 s in all, against 142 s in MoonEyes' gate-on run.
  • The device loss came about 25 s after world entry. At that moment the HUD showed VRAM over the budget (12.2 GB used against 10.6 GB), as in every world run on this 12 GB card. LEONIDA_DEVICE_FAULT was 0, so there is no fault report. With one run, I can't tell whether a submission running beside a warm-up create played a part. None of my gate-off runs lost the device. The next run here repeats F7 with LEONIDA_DEVICE_FAULT=1.
  • 320 builds ran on the dispatch workers. Compute warm-ups over 128 KiB were left to first use from t=76 s (LEONIDA_COMPUTE_WARMUP_LIVE_MAX_BYTES=131072).

AI-assisted (Claude Code).

@Tyrannys

Copy link
Copy Markdown
Contributor Author

Second run with this PR, the same recipe and the gate on, with LEONIDA_DEVICE_FAULT=1 (F7b). It never reached the world.

  • Up to ~200 s it matched F7. Then the submissions stalled behind pipeline creates the title had asked for (dispatch-worker builds of library compute programs of 130-150 KB, not warm-ups). The last gate summary, at 518 s, says: "56 submissions waited for pipeline creates (310559 ms in all, longest 33414 ms); 67 creates waited behind a submission (169458 ms in all, longest 9845 ms)". The device-stall watcher logged "could not sample the submit lock (its holder waits at the compile gate) for 15 s" 8 times.
  • Indirect graphics at the end: recorded 5,517, emitted 2,048. That is the load, not the world (world runs here reach 65,536 emitted). No device loss. I stopped it at 542 s.
  • So with the gate on, demanded builds can still hold submissions for tens of seconds at a time on this machine. Of 2 runs with the gate on, one lost the device at 270 s (F7) and one stalled (F7b). With the gate off, 4 of 4 recent runs on the same caches reached the world (F3g, F4a, F4b, F6). I'm going back to LEONIDA_COMPILE_GATE=0 here.

AI-assisted (Claude Code).

@HasiKe

HasiKe commented Nov 26, 2026

Copy link
Copy Markdown

@Tyrannys, here is the cold boot you asked for, with the gate on, on the RTX 2070 SUPER. AI-assisted (Claude Code).

Tree: main a73a57e13 + #2195 + #2233 + this PR (e4713a440, a clean merge). There is also a local diagnostic patch of mine, LEONIDA_SKIP_GRAPHICS, which was not set in these runs. d3d12_compile_pool_test and the other compile/submit tests pass.

Setup: NVIDIA 616.56, Windows 11 Pro 26300, my own 1.0.2.1 package. One binary for both runs, A/B via LEONIDA_COMPILE_GATE_WARMUPS=1. Both boots were cold: no session or seed cache, an empty journal and their own empty __GL_SHADER_DISK_CACHE_PATH. Settings: LEONIDA_ASYNC_PIPELINES=1, gate on (LEONIDA_COMPILE_GATE unset), LEONIDA_DEVICE_FAULT=2, the watchdog kicked, LEONIDA_CONSOLE_FIX_US=0, 4096 MB title windows and arena, the keyboard pad, 300 s each.

this PR (warm-ups free) LEONIDA_COMPILE_GATE_WARMUPS=1 (old)
warm-ups built 1,131, 284.4 s in all (12 over 2 s, max 5.5 s) 1,156, 290.3 s in all (10 over 2 s, max 6.9 s)
demanded builds 6 6
submissions waiting at the gate, at the last summary 1, 159 ms (a demanded dispatch-worker create at 28 s) 841, 264.6 s in all, the longest 6.9 s (t=294 s)
creates that waited behind a submission 0 1, 0 ms
submissions in 300 s 74,012 745
submissions/s and frames/s, steady 280-300/s, 140-150 frames/s from 45 s on 1.4-5/s, 0.8-2.6 frames/s
device loss none none

So, on this card:

  • The warm-ups compile just as long in both runs, about 285-290 s.
  • With this PR, though, the title is no longer behind them. It reaches the same 140-150 frames/s that a warm-cache boot gets here, about 45 s after launch.
  • In the old run, the gate summary accounts for the crawl directly: 264 s of submit waiting in 294 s of boot. My earlier reading, that the warm-ups at the gate caused it, now has its measurement.
  • The warm-up cap of one did not cost the title anything visible: the next demanded build waited 0 ms behind one.

Neither boot reached the world. My input script only enters it at 314 s. So this says nothing about the world-load hang. That hang is a separate problem, a VS-as-mesh-shader draw that never finishes on the GPU (#1608, follow-up), and it also happens with the gate off.

The cold boot on this machine goes from unusable to normal speed, so this PR looks like a clear win to me.

@qhukz13

qhukz13 commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

I checked e4713a440 merged onto main 73516a290 (no conflicts) on Windows 10 / MSVC 14.44, GTX 1050 Ti host. d3d12_compile_pool_test and submit_mutex_test pass 2/2, plain and with LEONIDA_VK_VALIDATION=1, three repeats each.

The production switch has no test. Only one line passes "this create is speculative" to the gate in the runtime: d3d12_pipeline_compile.h:168, gate_.emplace(submits, compile_job_speculative);. I replaced it with gate_.emplace(submits);, which is exactly main's behaviour: every warm-up holds the gate again. Then I rebuilt gta6rt, d3d12_compile_pool_test and submit_mutex_test:

  • everything builds;
  • both tests still pass, 2/2.

submit_mutex_test drives SubmitMutex::CompileTurn(m, true) directly. d3d12_compile_pool_test checks that compile_job_speculative is set for a warm-up and for the checkpoint. Nothing constructs a DriverTurn (git grep DriverTurn runtime/test/ finds only a comment at d3d12_compile_pool_test.cpp:356). So the one line that turns the feature on in the game is untested. A small test would close it:

  • a DriverTurn with a pipeline, made while compile_job_speculative is true;
  • a SubmitTurn on the same gate must then not wait;
  • and it must wait once the flag is false.

Docs that no longer match:

  • runtime/README.md:418 (LEONIDA_COMPILE_GATE) still says unset means the workers compile while other queues submit, and 1 opts into holding the lock. compile_gate_enabled() (vulkan_device_fault.h:434-440) has the gate on unless the variable is 0, which is what the next row says. Was this row already stale on main?
  • docs/d3d12_vulkan.md around 2617-2619 and 2635-2636 still says, in the present tense, that a compute warm-up holds the gate for its whole create and every submission waits behind it. The new paragraph between them says the opposite by default.
  • The new row and the comment at d3d12_pipeline_compile.h:145 say a prewarm and the checkpoint also pass as speculative. No prewarm exists on main (that is runtime: prewarm graphics pipelines in recorded order on the compile pool (RT-PIPELINE-PREWARM-ORDER phase 2) #2260). save_session_pipeline_cache does no pipeline create and never enters DriverTurn. So only compute warm-ups are actually affected today.

The risk is stated well. A submission can now be in the driver beside one warm-up create. That is the NVIDIA 630.20 case the gate was added for. It is capped at one at a time (LEONIDA_COMPILE_GATE_WARMUP_MAX, and PipelineCompiler::next_locked already starts one warm-up at a time), and LEONIDA_COMPILE_GATE_WARMUPS=1 restores the old behaviour. I have no world boot on this card yet, so I can't add a measurement.

The code reading behind these points was done with a second agent and checked line by line before writing this.

AI-assisted (Claude Code, with Antigravity / Gemini 4 Neon).

…te-warmup-free

Brings ubiquitarianism#2233's one-build-per-PSO fix and current main. Conflicts in
docs/d3d12_vulkan.md and d3d12_compile_pool_test.cpp's header, both kept.

Also, from qhukz13's review of ubiquitarianism#2275:
- test_a_driver_turn_passes_the_speculative_flag_to_the_gate: a DriverTurn
  made on a speculative job's thread lets a submission pass, and holds it
  otherwise. It fails when DriverTurn drops the flag.
- Docs say what is affected today: compute warm-up creates (graphics builds
  never pass the gate; the checkpoint makes no create). The
  LEONIDA_COMPILE_GATE row now describes both 0 and 1.
- test_a_checkpoint_sees_a_demand_that_started_during_it waits for the pool
  to be idle before its last check (it raced the job's removal).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Tyrannys added a commit to Tyrannys/leonida that referenced this pull request Nov 27, 2026
…test's last check

The demanded job leaves the running list only after its function returns,
so has_compile_waiter() could still see it right after the log said it had
finished (1 failure in 10 runs). Found while merging this into ubiquitarianism#2275.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Tyrannys

Copy link
Copy Markdown
Contributor Author

@qhukz13 thank you for checking this, and for finding the untested line. All three points are addressed; current main and #2233's fixes are merged in (a7a48f1).

  • The switch now has a test. test_a_driver_turn_passes_the_speculative_flag_to_the_gate in d3d12_compile_pool_test builds a real DriverTurn with a pipeline. With compile_job_speculative true, a SubmitTurn on the same gate passes at once; with it false, the submission is still held after 150 ms and passes once the create leaves. With your mutant (gate_.emplace(submits);) it fails (submitted.load() == speculative). Restored, it passes.
  • Docs:
    • The LEONIDA_COMPILE_GATE row was already stale on main. It now says the gate is on unless 0, and that 1 additionally holds the submit lock for compute builds (compute_driver_turn).
    • The "Compile workers" paragraph says only compute creates pass the gate.
    • The new paragraph names what is affected today: compute warm-up creates. A prewarm only once runtime: prewarm graphics pipelines in recorded order on the compile pool (RT-PIPELINE-PREWARM-ORDER phase 2) #2260 lands; the checkpoint is speculative but makes no create. The comment at d3d12_pipeline_compile.h says the same.
    • The older present-tense paragraphs are marked as describing LEONIDA_COMPILE_GATE_WARMUPS=1.
  • Also fixed on the way: the checkpoint test from d3d12: a pool of compile workers for the pipeline compiler (RT-ASYNC-COMPILE-POOL) #2233 raced the job's removal in its last check (1 failure in 10). It now waits for an idle pool; 30 of 30 runs pass.

After the merge: submit_mutex, d3d12_compile_pool, d3d12_compile_teardown*, d3d12_big_compute*, d3d12_pipeline_workers*, d3d12_m4_compute and big_compile_gate, 15 of 15. Profile M: RTX 4070 SUPER 12 GB desktop, NVIDIA 621.01.

@HasiKe thanks again for the A/B on the RTX 2070 SUPER (74,012 against 745 submissions in 300 s, no device loss). That is the measurement this needed.

AI-assisted (Claude Code)

Tyrannys and others added 2 commits November 27, 2026 07:33
…warmup-free

# Conflicts:
#	docs/d3d12_vulkan.md
…-warmup-free

Main now has ubiquitarianism#2233 (the compile pool) and the adaptive compile gate (ubiquitarianism#2412, ubiquitarianism#2462).
The warm-up-free gate is ported onto it: a speculative create is an InDriver entry
flagged speculative that submissions do not wait for, at most warmup_max in the
driver at once, except one of a kind whose verdict is driver_holds, which is waited
for as a demanded create is. submit_mutex_test checks that case too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Tyrannys

Copy link
Copy Markdown
Contributor Author

Merged main (ec91d69, with #2233 and the adaptive gate #2412/#2462; warm-up rule ported onto it) in at d61c909; submit_mutex, d3d12_compile_pool, d3d12_compile_teardown, d3d12_compile_teardown_one_worker, d3d12_pipeline_workers, d3d12_pipeline_workers_eager and pipeline_workers pass. AI-assisted (Claude Code)

@lixonik lixonik left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed and tested at d61c90965 (merged cleanly onto main ec91d695c).

The warm-up-free compile gate mechanics and test coverage in submit_mutex_test / d3d12_compile_pool_test are clear and well structured, and both suites pass. I found two behavioural edge cases on current main (plus one minor API guard) noted inline:

  1. classic / auto: classic / LEONIDA_COMPILE_GATE=1 bypass: because verdict_[kind] stays pending when adaptive_ is false, if (c.speculative) return false; in is_blocking() still lets submissions enter beside compute warm-ups even when auto calibration deliberately picked classic because the driver holds submissions (e.g. NVIDIA 630.20) or when LEONIDA_COMPILE_GATE=1 is requested.
  2. Interaction with #2260 graphics/mesh prewarm on main: PipelineState::prewarm_queue submits graphics/mesh prewarms with non-zero priority (compile_job_speculative = true), while auto calibration only probes a compute pipeline. On drivers where compute does not hold submissions (auto --> adaptive) but mesh creates do (e.g. 621.40), verdict_[graphics] starts pending and submissions enter immediately beside a mesh prewarm.
  3. Minor: set_warmup_policy() does not clamp policy.max >= 1 (passing 0 deadlocks a speculative create).

Verified locally on Windows 11 (MSVC 19.44.35230.0, Ninja Release):

  • submit_mutex: passed (42.26 s, including the warm-up and holding-kind cases)
  • d3d12_compile_pool: passed (2.10 s, including compile_job_speculative and DriverTurn checks)
  • scripts/check_no_game_data.py and git diff --check: clean

AI-assisted.

bool is_blocking(const InDriver& c) const {
if (kind_off(c.info.kind)) return false;
if (verdict_[std::size_t(c.info.kind)] == GateVerdict::driver_holds) return c.seq > held_overdue_through_;
if (c.speculative) return false; // a warm-up, of a kind not known to hold submissions

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In classic mode -- including LEONIDA_COMPILE_GATE=auto when startup calibration deliberately picks classic because the driver holds submissions behind compute creates (e.g. NVIDIA 630.20) -- and in LEONIDA_COMPILE_GATE=1 (GateMode::always), adaptive_ is false so probe() returns early and verdict_[kind] stays GateVerdict::pending permanently.

Because policy_.free defaults to true, if (c.speculative) return false; still lets vkQueueSubmit enter the driver beside compute warm-ups in auto: classic / classic (and beside graphics prewarms under =1), defeating the calibration fallback meant to avoid device loss on holding drivers. Gating the speculative bypass on adaptive_ (or disabling policy_.free when compile_gate_mode() is classic/always unless explicitly enabled) would preserve the non-adaptive modes' guarantee.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, right: with adaptive_ false no verdict ever comes, so the bypass hit exactly the drivers auto falls back to classic for. Fixed in 3582924: whether a speculative create passes is now decided in enter_compile under gate_mutex_ (warmup_passes): only a compute create with the adaptive gate. With classic (forced or chosen by auto) and with LEONIDA_COMPILE_GATE=1 every speculative create holds submissions as a demanded one does, and CompileTurn::speculative() reports false. LEONIDA_COMPILE_GATE_WARMUPS=0 is the explicit opt-in to let compute warm-ups pass with those gates too (documented with its cost on a holding driver); =1 still makes every warm-up hold. submit_mutex_test checks each mode: adaptive, classic, =1, =0 under classic and =1, and =1 under adaptive, each on a gate of its own. AI-assisted (Claude Code)

Comment thread runtime/shims/d3d12_pipeline_compile.h Outdated
stats_.most_running = (std::max)(stats_.most_running, running_.size());
const auto probe = probe_;
lock.unlock();
compile_job_speculative = speculative; // its creates do not hold submissions (DriverTurn)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With #2260 (LEONIDA_PIPELINE_PREWARM_ORDER) now on main, PipelineState::prewarm_queue submits graphics and mesh prewarm jobs with non-zero priority (leonida::pipeline_prewarm::priority(entry.rank)), so speculative (and compile_job_speculative) is true for graphics/mesh prewarms too, not just compute warm-ups (also making the (only compute warm-ups exist) note in runtime/README.md stale).

More importantly, auto calibration only probes a compute pipeline. On drivers where compute does not hold submissions (auto --> adaptive) but mesh pipeline creates do hold submissions (e.g. NVIDIA 621.40), verdict_[graphics] starts pending, so marking graphics/mesh prewarms speculative lets submissions enter the driver immediately beside a long mesh prewarm before a graphics verdict exists. Consider restricting the speculative bypass to CreateKind::compute (or requiring verdict_[graphics] == driver_does_not_hold for graphics prewarms).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, and thanks for catching the #2260 interaction. Graphics and mesh prewarms stay speculative jobs (the pool still schedules them as such: lower priority, never ahead of demanded builds), but at the gate they now hold submissions as a demanded create does: warmup_passes only lets a compute create through, since the calibration measures only compute and 621.40 held a submission 54 s beside a mesh create. So a mesh prewarm is waited for whatever the compute verdict is. The (only compute warm-ups exist) note is gone; README and docs/d3d12_vulkan.md now name the prewarms and say they hold the gate, and the compile_job_speculative comments say the gate decides. Tests: a speculative graphics create holds a submission with the adaptive gate and with =1 (submit_mutex_test), and the same through DriverTurn with kind = graphics (d3d12_compile_pool_test). AI-assisted (Claude Code)

}
return policy;
}
void set_warmup_policy(WarmupPolicy policy) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: set_warmup_policy() stores policy.max without clamping it to at least 1 (unlike warmup_policy_from_environment()). Calling set_warmup_policy({true, 0}) would make speculative_ >= policy_.max permanently true and deadlock any speculative create. Also, applying speculative = speculative && policy_.free inside enter_compile() under gate_mutex_ (instead of taking gate_mutex_ separately in warmups_free()) would make direct enter_compile() callers honor policy_.free atomically.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 3582924: set_warmup_policy clamps max to 1-64 (the same range the environment accepts), and policy_.free is read in enter_compile under gate_mutex_ together with the mode and kind, so direct enter_compile callers follow it too; the separate warmups_free() is gone. submit_mutex_test runs the cap case with max 0 (taken as 1, no deadlock), 1 and 2. AI-assisted (Claude Code)

@github-actions github-actions Bot removed the needs rebase Conflicts with the base branch: rebase it on main label Nov 27, 2026
Tyrannys and others added 2 commits November 27, 2026 10:17
…adaptive gate

lixonik's review of ubiquitarianism#2275: with the classic gate and LEONIDA_COMPILE_GATE=1
no verdict is ever reached, so a warm-up passed the gate there too, also
where auto's calibration chose classic because the driver holds submissions
(630.20). And since ubiquitarianism#2260, graphics and mesh prewarms are speculative jobs as
well, while the calibration measures only a compute create (621.40 held a
submission 54 s beside a mesh create).

warmup_passes now decides, under gate_mutex_, in enter_compile: a
speculative create passes without holding submissions only if it is a
compute one and the gate is adaptive, or LEONIDA_COMPILE_GATE_WARMUPS=0
asks for it with every gate. Every other one holds the gate as a demanded
create does. set_warmup_policy clamps max to 1-64 (0 deadlocked speculative
creates). Tests for each mode, for a graphics prewarm (also through
DriverTurn) and for max 0; docs updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Tyrannys

Copy link
Copy Markdown
Contributor Author

Thanks @lixonik for the careful review and for testing it. All three points are addressed in 3582924, and main (55bd6f4) is merged in at e1bf0b8: speculative creates now pass the gate without holding submissions only as compute creates with the adaptive gate (or with LEONIDA_COMPILE_GATE_WARMUPS=0 as an explicit opt-in); graphics/mesh prewarms and all warm-ups under classic / =1 hold it; max is clamped. submit_mutex, d3d12_compile_pool, d3d12_compile_teardown, d3d12_compile_teardown_one_worker, d3d12_pipeline_workers, d3d12_pipeline_workers_eager and pipeline_workers pass. AI-assisted (Claude Code)

@lixonik lixonik left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed 3582924b6 / e1bf0b8ae and re-tested:

  • All three earlier points are cleanly addressed:
    1. warmup_passes(CreateKind) lets speculative creates pass without holding submissions only for CreateKind::compute under the adaptive gate (unless LEONIDA_COMPILE_GATE_WARMUPS=0 explicitly opts into everywhere), keeping classic / LEONIDA_COMPILE_GATE=1 warm-ups and graphics/mesh prewarms holding the gate as demanded creates do.
    2. set_warmup_policy clamps max to 1..64 (kMaxWarmups), preventing a max == 0 deadlock.
    3. Docs (docs/d3d12_vulkan.md, runtime/README.md) and tests cover every gate mode, graphics prewarm through DriverTurn, and max == 0.
  • Tested on Windows 11 (MSVC 19.44):
    • submit_mutex: passed (43.70 s).
    • d3d12_compile_pool: passed (2.28 s).

Looks good to merge.

AI-assisted (Antigravity, Gemini).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants