Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 37 additions & 4 deletions docs/d3d12_vulkan.md
Original file line number Diff line number Diff line change
Expand Up @@ -2923,10 +2923,12 @@ submitting thread; at the maintainers' decision it was replaced by this one when
title submits (a submission in the last second, `src/pipeline_wait.h`); the pipeline is built at its first use
instead. Opt-in: unset or 0, every warm-up runs, as on `main`, and `LargeModuleGate` (#1889) orders them behind a
submission's compiles. Smaller warm-ups, and every warm-up before the first submission, run as before.
- **A bounded, adaptive compile gate, opt-in** (`SubmitMutex::enter_submit`, `src/vulkan_device_fault.h`,
`LEONIDA_COMPILE_GATE=adaptive`). Unset, the gate stays the classic one: compute creates only, each waited for
however long it takes, no probes, as before. The adaptive gate is opt-in because of what it costs on a driver that
does hold submissions behind a create (630.20, below): no run of it there has been reported yet. The gate keeps a
- **A bounded, adaptive compile gate, where the driver was measured for it** (`SubmitMutex::enter_submit`,
`src/vulkan_device_fault.h`; `LEONIDA_COMPILE_GATE=adaptive` forces it, `classic` forces the classic one). The
classic gate: compute creates only, each waited for however long it takes, no probes, as before. Unset or `auto`,
the device measures which one this driver gets before the title runs (the next item). The adaptive gate is not on
everywhere because of what it costs on a driver that does hold submissions behind a create (630.20, below): no run
of it there has been reported yet. The gate keeps a
`vkQueueSubmit` out of the driver while a create is in it, since on NVIDIA 630.20 one that entered during a long
`vkCreateComputePipelines` waited 10 s and lost the device. The waiting submission holds the submit lock, so all
queues stop: on an RTX 4070 Laptop (NVIDIA 621.40) one compute create of a 2.3 MB module stayed in the driver for
Expand Down Expand Up @@ -2990,6 +2992,37 @@ submitting thread; at the maintainers' decision it was replaced by this one when
create in the driver (kind, program, SPIR-V size, thread, how long it had been there, whether submissions waited
for it) and each kind's gate. Long graphics creates would leave the title's process only through the compile
helper, which builds compute pipelines alone today.
- **`LEONIDA_COMPILE_GATE=auto`, the default: a calibration at device creation** (`src/compile_gate_policy.h`,
`src/compile_gate_calibration.h`, `decide_auto_compile_gate` in `shims/d3d12_vulkan_device.cpp`). Before the
`VulkanContext` (and its `SubmitMutex`) exists, so nothing is gated before the decision, a worker thread creates a
compute pipeline written in code (a chain of `fract(sin(...))` steps and branches over a storage buffer, its
constants from specialization constant 0 with a new seed each run, so neither a pipeline cache nor the driver's
shader cache answers it; no game data) while this thread submits an empty command buffer to the device's queue and
waits for its fence, over and over, until the create returns. At least 3 submissions back in 50 ms or less, before
the create left and some in its second half, with none slower: adaptive. One of 250 ms or more that came back
within 200 ms of the create leaving: the driver holds submissions, classic. A create under 300 ms is tried again
larger (up to 4 trials, none started after 6 s); a slow submission the create does not explain, too few samples
or any failed call: classic. The verdict is kept per vendor, device, driver version and pipeline cache UUID in
`compile_gate_calibration.txt` beside the pipeline cache, so it runs once per driver; a failed call or an unclear
verdict (a slow submission the create does not explain) is not kept, and the next launch measures again, so one
busy moment on the GPU does not hold every later launch on the classic gate. After a wait that times out, the fence
and command pool are destroyed only once the submission's fence signals (left alive on a lost device).
`LEONIDA_COMPILE_GATE_RECALIBRATE=1` measures again. It is logged once, `[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
...)` (`classic` and the reason otherwise). Only gta6rt's title process calibrates; `--precompile-pipelines`,
`--compile-server` and the tests keep the classic gate, and a forced value never waits for it.
Why a calibration can ask what an in-game probe cannot: the adaptive gate learns by letting a submission into the
driver beside a create of the title's, which can take 30-60 s, and on a driver that holds submissions such a probe
loses the device once it waits 10 s more. The calibration's create takes about a second and its submissions are
empty, so on such a driver one is held about a second and comes back with the create; that cannot reach the 10 s
the driver allows. What is known for the verdict to agree with, `MEASURED` but small (#2412,
[comment 7217585003](https://github.com/ubiquitarianism/leonida/pull/2412#issuecomment-7217585003)): on an RTX 4070
Laptop with NVIDIA 621.40 a synthetic probe never held a submission past 80 ms beside 8-10 s graphics creates and
retail adaptive runs had no gate hang after #2418, and this calibration gives adaptive there (in 6 runs of
`vk_compile_gate_calibration_test`, 53-125 submissions each, none over 0.9 ms, beside creates of 354-783 ms); an RTX 4060 with 610.88 turned the adaptive gate off with no
regression reported; other 621.x users report fewer crashes with it; one freeze at about 231 s on an RTX 5070
(621.x) was at a head without #2418 and is being rechecked. On 630.20 the calibration has not run yet: the
expected verdict there is classic, from the 10 s hold measured beside a long compute create.

**Open:** whether the game uses `D3D12_PIPELINE_STATE_STREAM_DESC` for mesh/RT and which subobject types appear.
The trace will enumerate them.
Expand Down
21 changes: 21 additions & 0 deletions runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,10 @@ if(BUILD_TESTING)
target_link_libraries(big_compile_gate_test PRIVATE Threads::Threads)
add_test(NAME big_compile_gate COMMAND big_compile_gate_test)
set_tests_properties(big_compile_gate PROPERTIES TIMEOUT 120)
# LEONIDA_COMPILE_GATE=auto (src/compile_gate_policy.h): the setting, the calibration verdict, its cache file and the
# slow pipeline's SPIR-V: pure stdlib, no Vulkan device.
add_executable(compile_gate_policy_test test/compile_gate_policy_test.cpp)
add_test(NAME compile_gate_policy COMMAND compile_gate_policy_test)
# vk_pipeline_check's memory budget for large modules: pure stdlib, no Vulkan device.
add_executable(large_module_gate_test test/large_module_gate_test.cpp)
find_package(Threads REQUIRED)
Expand Down Expand Up @@ -2012,6 +2016,23 @@ if(TARGET Vulkan::Headers)
target_compile_definitions(${tool} PRIVATE WIN32_LEAN_AND_MEAN NOMINMAX)
endif()
endforeach()
# The LEONIDA_COMPILE_GATE=auto calibration (src/compile_gate_calibration.h) on this machine's GPU: a verdict within
# 20 s, adaptive on NVIDIA 621.40. 77 without a Vulkan device.
add_executable(vk_compile_gate_calibration_test test/vk_compile_gate_calibration_test.cpp)
target_link_libraries(vk_compile_gate_calibration_test PRIVATE Vulkan::Headers ${CMAKE_DL_LIBS})
if(WIN32)
target_compile_definitions(vk_compile_gate_calibration_test PRIVATE WIN32_LEAN_AND_MEAN NOMINMAX)
else()
find_package(Threads REQUIRED)
target_link_libraries(vk_compile_gate_calibration_test PRIVATE Threads::Threads)
endif()
if(MSVC)
target_compile_options(vk_compile_gate_calibration_test PRIVATE /W4 /permissive- /utf-8)
endif()
if(BUILD_TESTING)
add_test(NAME vk_compile_gate_calibration COMMAND vk_compile_gate_calibration_test)
set_tests_properties(vk_compile_gate_calibration PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 60)
endif()
# The ExecuteIndirect argument clamp's compute pass (runtime/src/vulkan_indirect_clamp.h): every argument kind and
# the counted variants, with garbage records bounded and the batch budget saturating, read back from the scratch
# the replay would use. 77 without a Vulkan device.
Expand Down
Loading
Loading