compile gate: auto default, calibrated per driver at device creation (RT-COMPILE-GATE-AUTO) #2462
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!2462
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2462"
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-27 12:26 UTC · original
OreoFR:rt-compile-gate-auto→main· +1359 −56 · 10 files · 3 commits · merged 2026-11-27 13:08 UTCClaimed in the coordination issue as: RT-COMPILE-GATE-AUTO. The claim describes an allow-list of driver branches; this PR measures the driver instead.
Depends on: nothing (#2412 is merged)
What and why
The follow-up @aslan2142 asked for on #2412 (merge comment). It turns on the adaptive compile gate where the driver does not hold a submission behind a pipeline create, and keeps the classic gate where it does.
The new default is
LEONIDA_COMPILE_GATEunset orauto. At device creation, before theVulkanContextand itsSubmitMutexexist, the runtime calibrates the gate once (decide_auto_compile_gate,runtime/shims/d3d12_vulkan_device.cpp;runtime/src/compile_gate_calibration.h):compile_gate_policy::slow_compute_spirv: a chain offract(sin(..))steps with branches, and specialization constant 0 seeded anew on each run, so no cache can answer it. No game data.compile_gate_policy::judge, a pure function):compile_gate_calibration.txt, beside the pipeline cache. So the calibration runs once per driver. Failures are not cached.LEONIDA_COMPILE_GATE_RECALIBRATE=1measures again.[rt] compile-gate: auto: adaptive (calibrated on NVIDIA 621.40 in 0.7 s: 115 submissions came back in <= 0.5 ms beside a 722 ms create; cached in ...\compile_gate_calibration.txt; LEONIDA_COMPILE_GATE=classic|adaptive overrides). Otherwise it saysauto: classic (...)with the reason, or(cached calibration of ...).compile_gate_policy::calibration_allowed, set inmain.cpp).--precompile-pipelines,--compile-serverand the test processes keep the classic gate. A forced value never waits for the calibration.What forcing still does:
classic(new),adaptive,1and0force a mode, as before.main, and is now logged.autois classic, so nothing can be gated differently frommainbefore it.How the gate's mode is read:
SubmitMutex::compile_gate_mode()now reads an atomic, set once bydecide_auto_gate.gate_defaults()keeps one set per mode, so the adaptive limit and budget apply whenautopicks adaptive.Why a calibration can ask what an in-game probe cannot: the adaptive gate learns by letting a submission into the driver beside one of the title's creates, which can take 30-60 s. On a driver that holds submissions (630.20), that probe loses the device once it waits 10 s more. The calibration's create takes about a second and its submissions are empty. On such a driver, one is held for about a second and comes back with the create, which cannot reach the 10 s TDR.
Evidence the verdict should agree with, from #2412 comment 7217585003, now in
docs/d3d12_vulkan.md:b2cccb9without #2418. @nicoco23, could you recheck on this branch? WithLEONIDA_COMPILE_GATEunset, the log should show[rt] compile-gate: auto: adaptive (calibrated on NVIDIA 621.xx ...). A freeze report with the thread dump would help most.README rows:
LEONIDA_COMPILE_GATE(defaultauto), the newLEONIDA_COMPILE_GATE_RECALIBRATE, and the wait and probe rows now say "with the adaptive gate".What changes for users: on
main,LEONIDA_COMPILE_GATEunset means the classic gate. With this PR, unset meansauto: calibrate once per driver, then adaptive or classic. Behaviour with any explicit value is unchanged. The real test is therefore a run with the variable unset, on several drivers.Tested
compile_gate_policy_test(new, pure stdlib, no GPU) passes. It covers:vk_compile_gate_calibration_test(new, GPU; 77 without a device) expects a verdict within 20 s, and adaptive on NVIDIA 621.40.MEASURED, on this RTX 4070 Laptop (621.40):submit_mutex_testpasses withLEONIDA_COMPILE_GATEunset,auto,classic,adaptive,1,0and an unknown value.vulkan_device_fault_testpasses.MEASUREDgta6rt,gta6rt_tls_hostand the tests build with MSVC 14.44.-std=c++20 -Wall -Wextra, header filter on the new headers) reports no errors or warnings in the two new tests,submit_mutex_test.cpporvulkan_device_fault_test.cpp. GCC was not checked.tests/test_docs_*.pypass.check_no_game_data.pyis clean on every changed file.decide_auto_compile_gate(cache read and write, the log line) runs only in the title process, so it isREAD IN CODEonly. The calibration it calls is the one the GPU test runs.GPUs tested: NVIDIA GeForce RTX 4070 Laptop 8 GB, driver 621.40, Windows 11 (calibration: adaptive). NVIDIA GeForce RTX 4060, driver 610.88 (MoonEyes): merges cleanly, builds, the new tests and
submit_mutex_testpass, calibration adaptive (163 submissions <= 0.7 ms beside a 957 ms create, 1.07 s); his in-game run follows.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
autodefault, calibrated at device creation 1d7c662b4b@OreoFR on GitHub · 2026-11-27 12:39 UTC · original
In-game check of the title path, which the PR body listed as not run.
main+ this PR only, RTX 4070 Laptop, NVIDIA 621.40,LEONIDA_COMPILE_GATEunset, first run on this driver:The game then booted normally into the world phase, with no device loss and no gate hang. Startup cost: 0.5 s.
MEASURED (n=1). The cached-verdict path, on a second run, is still to check. AI-assisted (Claude Code, Claude Opus 5.5).@OreoFR on GitHub · 2026-11-27 12:40 UTC · original
Second run on the same driver: the cached verdict is reused, with no calibration and no startup delay:
Both title paths (first run and cache) are now checked in game. AI-assisted (Claude Code, Claude Opus 5.5).
@aslan2142 on GitHub · 2026-11-27 12:41 UTC · original
Measuring the driver instead of maintaining a branch allow-list is much cleaner — and
vk_compile_gate_calibration_testpasses cleanly on Linux AMD RADV (RDNA2 iGPU: trial 1, 1,000 statements, 391 ms create, 61 submissions<= 1.5 ms→adaptivein 393 ms),compile_gate_policy_testbuilds with 0 warnings under GCC-Wall -Wextra, andslow_compute_spirv(1000)passesspirv-val(vulkan1.0 and vulkan1.2).Two small issues on
1d7c662b4to fix before merge:runtime/shims/d3d12_vulkan_device.cpp:218-236(decide_auto_compile_gate):Outcome::unclearstill hasresult.ok == true, so a transient background GPU spike during the first launch writesoutcome=uncleartocompile_gate_calibration.txtand permanently locks subsequent runs ontoclassicuntil a driver update or manualLEONIDA_COMPILE_GATE_RECALIBRATE=1. Skipping cache write onOutcome::unclear(just like!result.ok) lets the next launch get a clean measurement.runtime/src/compile_gate_calibration.h:198-210: ifvk.wait_fences(..., kFenceTimeoutNs)returnsVK_TIMEOUT,fail()immediately callscleanup()(vkDestroyFence/vkDestroyCommandPool) while the submitted command buffer and fence may still be pending onqueue(Vulkan UB). Afterworker.join(), waiting onfence(orvkQueueWaitIdle) before destroying them whensubmit_result == VK_TIMEOUTmakes cleanup spec-valid.AI-assisted review (Antigravity, Gemini 4 Neon).
@MoonEyes on GitHub · 2026-11-27 12:49 UTC · original
Second run, same recipe, 120 s, calibration cached: the log line reads
auto: adaptive (cached calibration of NVIDIA 610.88 ...)and no calibration trial ran again.What I checked on this branch:
compile_gate_policy_test: passes.submit_mutex_test: passes. MEASURED.vk_compile_gate_calibration_teston the RTX 4060 (610.88): adaptive at the first trial, 163 submissions of at most 0.7 ms beside a 957 ms create, 1071 ms in all. MEASURED.compile-gate: auto: adaptive (calibrated on NVIDIA 610.88 in 1.6 s: 264 submissions came back in <= 1.5 ms beside a 1543 ms create; ...). During 600 s, 581 submissions waited for pipeline creates, 10.3 s in all, longest 1.9 s, 7 went ahead at the limit. No device loss. MEASURED.Notes:
classiccomparison).AI-assisted (Claude Code, Claude Opus 5.5)
@OreoFR on GitHub · 2026-11-27 12:49 UTC · original
Thanks @aslan2142, both points are fixed in
e31f50bbc. It is on top of a merge of currentmain(6af3b1dac), which merged cleanly.decide_auto_compile_gatewrites the cache only whencompile_gate_policy::cache_verdict(outcome)is true. That is every outcome exceptunclear.not cached: the next launch measures again.find_entryalso ignores anunclearline written by the previous head, so a file that already has one measures again.compile_gate_policy_testcovers this:cache_verdictper outcome, and an unclear line next to a valid one for another key.too_fastresult at the largest size is still cached, because it does not change from one launch to the next.worker.join(), if the submit or wait failed, it waits on the fence again, for up to 60 s, beforecleanup()destroys the fence and command pool.VK_ERROR_DEVICE_LOST, or if the fence still has not signalled, the fence and pool are left alive. The verdict is classic, as before.Re-run on Windows 11, MSVC 14.44, RTX 4070 Laptop, NVIDIA 621.40,
MEASURED:compile_gate_policy_testpasses.vk_compile_gate_calibration_test, 3 runs: adaptive each time, 95-109 submissions of at most 0.5 ms beside 600-686 ms creates.submit_mutex_testandvulkan_device_fault_testpass.-Wall -Wextra): clean.test_docs_*.pypass, andcheck_no_game_data.pyis clean.The timeout path itself was not exercised: it needs a fence that does not signal within 10 s.
AI-assisted (Claude Code, Claude Opus 5.5).
@aslan2142 on GitHub · 2026-11-27 13:07 UTC · original
Both review items look cleanly fixed in
e31f50bbc(cache_verdictexcludingOutcome::unclearon both write and read, and draining a pending fence before destroyingfence/pool).Verified locally on
main(f5c3ea2e0) +e31f50bbc:scripts/check_no_game_data.pyclean;test_docs_env_vars(5/5),test_docs_repo_paths(3/3),test_ctest_registration(6/6),test_ci_registration(18/18) pass.compile_gate_policy_testbuilds with 0 warnings under GCC-Wall -Wextraand passes.compile_gate_policyandvk_compile_gate_calibrationpass; 0 regressions vsmain-e5a7c8942(433 pass, 40 skip, 23 pre-existing Wine-iGPU failures, 2 disabled).Merging.
AI-assisted review (Antigravity, Gemini 4 Neon).