Repository navigation
compile gate: auto default, calibrated per driver at device creation (RT-COMPILE-GATE-AUTO) - #2462
Conversation
With LEONIDA_COMPILE_GATE unset or `auto`, the device measures the driver once before the VulkanContext exists: a worker creates a synthetic compute pipeline (SPIR-V written in code, new specialization seed each run, no pipeline cache) while the queue gets empty submissions waited on a fence. Quick submissions with the create still in the driver give the adaptive gate; a held one, a create too fast to tell, an unexplained slow submission or any failure give classic. The verdict is cached per vendor/device/driver/pipelineCacheUUID in compile_gate_calibration.txt beside the pipeline cache; LEONIDA_COMPILE_GATE_RECALIBRATE=1 measures again. Only the title process calibrates; build hosts and tests keep classic. `classic`, `adaptive`, `1`, `0` still force a mode. Tests: compile_gate_policy_test (no GPU: settings, NVIDIA version decode, verdicts, cache file, SPIR-V shape) and vk_compile_gate_calibration_test (GPU: a verdict within 20 s, adaptive on NVIDIA 621.40). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
In-game check of the title path, which the PR body listed as not run. The game then booted normally into the world phase, with no device loss and no gate hang. Startup cost: 0.5 s. |
|
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). |
|
Measuring the driver instead of maintaining a branch allow-list is much cleaner — and Two small issues on
AI-assisted review (Antigravity, Gemini 4 Neon). |
…fence Review of ProjectLeonida#2462: - An unclear calibration (a slow submission the create does not explain) is no longer written to compile_gate_calibration.txt, and an unclear line an earlier build wrote is not read as a cached verdict: the next launch measures again instead of staying classic until the driver changes (compile_gate_policy::cache_verdict, tested in compile_gate_policy_test). - After a fence wait that fails, the fence and command pool are destroyed only once the pending submission's fence signals (up to 60 s); on a lost device or if it still has not, they are left alive. The verdict stays classic. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Second run, same recipe, 120 s, calibration cached: the log line reads What I checked on this branch:
Notes:
AI-assisted (Claude Code, Claude Opus 5.5) |
|
Thanks @aslan2142, both points are fixed in e31f50b. It is on top of a merge of current
Re-run on Windows 11, MSVC 14.44, RTX 4070 Laptop, NVIDIA 621.40,
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). |
|
Both review items look cleanly fixed in Verified locally on
Merging. AI-assisted review (Antigravity, Gemini 4 Neon). |
…-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>
|
Third driver, as asked by @OreoFR: the auto line, the cache reread, and a world run in auto. Not caused by this PR, as far as I can tell: m189 ( This comment was AI-assisted (Claude Code, Opus 5.5). |
Claimed 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:LEONIDA_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