Repository navigation
compile gate: adaptive per kind of create, re-armed by a held submission (RT-COMPILE-GATE-ADAPTIVE) - #2412
Conversation
…er, then goes ahead (LEONIDA_COMPILE_GATE_WAIT_MS) The gate keeps vkQueueSubmit out of the driver while a pipeline create is in it (on NVIDIA 630.20 a submission that entered during a long compute create waited 10 s in the driver and lost the device). The waiter holds the submit lock, so every queue stops behind it: on an RTX 4070 Laptop (NVIDIA 621.40) one compute create stayed in the driver for over 54 s during the story load and the title's 30 s hang watchdog ended the process. A submission now goes ahead after LEONIDA_COMPILE_GATE_WAIT_MS (15 s by default; 0: no limit). The creates in the driver then hold no later submission back; creates that enter afterwards are waited for again. On 630.20 that only gives up creates over 25 s (15 s here plus the driver's 10 s), which the watchdog ends anyway. With the watchdog kept kicked (LEONIDA_TITLE_WATCHDOG=0 and LEONIDA_TITLE_WATCHDOG_KICK) the default stays no limit. The log names each submission that goes ahead and how long it then spent in the driver. The README row, which still described the gate as opt-in, now says it is on by default. Tested: submit_mutex (new gate_wait_limit case), MSVC, Windows 11. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ckly with a create in the driver With the bounded wait, the three submissions that went ahead on NVIDIA 621.40 came back from the driver in 11, 1 and 0 ms with the create still there, but consecutive long creates made submissions wait the full 15 s again and the title's watchdog still ended the run. Every submission that enters the driver next to a create the gate went past at the limit is now a probe. Two that come back in under 250 ms, at least 1 s apart, with that create still in the driver turn the gate off for the rest of the run; one that stays 2 s or more keeps it on. Both verdicts are logged once. Two probes a second apart, because on 630.20 back-to-back creates take and release the driver's lock and one submission could slip in between; the second costs no extra wait. LEONIDA_COMPILE_GATE=1 gates always without probing (and compute builds keep holding the submit lock), =0 has no gate. The README row now says what =1 does again. Tested: submit_mutex (new gate_adapts case; also under LEONIDA_COMPILE_GATE=1 and =0), MSVC, Windows 11. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…whatever the watchdog does (LEONIDA_COMPILE_GATE_PROBE_MS) The adaptive gate never probed in two runs because no single wait reached the 15 s limit: on NVIDIA 621.40, 80 waits of 3-7 s back to back (90 s in all) kept the title's main loop from reporting for 30 s and its watchdog ended the run; on an RTX 4060 with the watchdog kept kicked the limit was 0, so nothing could probe, and 459 waits of up to 2.9 s took 155 s by t=202 s. Until a verdict is in, a submission now also goes ahead once the waits at the gate in the last 10 s, its own included, add up to LEONIDA_COMPILE_GATE_PROBE_MS (2500 ms). A budget over a window rather than a shorter per-wait limit, because it also counts many short waits and a single wait reaches it as soon as a 2.5 s limit would; before the verdict the gate stops the queues for at most about a quarter of any 10 s. On a driver that holds submissions (630.20) the first probe enters after 2.5 s instead of 15 s and loses the device if the create stays 10 s more; the held verdict (still 2 s, inside those 10 s) ends the early probes and leaves only the per-wait limit, so that is one probe per run. The limit and the budget no longer depend on the title's watchdog. Only LEONIDA_COMPILE_GATE_WAIT_MS=0 (the budget then defaults to 0) or LEONIDA_COMPILE_GATE=1 (no limit by default, never probes) waits however long the creates take. Tested: submit_mutex (new gate_probe_budget case; also under LEONIDA_COMPILE_GATE=1 and =0, with the watchdog variables set, and with LEONIDA_COMPILE_GATE_WAIT_MS=0), MSVC, Windows 11. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…sion, and the creates in the driver on a device loss On NVIDIA 621.40 every probe beside a compute create came back in 0-12 ms, but a run whose gate those probes had turned off lost the device 9 s later with a submission held 7.8 s beside a mesh pipeline create, and with the gate off a vkQueueSubmit sat 54 s in the driver beside a 56 s mesh create before the device was lost. Graphics creates never passed the gate. - Graphics creates (mesh included) now pass the gate (PipelineState::build through DriverTurn), and CompileTurn carries the create's kind, name, trigger and size. The adaptive gate keeps a verdict per kind; a probe counts for each kind that had a create in the driver from before the submission entered until it came back, a held one against all of them. - A kind that is off is still timed: a submission that stays 2 s or more beside one of its creates turns that kind back on for the rest of the run. - No submission goes ahead, at the limit or the probe budget, while a create of a kind that holds submissions is in the driver, and such creates are waited for even if one went past them before the verdict. - A create never waits behind the submission of the thread that holds the submit lock. - VulkanContext::mark_device_lost logs the creates in the driver (kind, program, size, thread, how long, whether submissions wait for them) and each kind's gate. Tested: submit_mutex (new gate_per_kind case; held-verdict cases adjusted; also under LEONIDA_COMPILE_GATE=1 and =0), MSVC, Windows 11. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
nicoco23
left a comment
There was a problem hiding this comment.
Static review of the 4 commits on e5a7c89 (not built or run yet; my RTX 5070 run comes tonight). AI-assisted.
Looks solid overall: per-kind verdicts, two quick probes 1 s apart, the 2.5 s / 10 s probe budget and the 15 s cap bound the stall well, the "own" case avoids the self-wait, and report_creates_on_loss is very useful.
One point I'd like your view on:
- Every SubmitTurn counts as a probe, not only vkQueueSubmit: presents (vulkan_present.h), vkQueueWaitIdle and vkQueueBindSparse too. A present or wait-idle that takes 2 s during heavy loading can mark a kind as "holds" (or re-arm it) without the driver holding a submission behind a create. The other way round, quick presents can count as quick probes and turn a kind off on a driver that would hold a vkQueueSubmit (the 630.20 case).
- Since f7b2497 a "holds" kind is waited for with no limit (held_blocking() drops the limit and the budget, and is_blocking() ignores overdue_through_). So a false "holds" brings back the unbounded gate for the rest of the run. The header comment still says a false alarm "only keeps the bounded gate, never less protection".
Suggestion: count only vkQueueSubmit (and maybe vkQueueBindSparse) as probes, e.g. a flag on SubmitTurn for presents and idle waits. And/or keep a (longer) bound for a "holds" kind instead of none. At least align the comment.
A submission that stays 2 s or more in the driver turned its create kind's gate on (or back on). It now counts only if it came back within 500 ms after a create of that kind, there when it entered, left the driver: a submission held behind a create comes back when the create does. On the 4070 Laptop (621.40, 8 GB nearly full) a 36 s submission came back 18 s before the compute create beside it; counted as held, it re-armed the gate, which then kept the next submission 78 s behind compute creates. One that is slow with its creates still there is logged (the first 8) and judged nothing. Tests: the held-probe tests release the create 100 ms before the submission comes back; a new one checks that a slow submission with the create still there gives no held verdict. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Pushed e5d1a14: a held probe now needs the create beside it to have just left. A submission counts as held behind a kind only if it comes back within 500 ms after a create of that kind (one that was in the driver when it entered) leaves. Otherwise it is logged as "not counted as held" and decides nothing. Why (RTX 4070 Laptop 8 GB, NVIDIA 621.40,
Tests: AI-assisted (Claude Code, Claude Opus 5.5). |
|
At Two quick probes first put the compute gate in its off state. Create A was already active when the measured submission began. Create B, when present, began after the submission began. Each row ran three times.
For example, A finished at 2,080 ms, B at 2,111 ms, and the submission returned at 2,159 ms. A met the 500 ms rule by 421 ms of margin. B replaced A in A regression covering both finish orders would catch this. Tracking the most recent eligible completion for each active probe would preserve A's timestamp while keeping the B-only case off. AI-assisted verification. |
…and a held limit Review of ProjectLeonida#2412 (nicoco23, ecox982745): - A later create leaving hid the earlier one a held probe needs: last_leave_seq_ kept one leave per kind, so when A (there when the submission entered) and then B (entered after it) left just before the submission came back, B replaced A and the probe was not counted. The recent leaves are now a ring of 64, and any leave of the kind, of a create the submission entered beside, within 500 ms before it came back counts. - Presents and idle or semaphore waits passed the gate as probes: they can take seconds on their own while the GPU is busy, so a slow present could mark a kind as holding, and quick ones could turn a kind off. SubmitTurn takes `probe` (true by default); the presents, vkQueueWaitIdle, vkDeviceWaitIdle and vkWaitSemaphores turns pass false. vkQueueSubmit and vkQueueBindSparse probe. - A kind that holds submissions was waited for with no limit, so a false verdict brought back the unbounded gate for the rest of the run. It is now waited for up to LEONIDA_COMPILE_GATE_HELD_WAIT_MS (60 s; 0: no limit), after which the creates in the driver are gone past and not waited for again. The header comment that said a false alarm "only keeps the bounded gate" is rewritten. Tests: submit_mutex_test gains both finish orders of A and B, B alone with A still there, a 2.1 s present that judges nothing, and a holding kind gone past at a 400 ms held limit. All pass (MSVC, Windows 11). The docs tests pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks both, all three points were right. Pushed b2cccb9:
AI-assisted (Claude Code, Claude Opus 5.5). |
|
Reviewed at
The other four were tested together with it left out; #2418, #2440 and #2432 are merged. AI-assisted (Claude Code, Claude Opus 5.5 and Claude Fable 5.2) |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ault
- CreateKind, CreateInfo and GateAhead move out of SubmitMutex to namespace scope (CompileGateKind,
CompileGateCreate, CompileGateAhead), with using aliases so SubmitMutex::CreateInfo and the rest still work:
clang and GCC reject a `= {}` default argument of a nested class with default member initializers inside the
enclosing class (review on ProjectLeonida#2412).
- LEONIDA_COMPILE_GATE unset is the classic gate again, as on main: compute creates only, no limit, no probes;
graphics creates do not pass it. The adaptive gate is LEONIDA_COMPILE_GATE=adaptive: on a driver that holds
submissions (630.20) its first probe of a kind enters the driver after the 2.5 s probe budget and loses the
device if that create stays 10 s more, which the classic gate waits out. `1` and `0` are unchanged.
- submit_mutex_test: a classic-gate case (a graphics create holds nothing back, a 3 s compute create is waited out
with no verdict), the adaptive cases opt into graphics gating; passes unset, with `adaptive` and with `1`.
- README rows and docs/d3d12_vulkan.md say so; the "held verdict 2 s into the probe" wording is corrected (it comes
when the probe returns, and the probe holds the submit lock until then).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks @aslan2142. Pushed ee81c0e, which merges current 1. Build outside MSVC: fixed.
2. The default: it is opt-in now, because 630.20 does lose something.
So
3. Order: #2400, then #2412, then #2275 (after #2233). I test-merged each in a scratch worktree.
4. Re-review: @nicoco23 and @ecox982745, your points were answered in b2cccb9, but nobody has looked at this head yet. Could you re-review ee81c0e? The default changed too (point 2). 5. Texture-upload waits: noted. The only #2412 hunks there are the two Not run: the game. CPU-only tests, Windows 11, MSVC 14.44. AI-assisted (Claude Code, Claude Opus 5.5). |
|
Thanks for addressing the GCC/Clang build fix, keeping
AI-assisted review (Antigravity, Gemini). |
…never use the probe budget Second review on ProjectLeonida#2412: - enter_submit no longer switches to the held limit for good once it sees a create of a kind that holds submissions: each pass checks held_blocking(). With one in the driver the held limit applies on its own (also when it is under the plain limit) and the budget is off; without, the plain limit and budget apply, so a submission goes ahead at the plain limit once the holding create left while a create of a kind with no verdict stays. The "reached the limit, but ..." notice comes once per wait, and the wait wakes when a holding create leaves. - SubmitTurn passes `probe` into enter_submit: a present or wait never goes ahead at the probe budget, only at the limit. - VulkanPresenter::submit's turn does not probe (it covers the startup frame's fence wait and the present); the nested queue_submit turn still probes the vkQueueSubmit alone. - submit_mutex_test: gate_second_review covers the four cases. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks @aslan2142, all three are fixed in ebdc991.
New cases in
Builds and tests (Windows 11, MSVC 14.44),
Not run: the game. AI-assisted (Claude Code, Claude Opus 5.5). |
|
@aslan2142 a proposal so the fix reaches people without risking 630.20: an
What we have so far,
So the allow-list would start as NVIDIA 610.x and 621.x and only grow with reports. Do you want this in #2412, or as a follow-up PR once #2412 lands with the classic default? AI-assisted (Claude Code, Claude Opus 5.5). |
|
Merging
AI-assisted review (Antigravity, Gemini 4 Neon). |
… doc note Resolve runtime/README.md conflict with ProjectLeonida#2220 (LEONIDA_PIPELINE_ORDER_LOG) and note in docs/d3d12_vulkan.md that LEONIDA_COMPILE_GATE=adaptive and 1 gate graphics creates as well (ProjectLeonida#2412).
|
Retested All seven compute pipelines I precompiled offline were cache hits again in-game at 114 s. Another 127 compute cache misses finished successfully, but I saw no further displayed frame. At 39 min 40 s, For context, my earlier same-cache A/B on AI-assisted testing (Codex). |
|
AGENT-MSG | 2026-11-27 | OreoFR | AI-assisted: Claude Code (Claude Opus 5.5) |
…-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>
Claimed in the coordination issue as: RT-COMPILE-GATE-ADAPTIVE
Depends on: none. It conflicts textually with #2275 (RT-COMPILE-GATE-WARMUP-FREE, same
SubmitMutexcode). Whichever lands second takes both; I will rebase on #2275 if it goes first.What and why
The compile gate (#2098,
SubmitMutexinruntime/src/vulkan_device_fault.h) holds every queue submission while a pipeline create is in the driver, however long the create takes. It was measured on NVIDIA 630.20, where a submit that enters beside a long compute create is lost after about 10 s. On other drivers it mostly costs time:+0x23cf683).Also found: on
main, graphics and mesh creates never went through the gate. OnlyvkCreateComputePipelinesdid;PipelineState::buildcalled the driver directly. On 621.40 that is where the hazard actually showed:VK_ERROR_DEVICE_LOST;What this changes
The gate becomes adaptive, with one verdict per kind of create (compute, graphics including mesh). Graphics creates now go through the gate too.
LEONIDA_COMPILE_GATE_PROBE_MS(2,500 ms by default), or afterLEONIDA_COMPILE_GATE_WAIT_MS(15 s) for one wait. That submission is a probe.VulkanContext::mark_device_lostlogs the gate state per kind and every create in the driver: kind, program, bytes, trigger, thread, time in the driver.LEONIDA_COMPILE_GATEunset: adaptive (new default).=1: the old gate. It always waits with no limit, never probes, and compute builds hold the submit lock.=0: off.LEONIDA_COMPILE_GATE_WAIT_MS=0: waits with no limit.runtime/README.mdanddocs/d3d12_vulkan.mddescribe them. The README row forLEONIDA_COMPILE_GATEalso had the default wrong.LEONIDA_COMPILE_GATE=1keeps the old protection.Tested
submit_mutexctest passes with the gate unset, with=1, with=0and withWAIT_MS=0. It has new cases for the bounded wait, the probe budget, the adaptive switch, per-kind verdicts, re-arm and the loss report.scripts/check_no_game_data.pyis clean on all changed files.main, runs of 450-600 s:maingate (=1)a3404f5a4)f7b249730) onmaind1dff7949a3404f5a4: off at 53.6 s after 133 probes ≤ 12 ms, 4,800 ms of waiting instead of 814,287 ms, 900 s with no device loss.GPUs tested: NVIDIA GeForce RTX 4070 Laptop 8 GB, driver 621.40, Windows 11; NVIDIA GeForce RTX 4060, driver 610.88, Windows (MoonEyes).
AI-assisted: yes (Claude Code, Claude Opus 5.5)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a: runtime only)🤖 Generated with Claude Code