diff --git a/docs/d3d12_vulkan.md b/docs/d3d12_vulkan.md index 7bd8dd2555..a368c77b48 100644 --- a/docs/d3d12_vulkan.md +++ b/docs/d3d12_vulkan.md @@ -2899,6 +2899,73 @@ 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 + `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 + more than 54 s during the story load, the submission waited for all of it and the title's 30 s hang watchdog ended + the process; with `LEONIDA_COMPILE_GATE=0` the same build went past that point. With the adaptive gate a + submission waits at most `LEONIDA_COMPILE_GATE_WAIT_MS` (15 s by default there) and then goes ahead; the creates in + the driver at that moment hold no later submission back, and creates that enter after it are waited for again. On + 630.20 that loses only creates over 25 s (15 s here, then the driver's 10 s), which the watchdog ends anyway. + On the same laptop the three submissions that went ahead came back from the driver in 11, 1 and 0 ms with the + create still there, and no device was lost; but consecutive long creates made submissions wait the full 15 s again + and again, and the title's watchdog still ended the run. So the adaptive gate adapts: every submission that + enters the driver next to a create it no longer waits for is 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 (a driver that holds a + submission behind a create holds it as long as the create stays, and 630.20 held one for the full 10 s). Two, and a + second apart, because back-to-back creates take and release that driver's lock, so one submission can slip in + between; the second costs no extra wait, since after one has gone ahead the next enter at once while the create is + still there. One probe that stays 2 s or more keeps the gate on for the rest of the run (presents and idle waits do + not probe, below). Both verdicts are logged once. `LEONIDA_COMPILE_GATE=1` gates always and never probes. + In the next run on that laptop the story load passed, but no wait reached 15 s, so no probe came: 80 submissions + waited 3-7 s each (90 s in all, the longest 6.7 s), back to back, and the title's watchdog ended the run at 433 s. + So until a verdict is in, a submission also goes ahead once the submissions' 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 limit per wait, because it also counts many short waits, and one wait reaches it as + soon as a 2.5 s limit would. Before the verdict the gate then stops the queues for at most about a quarter of any + 10 s, after a quick verdict not at all. On a driver that does hold submissions (630.20) the first probe now enters + the driver after 2.5 s of waiting instead of 15 s, and loses the device if the create stays there 10 s more (the + classic gate waits that create out). One probe per kind and run: it holds the submit lock while it is in the + driver, so no other submission enters until it comes back, and it then gives the held verdict (2 s or more, back + within 500 ms of the create leaving), after which no submission goes ahead beside a create of that kind before the + held limit. The held threshold stays 2 s, well inside the 10 s such a driver gives before the loss. The limit and the + budget apply with the title's watchdog kept kicked too (`LEONIDA_TITLE_WATCHDOG=0` and + `LEONIDA_TITLE_WATCHDOG_KICK`): nothing ends the run then, but the stops still cost the frames, and an RTX 4060 run + that way had 459 waits, 155 s in all and the longest 2.9 s, by t=202 s. Only `LEONIDA_COMPILE_GATE_WAIT_MS=0` (with + no `LEONIDA_COMPILE_GATE_PROBE_MS`) or `LEONIDA_COMPILE_GATE=1` (with no `LEONIDA_COMPILE_GATE_WAIT_MS`) waits + however long the creates take and never adapts. + Tested by `submit_mutex` (no GPU); the probe budget is not yet measured in the title. + The verdict is kept per kind of create, compute and graphics (mesh pipelines included), and graphics creates + pass this gate and `LEONIDA_COMPILE_GATE=1` too (the classic gate, as before, only compute builds). On 621.40 every probe beside a compute create came back in + 0-12 ms (and on an RTX 4060 with 610.88, 133 of them), 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 create, and with `LEONIDA_COMPILE_GATE=0` a + `vkQueueSubmit` sat 54 s in the driver beside a 56 s mesh create (541 KB) and the device was lost. 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 + counts against all of them, since which create held it cannot be told. 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. A + held probe (pending or off) counts only if the submission 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 58 s compute create beside it; + counted as held, it re-armed the gate, which then kept the next submission 78 s behind compute creates. A + synthetic probe on the same machine (one to three threads creating 2 MB graphics pipelines of 8-10 s each, with + and without `VK_NV_device_diagnostics_config` and a shared pipeline cache) never held a submission past 80 ms. + The recent leaves are kept in a ring, so a create that entered after the submission and left after the one it + entered beside does not hide that one. Only submissions (`vkQueueSubmit`, `vkQueueBindSparse`) probe: presents and + idle or semaphore waits pass the gate the same way but can take seconds on their own, so they judge nothing, and + they never go ahead at the probe budget, only at the limit. While a create of a kind that holds submissions is in + the driver, no submission goes ahead at the limit or the budget, and such a create is waited for even when one went + past it before the verdict, up to the held limit (`LEONIDA_COMPILE_GATE_HELD_WAIT_MS`, 60 s; 0 waits however long, + and a held limit under the plain one applies on its own): then the creates in the driver are gone past and the + next submissions no longer wait for them. This is checked on every pass of the wait: once such a create leaves + while creates of a kind with no verdict stay, the plain limit and budget apply again. A false + "holds" verdict so costs at most that per create, not the rest of the run. On a device loss the log names every + 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. **Open:** whether the game uses `D3D12_PIPELINE_STATE_STREAM_DESC` for mesh/RT and which subobject types appear. The trace will enumerate them. diff --git a/runtime/README.md b/runtime/README.md index ab8451e6ff..b885981fc3 100644 --- a/runtime/README.md +++ b/runtime/README.md @@ -421,7 +421,10 @@ ones marked *diagnostic* only add log lines or exist to compare a run with and w | `LEONIDA_TEXTURE_REFRESH_ASYNC` | unset | `1` moves the before-submission refresh of the title textures (`refresh_title_textures`) to a worker: a submission only wakes it, and fills by itself only the mapped textures that were never filled, so their first draw has their bytes. Persistent mappings are hashed whole on the worker every pass; the rest is swept 128 textures at a time. A texture changed since may be sampled a frame behind. | | `LEONIDA_SUBMIT_ASYNC` | `0` | ``: each queue's `ExecuteCommandLists`, `Signal`, `Wait` and markers run in call order on a worker of the queue's own (`src/vulkan_backend.h`), at most n batches queued; the caller of the next one waits for room. The replay, the before-submission refreshes and `vkQueueSubmit` then leave the title's thread. A batch that fails is reported as a held one is. `0`: on the caller's thread. | | `LEONIDA_COMPUTE_WARMUP_LIVE_MAX_BYTES` | unset | ``: a compute warm-up of a module over n bytes of SPIR-V is not started while the title submits (a submission in the last second); the pipeline is built at its first use instead (docs/d3d12_vulkan.md, "Pipelines still being built"). Unset or `0`: every warm-up runs, ordered behind a submission's compiles by the large-compile gate. | -| `LEONIDA_COMPILE_GATE` | unset | `1`: a compute pipeline build holds the device's submit lock for its driver calls, so no compute compile runs while a queue submits. Unset: the asynchronous workers compile while other queues submit. | +| `LEONIDA_COMPILE_GATE` | on (classic) | The compile gate (`SubmitMutex::CompileTurn`, `src/vulkan_device_fault.h`): a queue submission (or a present or device wait) does not enter the driver while a pipeline create is in it, and waits in the runtime instead, since on NVIDIA 630.20 a `vkQueueSubmit` that entered during a long `vkCreateComputePipelines` waited 10 s in the driver and lost the device. Creates pass together; one that arrives while a submission waits queues behind it. Unset: the classic gate, as before the adaptive one: compute creates only, waited for however long they take (`LEONIDA_COMPILE_GATE_WAIT_MS` can bound it), no probes. `adaptive`: the adaptive gate, opt-in until it has run on a driver that holds submissions (630.20), where its first probe of a kind enters the driver after the probe budget and loses the device if that create stays 10 s more. The adaptive gate's wait is bounded by `LEONIDA_COMPILE_GATE_WAIT_MS`. Each submission that enters the driver next to a create the gate went past (at that limit, or earlier at the probe budget, `LEONIDA_COMPILE_GATE_PROBE_MS`) is a probe; two that come back in under 250 ms, at least 1 s apart, with the create still in the driver turn the gate off for the rest of the run (NVIDIA 621.40: 0-11 ms), and one that stays 2 s or more keeps it on; both are logged once. The verdict is kept per kind of create, compute and graphics (mesh included; graphics creates pass the gate since then, only compute ones did before): on NVIDIA 621.40 submissions came back in 0-12 ms beside compute creates, but one sat 54 s in the driver beside a 56 s mesh create and the device was lost. A kind that is off is still timed, and a submission that stays 2 s beside one of its creates turns it back on. A submission never goes ahead, at the limit or the budget, beside a create of a kind whose verdict is that it holds submissions: it waits for that create up to `LEONIDA_COMPILE_GATE_HELD_WAIT_MS`. On a device loss the log names the creates in the driver (kind, program, size, how long) and each kind's gate. `1`: always gate, graphics creates too, with no limit unless `LEONIDA_COMPILE_GATE_WAIT_MS` sets one, never probe or turn it off, and a compute pipeline build also holds the submit lock for its driver calls (`compute_driver_turn`, `shims/d3d12_vulkan_device.cpp`). `0`: no gate. | +| `LEONIDA_COMPILE_GATE_WAIT_MS` | 0 (15000 with `LEONIDA_COMPILE_GATE=adaptive`) | ``: how long a submission waits at the compile gate before it goes ahead anyway; the creates in the driver then hold no later submission back (creates that enter after it are waited for again), and the log says how long the submission then took in the driver. The waiter holds the submit lock, so every queue stops behind it, and the title's hang watchdog ends the process after 30 s (one create stayed in the driver for over 54 s on NVIDIA 621.40). 15 s keeps the 630.20 protection for creates of up to 25 s. The same with the watchdog kept kicked: nothing ends the run then, but the stops still cost the frames (an RTX 4060 run that way had 459 waits, 155 s in all, by t=202 s). `0`: no limit, and with `LEONIDA_COMPILE_GATE_PROBE_MS` unset no probes either: the gate waits however long the creates take and never adapts. | +| `LEONIDA_COMPILE_GATE_HELD_WAIT_MS` | 60000 | ``: with the adaptive gate, how long a submission waits for creates of a kind the gate found to hold submissions (`docs/d3d12_vulkan.md`) before it goes ahead anyway; those creates are then not waited for again. `0`: until they leave. | +| `LEONIDA_COMPILE_GATE_PROBE_MS` | 2500 with `LEONIDA_COMPILE_GATE=adaptive` (0 with `LEONIDA_COMPILE_GATE_WAIT_MS=0`) | ``: the adaptive gate's probe budget. Until it knows whether the driver holds a submission behind a create, a submission also goes ahead once the submissions' waits at the gate in the last 10 s, its own included, add up to this; a single wait reaches it at 2.5 s. On NVIDIA 621.40 waits of 3-7 s, none near the 15 s limit, came back to back and kept the title's main loop from reporting for 30 s; on an RTX 4060 with the watchdog kept kicked, 459 waits of up to 2.9 s took 155 s by t=202 s. The cost on a driver that does hold submissions (630.20): the first probe enters the driver after 2.5 s of waiting and loses the device if the create stays 10 s more; the held verdict then stops the early probes. `0`: probes only at `LEONIDA_COMPILE_GATE_WAIT_MS`. Used only with `LEONIDA_COMPILE_GATE=adaptive`. | | `LEONIDA_FAST_PIPELINES` | unset | `graphics`, `compute` or `all` (`1` = all) creates those pipelines with `VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT` (`shims/d3d12_pipeline_compile.h`): slower shaders, much shorter builds. Part of the compute journal key, so optimized and fast builds keep separate files. | | `LEONIDA_GRAPHICS_COMPILE_WORKER` | on | A second compile worker that takes graphics pipeline builds only, so a long compute build does not hold them up (`shims/d3d12_pipeline_compile.h`). `0`: the one general worker builds everything. | | `LEONIDA_CONSOLE_HEAP_GPU` | unset | `1`: the V#s of the console descriptor heaps are rebased by a compute pass at the start of each submission (`src/console_heap_gpu.h`) instead of on the CPU. The CPU still finds the changed slots and registers the T#s; a V# the pass cannot answer is resolved after its submission and its slot queued again. | diff --git a/runtime/shims/d3d12_pipeline_compile.h b/runtime/shims/d3d12_pipeline_compile.h index a0ff0e86d0..bb4ab03276 100644 --- a/runtime/shims/d3d12_pipeline_compile.h +++ b/runtime/shims/d3d12_pipeline_compile.h @@ -165,13 +165,15 @@ inline bool compile_worker_trigger(const char* trigger) { // behind it go first, and does so before its vkCreateShaderModule and vkDestroyShaderModule too; a title thread // waits only for the holder, and only before a pipeline create (it may wait out a vkDeviceWaitIdle or a present: // waits of 50 ms or more are logged). -// - a pipeline create passes the compile gate (SubmitMutex::CompileTurn) for the length of the call. +// - a pipeline create passes the compile gate (SubmitMutex::CompileTurn) for the length of the call, as its kind +// (compute, or graphics with mesh): the adaptive gate keeps a verdict per kind. // - the compile worker, which runs below normal priority, runs the call at normal priority, so a preempted worker // does not sit on a driver lock a submit waits for. class DriverTurn { public: DriverTurn(leonida::SubmitMutex& submits, const char* trigger, const char* call, bool pipeline, - const char* name = nullptr) + const char* name = nullptr, + leonida::SubmitMutex::CreateKind kind = leonida::SubmitMutex::CreateKind::compute, std::size_t bytes = 0) : worker_(compile_worker_trigger(trigger)) { // Normal priority first: a below-normal worker that waits its turn at normal priority cannot keep losing the // race to the next submit, and holds the gate (below) only at normal priority. @@ -187,7 +189,7 @@ class DriverTurn { if (waited >= 50) note("waited for the submit lock", trigger, call, name, waited); } if (pipeline) { - gate_.emplace(submits); + gate_.emplace(submits, leonida::SubmitMutex::CreateInfo{kind, name, trigger, bytes}); if (gate_->waited_ms() >= 50) note("waited at the compile gate", trigger, call, name, gate_->waited_ms()); } } diff --git a/runtime/shims/d3d12_vulkan_device.cpp b/runtime/shims/d3d12_vulkan_device.cpp index 37d1d007ee..6c8d9345c3 100644 --- a/runtime/shims/d3d12_vulkan_device.cpp +++ b/runtime/shims/d3d12_vulkan_device.cpp @@ -11266,7 +11266,8 @@ ComputeBuild build_compute_pipeline(DeviceState& device, const leonida::ShaderEn // gate: from the journal a build takes milliseconds and the warm-up worker makes them back to back, and // three warm boots lost the device in a vkQueueSubmit (no GPU fault, no TDR) while only the create was // gated. No file I/O in here. - const DriverTurn turn(submits, trigger, "vkCreateComputePipelines", true, entry->name.c_str()); + const DriverTurn turn(submits, trigger, "vkCreateComputePipelines", true, entry->name.c_str(), + leonida::SubmitMutex::CreateKind::compute, bytes); { const leonida::aftermath::ShaderName named(entry->name); if (vk.vkCreateShaderModule(dev, &module_info, nullptr, &module) != VK_SUCCESS) return out; @@ -12902,11 +12903,26 @@ class PipelineState final const leonida::dev_status::Build dev_build(r.mesh ? "mesh pipeline" : "graphics pipeline"); const leonida::pipeline_profile::DriverCall profile(r.mesh ? "ms" : "vs", lazy_ ? "lazy" : "eager", program, fragment, unbound); - const auto result = device_.create_pipeline(flags, [&](VkPipelineCache with, VkPipelineCreateFlags f) { - info.flags = f; - pipeline = VK_NULL_HANDLE; - return device_.context->vk.vkCreateGraphicsPipelines(device_.info.device, with, 1, &info, nullptr, &pipeline); - }); + // Through the compile gate as a graphics create (a mesh pipeline is one): on NVIDIA 621.40 a vkQueueSubmit + // sat in the driver for as long as a mesh create was in it (54 s) and lost the device. Not with the classic + // gate (the default), which keeps graphics creates out of it as before. + const char* gate_name = nullptr; + for (const auto& source : sources_) + if (source.entry && source.slot == 0) gate_name = source.entry->name.c_str(); + VkResult result = VK_ERROR_UNKNOWN; + { + std::optional turn; + if (leonida::SubmitMutex::compile_gate_graphics()) + turn.emplace(device_.context->submit_mutex(), trigger, + r.mesh ? "vkCreateGraphicsPipelines (mesh)" : "vkCreateGraphicsPipelines", true, gate_name, + leonida::SubmitMutex::CreateKind::graphics, bytes); + result = device_.create_pipeline(flags, [&](VkPipelineCache with, VkPipelineCreateFlags f) { + info.flags = f; + pipeline = VK_NULL_HANDLE; + return device_.context->vk.vkCreateGraphicsPipelines(device_.info.device, with, 1, &info, nullptr, + &pipeline); + }); + } if (status) *status = result; profile.finish(int(result)); trace.end(trigger, profile_shaders_.c_str(), unbound, bytes, result); @@ -14956,7 +14972,7 @@ class Device final // after it, so the generations flush() retires are free at once. { std::lock_guard submit(context.submit_mutex()); - const leonida::SubmitMutex::SubmitTurn turn(context.submit_mutex()); // the compile gate + const leonida::SubmitMutex::SubmitTurn turn(context.submit_mutex(), false); // the compile gate context.observe_result(context.vk.vkDeviceWaitIdle(state_.info.device), "vkDeviceWaitIdle"); } state_.bindless_idle_waits.fetch_add(1, std::memory_order_relaxed); @@ -15275,7 +15291,7 @@ class Device final if (state_.context) { { std::lock_guard lock(state_.context->submit_mutex()); - const leonida::SubmitMutex::SubmitTurn turn(state_.context->submit_mutex()); // the compile gate + const leonida::SubmitMutex::SubmitTurn turn(state_.context->submit_mutex(), false); // the compile gate state_.context->observe_result(state_.context->vk.vkDeviceWaitIdle(state_.info.device), "vkDeviceWaitIdle"); } diff --git a/runtime/shims/dxgi_swapchain.h b/runtime/shims/dxgi_swapchain.h index 477bc29b2e..87351a344d 100644 --- a/runtime/shims/dxgi_swapchain.h +++ b/runtime/shims/dxgi_swapchain.h @@ -220,7 +220,7 @@ class VulkanSwapchain { pi.pSwapchains = &swapchain_; pi.pImageIndices = &image_index; std::lock_guard lock(submit_mutex_); - const SubmitMutex::SubmitTurn turn(submit_mutex_); // a queue operation: the compile gate + const SubmitMutex::SubmitTurn turn(submit_mutex_, false); // a queue operation: the compile gate const VkResult r = observe(fn_.queue_present(queue_, &pi), "vkQueuePresentKHR (DXGI)"); return r == VK_SUCCESS || r == VK_SUBOPTIMAL_KHR; } diff --git a/runtime/src/vulkan_backend.h b/runtime/src/vulkan_backend.h index bf970aa282..18bcc07baa 100644 --- a/runtime/src/vulkan_backend.h +++ b/runtime/src/vulkan_backend.h @@ -1700,7 +1700,7 @@ class VulkanContext { ++host_texture_stats_.waits; // A device wait is a queue operation: it passes the compile gate, so it never waits in the driver behind a // long pipeline create (the starved wait that loses the device after 10 s). - const SubmitMutex::SubmitTurn turn(submit_mutex_); + const SubmitMutex::SubmitTurn turn(submit_mutex_, false); const auto result = wait_submitted_locked(kTitleWriteWaitNs, "vkWaitSemaphores (title texture upload)"); // Not done in time: VK_NOT_READY, so the caller takes its staged path (ordered on the queue) or tries // again later, and the skip is not counted as a failed fill. @@ -1722,7 +1722,7 @@ class VulkanContext { LayoutPieces pieces; if (!tracker_.pieces(id, range, pieces) || pieces.empty()) return VK_ERROR_UNKNOWN; if (image_work_pending_) { - const SubmitMutex::SubmitTurn turn(submit_mutex_); // a queue operation: the compile gate (as above) + const SubmitMutex::SubmitTurn turn(submit_mutex_, false); // a queue operation: the compile gate (as above) const auto r = wait_submitted_locked(kTitleWriteWaitNs, "vkWaitSemaphores (title staging)"); if (r != VK_SUCCESS) return r; image_work_pending_ = false; @@ -2073,7 +2073,7 @@ class VulkanContext { } void mark_device_lost(const char* where = "a Vulkan call returned VK_ERROR_DEVICE_LOST") noexcept { - set_device_lost(device_lost_, where); + if (set_device_lost(device_lost_, where)) submit_mutex_.report_creates_on_loss(); // which creates were in it run_device_lost_hook(); // LEONIDA_AFTERMATH: the GPU crash dump is written before waiters wake if (fence_dispatcher_) { try { @@ -2308,10 +2308,11 @@ class VulkanContext { if (gate.submits != gate_logged.submits || gate.creates != gate_logged.creates) { gate_logged = gate; std::fprintf(stderr, "[rt] compile-gate: t=%.0f s: %llu submissions waited for pipeline creates " - "(%lld ms in all, longest %lld ms); %llu creates waited behind a submission " - "(%lld ms in all, longest %lld ms)\n", + "(%lld ms in all, longest %lld ms, %llu went ahead at the limit); %llu creates " + "waited behind a submission (%lld ms in all, longest %lld ms)\n", double(diagnostic_ms()) / 1000.0, static_cast(gate.submits), static_cast(gate.submit_ms), static_cast(gate.submit_max_ms), + static_cast(gate.ahead), static_cast(gate.creates), static_cast(gate.create_ms), static_cast(gate.create_max_ms)); } @@ -2614,7 +2615,7 @@ class VulkanQueue : private QueueHolds::Holder { context_.holds().pump_ready(); // presents queued behind what was just dropped can run if (queue_) { std::lock_guard lock(context_.submit_mutex()); - const SubmitMutex::SubmitTurn turn(context_.submit_mutex()); // a queue operation: the compile gate + const SubmitMutex::SubmitTurn turn(context_.submit_mutex(), false); // a queue operation: the compile gate for (; open_labels_; --open_labels_) context_.labels_.queue_end(queue_); const VkResult idle_result = context_.observe_result(vk.vkQueueWaitIdle(queue_), "vkQueueWaitIdle"); if (idle_result == VK_SUCCESS) { @@ -2903,7 +2904,7 @@ class VulkanQueue : private QueueHolds::Holder { bool idle() { flush_async(); std::lock_guard lock(context_.submit_mutex()); - const SubmitMutex::SubmitTurn turn(context_.submit_mutex()); // a queue operation: the compile gate + const SubmitMutex::SubmitTurn turn(context_.submit_mutex(), false); // a queue operation: the compile gate return context_.observe_result(context_.vk.vkQueueWaitIdle(queue_), "vkQueueWaitIdle") == VK_SUCCESS; } diff --git a/runtime/src/vulkan_device_fault.h b/runtime/src/vulkan_device_fault.h index b3af188d13..17f4209344 100644 --- a/runtime/src/vulkan_device_fault.h +++ b/runtime/src/vulkan_device_fault.h @@ -309,6 +309,27 @@ struct DriverCompile { }; inline DriverCompile driver_compile; +// The compile gate's types, for SubmitMutex (which names them CreateKind, CreateInfo and GateAhead). At namespace +// scope, not nested: a default argument `= {}` of a nested class with default member initializers is rejected by +// clang and GCC inside the enclosing class (the member initializers are not parsed until that class is complete). +enum class CompileGateKind : std::uint8_t { compute, graphics }; // graphics: mesh pipelines too +// What a create is, for the verdicts and the reports. Names are ShaderLibrary strings, valid until device teardown +// (or literals). +struct CompileGateCreate { + CompileGateKind kind = CompileGateKind::compute; + const char* name = nullptr; + const char* trigger = nullptr; + std::size_t bytes = 0; // SPIR-V +}; +struct CompileGateAhead { // a submission that entered the driver alongside creates not waited for + std::int64_t since_ms = -1; // when it entered, or -1: no such create was in the driver + std::uint64_t last_create = 0; // the number of the last create that had entered then + std::uint32_t creates = 0; // such creates in the driver then + std::uint8_t kinds = 0; // their kinds, bit per CompileGateKind + bool went_ahead = false; // it waited at the gate up to the limit or the probe budget + bool probe = true; // its time in the driver is a probe (a submission, not a present or a wait) +}; + // VulkanContext's submit lock, which also remembers who holds it, since when and how many threads wait for it. A // submit or an idle wait blocked inside the driver holds it for as long as it blocks; the stall watchdog and the loss // report name that thread, and a hold of a second or more is logged when it ends. @@ -398,36 +419,243 @@ class SubmitMutex { // that arrives while a submission waits queues behind it, so a submission waits only for the creates already in // the driver. A long compile then stalls the submitting thread here, in our code, instead of in the driver. // No deadlock: a create holds the gate only across its vkCreate*Pipelines and a submission only across its - // vkQueueSubmit, and neither driver call waits for anything of ours. LEONIDA_COMPILE_GATE=0 turns it off. + // vkQueueSubmit, and neither driver call waits for anything of ours. + // + // By default (classic) only compute creates pass the gate and a submission waits for them however long they take, + // as before the adaptive gate; LEONIDA_COMPILE_GATE_WAIT_MS bounds that too. With the adaptive gate + // (LEONIDA_COMPILE_GATE=adaptive) the wait is bounded (gate_wait_limit_ms, LEONIDA_COMPILE_GATE_WAIT_MS): a + // submission waiting at the gate holds the submit lock, so every queue stops behind it, and the title's hang + // watchdog ends the process once its main loop has not reported for 30 s. One create stayed in the driver for more + // than 54 s (RTX 4070 Laptop, NVIDIA 621.40), and the gate turned it into that exit. Past the limit the submission + // goes ahead, and the creates that were in the driver then no longer hold any submission back; creates that enter + // later are waited for again. The default limit, 15 s, keeps the protection measured above for every create of up + // to 25 s: 630.20 gave the submission 10 s in the driver before the loss, and a stop much longer than 25 s ends at + // the watchdog anyway. The same with the watchdog kept kicked (LEONIDA_TITLE_WATCHDOG=0 with + // LEONIDA_TITLE_WATCHDOG_KICK): nothing ends the run then, but the stops still cost the frames (an RTX 4060 run + // that way had 459 waits, 155 s in all, by t=202 s). Only LEONIDA_COMPILE_GATE_WAIT_MS=0 waits for the creates + // however long they take. + // + // Adaptive (LEONIDA_COMPILE_GATE=adaptive, opt-in): each submission that enters the driver alongside a create the + // gate no longer waits for is a probe of whether this driver holds a submission behind a create. Back while that + // create is still in the driver: under kProbeQuickMs is quick, kProbeHeldMs or more is held, between says nothing. + // On 621.40 the three that went ahead came back in 0-11 ms, the create still there; the one 630.20 held stayed 10 + // s, until the loss. Two quick probes at least kProbeSpanMs apart turn the gate off for the rest of the run (the + // device's, which is the process's), logged once. Two because on 630.20 back-to-back creates take and release the + // driver's lock (see let_submit_finish), so one submission could slip in between and come back quickly from a + // driver that does hold submissions; a second one a second later must be as lucky. It costs no extra wait: once one + // has gone ahead, the next ones enter at once while that create is still in the driver. One held probe keeps the + // gate on for the rest of the run. Only submissions (vkQueueSubmit, vkQueueBindSparse) probe: presents and idle or + // semaphore waits pass the gate as submissions do, but take seconds on their own while the GPU is busy, so their + // time in the driver judges nothing. LEONIDA_COMPILE_GATE=1 gates without probing, LEONIDA_COMPILE_GATE=0 turns the + // gate off. let_submit_finish is unaffected by all of this. + // + // The first probes come early: while no verdict is in, a submission also goes ahead once the submissions' waits at + // the gate in the last kProbeWindowMs, its own included, add up to the probe budget (gate_probe_budget_ms, + // LEONIDA_COMPILE_GATE_PROBE_MS, 2500 ms). On 621.40 no single wait reached 15 s, but 80 waits of up to 6.7 s, + // back to back, kept the main loop from reporting for 30 s. A budget over a window rather than a shorter limit + // per wait, 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 then stops the queues for at most a quarter of any 10 s; after a quick + // verdict not at all. The price is on a driver that does hold submissions (630.20): the first probe enters the + // driver after 2.5 s of waiting instead of 15, and loses the device if the create stays in the driver 10 s more. + // That is one probe per kind and run: the probe holds the submit lock while it is in the driver, so no other + // submission enters until it comes back, and then (within 500 ms of the create leaving, 2 s or more) it gives the + // held verdict, after which no submission enters next to a create of that kind early again. This is why the + // adaptive gate is opt-in until it has run on such a driver. The alternative there is the same run starved + // by waits like the ones above. LEONIDA_COMPILE_GATE_WAIT_MS=0 without LEONIDA_COMPILE_GATE_PROBE_MS also makes the + // budget 0: the gate then waits however long the creates take and never probes, as LEONIDA_COMPILE_GATE=1 does. + // + // A verdict per kind of create (CreateKind: compute, or graphics with mesh): a submission that came back quickly + // beside a compute create says nothing about a graphics one, and a run on 621.40 lost the device beside a mesh + // pipeline create 9 s after compute probes had turned the gate off. A probe counts for each kind that had a + // create in the driver from before the submission entered until it came back: a quick one for all of them, a + // held one against all of them, since which create held it cannot be told. A submission waits for the creates of + // every kind whose gate is not off; the probe budget applies only while all of those are of kinds still pending. + // A kind that is off is still timed: a submission that stays kProbeHeldMs or more beside one of its creates turns + // that kind's gate back on for the rest of the run (logged once), so the submissions after it wait. The one that + // stayed cannot be helped. A held probe counts only if the submission came back within kHeldReturnMs 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. One that comes back slow with its creates still there was slow for another reason (on 621.40, + // a 36 s submission came back 18 s before the compute create beside it, and the 4070 Laptop's 8 GB were full); + // counting it re-armed the gate and starved the title for 78 s behind creates that were not holding anything. A submission never goes ahead (at the limit or the budget) while a create of a kind + // that holds submissions is in the driver, and such creates are waited for even if one was gone past before the + // verdict: on 621.40, with the gate off, a vkQueueSubmit sat 54 s in the driver beside a 56 s mesh create and the + // device was lost; waiting here starves the title as long, but keeps the device. Graphics creates pass the gate + // since this split (adaptive and LEONIDA_COMPILE_GATE=1; the classic gate, as before, only compute ones). On a + // device loss, report_creates_on_loss names the creates in the driver and the verdicts. + // classic (the default): the gate as on main before the adaptive one, compute creates only, no limit, no probes. + enum class GateMode { off, classic, adaptive, always }; + enum class GateVerdict { pending, driver_does_not_hold, driver_holds }; + static constexpr std::int64_t kProbeQuickMs = 250; + static constexpr std::int64_t kProbeHeldMs = 2000; + static constexpr std::int64_t kHeldReturnMs = 500; + static constexpr std::int64_t kProbeSpanMs = 1000; + static constexpr unsigned kQuickProbes = 2; + static constexpr std::int64_t kProbeWindowMs = 10000; + static constexpr std::int64_t kDefaultProbeBudgetMs = 2500; + using CreateKind = CompileGateKind; // graphics: mesh pipelines too + static constexpr std::size_t kKinds = 2; + static const char* kind_name(CreateKind kind) { return kind == CreateKind::compute ? "compute" : "graphics"; } + using CreateInfo = CompileGateCreate; + using GateAhead = CompileGateAhead; class CompileTurn { // around vkCreate*Pipelines public: - explicit CompileTurn(SubmitMutex& gate) : gate_(gate), waited_(gate.enter_compile()) {} - ~CompileTurn() { gate_.leave_compile(); } + explicit CompileTurn(SubmitMutex& gate, const CreateInfo& info = {}) + : gate_(gate), waited_(gate.enter_compile(seq_, info)) {} + ~CompileTurn() { gate_.leave_compile(seq_); } CompileTurn(const CompileTurn&) = delete; CompileTurn& operator=(const CompileTurn&) = delete; std::int64_t waited_ms() const { return waited_; } private: SubmitMutex& gate_; + std::uint64_t seq_ = 0; // declared before waited_: enter_compile sets it std::int64_t waited_; }; class SubmitTurn { // around vkQueueSubmit, with the submit lock held public: - explicit SubmitTurn(SubmitMutex& gate) : gate_(gate) { gate.enter_submit(); } - ~SubmitTurn() { gate_.leave_submit(); } + // `probe` false for a present or an idle or semaphore wait: it waits at the gate like a submission, but its + // time in the driver judges nothing (it can take seconds on its own while the GPU is busy). + explicit SubmitTurn(SubmitMutex& gate, bool probe = true) : gate_(gate) { + gate.enter_submit(&ahead_, probe); + ahead_.probe = probe; + } + ~SubmitTurn() { gate_.leave_submit(ahead_); } SubmitTurn(const SubmitTurn&) = delete; SubmitTurn& operator=(const SubmitTurn&) = delete; + // It went ahead at the wait limit with creates still in the driver. + bool went_ahead() const { return ahead_.went_ahead; } private: SubmitMutex& gate_; + GateAhead ahead_; }; - static bool compile_gate_enabled() { - static const bool on = [] { + // LEONIDA_COMPILE_GATE: 0 off, 1 always (both kinds, and compute builds hold the submit lock, compute_driver_turn + // in shims/d3d12_vulkan_device.cpp), `adaptive` the adaptive gate, anything else (unset) classic. Classic stays + // the default until the adaptive gate has run on a driver that holds submissions (630.20): there its first probe + // of a kind enters the driver after the probe budget and loses the device if the create stays 10 s more. + static GateMode compile_gate_mode() { + static const GateMode mode = [] { const char* value = std::getenv("LEONIDA_COMPILE_GATE"); - return !(value && !std::strcmp(value, "0")); + if (value && !std::strcmp(value, "0")) return GateMode::off; + if (value && !std::strcmp(value, "1")) return GateMode::always; + if (value && !std::strcmp(value, "adaptive")) return GateMode::adaptive; + return GateMode::classic; + }(); + return mode; + } + static bool compile_gate_enabled() { return compile_gate_mode() != GateMode::off; } + // Whether graphics (and mesh) creates pass the gate: not in the classic gate, where only compute ones did. + static bool compile_gate_graphics() { + return compile_gate_mode() == GateMode::adaptive || compile_gate_mode() == GateMode::always; + } + + // Read once. How long one submission waits at the gate before it goes ahead (0: until the creates leave): + // LEONIDA_COMPILE_GATE_WAIT_MS=. The adaptive gate's probe budget over kProbeWindowMs (0: no early probes): + // LEONIDA_COMPILE_GATE_PROBE_MS=. Unset, kDefaultGateWaitMs and kDefaultProbeBudgetMs, whatever the title's + // hang watchdog does; the budget is 0 when the limit is, and the limit 0 with LEONIDA_COMPILE_GATE=1. + static constexpr std::int64_t kDefaultGateWaitMs = 15000; + struct GateDefaults { + std::int64_t wait_ms; + std::int64_t probe_ms; + }; + static GateDefaults gate_defaults() { + static const GateDefaults defaults = [] { + const auto read = [](const char* name, std::int64_t fallback) -> std::int64_t { + const char* value = std::getenv(name); + if (!value || !*value) return fallback; + char* end = nullptr; + const long long n = std::strtoll(value, &end, 10); + if (end && !*end && n >= 0) return n; + std::fprintf(stderr, "[rt] compile-gate: %s=%s is not a number of milliseconds; ignored\n", name, value); + return fallback; + }; + const GateMode mode = compile_gate_mode(); + const bool always = mode == GateMode::always; + const bool adaptive = mode == GateMode::adaptive; // classic and always: no limit by default + const std::int64_t wait_ms = read("LEONIDA_COMPILE_GATE_WAIT_MS", adaptive ? kDefaultGateWaitMs : 0); + const GateDefaults d{wait_ms, read("LEONIDA_COMPILE_GATE_PROBE_MS", wait_ms ? kDefaultProbeBudgetMs : 0)}; + if (mode == GateMode::classic && d.wait_ms) + std::fprintf(stderr, "[rt] compile-gate: classic (compute creates); a submission waits at most %lld ms " + "for them to leave the driver (LEONIDA_COMPILE_GATE_WAIT_MS; " + "LEONIDA_COMPILE_GATE=adaptive for the adaptive gate)\n", + static_cast(d.wait_ms)); + else if (always && d.wait_ms) + std::fprintf(stderr, "[rt] compile-gate: always (LEONIDA_COMPILE_GATE=1); a submission waits at most " + "%lld ms for pipeline creates to leave the driver (LEONIDA_COMPILE_GATE_WAIT_MS)\n", + static_cast(d.wait_ms)); + else if (always) + std::fprintf(stderr, "[rt] compile-gate: always (LEONIDA_COMPILE_GATE=1); a submission waits for " + "pipeline creates to leave the driver, however long they take\n"); + else if (adaptive) + std::fprintf(stderr, "[rt] compile-gate: adaptive (LEONIDA_COMPILE_GATE=adaptive), off once " + "submissions come back quickly with a create in the driver; a submission goes " + "ahead after %lld ms of waiting (0: no limit, LEONIDA_COMPILE_GATE_WAIT_MS) or, " + "until that is known, once the waits of the last " + "%lld s add up to %lld ms (0: never, LEONIDA_COMPILE_GATE_PROBE_MS)\n", + static_cast(d.wait_ms), static_cast(kProbeWindowMs / 1000), + static_cast(d.probe_ms)); + return d; + }(); + return defaults; + } + static std::int64_t default_gate_wait_limit_ms() { return gate_defaults().wait_ms; } + static std::int64_t default_gate_probe_budget_ms() { return gate_defaults().probe_ms; } + // How long a submission waits for creates of a kind that holds submissions before it goes ahead anyway + // (LEONIDA_COMPILE_GATE_HELD_WAIT_MS, 0: until they leave). Longer than the plain limit: going ahead there means + // waiting in the driver, where the device was lost once (a 54 s submission beside a 56 s mesh create on 621.40, + // the gate off); a false "holds" verdict costs at most this per create instead of the rest of the run. + static constexpr std::int64_t kDefaultHeldWaitMs = 60000; + static std::int64_t default_gate_held_limit_ms() { + static const std::int64_t ms = [] { + const char* value = std::getenv("LEONIDA_COMPILE_GATE_HELD_WAIT_MS"); + if (!value || !*value) return kDefaultHeldWaitMs; + char* end = nullptr; + const long long n = std::strtoll(value, &end, 10); + if (end && !*end && n >= 0) return std::int64_t{n}; + std::fprintf(stderr, "[rt] compile-gate: LEONIDA_COMPILE_GATE_HELD_WAIT_MS=%s is not a number of " + "milliseconds; ignored\n", value); + return kDefaultHeldWaitMs; }(); - return on; + return ms; + } + void set_gate_held_limit_ms(std::int64_t ms) { // for tests + std::lock_guard lock(gate_mutex_); + held_limit_ms_ = (std::max)(ms, std::int64_t{0}); + } + std::int64_t gate_wait_limit_ms() { + std::lock_guard lock(gate_mutex_); + return wait_limit_ms_; + } + void set_gate_wait_limit_ms(std::int64_t ms) { // for tests + std::lock_guard lock(gate_mutex_); + wait_limit_ms_ = (std::max)(ms, std::int64_t{0}); + } + std::int64_t gate_probe_budget_ms() { + std::lock_guard lock(gate_mutex_); + return probe_budget_ms_; + } + void set_gate_probe_budget_ms(std::int64_t ms) { // for tests + std::lock_guard lock(gate_mutex_); + probe_budget_ms_ = (std::max)(ms, std::int64_t{0}); + } + void set_gate_adaptive(bool on) { // for tests + std::lock_guard lock(gate_mutex_); + adaptive_ = on; + } + void set_gate_graphics(bool on) { // for tests: whether graphics creates pass the gate + std::lock_guard lock(gate_mutex_); + graphics_ = on; + } + GateVerdict gate_verdict(CreateKind kind = CreateKind::compute) { + std::lock_guard lock(gate_mutex_); + return verdict_[std::size_t(kind)]; + } + + // How many "reached the limit, but a create of a kind that holds ..." notices were due (for tests: one per wait). + unsigned gate_held_notices() { + std::lock_guard lock(gate_mutex_); + return logged_held_waits_; } // The thread waiting in enter_submit for creates to leave the driver, or 0. @@ -436,6 +664,7 @@ class SubmitMutex { struct GateStats { std::uint64_t submits = 0; // submissions that had to wait for a create std::int64_t submit_ms = 0, submit_max_ms = 0; + std::uint64_t ahead = 0; // of those, the ones that went ahead at the wait limit std::uint64_t creates = 0; // creates that waited behind a submission std::int64_t create_ms = 0, create_max_ms = 0; }; @@ -444,64 +673,342 @@ class SubmitMutex { return stats_; } - std::int64_t enter_compile() { + // `seq` receives the create's number, which leave_compile takes back. + std::int64_t enter_compile(std::uint64_t& seq, const CreateInfo& info = {}) { if (!compile_gate_enabled()) return 0; std::unique_lock lock(gate_mutex_); std::int64_t waited = 0; - if (submits_) { + if (info.kind == CreateKind::graphics && !graphics_) { // the classic gate: compute creates only + seq = 0; + return 0; + } + // Not behind this thread's own submission (it holds the submit lock: none of its submissions is in the + // driver now, and waiting for them would never end). + const bool own = owner_.load(std::memory_order_relaxed) == diagnostic_thread_id(); + if (submits_ && !own && !kind_off(info.kind)) { const std::int64_t start = diagnostic_ms(); - gate_changed_.wait(lock, [&] { return submits_ == 0; }); + gate_changed_.wait(lock, [&] { return submits_ == 0 || kind_off(info.kind); }); waited = diagnostic_ms() - start; ++stats_.creates; stats_.create_ms += waited; stats_.create_max_ms = (std::max)(stats_.create_max_ms, waited); } - ++compiles_; + seq = ++last_create_; + in_driver_.push_back(InDriver{seq, info, diagnostic_ms(), diagnostic_thread_id()}); return waited; } - void leave_compile() { + void leave_compile(std::uint64_t seq) { if (!compile_gate_enabled()) return; std::lock_guard lock(gate_mutex_); - if (--compiles_ == 0 && submits_) gate_changed_.notify_all(); + for (auto it = in_driver_.begin(); it != in_driver_.end(); ++it) + if (it->seq == seq) { + recent_leaves_[leave_count_++ % kRecentLeaves] = Leave{seq, diagnostic_ms(), it->info.kind}; + in_driver_.erase(it); + break; + } + if (submits_) gate_changed_.notify_all(); } - std::int64_t enter_submit() { + // `ahead` (optional) is told whether the submission entered the driver alongside creates the gate does not wait + // for, and whether it went ahead at the wait limit or the probe budget, for leave_submit. + // `probe` false (a present or an idle or semaphore wait): it never goes ahead at the probe budget, only at the + // wait limit, since its time in the driver judges nothing. + std::int64_t enter_submit(GateAhead* ahead = nullptr, bool probe = true) { if (!compile_gate_enabled()) return 0; std::unique_lock lock(gate_mutex_); ++submits_; - if (!compiles_) return 0; + const InDriver* first = first_blocking(); + if (!first) { + if (ahead) *ahead = beside(diagnostic_ms(), false); + return 0; + } const std::uint32_t self = diagnostic_thread_id(); gate_waiter_.store(self, std::memory_order_relaxed); const std::int64_t start = diagnostic_ms(); - const GateWait what{self, compiles_, driver_compile.name.load(std::memory_order_acquire), - driver_compile.trigger.load(std::memory_order_relaxed), - driver_compile.bytes.load(std::memory_order_relaxed)}; + const GateWait what{self, blocking(), first->info}; std::int64_t next_note = 2000; - while (!gate_changed_.wait_for(lock, std::chrono::milliseconds(250), [&] { return compiles_ == 0; })) { - const std::int64_t waited = diagnostic_ms() - start; - if (waited < next_note) continue; - next_note = waited + 5000; - note_gate_wait("has waited", what, waited); + const char* why = nullptr; // set: it goes ahead + std::int64_t limit = 0, budget = 0; // in force at the last check + std::int64_t window_ms = 0; // with the probe budget: the waits of the window, this one's included + bool held_noted = false; // the "reached the limit, but ..." notice, once per wait + for (;;) { + const std::int64_t now = diagnostic_ms(); + const std::int64_t waited = now - start; + // Checked each time: a create of a kind that holds submissions, not gone past, may have left (or entered) + // since, while creates of other kinds stay. + const bool held = held_blocking(); + // The plain limit, and the probe budget only for a probe while every kind it waits for has no verdict. + const std::int64_t plain_budget = probe && adaptive_ && blocking_kinds_pending() ? probe_budget_ms_ : 0; + const char* plain = nullptr; + if (plain_budget > 0) window_ms = recent_waits_ms(now) + waited; + if (wait_limit_ms_ > 0 && waited >= wait_limit_ms_) { + plain = "limit"; + } else if (plain_budget > 0 && window_ms >= plain_budget) { + plain = "probe budget"; + } + if (!held) { + limit = wait_limit_ms_; + budget = plain_budget; + why = plain; + } else { + // Not into the driver beside a create of a kind that holds submissions: there it would wait for the + // create anyway, and the driver lost the device under such waits (621.40, a mesh create). It waits + // here for those, up to the held limit (LEONIDA_COMPILE_GATE_HELD_WAIT_MS; 0: however long), which + // applies on its own, also when it is shorter than the plain limit. + limit = held_limit_ms_; + budget = 0; + if (limit > 0 && waited >= limit) why = "held limit"; + if (plain && !why && !held_noted) { + held_noted = true; + if (logged_held_waits_++ < 8) + std::fprintf(stderr, "[rt] compile-gate: vkQueueSubmit on thread %u reached the %s after %lld " + "ms, but a create of a kind that holds submissions is in the driver: it " + "waits until that create leaves or %lld ms have passed\n", + self, plain, static_cast(waited), + static_cast(held_limit_ms_)); + } + } + if (why) { + // Every create in the driver now stops holding submissions back; later ones are waited for. + overdue_through_ = last_create_; + if (why[0] == 'h') held_overdue_through_ = last_create_; + gate_changed_.notify_all(); + break; + } + if (waited >= next_note) { + next_note = waited + 5000; + note_gate_wait("has waited", what, waited); + } + std::int64_t step = 250; + if (limit > 0) step = (std::min)(step, limit - waited); + if (budget > 0) step = (std::min)(step, budget - window_ms); + step = (std::max)(step, std::int64_t{1}); + // Woken when no create holds it back any more, or when whether a holding create does has changed. + if (gate_changed_.wait_for(lock, std::chrono::milliseconds(step), + [&] { return !first_blocking() || held_blocking() != held; }) && + !first_blocking()) + break; } gate_waiter_.store(0, std::memory_order_relaxed); - const std::int64_t waited = diagnostic_ms() - start; + const std::int64_t end = diagnostic_ms(); + const std::int64_t waited = end - start; + remember_wait(start, end); ++stats_.submits; stats_.submit_ms += waited; stats_.submit_max_ms = (std::max)(stats_.submit_max_ms, waited); - // Every wait of 500 ms or more, and the first 32 of 50 ms or more. - if (waited >= 500 || (waited >= 50 && logged_waits_ < 32)) { + const auto creates = static_cast(in_driver_.size()); + if (why && logged_go_ahead_ >= 16) { + ++stats_.ahead; // the stats line counts the rest + } else if (why) { + ++stats_.ahead; + ++logged_go_ahead_; + note_gate_wait("goes ahead after", what, waited); + if (why[0] == 'l') + std::fprintf(stderr, "[rt] compile-gate: at the %lld ms limit (LEONIDA_COMPILE_GATE_WAIT_MS): the %u " + "create(s) still in the driver hold no submission back from now on (%llu " + "submissions went ahead so far)\n", + static_cast(limit), creates, static_cast(stats_.ahead)); + else if (why[0] == 'h') + std::fprintf(stderr, "[rt] compile-gate: at the %lld ms held limit (LEONIDA_COMPILE_GATE_HELD_WAIT_MS): " + "the %u create(s) still in the driver hold no submission back from now on, those " + "of a kind that holds submissions included (%llu submissions went ahead so far)\n", + static_cast(limit), creates, static_cast(stats_.ahead)); + else + std::fprintf(stderr, "[rt] compile-gate: the waits of the last %lld s add up to %lld ms, the probe " + "budget is %lld ms (LEONIDA_COMPILE_GATE_PROBE_MS): the %u create(s) still in the " + "driver hold no submission back from now on (%llu submissions went ahead so far)\n", + static_cast(kProbeWindowMs / 1000), static_cast(window_ms), + static_cast(budget), creates, static_cast(stats_.ahead)); + } else if (waited >= 500 || (waited >= 50 && logged_waits_ < 32)) { + // Every wait of 500 ms or more, and the first 32 of 50 ms or more. ++logged_waits_; note_gate_wait("waited", what, waited); } + if (ahead) *ahead = beside(end, why != nullptr); return waited; } - void leave_submit() { + void leave_submit(const GateAhead& ahead = {}) { if (!compile_gate_enabled()) return; std::lock_guard lock(gate_mutex_); + if (ahead.since_ms >= 0 && ahead.probe) probe(ahead); if (--submits_ == 0) gate_changed_.notify_all(); } + // On a device loss (VulkanContext::mark_device_lost, once): the creates in the driver, how long each has been + // there and whether submissions wait for it, and the verdict of each kind. + void report_creates_on_loss() noexcept { + if (!compile_gate_enabled()) return; + try { + std::lock_guard lock(gate_mutex_); + const std::int64_t now = diagnostic_ms(); + std::fprintf(stderr, "[rt] compile-gate: at the device loss (t=%.3f s): compute gate %s, graphics gate %s; " + "%zu pipeline create(s) in the driver\n", + double(now) / 1000.0, verdict_name(CreateKind::compute), verdict_name(CreateKind::graphics), + in_driver_.size()); + for (const auto& c : in_driver_) + std::fprintf(stderr, "[rt] compile-gate: %s create %s (%zu B SPIR-V, %s) on thread %u, in the driver " + "for %lld ms, %s\n", + kind_name(c.info.kind), c.info.name ? c.info.name : "-", c.info.bytes, + c.info.trigger ? c.info.trigger : "-", c.thread, static_cast(now - c.since_ms), + is_blocking(c) ? "submissions wait for it" : "submissions do not wait for it"); + } catch (...) { + } + } + private: + struct InDriver { + std::uint64_t seq; + CreateInfo info; + std::int64_t since_ms; + std::uint32_t thread; + }; + + // With gate_mutex_ held. + bool kind_off(CreateKind kind) const { + return verdict_[std::size_t(kind)] == GateVerdict::driver_does_not_hold; + } + // A create a submission waits for: of a kind whose gate is on, and either of a kind that holds submissions or not + // gone past at the limit or the budget. + bool is_blocking(const InDriver& c) const { + if (kind_off(c.info.kind)) return false; + if (verdict_[std::size_t(c.info.kind)] == GateVerdict::driver_holds) return c.seq > held_overdue_through_; + return c.seq > overdue_through_; + } + bool held_blocking() const { + for (const auto& c : in_driver_) + if (verdict_[std::size_t(c.info.kind)] == GateVerdict::driver_holds && c.seq > held_overdue_through_) + return true; + return false; + } + const InDriver* first_blocking() const { + for (const auto& c : in_driver_) + if (is_blocking(c)) return &c; + return nullptr; + } + std::uint32_t blocking() const { + std::uint32_t n = 0; + for (const auto& c : in_driver_) n += is_blocking(c); + return n; + } + bool blocking_kinds_pending() const { + for (const auto& c : in_driver_) + if (is_blocking(c) && verdict_[std::size_t(c.info.kind)] != GateVerdict::pending) return false; + return true; + } + // The creates a submission entering the driver at `now` does not wait for (all of those in it: it got past the + // gate). + GateAhead beside(std::int64_t now, bool went_ahead) const { + GateAhead a; + if (in_driver_.empty()) return a; + a.since_ms = now; + a.last_create = last_create_; + a.creates = static_cast(in_driver_.size()); + for (const auto& c : in_driver_) a.kinds |= std::uint8_t(1u << unsigned(c.info.kind)); + a.went_ahead = went_ahead; + return a; + } + const char* verdict_name(CreateKind kind) const { + switch (verdict_[std::size_t(kind)]) { + case GateVerdict::driver_does_not_hold: return "off (the driver does not hold submissions)"; + case GateVerdict::driver_holds: return rearmed_[std::size_t(kind)] ? "on again (re-armed)" : "on (held probe)"; + default: return adaptive_ ? "on (no verdict yet)" : "on"; + } + } + + // With gate_mutex_ held: the submissions' past waits at the gate, for the probe budget. The last kRecentWaits + // are kept; more in one window are short ones, so dropping the oldest of them costs little. + static constexpr std::size_t kRecentWaits = 64; + void remember_wait(std::int64_t start, std::int64_t end) { + if (end <= start) return; + recent_waits_[recent_count_++ % kRecentWaits] = {start, end}; + } + // How much of the last kProbeWindowMs before `now` they took. + std::int64_t recent_waits_ms(std::int64_t now) const { + const std::int64_t from = now - kProbeWindowMs; + std::int64_t sum = 0; + for (std::size_t i = 0; i < (std::min)(recent_count_, kRecentWaits); ++i) { + const auto& [start, end] = recent_waits_[i]; + sum += (std::max)(std::int64_t{0}, (std::min)(end, now) - (std::max)(start, from)); + } + return sum; + } + + // With gate_mutex_ held, as a submission leaves the driver: what its time there says about the driver, for each + // kind with a create in the driver from before it entered until now (see the gate's comment). The ones that went + // ahead are logged (the first 8), each verdict once. + void probe(const GateAhead& ahead) { + const std::int64_t now = diagnostic_ms(); + const std::int64_t took = now - ahead.since_ms; + std::uint32_t still = 0; + std::uint8_t kinds = 0; // of the creates it entered beside, the kinds still in the driver + for (const auto& c : in_driver_) + if (c.seq <= ahead.last_create) { + ++still; + kinds |= std::uint8_t(1u << unsigned(c.info.kind)); + } + kinds &= ahead.kinds; + if (ahead.went_ahead && logged_ahead_ < 8) { + ++logged_ahead_; + std::fprintf(stderr, "[rt] compile-gate: the submission that went ahead on thread %u was in the driver " + "for %lld ms; %u of the %u create(s) it went past are still there\n", + diagnostic_thread_id(), static_cast(took), still, ahead.creates); + } + if (!adaptive_) return; + for (std::size_t k = 0; k < kKinds; ++k) { + if (!(ahead.kinds & (1u << k))) continue; + if (took >= kProbeHeldMs) { + // Held behind a create of this kind only if one it entered beside has just left. + bool left_just_before = false; + for (std::size_t i = 0; i < (std::min)(leave_count_, kRecentLeaves) && !left_just_before; ++i) { + const Leave& l = recent_leaves_[i]; + left_just_before = std::size_t(l.kind) == k && l.seq <= ahead.last_create && + l.ms >= ahead.since_ms && now - l.ms <= kHeldReturnMs; + } + if (left_just_before) { + judge(CreateKind(k), took, now); + } else if (logged_not_held_++ < 8) { + std::fprintf(stderr, "[rt] compile-gate: a submission stayed %lld ms in the driver beside a %s " + "create but came back %s: not counted as held by it\n", + static_cast(took), kind_name(CreateKind(k)), + (kinds & (1u << k)) ? "with the create still there" : "long after the create left"); + } + } else if (kinds & (1u << k)) { + judge(CreateKind(k), took, now); + } + } + } + void judge(CreateKind kind, std::int64_t took, std::int64_t now) { + const std::size_t k = std::size_t(kind); + GateVerdict& verdict = verdict_[k]; + if (verdict == GateVerdict::driver_holds) return; + if (took >= kProbeHeldMs) { + const bool was_off = verdict == GateVerdict::driver_does_not_hold; + verdict = GateVerdict::driver_holds; + rearmed_[k] = was_off; + std::fprintf(stderr, "[rt] compile-gate: a submission stayed %lld ms in the driver beside a %s create at " + "t=%.3f s: this driver may hold submissions behind %s creates, so the %s gate is %s " + "for the rest of the run\n", + static_cast(took), kind_name(kind), double(now) / 1000.0, kind_name(kind), + kind_name(kind), was_off ? "back on" : "on"); + return; + } + if (verdict != GateVerdict::pending || took >= kProbeQuickMs) return; // off already, or says nothing + if (quick_probes_[k]++ == 0) first_quick_ms_[k] = now; + longest_quick_ms_[k] = (std::max)(longest_quick_ms_[k], took); + if (quick_probes_[k] < kQuickProbes || now - first_quick_ms_[k] < kProbeSpanMs) return; + verdict = GateVerdict::driver_does_not_hold; + gate_changed_.notify_all(); // the submissions and creates waiting now go + std::fprintf(stderr, "[rt] compile-gate: %s gate off at t=%.3f s: %u submissions entered the driver beside a " + "%s create and came back in at most %lld ms (under %lld ms), the first and last %lld ms " + "apart, the create still there: this driver does not hold a submission behind a %s " + "create. Still timed: one that stays %lld ms turns it back on (LEONIDA_COMPILE_GATE=1 " + "keeps the gate)\n", + kind_name(kind), double(now) / 1000.0, quick_probes_[k], kind_name(kind), + static_cast(longest_quick_ms_[k]), static_cast(kProbeQuickMs), + static_cast(now - first_quick_ms_[k]), kind_name(kind), + static_cast(kProbeHeldMs)); + } + void taken() { since_.store(diagnostic_ms(), std::memory_order_relaxed); owner_.store(diagnostic_thread_id(), std::memory_order_relaxed); @@ -518,23 +1025,21 @@ class SubmitMutex { } // With gate_mutex_ held. - // The creates a submission found in the driver: how many, and the compute one named last (graphics creates are - // not named). Names are ShaderLibrary strings, valid until device teardown. + // The creates a submission found in the driver: how many it waits for, and the first of them. struct GateWait { std::uint32_t thread; std::uint32_t creates; - const char* name; - const char* trigger; - std::size_t bytes; + CreateInfo first; }; void note_gate_wait(const char* how, const GateWait& what, std::int64_t waited) const { std::fprintf(stderr, "[rt] compile-gate: vkQueueSubmit on thread %u %s %lld ms for %u pipeline create(s) to " - "leave the driver (compute %s, %zu B SPIR-V, %s) at t=%.3f s; %llu such waits so far, " + "leave the driver (%s %s, %zu B SPIR-V, %s) at t=%.3f s; %llu such waits so far, " "%lld ms in all, longest %lld ms\n", - what.thread, how, static_cast(waited), what.creates, what.name ? what.name : "-", - what.name ? what.bytes : std::size_t{0}, what.name && what.trigger ? what.trigger : "-", - double(diagnostic_ms()) / 1000.0, static_cast(stats_.submits), - static_cast(stats_.submit_ms), static_cast(stats_.submit_max_ms)); + what.thread, how, static_cast(waited), what.creates, kind_name(what.first.kind), + what.first.name ? what.first.name : "-", what.first.bytes, + what.first.trigger ? what.first.trigger : "-", double(diagnostic_ms()) / 1000.0, + static_cast(stats_.submits), static_cast(stats_.submit_ms), + static_cast(stats_.submit_max_ms)); } std::mutex mutex_; @@ -548,11 +1053,40 @@ class SubmitMutex { std::mutex gate_mutex_; // leaf: guards the gate counts and stats std::condition_variable gate_changed_; - std::uint32_t compiles_ = 0; // creates in the driver + std::vector in_driver_; // the creates in the driver now, oldest first + std::uint64_t last_create_ = 0; // the number of the last create that entered + std::uint64_t overdue_through_ = 0; // creates up to this number were in the driver when a submission went ahead + std::uint64_t held_overdue_through_ = 0; // the same, for creates of a kind that holds (at the held limit) + std::int64_t held_limit_ms_ = default_gate_held_limit_ms(); // 0: no limit std::uint32_t submits_ = 0; // submissions waiting for them or in the driver + std::int64_t wait_limit_ms_ = default_gate_wait_limit_ms(); // 0: no limit + std::int64_t probe_budget_ms_ = default_gate_probe_budget_ms(); // 0: no early probes + bool adaptive_ = compile_gate_mode() == GateMode::adaptive; + bool graphics_ = compile_gate_graphics(); // graphics creates pass the gate + std::array, kRecentWaits> recent_waits_{}; // [start, end) ms + std::size_t recent_count_ = 0; + // Per CreateKind. + std::array verdict_{GateVerdict::pending, GateVerdict::pending}; + std::array rearmed_{}; + // The last creates to leave the driver: a held probe needs one it entered beside to have just left. A ring, so a + // later create leaving does not hide an earlier one that did. + struct Leave { + std::uint64_t seq = 0; + std::int64_t ms = 0; + CreateKind kind{}; + }; + static constexpr std::size_t kRecentLeaves = 64; + std::array recent_leaves_{}; + std::size_t leave_count_ = 0; + unsigned logged_not_held_ = 0; + std::array quick_probes_{}; + std::array first_quick_ms_{}, longest_quick_ms_{}; + unsigned logged_held_waits_ = 0; std::atomic gate_waiter_{0}; GateStats stats_; unsigned logged_waits_ = 0; + unsigned logged_ahead_ = 0; + unsigned logged_go_ahead_ = 0; }; // One vkQueueSubmit of a VulkanQueue: its waits, its signals and how long the call took (-1: not returned yet). diff --git a/runtime/src/vulkan_present.h b/runtime/src/vulkan_present.h index 81f3b57e1d..da9376e545 100644 --- a/runtime/src/vulkan_present.h +++ b/runtime/src/vulkan_present.h @@ -212,7 +212,7 @@ class VulkanPresenter { const VkDevice device = context_.device(); { std::lock_guard lock(context_.submit_mutex()); - const SubmitMutex::SubmitTurn turn(context_.submit_mutex()); // a queue operation: the compile gate + const SubmitMutex::SubmitTurn turn(context_.submit_mutex(), false); // a queue operation: the compile gate context_.observe_result(vk.vkQueueWaitIdle(queue_), "vkQueueWaitIdle (present)"); // A WSI layer may perform a device-wide idle while destroying the swapchain. // Keep that implicit idle serialized with submits from every context queue. @@ -650,8 +650,9 @@ class VulkanPresenter { { std::lock_guard lock(context_.submit_mutex()); // One turn of the compile gate for the submit and the present after it: no pipeline create enters the - // driver between the two (queue_submit's own turn nests inside this one). - const SubmitMutex::SubmitTurn turn(context_.submit_mutex()); // a queue operation: the compile gate + // driver between the two (queue_submit's own turn nests inside this one). Not a probe: it also covers + // finish_startup_frame's fence wait and the present; the nested turn probes the vkQueueSubmit alone. + const SubmitMutex::SubmitTurn turn(context_.submit_mutex(), false); // a queue operation: the compile gate submitted = context_.observe_result(context_.queue_submit(queue_, 1, &submit_info, frame.done), "vkQueueSubmit (present)"); if (submitted == VK_SUCCESS) context_.note_image_work_locked(); @@ -1083,7 +1084,7 @@ class VulkanPresenter { const VkDevice device = context_.device(); { std::lock_guard lock(context_.submit_mutex()); - const SubmitMutex::SubmitTurn turn(context_.submit_mutex()); // a queue operation: the compile gate + const SubmitMutex::SubmitTurn turn(context_.submit_mutex(), false); // a queue operation: the compile gate // The old swapchain's images and semaphores may still be in use. context_.observe_result(vk.vkQueueWaitIdle(queue_), "vkQueueWaitIdle (present)"); release(swapchain_); @@ -1174,7 +1175,7 @@ class VulkanPresenter { return true; { std::lock_guard lock(context_.submit_mutex()); - const SubmitMutex::SubmitTurn turn(context_.submit_mutex()); // a queue operation: the compile gate + const SubmitMutex::SubmitTurn turn(context_.submit_mutex(), false); // a queue operation: the compile gate // The old target may still be in use. context_.observe_result(context_.vk.vkQueueWaitIdle(queue_), "vkQueueWaitIdle (present)"); } @@ -1531,7 +1532,7 @@ class VulkanPresenter { const VkDevice device = context_.device(); { std::lock_guard lock(context_.submit_mutex()); - const SubmitMutex::SubmitTurn turn(context_.submit_mutex()); // a queue operation: the compile gate + const SubmitMutex::SubmitTurn turn(context_.submit_mutex(), false); // a queue operation: the compile gate // The old swapchain's images and semaphores may still be in use. context_.observe_result(vk.vkQueueWaitIdle(queue_), "vkQueueWaitIdle (present)"); } diff --git a/runtime/test/submit_mutex_test.cpp b/runtime/test/submit_mutex_test.cpp index 345f308871..a98c6effa6 100644 --- a/runtime/test/submit_mutex_test.cpp +++ b/runtime/test/submit_mutex_test.cpp @@ -9,6 +9,8 @@ #include #include #include +#include +#include #include #include @@ -136,6 +138,8 @@ int compile_gate() { return 0; } SubmitMutex m; + m.set_gate_wait_limit_ms(0); // no limit: gate_wait_limit checks the limit + m.set_gate_adaptive(false); // gate_adapts checks the switch // Nothing in the driver: a submission passes at once. { const std::int64_t start = now_ms(); @@ -197,12 +201,760 @@ int compile_gate() { return 0; } +int gate_wait_limit() { + if (!SubmitMutex::compile_gate_enabled()) { + std::printf("compile gate off (LEONIDA_COMPILE_GATE=0): wait limit not checked\n"); + return 0; + } + // The default with LEONIDA_COMPILE_GATE_WAIT_MS unset, whatever the title watchdog variables say: none with + // LEONIDA_COMPILE_GATE=1 or unset (classic), kDefaultGateWaitMs with LEONIDA_COMPILE_GATE=adaptive. + const bool adaptive = SubmitMutex::compile_gate_mode() == SubmitMutex::GateMode::adaptive; + if (!std::getenv("LEONIDA_COMPILE_GATE_WAIT_MS")) + EXPECT(SubmitMutex::default_gate_wait_limit_ms() == (adaptive ? SubmitMutex::kDefaultGateWaitMs : 0)); + SubmitMutex m; + m.set_gate_adaptive(false); // as LEONIDA_COMPILE_GATE=1: it never turns off + m.set_gate_wait_limit_ms(150); + EXPECT(m.gate_wait_limit_ms() == 150); + // A create that stays in the driver until it is let go (one that takes longer than the limit). + std::atomic long_in{false}, release_long{false}; + std::atomic long_left_at{0}; + std::thread long_create([&] { + const SubmitMutex::CompileTurn turn(m); + long_in = true; + while (!release_long) std::this_thread::sleep_for(1ms); + long_left_at = now_ms(); + }); + EXPECT(eventually([&] { return long_in.load(); })); + // The submission goes ahead at the limit, the create still in the driver. + std::int64_t first_waited = 0; + bool first_ahead = false; + { + const std::int64_t start = now_ms(); + const SubmitMutex::SubmitTurn turn(m); + first_waited = now_ms() - start; + first_ahead = turn.went_ahead(); + } + // The next one passes at once: the create the first went past holds no submission back. + std::int64_t second_waited = 0; + bool second_ahead = true; + { + const std::int64_t start = now_ms(); + const SubmitMutex::SubmitTurn turn(m); + second_waited = now_ms() - start; + second_ahead = turn.went_ahead(); + } + // A create that enters after that is waited for again, until it leaves (well within the limit now), while the + // long one is still in the driver. + m.set_gate_wait_limit_ms(5000); + std::atomic short_in{false}; + std::atomic short_left_at{0}; + std::thread short_create([&] { + const SubmitMutex::CompileTurn turn(m); + short_in = true; + std::this_thread::sleep_for(200ms); + short_left_at = now_ms(); + }); + const bool short_entered = eventually([&] { return short_in.load(); }); + std::int64_t third_entered_at = 0; + bool third_ahead = true; + { + const SubmitMutex::SubmitTurn turn(m); + third_entered_at = now_ms(); + third_ahead = turn.went_ahead(); + } + const bool long_still_in = long_left_at.load() == 0; + release_long = true; + long_create.join(); + short_create.join(); + EXPECT(short_entered); + EXPECT(first_ahead && first_waited >= 140 && first_waited < 1000); + EXPECT(!second_ahead && second_waited < 50); + EXPECT(!third_ahead && third_entered_at >= short_left_at.load() && long_still_in); + const SubmitMutex::GateStats stats = m.gate_stats(); + EXPECT(stats.submits == 2 && stats.ahead == 1); + EXPECT(m.gate_verdict() == SubmitMutex::GateVerdict::pending); // quick probes, but not adaptive + // Both gone: a submission passes at once. + { + const std::int64_t start = now_ms(); + const SubmitMutex::SubmitTurn turn(m); + EXPECT(now_ms() - start < 50 && !turn.went_ahead()); + } + std::printf("compile gate: a submission went ahead after %lld ms (limit 150 ms) with the create still in the " + "driver, the next passed in %lld ms, and a create that entered later was waited for again\n", + static_cast(first_waited), static_cast(second_waited)); + return 0; +} + +int gate_adapts() { + if (!SubmitMutex::compile_gate_enabled()) { + std::printf("compile gate off (LEONIDA_COMPILE_GATE=0): adaptive switch not checked\n"); + return 0; + } + using Verdict = SubmitMutex::GateVerdict; + // Quick probes: the gate goes off once two, a second apart, came back with the create still in the driver. + { + SubmitMutex m; + m.set_gate_adaptive(true); + m.set_gate_graphics(true); // as LEONIDA_COMPILE_GATE=adaptive + m.set_gate_wait_limit_ms(100); + m.set_gate_probe_budget_ms(0); // probes at the limit only: gate_probe_budget checks the budget + std::atomic in{false}, release{false}; + std::thread create([&] { + const SubmitMutex::CompileTurn turn(m); + in = true; + while (!release) std::this_thread::sleep_for(1ms); + }); + const bool entered = eventually([&] { return in.load(); }); + bool first_ahead = false; + { + const SubmitMutex::SubmitTurn turn(m); // goes ahead at the limit: the first quick probe + first_ahead = turn.went_ahead(); + } + { const SubmitMutex::SubmitTurn turn(m); } // the second, too soon after the first + const Verdict soon = m.gate_verdict(); + std::this_thread::sleep_for(1100ms); + { const SubmitMutex::SubmitTurn turn(m); } // the third, a second later + const Verdict later = m.gate_verdict(); + // Off: a create that enters now holds no submission back. + std::atomic fresh_in{false}, release_fresh{false}; + std::thread fresh([&] { + const SubmitMutex::CompileTurn turn(m); + fresh_in = true; + while (!release_fresh) std::this_thread::sleep_for(1ms); + }); + const bool fresh_entered = eventually([&] { return fresh_in.load(); }); + const std::int64_t start = now_ms(); + bool fresh_ahead = true; + { + const SubmitMutex::SubmitTurn turn(m); + fresh_ahead = turn.went_ahead(); + } + const std::int64_t passed = now_ms() - start; + release = true; + release_fresh = true; + create.join(); + fresh.join(); + EXPECT(entered && fresh_entered && first_ahead); + EXPECT(soon == Verdict::pending); + EXPECT(later == Verdict::driver_does_not_hold); + EXPECT(passed < 50 && !fresh_ahead); + } + std::printf("compile gate: off after two quick probes a second apart, not after two within the second\n"); + // A held probe: a submission that comes back just after the create beside it leaves. The gate stays on, and a + // later create is waited for however long it takes. + { + SubmitMutex m; + m.set_gate_adaptive(true); + m.set_gate_graphics(true); // as LEONIDA_COMPILE_GATE=adaptive + m.set_gate_wait_limit_ms(100); + m.set_gate_probe_budget_ms(0); // probes at the limit only: gate_probe_budget checks the budget + std::atomic first_in{false}, first_release{false}; + std::thread first([&] { + const SubmitMutex::CompileTurn turn(m); + first_in = true; + while (!first_release) std::this_thread::sleep_for(1ms); + }); + const bool first_entered = eventually([&] { return first_in.load(); }); + { + const SubmitMutex::SubmitTurn turn(m); // goes ahead, then stays "in the driver" for 2.1 s + std::this_thread::sleep_for(2000ms); + first_release = true; // the create leaves 100 ms before the submission comes back + first.join(); + std::this_thread::sleep_for(100ms); + } + const Verdict held = m.gate_verdict(); + // A create of the same kind is waited for, past the limit (its kind holds submissions), until it leaves. + std::atomic in{false}, release{false}; + std::thread create([&] { + const SubmitMutex::CompileTurn turn(m); + in = true; + while (!release) std::this_thread::sleep_for(1ms); + }); + const bool entered = first_entered && eventually([&] { return in.load(); }); + std::atomic released_at{0}; + std::thread releaser([&] { + std::this_thread::sleep_for(300ms); + released_at = now_ms(); + release = true; + }); + std::int64_t entered_at = 0; + bool ahead = true; + { + const SubmitMutex::SubmitTurn turn(m); + entered_at = now_ms(); + ahead = turn.went_ahead(); + } + releaser.join(); + create.join(); + const Verdict still = m.gate_verdict(); + EXPECT(entered); + EXPECT(held == Verdict::driver_holds && still == Verdict::driver_holds); + EXPECT(!ahead && entered_at >= released_at.load()); + } + std::printf("compile gate: a probe held 2.1 s keeps it on, and the create is then waited out past the limit\n"); + // A slow submission that comes back with the create beside it still there was not held by it: no verdict. + { + SubmitMutex m; + m.set_gate_adaptive(true); + m.set_gate_graphics(true); // as LEONIDA_COMPILE_GATE=adaptive + m.set_gate_wait_limit_ms(100); + m.set_gate_probe_budget_ms(0); + std::atomic in{false}, release{false}; + std::thread create([&] { + const SubmitMutex::CompileTurn turn(m); + in = true; + while (!release) std::this_thread::sleep_for(1ms); + }); + const bool entered = eventually([&] { return in.load(); }); + { + const SubmitMutex::SubmitTurn turn(m); // goes ahead at the limit, then stays 2.1 s + std::this_thread::sleep_for(2100ms); + } + const Verdict after = m.gate_verdict(); + release = true; + create.join(); + EXPECT(entered); + EXPECT(after != Verdict::driver_holds); + } + std::printf("compile gate: a 2.1 s submission that came back with the create still there is not a held probe\n"); + return 0; +} + +int gate_probe_budget() { + if (!SubmitMutex::compile_gate_enabled()) { + std::printf("compile gate off (LEONIDA_COMPILE_GATE=0): probe budget not checked\n"); + return 0; + } + using Verdict = SubmitMutex::GateVerdict; + // The default budget, 0 when the limit is. + if (!std::getenv("LEONIDA_COMPILE_GATE_PROBE_MS")) + EXPECT(SubmitMutex::default_gate_probe_budget_ms() == + (SubmitMutex::default_gate_wait_limit_ms() ? SubmitMutex::kDefaultProbeBudgetMs : 0)); + // Short waits add up: with no per-wait limit, a submission goes ahead once the waits of the window reach the budget. + { + SubmitMutex m; + m.set_gate_adaptive(true); + m.set_gate_graphics(true); // as LEONIDA_COMPILE_GATE=adaptive + m.set_gate_wait_limit_ms(0); + m.set_gate_probe_budget_ms(300); + EXPECT(m.gate_probe_budget_ms() == 300); + std::atomic a_in{false}; + std::thread a([&] { + const SubmitMutex::CompileTurn turn(m); + a_in = true; + std::this_thread::sleep_for(200ms); + }); + const bool a_entered = eventually([&] { return a_in.load(); }); + std::int64_t first_waited = 0; + bool first_ahead = true; + { + const std::int64_t start = now_ms(); + const SubmitMutex::SubmitTurn turn(m); // waits the create out: under the budget + first_waited = now_ms() - start; + first_ahead = turn.went_ahead(); + } + a.join(); + std::atomic b_in{false}, release{false}; + std::thread b([&] { + const SubmitMutex::CompileTurn turn(m); + b_in = true; + while (!release) std::this_thread::sleep_for(1ms); + }); + const bool b_entered = eventually([&] { return b_in.load(); }); + std::int64_t second_waited = 0; + bool second_ahead = false; + { + const std::int64_t start = now_ms(); + const SubmitMutex::SubmitTurn turn(m); // goes ahead once both waits add up to 300 ms + second_waited = now_ms() - start; + second_ahead = turn.went_ahead(); + } + const Verdict after_one = m.gate_verdict(); + release = true; + b.join(); + EXPECT(a_entered && b_entered); + EXPECT(!first_ahead && first_waited >= 100); + EXPECT(second_ahead && first_waited + second_waited >= 250 && second_waited < 300); + EXPECT(after_one == Verdict::pending); // one quick probe is not enough + std::printf("compile gate: waits of %lld and %lld ms reached the 300 ms probe budget, the second went ahead\n", + static_cast(first_waited), static_cast(second_waited)); + } + // After a held verdict the budget no longer applies: a submission waits a create out again. + { + SubmitMutex m; + m.set_gate_adaptive(true); + m.set_gate_graphics(true); // as LEONIDA_COMPILE_GATE=adaptive + m.set_gate_wait_limit_ms(0); + m.set_gate_probe_budget_ms(100); + std::atomic in{false}, release{false}; + std::thread create([&] { + const SubmitMutex::CompileTurn turn(m); + in = true; + while (!release) std::this_thread::sleep_for(1ms); + }); + const bool entered = eventually([&] { return in.load(); }); + bool ahead = false; + { + const SubmitMutex::SubmitTurn turn(m); // goes ahead at the budget, then is held 2.1 s + ahead = turn.went_ahead(); + std::this_thread::sleep_for(2000ms); + release = true; // the create it stayed beside leaves 100 ms before it comes back: a held probe + create.join(); + std::this_thread::sleep_for(100ms); + } + const Verdict held = m.gate_verdict(); + std::atomic short_in{false}; + std::atomic short_left_at{0}; + std::thread short_create([&] { + const SubmitMutex::CompileTurn turn(m); + short_in = true; + std::this_thread::sleep_for(400ms); + short_left_at = now_ms(); + }); + const bool short_entered = eventually([&] { return short_in.load(); }); + std::int64_t entered_at = 0; + bool later_ahead = true; + { + const SubmitMutex::SubmitTurn turn(m); + entered_at = now_ms(); + later_ahead = turn.went_ahead(); + } + short_create.join(); + EXPECT(entered && short_entered && ahead); + EXPECT(held == Verdict::driver_holds); + EXPECT(!later_ahead && entered_at >= short_left_at.load()); + } + std::printf("compile gate: after a held probe a 400 ms create is waited out past the 100 ms budget\n"); + return 0; +} + +int gate_per_kind() { + if (!SubmitMutex::compile_gate_enabled()) { + std::printf("compile gate off (LEONIDA_COMPILE_GATE=0): per-kind verdicts not checked\n"); + return 0; + } + using Verdict = SubmitMutex::GateVerdict; + using Kind = SubmitMutex::CreateKind; + SubmitMutex m; + m.set_gate_adaptive(true); + m.set_gate_graphics(true); // as LEONIDA_COMPILE_GATE=adaptive + m.set_gate_wait_limit_ms(100); + m.set_gate_probe_budget_ms(0); + const SubmitMutex::CreateInfo compute{Kind::compute, "test compute", "test", 1000}; + const SubmitMutex::CreateInfo graphics{Kind::graphics, "test mesh", "test", 2000}; + // A compute create that stays until let go; the compute gate goes off after two quick probes a second apart. + std::atomic c_in{false}, c_release{false}; + std::atomic c_left_at{0}; + std::thread c([&] { + const SubmitMutex::CompileTurn turn(m, compute); + c_in = true; + while (!c_release) std::this_thread::sleep_for(1ms); + c_left_at = now_ms(); + }); + const bool c_entered = eventually([&] { return c_in.load(); }); + { const SubmitMutex::SubmitTurn turn(m); } // goes ahead at the limit: the first quick probe + std::this_thread::sleep_for(1100ms); + { const SubmitMutex::SubmitTurn turn(m); } // the second + const Verdict compute_off = m.gate_verdict(Kind::compute), graphics_before = m.gate_verdict(Kind::graphics); + // A graphics create is still waited for: its kind has no verdict, so the submission goes ahead only at the limit. + std::atomic g_in{false}, g_release{false}; + std::thread g([&] { + const SubmitMutex::CompileTurn turn(m, graphics); + g_in = true; + while (!g_release) std::this_thread::sleep_for(1ms); + }); + const bool g_entered = eventually([&] { return g_in.load(); }); + std::int64_t g_waited = 0; + bool g_ahead = false; + { + const std::int64_t start = now_ms(); + const SubmitMutex::SubmitTurn turn(m); + g_waited = now_ms() - start; + g_ahead = turn.went_ahead(); + } + g_release = true; + g.join(); + const Verdict graphics_after = m.gate_verdict(Kind::graphics); // one quick probe: still pending + // A second compute create, there through the rest. + std::atomic c2_in{false}, c2_release{false}; + std::atomic c2_left_at{0}; + std::thread c2([&] { + const SubmitMutex::CompileTurn turn(m, compute); + c2_in = true; + while (!c2_release) std::this_thread::sleep_for(1ms); + c2_left_at = now_ms(); + }); + const bool c2_entered = eventually([&] { return c2_in.load(); }); + // Re-arm: beside the compute creates (gate off), a submission stays 2.1 s in the "driver" and comes back 100 ms + // after the first one leaves. + { + const SubmitMutex::SubmitTurn turn(m); + std::this_thread::sleep_for(2000ms); + c_release = true; + c.join(); + std::this_thread::sleep_for(100ms); + } + const Verdict compute_rearmed = m.gate_verdict(Kind::compute); + // The second compute create is waited for, and not gone past at the limit: its kind holds submissions. + std::atomic released_at{0}; + std::thread releaser([&] { + std::this_thread::sleep_for(400ms); + released_at = now_ms(); + c2_release = true; + }); + std::int64_t entered_at = 0; + bool after_ahead = true; + { + const SubmitMutex::SubmitTurn turn(m); + entered_at = now_ms(); + after_ahead = turn.went_ahead(); + } + releaser.join(); + c2.join(); + EXPECT(c_entered && c2_entered && g_entered); + EXPECT(compute_off == Verdict::driver_does_not_hold && graphics_before == Verdict::pending); + EXPECT(g_ahead && g_waited >= 90 && g_waited < 1000); + EXPECT(graphics_after == Verdict::pending); + EXPECT(compute_rearmed == Verdict::driver_holds); + EXPECT(!after_ahead && entered_at >= c2_left_at.load() && entered_at >= released_at.load()); + m.report_creates_on_loss(); // nothing in the driver now: the verdicts only + std::printf("compile gate: compute off with graphics still gated; a 2.1 s submission re-armed compute, and the next " + "one waited %lld ms past the 100 ms limit for the compute create\n", + static_cast(entered_at - (released_at.load() - 400))); + return 0; +} + +// A create that stays in the "driver" until `release` is set; `in` is set once it is there, `left_at` when it leaves. +struct HeldCreate { + std::atomic in{false}, release{false}; + std::atomic left_at{0}; + std::thread thread; + HeldCreate(SubmitMutex& m, const SubmitMutex::CreateInfo& info) { + thread = std::thread([&m, info, this] { + const SubmitMutex::CompileTurn turn(m, info); + in = true; + while (!release) std::this_thread::sleep_for(1ms); + left_at = now_ms(); + }); + } + void let_go() { + release = true; + if (thread.joinable()) thread.join(); + } + ~HeldCreate() { let_go(); } +}; + +// The cases raised in review of #2412: a later create leaving does not hide an earlier one, presents and waits do +// not probe, and a kind that holds submissions is waited for up to the held limit only. +int gate_review_cases() { + if (!SubmitMutex::compile_gate_enabled()) { + std::printf("compile gate off (LEONIDA_COMPILE_GATE=0): review cases not checked\n"); + return 0; + } + using Verdict = SubmitMutex::GateVerdict; + using Kind = SubmitMutex::CreateKind; + const SubmitMutex::CreateInfo compute{Kind::compute, "test compute", "test", 1000}; + const auto turn_compute_off = [&](SubmitMutex& m, HeldCreate& c) { + { const SubmitMutex::SubmitTurn turn(m); } + std::this_thread::sleep_for(1100ms); + { const SubmitMutex::SubmitTurn turn(m); } + return m.gate_verdict(Kind::compute) == Verdict::driver_does_not_hold && c.in.load(); + }; + // A, there when the submission entered, leaves; then B, which entered after it, leaves; then the submission comes + // back. A's leave still counts: re-armed. + for (const bool a_first : {true, false}) { + SubmitMutex m; + m.set_gate_adaptive(true); + m.set_gate_graphics(true); // as LEONIDA_COMPILE_GATE=adaptive + m.set_gate_wait_limit_ms(100); + m.set_gate_probe_budget_ms(0); + HeldCreate a(m, compute); + const bool off = eventually([&] { return a.in.load(); }) && turn_compute_off(m, a); + std::unique_ptr b; + { + const SubmitMutex::SubmitTurn turn(m); + b = std::make_unique(m, compute); // enters after the submission did + EXPECT(eventually([&] { return b->in.load(); })); + std::this_thread::sleep_for(2000ms); + if (a_first) { + a.let_go(); + std::this_thread::sleep_for(30ms); + b->let_go(); + } else { + b->let_go(); + std::this_thread::sleep_for(30ms); + a.let_go(); + } + std::this_thread::sleep_for(50ms); + } + EXPECT(off); + EXPECT(m.gate_verdict(Kind::compute) == Verdict::driver_holds); + } + std::printf("compile gate: A then B and B then A leaving just before a 2.1 s submission both re-arm compute\n"); + // B alone leaves (it entered after the submission), A is still there: not held. + { + SubmitMutex m; + m.set_gate_adaptive(true); + m.set_gate_graphics(true); // as LEONIDA_COMPILE_GATE=adaptive + m.set_gate_wait_limit_ms(100); + m.set_gate_probe_budget_ms(0); + HeldCreate a(m, compute); + const bool off = eventually([&] { return a.in.load(); }) && turn_compute_off(m, a); + { + const SubmitMutex::SubmitTurn turn(m); + HeldCreate b(m, compute); + EXPECT(eventually([&] { return b.in.load(); })); + std::this_thread::sleep_for(2000ms); + b.let_go(); + std::this_thread::sleep_for(50ms); + } + EXPECT(off); + EXPECT(m.gate_verdict(Kind::compute) == Verdict::driver_does_not_hold); + } + std::printf("compile gate: a create that entered after the submission leaving does not re-arm compute\n"); + // A present or wait (probe false) that comes back 2.1 s later, just after the create left, judges nothing. + { + SubmitMutex m; + m.set_gate_adaptive(true); + m.set_gate_graphics(true); // as LEONIDA_COMPILE_GATE=adaptive + m.set_gate_wait_limit_ms(100); + m.set_gate_probe_budget_ms(0); + HeldCreate a(m, compute); + EXPECT(eventually([&] { return a.in.load(); })); + { + const SubmitMutex::SubmitTurn turn(m, false); + std::this_thread::sleep_for(2000ms); + a.let_go(); + std::this_thread::sleep_for(50ms); + } + EXPECT(m.gate_verdict(Kind::compute) == Verdict::pending); + } + std::printf("compile gate: a 2.1 s present or wait judges nothing\n"); + // A kind that holds is waited for up to the held limit, then gone past; the next submission does not wait for it. + { + SubmitMutex m; + m.set_gate_adaptive(true); + m.set_gate_graphics(true); // as LEONIDA_COMPILE_GATE=adaptive + m.set_gate_wait_limit_ms(100); + m.set_gate_probe_budget_ms(0); + m.set_gate_held_limit_ms(400); + { + HeldCreate first(m, compute); + EXPECT(eventually([&] { return first.in.load(); })); + const SubmitMutex::SubmitTurn turn(m); + std::this_thread::sleep_for(2000ms); + first.let_go(); + std::this_thread::sleep_for(50ms); + } + const Verdict held = m.gate_verdict(Kind::compute); + HeldCreate stays(m, compute); + EXPECT(eventually([&] { return stays.in.load(); })); + std::int64_t waited = 0, next_waited = 0; + bool ahead = false; + { + const std::int64_t start = now_ms(); + const SubmitMutex::SubmitTurn turn(m); + waited = now_ms() - start; + ahead = turn.went_ahead(); + } + { + const std::int64_t start = now_ms(); + const SubmitMutex::SubmitTurn turn(m); + next_waited = now_ms() - start; + } + EXPECT(held == Verdict::driver_holds); + EXPECT(ahead && waited >= 390 && waited < 2000); + EXPECT(next_waited < 50); + std::printf("compile gate: with a holding kind a submission waited %lld ms (held limit 400 ms), the next %lld ms\n", + static_cast(waited), static_cast(next_waited)); + } + return 0; +} + +// The second review of #2412: whether a create that holds is in the driver is checked on every pass of the wait, the +// held limit applies on its own, the notice comes once per wait, and a present or wait never uses the probe budget. +int gate_second_review() { + if (!SubmitMutex::compile_gate_enabled()) { + std::printf("compile gate off (LEONIDA_COMPILE_GATE=0): second review cases not checked\n"); + return 0; + } + using Verdict = SubmitMutex::GateVerdict; + using Kind = SubmitMutex::CreateKind; + const SubmitMutex::CreateInfo compute{Kind::compute, "test compute", "test", 1000}; + const SubmitMutex::CreateInfo graphics{Kind::graphics, "test mesh", "test", 2000}; + const auto adaptive = [](SubmitMutex& m) { + m.set_gate_adaptive(true); + m.set_gate_graphics(true); // as LEONIDA_COMPILE_GATE=adaptive + m.set_gate_probe_budget_ms(0); + }; + // Compute gets the held verdict: a submission goes ahead at a 100 ms limit, stays 2 s, and comes back just after + // the create leaves. + const auto compute_holds = [&](SubmitMutex& m) { + m.set_gate_wait_limit_ms(100); + HeldCreate first(m, compute); + if (!eventually([&] { return first.in.load(); })) return false; + { + const SubmitMutex::SubmitTurn turn(m); + std::this_thread::sleep_for(2000ms); + first.let_go(); + std::this_thread::sleep_for(50ms); + } + return m.gate_verdict(Kind::compute) == Verdict::driver_holds; + }; + // (a) The holding compute create leaves while a graphics create (no verdict) stays: the submission goes ahead at + // the plain limit, even with no held limit. + { + SubmitMutex m; + adaptive(m); + const bool holds = compute_holds(m); + m.set_gate_wait_limit_ms(300); + m.set_gate_held_limit_ms(0); + HeldCreate c(m, compute); + HeldCreate g(m, graphics); + EXPECT(eventually([&] { return c.in.load() && g.in.load(); })); + std::atomic waited{-1}; + std::atomic ahead{false}; + std::thread submit([&] { + const std::int64_t start = now_ms(); + const SubmitMutex::SubmitTurn turn(m); + waited = now_ms() - start; + ahead = turn.went_ahead(); + }); + std::this_thread::sleep_for(150ms); + c.let_go(); + const bool went = eventually([&] { return waited.load() >= 0; }); // within 2 s, the graphics one still there + g.let_go(); + submit.join(); + EXPECT(holds); + EXPECT(went && ahead.load() && waited.load() >= 290 && waited.load() < 1000); + std::printf("compile gate: the holding create left, the other kind's stayed: went ahead after %lld ms " + "(limit 300 ms, no held limit)\n", static_cast(waited.load())); + } + // (b) and (c): a held limit under the plain limit applies on its own, and one over it gives one notice per wait. + for (const bool shorter : {true, false}) { + SubmitMutex m; + adaptive(m); + const bool holds = compute_holds(m); + m.set_gate_wait_limit_ms(shorter ? 2000 : 100); + m.set_gate_held_limit_ms(shorter ? 300 : 400); + HeldCreate c(m, compute); + EXPECT(eventually([&] { return c.in.load(); })); + const unsigned notices = m.gate_held_notices(); + std::int64_t waited = 0; + bool ahead = false; + { + const std::int64_t start = now_ms(); + const SubmitMutex::SubmitTurn turn(m); + waited = now_ms() - start; + ahead = turn.went_ahead(); + } + const unsigned noted = m.gate_held_notices() - notices; + c.let_go(); + EXPECT(holds && ahead); + if (shorter) { + EXPECT(waited >= 290 && waited < 1000 && noted == 0); + } else { + EXPECT(waited >= 390 && waited < 1000 && noted == 1); + } + std::printf("compile gate: held limit %s the plain limit: went ahead after %lld ms, %u notice(s)\n", + shorter ? "300 ms, under" : "400 ms, over", static_cast(waited), noted); + } + // (d) A present or wait beside a create with no verdict never goes ahead at the probe budget, only at the limit. + { + SubmitMutex m; + adaptive(m); + m.set_gate_wait_limit_ms(1000); + m.set_gate_probe_budget_ms(200); + HeldCreate c(m, compute); + EXPECT(eventually([&] { return c.in.load(); })); + std::int64_t waited = 0; + bool ahead = false; + { + const std::int64_t start = now_ms(); + const SubmitMutex::SubmitTurn turn(m, false); + waited = now_ms() - start; + ahead = turn.went_ahead(); + } + c.let_go(); + EXPECT(ahead && waited >= 990 && waited < 2000); + EXPECT(m.gate_verdict(Kind::compute) == Verdict::pending); + std::printf("compile gate: a present beside an unverified create waited %lld ms (budget 200 ms, limit 1000 " + "ms)\n", static_cast(waited)); + } + return 0; +} + +// The classic gate (LEONIDA_COMPILE_GATE unset, the default): compute creates are waited for however long they take, +// graphics creates do not pass the gate, nothing probes. +int gate_classic() { + if (!SubmitMutex::compile_gate_enabled()) { + std::printf("compile gate off (LEONIDA_COMPILE_GATE=0): classic gate not checked\n"); + return 0; + } + using Kind = SubmitMutex::CreateKind; + using Verdict = SubmitMutex::GateVerdict; + const SubmitMutex::GateMode mode = SubmitMutex::compile_gate_mode(); + if (mode == SubmitMutex::GateMode::classic) { + EXPECT(!SubmitMutex::compile_gate_graphics()); + if (!std::getenv("LEONIDA_COMPILE_GATE_PROBE_MS") && !std::getenv("LEONIDA_COMPILE_GATE_WAIT_MS")) + EXPECT(SubmitMutex::default_gate_wait_limit_ms() == 0 && SubmitMutex::default_gate_probe_budget_ms() == 0); + } + SubmitMutex m; + m.set_gate_adaptive(false); + m.set_gate_graphics(false); + m.set_gate_wait_limit_ms(0); + m.set_gate_probe_budget_ms(0); + // A graphics create in the driver holds no submission back. + std::atomic g_in{false}, g_release{false}; + std::thread g([&] { + const SubmitMutex::CompileTurn turn(m, SubmitMutex::CreateInfo{Kind::graphics, "test mesh", "test", 2000}); + g_in = true; + while (!g_release) std::this_thread::sleep_for(1ms); + }); + const bool g_entered = eventually([&] { return g_in.load(); }); + std::int64_t beside_graphics = 0; + { + const std::int64_t start = now_ms(); + const SubmitMutex::SubmitTurn turn(m); + beside_graphics = now_ms() - start; + } + g_release = true; + g.join(); + // A compute create is waited for until it leaves, well past the adaptive gate's 2.5 s budget, and decides nothing. + std::atomic c_in{false}; + std::atomic c_left_at{0}; + std::thread c([&] { + const SubmitMutex::CompileTurn turn(m, SubmitMutex::CreateInfo{Kind::compute, "test compute", "test", 1000}); + c_in = true; + std::this_thread::sleep_for(3000ms); + c_left_at = now_ms(); + }); + const bool c_entered = eventually([&] { return c_in.load(); }); + std::int64_t entered_at = 0; + bool ahead = true; + { + const SubmitMutex::SubmitTurn turn(m); + entered_at = now_ms(); + ahead = turn.went_ahead(); + } + c.join(); + EXPECT(g_entered && c_entered); + EXPECT(beside_graphics < 50); + EXPECT(entered_at >= c_left_at.load() && !ahead); + EXPECT(m.gate_verdict(Kind::compute) == Verdict::pending && m.gate_verdict(Kind::graphics) == Verdict::pending); + std::printf("classic gate: %lld ms beside a graphics create; a submission waited out a 3 s compute create\n", + static_cast(beside_graphics)); + return 0; +} + } // namespace int main() { std::setvbuf(stdout, nullptr, _IONBF, 0); if (owner_tracking() || waits_for_holder() || waits_for_queued_submitter() || handoff_is_capped() || - compile_gate()) + compile_gate() || gate_wait_limit() || gate_adapts() || + gate_probe_budget() || gate_per_kind() || gate_review_cases() || gate_second_review() || + gate_classic()) return 1; std::printf("submit_mutex_test: all passed\n"); return 0;