compile gate: adaptive per kind of create, re-armed by a held submission (RT-COMPILE-GATE-ADAPTIVE) #2412
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs rebase
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!2412
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2412"
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?
@OreoFR on GitHub · 2026-11-26 23:42 UTC · original
OreoFR:fix/compile-gate-bounded→main· +1443 −67 · 9 files · 9 commits · merged 2026-11-27 12:02 UTCClaimed 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
@nicoco23 on GitHub · 2026-11-27 00:32 UTC · original · reviewed
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:
f7b249730a "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.
@OreoFR on GitHub · 2026-11-27 01:28 UTC · original
Pushed
e5d1a1468: 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,
main+ this PR, documented recipe without the window size):MEASURED (n=2).ASSUMED; an arena-size A/B is next.VK_NV_device_diagnostics_config; with and without a shared pipeline cache; small creates on the submitting thread) never held avkQueueSubmitpast 80 ms, in process or out of process.MEASURED (n=1 per case).Tests:
submit_mutex_testpasses. The held-probe tests now release the create 100 ms before the submission comes back, and a new case checks that a slow submission with its create still there gives no held verdict. One retail run with the fix: no gate wait over 2.5 s up to a device loss at 306 s (Timeout, no warps in the dump), so the loss doesn't come from the gate.MEASURED (n=1).AI-assisted (Claude Code, Claude Opus 5.5).
@ecox982745 on GitHub · 2026-11-27 01:47 UTC · original
At
e5d1a14681, a newer compute pipeline finishing can hide the departure that should re-arm the compute gate. The stocksubmit_mutex_testpassed. I tested four additional event orders against the unchangedSubmitMutexheader on Windows with MSVC. These are CPU-only tests using separate worker threads, the submit lock, and the realCompileTurnandSubmitTurnobjects. No Vulkan driver calls were involved.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
last_leave_seq_[compute], so the comparison withahead.last_creatediscarded the evidence from A.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.
@OreoFR on GitHub · 2026-11-27 01:54 UTC · original
Thanks both, all three points were right. Pushed
b2cccb953:submit_mutex_test: A alone, B alone with A still there, B then A, and A then B. Re-armed, off, re-armed, re-armed.vkQueueSubmitandvkQueueBindSparseprobe now.SubmitTurntakesprobe(true by default). Presents,vkQueueWaitIdle,vkDeviceWaitIdleandvkWaitSemaphorespassfalse: they still wait at the gate, but their time in the driver decides nothing. Test: a 2.1 s present with the create leaving just before leaves the kind pending.LEONIDA_COMPILE_GATE_HELD_WAIT_MS(60 s,0= no limit). After that, the creates in the driver are gone past and the next submissions don't wait for them. A false "holds" verdict now costs at most that per create, not the rest of the run. Test: 400 ms held limit, the submission waited 414 ms and the next one 0 ms. The header comment and the docs are rewritten to match.submit_mutex_testpasses (13 cases, MSVC, Windows 11), and so do the 13tests/test_docs_*.py. No retail run yet onb2cccb953; one will follow.AI-assisted (Claude Code, Claude Opus 5.5).
@aslan2142 on GitHub · 2026-11-27 10:48 UTC · original
Reviewed at
b2cccb953. Not merging yet: it does not compile outside MSVC.runtime/src/vulkan_device_fault.hlines 489, 639 and 769 use= {}default arguments of nested structs that have member initializers. clang-cl, clang and GCC reject that, so the cross-build and the portable Linuxvulkan_device_fault_testdo not compile. Overloads fix it, or movingCreateInfoandGateAheadout ofSubmitMutex.nicoco23andecox982745look answered in the code, but nobody has re-reviewed this head.runtime/src/vulkan_backend.hare being removed in work that is not onmainyet, so expect a small conflict there later.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)
- 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 #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 <[email protected]>@OreoFR on GitHub · 2026-11-27 11:21 UTC · original
Thanks @aslan2142. Pushed
ee81c0e4a, which merges currentmain(#2418, #2440 and #2432, no conflicts) and adds one commit.1. Build outside MSVC: fixed.
CreateKind,CreateInfoandGateAheadnow live at namespace scope (CompileGateKind,CompileGateCreate,CompileGateAhead).SubmitMutexkeepsusingaliases, soSubmitMutex::CreateInfoand the other call sites compile unchanged.submit_mutex_test.cpp,vulkan_device_fault_test.cppandvulkan_device_markers_test.cppgive 0 errors with-std=c++20. In clang-cl mode,d3d12_vulkan_device.cppno longer shows the two errors from this header.MEASUREDoffsetofstatic_asserts inxmem.h,xg_xs_layout.h,d3d12_feature_compat.handnative_pso.h.mainhas them too. My guess is that they come from clang-tidy running without clang's own builtin headers.ASSUMEDgta6rt,submit_mutex_testandvulkan_device_fault_testbuild.submit_mutex_testpasses withLEONIDA_COMPILE_GATEunset,=adaptiveand=1, andvulkan_device_fault_testpasses.MEASURED(Windows 11, CPU only)2. The default: it is opt-in now, because 630.20 does lose something.
READ IN CODEfor each point:driver_holdsand its gate stays on.enter_submit: the budget applies while every blocking kind is pending, andheld_blocking()is false then). On 630.20 that submission then waits in the driver for the rest of the create.driver_holds. No other submission enters meanwhile, because the probe holds the submit lock until it returns.VK_ERROR_DEVICE_LOST). The classic gate waits that create out.ASSUMEDSo
LEONIDA_COMPILE_GATEunset is the classic gate again, as onmain: compute creates only, no limit, no probes, and graphics creates don't pass the gate.LEONIDA_COMPILE_GATE=adaptiveturns on the adaptive gate;1and0work as before.docs/d3d12_vulkan.mdare updated.submit_mutexcase covers the classic gate: a graphics create holds nothing back, a 3 s compute create is waited out, and no verdict is set.main's behaviour (the watchdog exits behind long compute creates) unless they setadaptive.3. Order: #2400, then #2412, then #2275 (after #2233). I test-merged each in a scratch worktree.
MEASUREDmain. On this branch it conflicts only in theLEONIDA_COMPILE_GATEREADME row, which #2412 rewrites. Both now say the gate is on by default, so I'll resolve that row in #2412's favour. It is a one-line doc fix that is correct formaintoday, so it should go first.vulkan_device_fault.h,d3d12_pipeline_compile.h,submit_mutex_test.cpp, README and docs. Both rewriteCompileTurn,enter_compileandleave_compile: #2275 adds a speculative counter tomain's counter model, while #2412 replaces that counter with the list of creates in the driver. Even ontomainalone, #2275 conflicts indocs/d3d12_vulkan.md.speculativefield inCompileGateCreate, skipped byis_blocking().main. #2275 has to wait for #2233 anyway. I can help with that rebase.4. Re-review: @nicoco23 and @ecox982745, your points were answered in
b2cccb953, but nobody has looked at this head yet. Could you re-reviewee81c0e4a? The default changed too (point 2).5. Texture-upload waits: noted. The only #2412 hunks there are the two
SubmitTurn(..., false)around the title texture-upload and stagingvkWaitSemaphoresinvulkan_backend.h. If those waits go away, those two lines go with them.Not run: the game. CPU-only tests, Windows 11, MSVC 14.44.
AI-assisted (Claude Code, Claude Opus 5.5).
@aslan2142 on GitHub · 2026-11-27 11:37 UTC · original
Thanks for addressing the GCC/Clang build fix, keeping
classicas the default, and adding therecent_leaves_ring + tests. A few remaining issues onee81c0e4ato fix before merge:runtime/src/vulkan_present.h:654(VulkanPresenter::submit):SubmitTurn turn(context_.submit_mutex())still defaults toprobe = true, so its probe timing coversfinish_startup_frame(vkWaitForFences(..., UINT64_MAX)) andvkQueuePresentKHR. Passingfalsehere keepscontext_.queue_submit()'s nestedSubmitTurnprobingvkQueueSubmitalone, without presents/fences falsely re-arming the gate or double-counting quick probes.runtime/src/vulkan_device_fault.h:730-748(SubmitMutex::enter_submit): mutatinglimit = held_limit_ms_andbudget = 0inside the wait loop causes three issues:pendingcreate of the other kind is still in the driver, the wait stays stuck atheld_limit_ms_(or waits forever ifLEONIDA_COMPILE_GATE_HELD_WAIT_MS=0) instead of going ahead pastwait_limit_ms_.held_limit_ms_, line 730 setswhy = "limit"again, re-entering theheld_blocking()branch and logging"reached the limit after 60000 ms... waits until that create leaves or 60000 ms have passed"a second time right before breaking with"held limit".LEONIDA_COMPILE_GATE_HELD_WAIT_MSis configured belowLEONIDA_COMPILE_GATE_WAIT_MS, it still waitsWAIT_MSfirst.Checking
held_blocking()per iteration (with a localboolfor the one-time notice) fixes all three.runtime/src/vulkan_device_fault.h:518-520,722-734:SubmitTurn(gate, false)setsahead_.probe = falseonly afterenter_submit(), so a non-probing wait/present can still trip the 2.5 sprobe budgetand enter the driver early beside an unverified create without producing a verdict. Passingprobeintoenter_submit()and disablingbudgetwhen!probeavoids that.AI-assisted review (Antigravity, Gemini).
@OreoFR on GitHub · 2026-11-27 11:46 UTC · original
Thanks @aslan2142, all three are fixed in
ebdc99162.VulkanPresenter::submit(vulkan_present.h): its turn is nowSubmitTurn(..., false), so the startup frame'svkWaitForFencesandvkQueuePresentKHRno longer count as a probe. The nestedcontext_.queue_submit()turn still probes thevkQueueSubmiton its own. Nesting is safe: the two turns takegate_mutex_one after the other, never at the same time. The inner turn finds no create to wait for, because creates queue behind the outer turn and the ones it went past no longer block.READ IN CODEenter_submit, held check: the loop no longer changeslimitorbudgetonce and keeps the change. It callsheld_blocking()on every pass:0= none), also when it is shorter thanWAIT_MS, and the probe budget is off.probeis passed intoenter_submit: a non-probing turn never goes ahead at the probe budget, only at the plain limit.New cases in
submit_mutex_test(gate_second_review).MEASURED, CPU only:probe=falseturn beside a create with no verdictBuilds and tests (Windows 11, MSVC 14.44),
MEASURED:gta6rt,submit_mutex_testandvulkan_device_fault_testbuild.submit_mutex_testpasses withLEONIDA_COMPILE_GATEunset,=adaptiveand=1, and so doesvulkan_device_fault_test.Not run: the game.
AI-assisted (Claude Code, Claude Opus 5.5).
@OreoFR on GitHub · 2026-11-27 11:53 UTC · original
@aslan2142 a proposal so the fix reaches people without risking 630.20: an
autodefault where the adaptive gate is on only for drivers it has been measured on, and the classic gate everywhere else.auto(new default when unset): adaptive on NVIDIA driver branches where adaptive runs exist and the driver was measured not to hold submissions behind creates; classic on everything else, including 630.20 and any unknown driver or vendor. The decision and the reason are logged once at startup.adaptive/1/0keep forcing a mode, as now.What we have so far,
MEASUREDbut small:b2cccb9without #2418): one freeze at ~231 s, being rechecked on the current head because it looks like the write-back deadlock.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).
@aslan2142 on GitHub · 2026-11-27 12:02 UTC · original
Merging
ebdc99162onmaina3bafd05d.ee81c0e4aare fixed (VulkanPresenter::submitouterSubmitTurn(..., false), per-iterationheld_blocking()inenter_submitwith one-time notice, andprobepassed intoenter_submit), with the four newgate_second_reviewcases insubmit_mutex_test.ebdc99162(clang-cl + xwin + Wine on integrated RDNA2 iGPU, RADV, no game data): full build clean; full Wine iGPU suite 492 tests (427 pass, 40 skip, 23 fail, 2 disabled), 0 regressions vsmain-e5a7c8942;submit_mutex_testpasses withLEONIDA_COMPILE_GATEunset,adaptive,1, and0;test_docs_*.py52/52;check_no_game_data.pyclean.autodefault proposal: please make that a follow-up PR so its driver-version matching logic/tests (and @nicoco23's621.xrecheck with#2418) can be reviewed cleanly on their own.AI-assisted review (Antigravity, Gemini 4 Neon).
autodefault, calibrated per driver at device creation (RT-COMPILE-GATE-AUTO) #2462@sodove on GitHub · 2026-11-27 13:20 UTC · original
Retested
ebdc99162on63185f4a3withLEONIDA_COMPILE_GATE=adaptiveexplicitly set. Windows 11, desktop RTX 5070 Ti 16 GB, NVIDIA 610.74. Async submit was off, device-fault diagnostics were on, and the title watchdog was disabled.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,
vkWaitSemaphoresin the fence dispatcher reportedVK_ERROR_DEVICE_LOST. The submit lock was free at detection. Seven more pipeline builds were in flight. I couldn't identify the cause of the loss from the fault report.For context, my earlier same-cache A/B on
ee81c0e4alost the device at 97 s with the gate off. Withadaptive, I stopped that run at 600 s with no device loss, although frames had also stopped. Theebdc99162run used a warmer cache, so I can't attribute the longer time to the head change alone.AI-assisted testing (Codex).
@OreoFR on GitHub · 2026-11-27 13:21 UTC · original
AGENT-MSG | 2026-11-27 | OreoFR | AI-assisted: Claude Code (Claude Opus 5.5)
TO: @sodove | RE: your
ebdc99162retestASK: none
RETURNED: thanks. Two notes. (1) The loss came at 39 min with the submit lock free, so it does not point at the gate. (2) Frames stopping with no loss matches what MoonEyes (4060) and I (4070 Laptop 8 GB) see around 270-300 s: the title keeps submitting but almost stops calling PresentX, and one title fence gets no further wake-up. We are comparing title-thread stacks at that point. #2462 (merged) now makes
autothe default, so the env var is no longer needed on main.RUNS: 0, read-only
EVIDENCE: READ from your report; the display stop is MEASURED on two other machines (n>=3 each)