A diagnostic for the retail boot (RT-5 follow-ups), off the hot path and with no behaviour change unless asked
for: LEONIDA_SKIP_ASSERTS=N (src/assert_skip.h, installed by main.cpp before any image code runs under
--init/--run): a vectored handler, added last, steps over up to N int3 (0xCC) at addresses in no host module and
logs each one as module+RVA (and as an int3_skipped trace event when --trace is open). After N it says so once
and the next int3 ends the run as before. An int3 in a host module, a breakpoint with no 0xCC at its address, or
a RIP that is neither at nor one past the 0xCC is passed on. Needs no --trace and no debugger.
Tests (synthetic, no game files): assert_skip_test (int3 in a VirtualAlloc'd page, the limit, a host-module int3,
a two-byte int 3, value parsing) and run_tiny_game_skip_asserts (two int3 in the mapped stand-in game, stepped
over end to end).
Carried over from old upstream PR 9961 (#228) without its caller logging for forwarded device slots, which the
carry-over of old PR 9990 (#1390) brings instead.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Gate 4-byte 0xC5 cross-instruction fusion in isa_jit_patch::patch_image behind
opt-in LEONIDA_ISA_FUSE_4B=1 (off by default) and document LEONIDA_ISA_FUSE_4B
in runtime/README.md.
- When LEONIDA_ISA_FUSE_4B=1 is enabled and mark_block_targets resolves a
RIP-relative target inside a non-executable data section, also scan
consecutive signed 32-bit Clang/LLVM table-relative jump-table entries
( arget_rva = tbl_rva + entry) within [beg_rva, end_rva) so fusion never
crosses a relative switch case boundary.
- Update isa_jit_patch_test to verify default non-fusion of 4-byte 0xC5 sites,
opt-in fusion under LEONIDA_ISA_FUSE_4B=1, and fusion refusal across both
image-base RVA tables and negative table-relative int32_t .rdata switch tables.
Review follow-up for #1564:
- Registration and the cleanup of exit, quick_exit and _cexit hold one recursive lock of the run's own, from before the thread-local callback through the table's drain (and _cexit's stream flush), as the UCRT holds its exit lock: two threads never clean up at once, and a registration from another thread waits for the cleanup. The exiting thread may still register from a handler, _cexit still returns, and the lock is released before the run ends (end_run), also when a handler ends the run from inside a drain.
- Each guest cleanup callback (atexit, at_quick_exit, the thread-local destructor callback) runs inside a C++ exception boundary: one that throws ends the run through game_abort, as the UCRT's terminate() would (exit code 3), instead of leaving the process with 0xE06D7363.
tiny_atexit gains four modes, held to the native sequence: concurrent_cexit (a second thread's _cexit, with a thread_local of its own, waits for the cleanup), quick_exit_register (an at_quick_exit from a second thread during a quick_exit drain waits, so its handler never runs), quick_exit_throw and exit_throw (exit code 3). In the concurrent modes the slow handler waits until the second thread is about to call, so the sequence is fixed under any scheduling with the lock. All four fail on c5b51e9 through --run.
The game's at_quick_exit() (_crt_at_quick_exit) and _register_thread_local_exe_atexit_callback still
reached the host CRT, which the game shares with gta6rt. Under `gta6rt --run`:
- quick_exit() ran none of the game's at_quick_exit handlers;
- exit() and _cexit() never ran the exiting thread's thread_local destructors, and a second
registration in the host's one-slot callback would terminate gta6rt.
Now _crt_at_quick_exit goes to a second table of the run's own, which quick_exit() runs newest first
under the exit lock; _exit() and _Exit() run none (they no longer share game_quick_exit). The thread-local
callback is the run's own: exit() and _cexit() call it with DLL_PROCESS_DETACH before the atexit handlers,
as the UCRT does, and a second registration aborts, as the UCRT's terminate() does. Both reset per run.
tiny_atexit gains five modes (at_quick_exit, at_quick_exit_exit, at_quick_exit__exit, thread_local_exit,
thread_local_cexit). Their expected sequences in check_atexit.cmake were measured by running the fixture
natively on Windows 11; before this change --run differed on at_quick_exit, thread_local_exit and
thread_local_cexit. run_tiny_atexit now holds 13 paths to the Windows sequence.
With LEONIDA_ASYNC_PIPELINES=1, graphics and mesh pipelines (all their stages) now take
LEONIDA_ASYNC_MIN_BYTES_GRAPHICS when it is set, and LEONIDA_ASYNC_MIN_BYTES otherwise, so
nothing changes while it is unset. Compute keeps LEONIDA_ASYNC_MIN_BYTES. 0 makes every graphics
pipeline asynchronous. One startup line states both thresholds; text that is not a number is
ignored with a log line.
Thread dumps from a retail run showed the draw thread building lazy graphics variants under the
1 MiB threshold in place, 2.5-11 s each, back to back, with no present for about 100 s. A skipped
draw costs one draw. The image needs the small lighting and post compute programs, and those
are still built in place.
Tests: async_pipeline_size_test covers the per-kind decision and the unset fallback;
d3d12_pipeline_workers_test --async-graphics-zero / --async-graphics-unset (new ctests) hold
the compile worker with compute over its threshold.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resolve runtime/README.md conflict with #2220 (LEONIDA_PIPELINE_ORDER_LOG)
and note in docs/d3d12_vulkan.md that LEONIDA_COMPILE_GATE=adaptive and 1
gate graphics creates as well (#2412).
Review of #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>
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>
docs/design.md states what the pack and the runtime agree on (the tag 0xA << 28, index 0, how an older pack is
recognised) with the counts; runtime/README.md says what LEONIDA_CONSOLE_HEAP_GPU does with an index-word pack;
make_game.py and runtime/cmake/translator_deps.cmake list the translator's new imports (descriptor_sources.py,
heap_index_census.py), so a pack and the test shaders are made again when they change.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- 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 <noreply@anthropic.com>
With LEONIDA_COMPILE_THREADS=1 (the layout of main: one general worker and
the graphics-only one) next_locked did not look at the owner, so two variants
of one graphics PSO could build at once, one on each worker. A last Release
meanwhile hands the PSO's deletion to the running build it finds first
(after_running), and that worker deleted the PSO while the other was still
in build() on it. The single-worker selection now skips a job whose PSO has
a build running, as the pool already did.
New test in d3d12_compile_pool_test: two graphics variants of one PSO with
one worker plus the graphics worker; the second must not start while the
first runs, another PSO's build still uses the free worker, and a last
Release runs after the first build with the second dropped. It fails
without the fix.
Docs: the heavy count also bounds LEONIDA_SERIAL_BIG_COMPILES=0 on the
workers; only compute creates pass the compile gate.
Found by qhukz13 in review of #2233.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Two always-on lines every LEONIDA_SUBMIT_FRAME_SECONDS (10 by default, 0
off), from the counters the phase line already keeps and a few more:
[rt] submit frame: frames presented and, per frame, the submissions by
queue kind and the milliseconds the title's threads spent in the layer:
the existing phases counted per frame instead of per submission, plus
what the phase line leaves out - ExecuteCommandLists outside the phases
(list unwrapping, the console's list-value waits and writes, the queue
lock), the queues' Signal and Wait, and the present. Inside those, the
vkQueueSubmit calls and waits for contended submission-path locks are
given apart. Then the window's worst frame and the time of our own
threads per frame: the submit worker (LEONIDA_SUBMIT_ASYNC), the texture
read threads and filler, the console heap resolver, the geometry
refresher, the list values' pump and releaser, the fence callbacks.
[rt] submit floor: how many submissions changed nothing (no heap slot or
page, shadow page, geometry, texture fill or pipeline build), their
average and least cost and their phases, against all submissions.
Title calls are timed once, at their outermost entry, less the phases
inside them; a WorkerScope marks our own threads so their phases are not
counted as the title's. A frame ends at each present the presenter takes.
submit_frame_test checks a scripted run on the CPU (frame sums, title and
own threads, worst frame, floor) and, with a Vulkan device, that the floor
of 20 empty submissions through VulkanQueue sums to exactly what the
phase totals grew by.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With LEONIDA_ASYNC_PIPELINES=1 every pipeline not built yet has its draws
and dispatches skipped, the small lighting and post programs too, so the
world phase stays black while anything compiles; with it off a submission
waits minutes for each large ray-tracing compute program.
LEONIDA_ASYNC_MIN_BYTES=<n> (with async on): a pipeline under n bytes of
SPIR-V (compute: its module; graphics: all its stages) takes the path of
async off: no record-time request, PipelineCompiles builds it at prepare,
and a compile-helper build waits for its file. One of n bytes or more stays
asynchronous. Decided once per pipeline at create (async_build). Unset, 0
or not a number: every pipeline asynchronous, as before.
Tests: async_pipeline_size_test (parsing and decision);
d3d12_m4_compute --async-small-waits (both pipelines under the threshold,
compile worker held: no job reaches it and every word matches).
Docs: runtime/README.md row, docs/d3d12_vulkan.md, docs/running.md.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With LEONIDA_TRACE_XGAMESAVE=1 the offline XGameSaveImpl logs one
"[rt] xgamesave:" line per XGameSave* and XGameSaveFiles* call: the call,
its handles, container and blob names, sizes and HRESULT, with the
milliseconds since the process started and the thread id. An async call
also logs when begin() schedules its job, when the work runs (and how
long it waited on the queue), when it completes and when the title
collects the result, all naming the title's XAsyncBlock. Blob contents
are never logged. Off by default: a call then pays one relaxed load.
xgameruntime_gamesave_test turns it on through a test hook, writes and
reads a blob (sync and async) and checks the lines.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review of #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>
With LEONIDA_DEVICE_MARKERS=1 every draw the replay records takes a seq from the dispatch numbering and writes the
VK_AMD_buffer_marker pair: started before its helper passes and rendering scope, finished after the scope ends (the
legacy indirect path inside the caller's scope, which the extension allows). The marker history (now 65,536 items)
keeps each draw's kind and counts, pipeline names, execute, list, command and its place among the draws to the same
targets. The loss and stall reports name the last finished item, the likely hang, the rest in flight and an idle
queue's next one not started, for draws and dispatches alike; a device-fault address is followed by the last draw
each queue started. Tests: the CPU marker test records draws and dispatches and checks the lines; the GPU marker
test writes draw markers outside and inside a dynamic-rendering scope.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A diagnostic, off by default. Each submission on a queue whose family has
timestamp bits gets a query pool, reset once at the start of its command
buffer, and bottom-of-pipe timestamps: after the opening barrier and
bindless upload, before each run of consecutive draws or dispatches of one
pipeline, after a run that another command follows, and at the end. The
difference between two consecutive timestamps is what lies between them
added to the queue's work: a run's GPU time, or "other" when no draw or
dispatch lies between. The results are read on the fence callback once the
submission is done, never waited for, and summed by pipeline under its
stages' ShaderLibrary names (as the pass trace prints them), else its id.
Every 10 s, [rt] gpu profile lines give per frame the compute, graphics
and mesh totals, other work, per queue kind the busy time (measured as
LEONIDA_GPU_LATENCY does) against the timestamped span and the share in
draws and dispatches, and the 20 pipelines with the most GPU time (ms per
frame, share, kind, calls per frame, ms per call).
PSOs register their names with the context when the profile is on, as
they already do for the device-fault report; the device passes the
families' timestamp bits to the context. Off: one test per submission and
per command. On: about 1 us per timestamp on the Raphael iGPU, submit to
idle (vk_gpu_profile_test).
vk_gpu_profile_test runs known dispatches of two pipelines and a draw
through VulkanQueue and checks each pipeline's name, calls, runs, a time
that grows with its loop count, and that the intervals add up to the span.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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>
runtime/README.md: the console-heap rows come from the refill branch, the shadow rows from #1867.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
runtime/README.md: the sparse arena changed the LEONIDA_IMPORT_BELOW_ARENA row and the texture work removed the LEONIDA_ORDER_TEXTURE_UPLOADS row next to it; the arena's row is kept and the removed row stays removed.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>