Skip to content

compile gate: adaptive per kind of create, re-armed by a held submission (RT-COMPILE-GATE-ADAPTIVE) - #2412

Merged
aslan2142 merged 9 commits into
ProjectLeonida:mainfrom
OreoFR:fix/compile-gate-bounded
Nov 27, 2026
Merged

aslan2142 merged 9 commits into
ProjectLeonida:mainfrom
OreoFR:fix/compile-gate-bounded

Conversation

@OreoFR

@OreoFR OreoFR commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: RT-COMPILE-GATE-ADAPTIVE

Depends on: none. It conflicts textually with #2275 (RT-COMPILE-GATE-WARMUP-FREE, same SubmitMutex code). Whichever lands second takes both; I will rebase on #2275 if it goes first.

What and why

The compile gate (#2098, SubmitMutex in runtime/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:

  • RTX 4070 Laptop, NVIDIA 621.40: one demanded 2.3 MB library compute create sat 54+ s in the driver. No submission went through, the title's fence stopped, and its hang watchdog ended the run (+0x23cf683).
  • @MoonEyes, RTX 4060, NVIDIA 610.88, watchdog kicked: 814,287 ms of 895 s (91 % of the run) waiting behind creates, mostly small warm-up programs. The gate never let go.

Also found: on main, graphics and mesh creates never went through the gate. Only vkCreateComputePipelines did; PipelineState::build called the driver directly. On 621.40 that is where the hazard actually showed:

  • with the gate off, a cold 541 KB mesh pipeline create took 55.7 s, a submit sat 54.2 s in the driver beside it, then VK_ERROR_DEVICE_LOST;
  • in another run, a submit sat 7.8 s beside a 1.78 MB mesh create, then the same loss.

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.

  • Bounded wait while a kind is undecided. A submission goes ahead once the gate waits of the last 10 s add up to LEONIDA_COMPILE_GATE_PROBE_MS (2,500 ms by default), or after LEONIDA_COMPILE_GATE_WAIT_MS (15 s) for one wait. That submission is a probe.
  • Verdict. Two quick probes, each under 250 ms and at least 1 s apart, with a create of that kind still in the driver when they return, turn the gate off for that kind for the rest of the run. A probe held 2 s or more marks the kind as holding: submissions then wait for its creates however long they take. The bounded go-ahead never enters beside a create of a holding kind.
  • Re-arm. A kind that is off is still timed. A submission that stays 2 s or more in the driver beside one of its creates turns that kind back on, logged once.
  • Device-loss report. On the first device loss, VulkanContext::mark_device_lost logs the gate state per kind and every create in the driver: kind, program, bytes, trigger, thread, time in the driver.
  • Switches.
    • LEONIDA_COMPILE_GATE unset: 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.md and docs/d3d12_vulkan.md describe them. The README row for LEONIDA_COMPILE_GATE also had the default wrong.
  • Tradeoff on a driver that holds (630.20). The first probe of a kind now enters the driver after about 2.5 s of waiting instead of never. If that create then stays another 10 s, that driver loses the device, at most once per run per kind: the probe returns a held verdict 2 s in. LEONIDA_COMPILE_GATE=1 keeps the old protection.

Tested

  • submit_mutex ctest passes with the gate unset, with =1, with =0 and with WAIT_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.py is clean on all changed files.
  • Retail story load, RTX 4070 Laptop 8 GB, NVIDIA 621.40, shaders retranslated with main, runs of 450-600 s:
Build / gate Waiting behind creates Result
main gate (=1) 130 s, longest 21.7 s no loss in that run; stalls up to 14.5 s
bounded only, 15 s limit 90 s of 3-7 s waits back to back watchdog at 433 s, gate never adapted
adaptive, compute only (a3404f5a4) 2.6 s off at 279 s, no loss in 450 s (one other run: loss beside an ungated mesh create)
this PR (f7b249730) on main d1dff7949 5.2 s graphics off at 199 s (581 probes ≤ 112 ms), compute off at 250 s (1,969 probes ≤ 11 ms), no device loss
  • @MoonEyes, RTX 4060, NVIDIA 610.88, on a3404f5a4: 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.
  • Not seen in a game yet: a re-arm, and a held verdict for graphics. Both need a cold create that holds a submission, and the long mesh creates were cached by then. They are covered by the unit test only. More runs on other GPUs (RTX 5070, RTX 5080) are coming, and I will add them here.

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

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • 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: runtime only)

🤖 Generated with Claude Code

OreoFR and others added 4 commits November 26, 2026 23:07
…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 nicoco23 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.

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>
@OreoFR

OreoFR commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

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, main + this PR, documented recipe without the window size):

  • One submission stayed 35.7 s in the driver beside a 58.4 s compute create, but came back 18 s before that create finished. So it wasn't held by the create. The old rule counted it as held and turned the compute gate back on. The gate then kept the next submissions behind compute creates for 18 s and then 78 s ("waits until that create leaves"). Same pattern in a second run: a 2.1 s submission re-armed the gate, then waits of 19.6 s and 13 s followed. MEASURED (n=2).
  • In both runs device-local memory was ~7.7 GB of 8 GB. My guess is that the slow submissions come from memory pressure, not from the creates. ASSUMED; an arena-size A/B is next.
  • A synthetic probe on the same machine (2 MB graphics pipelines of 8-10 s each; 1-3 creating threads; with and without VK_NV_device_diagnostics_config; with and without a shared pipeline cache; small creates on the submitting thread) never held a vkQueueSubmit past 80 ms, in process or out of process. MEASURED (n=1 per case).

Tests: submit_mutex_test passes. 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

Copy link
Copy Markdown

At e5d1a14681, a newer compute pipeline finishing can hide the departure that should re-arm the compute gate. The stock submit_mutex_test passed. I tested four additional event orders against the unchanged SubmitMutex header on Windows with MSVC. These are CPU-only tests using separate worker threads, the submit lock, and the real CompileTurn and SubmitTurn objects. 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.

Creates finishing within 500 ms before submission return Expected gate Observed
A alone Re-armed Re-armed 3/3
B alone, with A still active at return Off Off 3/3
B, then A Re-armed Re-armed 3/3
A, then B Re-armed Off 3/3

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 with ahead.last_create discarded 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.

…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>
@OreoFR

OreoFR commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

Thanks both, all three points were right. Pushed b2cccb9:

  • @ecox982745: a later create's leave no longer hides an earlier one. Leaves now go in a ring of 64, and any leave of that kind within 500 ms before the submission comes back counts, as long as the create was in the driver when the submission entered. Your four orders are in 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.
  • @nicoco23, probes: only vkQueueSubmit and vkQueueBindSparse probe now. SubmitTurn takes probe (true by default). Presents, vkQueueWaitIdle, vkDeviceWaitIdle and vkWaitSemaphores pass false: 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.
  • @nicoco23, the unbounded wait: a kind that holds is now waited for up to 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_test passes (13 cases, MSVC, Windows 11), and so do the 13 tests/test_docs_*.py. No retail run yet on b2cccb9; one will follow.

AI-assisted (Claude Code, Claude Opus 5.5).

@aslan2142

Copy link
Copy Markdown
Collaborator

Reviewed at b2cccb953. Not merging yet: it does not compile outside MSVC.

  • Build error. runtime/src/vulkan_device_fault.h lines 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 Linux vulkan_device_fault_test do not compile. Overloads fix it, or moving CreateInfo and GateAhead out of SubmitMutex.
  • The default. This makes the adaptive gate the default, which gives up the old protection on 630.20 drivers. Please say why that is safe there, or keep it opt-in.
  • Overlap. d3d12: warm-up creates no longer hold the compile gate (RT-COMPILE-GATE-WARMUP-FREE) #2275 and runtime/README: LEONIDA_COMPILE_GATE is on by default (DOC-COMPILE-GATE-DEFAULT) #2400 touch the same gate. Please say which order they should go in.
  • Earlier review points from nicoco23 and ecox982745 look answered in the code, but nobody has re-reviewed this head.
  • Heads-up: the texture-upload waits in runtime/src/vulkan_backend.h are being removed in work that is not on main yet, 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)

OreoFR and others added 2 commits November 27, 2026 11:55
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>
@OreoFR

OreoFR commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @aslan2142. Pushed ee81c0e, which merges current main (#2418, #2440 and #2432, no conflicts) and adds one commit.

1. Build outside MSVC: fixed. CreateKind, CreateInfo and GateAhead now live at namespace scope (CompileGateKind, CompileGateCreate, CompileGateAhead). SubmitMutex keeps using aliases, so SubmitMutex::CreateInfo and the other call sites compile unchanged.

  • This machine has no clang or GCC driver, so I used the clang front end in clang-tidy (LLVM 19.1.5, from VS BuildTools). Before the fix it gave your errors at lines 489 and 769, with "default member initializer ... needed within definition of enclosing class". After it, submit_mutex_test.cpp, vulkan_device_fault_test.cpp and vulkan_device_markers_test.cpp give 0 errors with -std=c++20. In clang-cl mode, d3d12_vulkan_device.cpp no longer shows the two errors from this header. MEASURED
  • The 11 errors still left in clang-cl mode are offsetof static_asserts in xmem.h, xg_xs_layout.h, d3d12_feature_compat.h and native_pso.h. main has them too. My guess is that they come from clang-tidy running without clang's own builtin headers. ASSUMED
  • Not checked: GCC or Linux headers. Neither is on this machine.
  • MSVC: gta6rt, submit_mutex_test and vulkan_device_fault_test build. submit_mutex_test passes with LEONIDA_COMPILE_GATE unset, =adaptive and =1, and vulkan_device_fault_test passes. MEASURED (Windows 11, CPU only)

2. The default: it is opt-in now, because 630.20 does lose something. READ IN CODE for each point:

  • Held probes. A probe counts as held when the submission stays 2 s or more and comes back within 500 ms after a create of that kind leaves (one that was in the driver when it entered). A driver that holds submissions returns them when the create leaves. So if the device survives, the kind gets driver_holds and its gate stays on.
  • Quick probes. The verdict needs two probes under 250 ms, at least 1 s apart, with the create still in the driver. A driver that holds submissions can't produce those. The only exception is a slip between driver calls, which is why two are required.
  • The cost. Before any verdict, a submission goes ahead at the 2.5 s probe budget (enter_submit: the budget applies while every blocking kind is pending, and held_blocking() is false then). On 630.20 that submission then waits in the driver for the rest of the create.
    • Create leaves within about 10 s: that one submission waits in the driver instead of at the gate, and the kind gets driver_holds. No other submission enters meanwhile, because the probe holds the submit lock until it returns.
    • Create stays 10 s more or longer: the device is lost (wf6: 10 s, then VK_ERROR_DEVICE_LOST). The classic gate waits that create out.
    • This happens at most once per kind (compute, graphics) per run.
  • The held limit. After a held verdict, a submission goes ahead beside a held kind's create at the 60 s held limit. Unbounded, the old gate does not do that.
  • No adaptive run on 630.20 yet. None has been reported, so all of this is from the code. ASSUMED

So LEONIDA_COMPILE_GATE unset is the classic gate again, as on main: compute creates only, no limit, no probes, and graphics creates don't pass the gate. LEONIDA_COMPILE_GATE=adaptive turns on the adaptive gate; 1 and 0 work as before.

  • The README rows (gate, wait limit, probe budget) and docs/d3d12_vulkan.md are updated.
  • A new submit_mutex case covers the classic gate: a graphics create holds nothing back, a 3 s compute create is waited out, and no verdict is set.
  • The cost of this choice: 621.40 users keep main's behaviour (the watchdog exits behind long compute creates) unless they set adaptive.
  • I also fixed the wording "held verdict 2 s into the probe". The verdict comes when the probe returns.

3. Order: #2400, then #2412, then #2275 (after #2233). I test-merged each in a scratch worktree. MEASURED

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 SubmitTurn(..., false) around the title texture-upload and staging vkWaitSemaphores in vulkan_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

Copy link
Copy Markdown
Collaborator

Thanks for addressing the GCC/Clang build fix, keeping classic as the default, and adding the recent_leaves_ ring + tests. A few remaining issues on ee81c0e4a to fix before merge:

  • runtime/src/vulkan_present.h:654 (VulkanPresenter::submit): SubmitTurn turn(context_.submit_mutex()) still defaults to probe = true, so its probe timing covers finish_startup_frame (vkWaitForFences(..., UINT64_MAX)) and vkQueuePresentKHR. Passing false here keeps context_.queue_submit()'s nested SubmitTurn probing vkQueueSubmit alone, without presents/fences falsely re-arming the gate or double-counting quick probes.
  • runtime/src/vulkan_device_fault.h:730-748 (SubmitMutex::enter_submit): mutating limit = held_limit_ms_ and budget = 0 inside the wait loop causes three issues:
    1. If a held create leaves while a pending create of the other kind is still in the driver, the wait stays stuck at held_limit_ms_ (or waits forever if LEONIDA_COMPILE_GATE_HELD_WAIT_MS=0) instead of going ahead past wait_limit_ms_.
    2. When a held create hits held_limit_ms_, line 730 sets why = "limit" again, re-entering the held_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".
    3. If LEONIDA_COMPILE_GATE_HELD_WAIT_MS is configured below LEONIDA_COMPILE_GATE_WAIT_MS, it still waits WAIT_MS first.
      Checking held_blocking() per iteration (with a local bool for the one-time notice) fixes all three.
  • runtime/src/vulkan_device_fault.h:518-520, 722-734: SubmitTurn(gate, false) sets ahead_.probe = false only after enter_submit(), so a non-probing wait/present can still trip the 2.5 s probe budget and enter the driver early beside an unverified create without producing a verdict. Passing probe into enter_submit() and disabling budget when !probe avoids that.

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>
@OreoFR

OreoFR commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @aslan2142, all three are fixed in ebdc991.

  • VulkanPresenter::submit (vulkan_present.h): its turn is now SubmitTurn(..., false), so the startup frame's vkWaitForFences and vkQueuePresentKHR no longer count as a probe. The nested context_.queue_submit() turn still probes the vkQueueSubmit on its own. Nesting is safe: the two turns take gate_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 CODE
  • enter_submit, held check: the loop no longer changes limit or budget once and keeps the change. It calls held_blocking() on every pass:
    • While a create of a kind that holds is in the driver, only the held limit applies (0 = none), also when it is shorter than WAIT_MS, and the probe budget is off.
    • Otherwise the plain limit and the budget apply.
    • The "reached the limit, but ..." notice is logged at most once per wait (a local bool).
    • The wait also wakes as soon as a holding create leaves, instead of on the next 250 ms tick.
  • probe is passed into enter_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:

Case Setting Result
(a) the holding compute create leaves, a graphics create with no verdict stays limit 300 ms, no held limit went ahead after 304 ms
(c) held limit under the plain limit held 300 ms, plain 2000 ms went ahead after 303 ms
(b) held limit over the plain limit held 400 ms, plain 100 ms went ahead after 409 ms, notice logged once
(d) probe=false turn beside a create with no verdict budget 200 ms, limit 1000 ms went ahead after 1012 ms (at the limit, not the budget), verdict still pending

Builds and tests (Windows 11, MSVC 14.44), MEASURED:

  • gta6rt, submit_mutex_test and vulkan_device_fault_test build.
  • submit_mutex_test passes with LEONIDA_COMPILE_GATE unset, =adaptive and =1, and so does vulkan_device_fault_test.
  • clang-tidy's clang front end (LLVM 19.1.5) finds 0 errors in the test files that include the header.
  • The docs paragraph is updated, and the docs tests pass.

Not run: the game.

AI-assisted (Claude Code, Claude Opus 5.5).

@OreoFR

OreoFR commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

@aslan2142 a proposal so the fix reaches people without risking 630.20: an auto default 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 / 0 keep forcing a mode, as now.

What we have so far, MEASURED but small:

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

Copy link
Copy Markdown
Collaborator

Merging ebdc99162 on main a3bafd05d.

  • All three review items from ee81c0e4a are fixed (VulkanPresenter::submit outer SubmitTurn(..., false), per-iteration held_blocking() in enter_submit with one-time notice, and probe passed into enter_submit), with the four new gate_second_review cases in submit_mutex_test.
  • Tested locally at 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 vs main-e5a7c8942; submit_mutex_test passes with LEONIDA_COMPILE_GATE unset, adaptive, 1, and 0; test_docs_*.py 52/52; check_no_game_data.py clean.
  • On the auto default proposal: please make that a follow-up PR so its driver-version matching logic/tests (and @nicoco23's 621.x recheck with #2418) can be reviewed cleanly on their own.

AI-assisted review (Antigravity, Gemini 4 Neon).

@aslan2142
aslan2142 merged commit f75b2b4 into ProjectLeonida:main Nov 27, 2026
6 of 11 checks passed
aslan2142 added a commit to Tyrannys/leonida that referenced this pull request Nov 27, 2026
… 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).
@sodove

sodove commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Retested ebdc99162 on 63185f4a3 with LEONIDA_COMPILE_GATE=adaptive explicitly 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, vkWaitSemaphores in the fence dispatcher reported VK_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 ee81c0e4a lost the device at 97 s with the gate off. With adaptive, I stopped that run at 600 s with no device loss, although frames had also stopped. The ebdc99162 run used a warmer cache, so I can't attribute the longer time to the head change alone.

AI-assisted testing (Codex).

@OreoFR

OreoFR commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

AGENT-MSG | 2026-11-27 | OreoFR | AI-assisted: Claude Code (Claude Opus 5.5)
TO: @sodove | RE: your ebdc991 retest
ASK: 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 auto the 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)

Tyrannys added a commit to Tyrannys/leonida that referenced this pull request Nov 27, 2026
…-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>
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.

5 participants