From 7acf84d38f77b11a9959602686ec624314ebffbf Mon Sep 17 00:00:00 2001 From: fiestorra Date: Sun, 29 Nov 2026 14:07:41 +0100 Subject: [PATCH 1/2] d3d12: say where a slow pipeline came from, and whether its journal was written The slow-pipeline line reported ook N s to build for a timer that starts before the journal file is read and before the shared cache is asked, so it named a compile for what could be a cache lookup. Chasing a compile cost from it is chasing the wrong number: a run with 16 such lines had compiled exactly one pipeline. The line now names the source (a compile, the shared cache, or the pipeline's own journal file) and carries the hit the journal reported, whether its cache was seeded from a file, and whether the file was written afterwards. That is what turned three contradictory readings of the same log into one, on an RTX 4090 with a warm journal: 23 slow lines, all hit 0, seeded 0, written 1 - first-sight pipelines, each compiled once and journaled. --- runtime/shims/d3d12_vulkan_device.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/runtime/shims/d3d12_vulkan_device.cpp b/runtime/shims/d3d12_vulkan_device.cpp index 9eca923131..eb1c057892 100644 --- a/runtime/shims/d3d12_vulkan_device.cpp +++ b/runtime/shims/d3d12_vulkan_device.cpp @@ -17727,6 +17727,7 @@ ComputeBuild build_compute_pipeline(DeviceState& device, const leonida::ShaderEn auto& compiling = leonida::driver_compile; VkResult created = VK_ERROR_UNKNOWN; bool from_shared = false, probe_compiled = false; + int hit_reported = -1; // what the journal sees as its hit, printed below to explain a missing write ULONGLONG probe_ms = 0, driver_ms = 0; { // Every driver call of the build (shader module, journal cache, pipeline) in one turn through the compile @@ -17773,7 +17774,8 @@ ComputeBuild build_compute_pipeline(DeviceState& device, const leonida::ShaderEn } compiling.name.store(nullptr, std::memory_order_release); vk.vkDestroyShaderModule(dev, module, nullptr); // Vulkan lets a module go once the pipeline exists - journal.finish(!from_shared && created == VK_SUCCESS && built, trace.hit(), driver_ms); + hit_reported = trace.hit(); // what finish() sees; decides whether the file is written + journal.finish(!from_shared && created == VK_SUCCESS && built, hit_reported, driver_ms); } std::vector().swap(words); profile.finish(int(created)); @@ -17793,9 +17795,15 @@ ComputeBuild build_compute_pipeline(DeviceState& device, const leonida::ShaderEn out.journaled = journal.written(); out.ms = GetTickCount64() - started; if (created == VK_SUCCESS && built && out.ms >= 2000) - std::fprintf(stderr, "[rt] d3d12: compute pipeline %s took %.1f s to build (%zu B SPIR-V)\n", - entry->name.c_str(), double(out.ms) / 1000.0, bytes); - return out; + // The timer starts before the journal file is read and before the shared cache is asked, so this + // line reports the whole call. Name where the pipeline came from: a compile, the shared cache or + // its own journal file, which is what a compile cost has to be read from. + std::fprintf(stderr, + "[rt] d3d12: compute pipeline %s took %.1f s to obtain from %s (%zu B SPIR-V; hit %d," + " seeded %d, written %d)\n", + entry->name.c_str(), double(out.ms) / 1000.0, + out.journal_hit ? "its journal file" : out.from_shared ? "the shared cache" : "a compile", + bytes, hit_reported, int(journal.seeded), int(out.journaled)); } class PipelineState final From e3af36070910e80474f708624ea1b71c924dabee Mon Sep 17 00:00:00 2001 From: fiestorra Date: Mon, 30 Nov 2026 15:35:28 +0100 Subject: [PATCH 2/2] d3d12: keep the return of build_compute_pipeline, and align the new lines The slow-pipeline line replaced the fprintf but also removed the function's return out; - the body then fell off the end of a non-void function. MSVC at /W4 reports neither C4715 nor C4716 for this shape and the build stays green, so the caller would have read an uninitialised ComputeBuild; the test suite does not distinguish the two, which is why the earlier build-based check missed it. Restored, and the new statements dedented to the block they belong to. --- runtime/shims/d3d12_vulkan_device.cpp | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/runtime/shims/d3d12_vulkan_device.cpp b/runtime/shims/d3d12_vulkan_device.cpp index eb1c057892..a9f3320867 100644 --- a/runtime/shims/d3d12_vulkan_device.cpp +++ b/runtime/shims/d3d12_vulkan_device.cpp @@ -17727,7 +17727,7 @@ ComputeBuild build_compute_pipeline(DeviceState& device, const leonida::ShaderEn auto& compiling = leonida::driver_compile; VkResult created = VK_ERROR_UNKNOWN; bool from_shared = false, probe_compiled = false; - int hit_reported = -1; // what the journal sees as its hit, printed below to explain a missing write + int hit_reported = -1; // what the journal sees as its hit, printed below to explain a missing write ULONGLONG probe_ms = 0, driver_ms = 0; { // Every driver call of the build (shader module, journal cache, pipeline) in one turn through the compile @@ -17774,8 +17774,8 @@ ComputeBuild build_compute_pipeline(DeviceState& device, const leonida::ShaderEn } compiling.name.store(nullptr, std::memory_order_release); vk.vkDestroyShaderModule(dev, module, nullptr); // Vulkan lets a module go once the pipeline exists - hit_reported = trace.hit(); // what finish() sees; decides whether the file is written - journal.finish(!from_shared && created == VK_SUCCESS && built, hit_reported, driver_ms); + hit_reported = trace.hit(); // what finish() sees; decides whether the file is written + journal.finish(!from_shared && created == VK_SUCCESS && built, hit_reported, driver_ms); } std::vector().swap(words); profile.finish(int(created)); @@ -17795,15 +17795,16 @@ ComputeBuild build_compute_pipeline(DeviceState& device, const leonida::ShaderEn out.journaled = journal.written(); out.ms = GetTickCount64() - started; if (created == VK_SUCCESS && built && out.ms >= 2000) - // The timer starts before the journal file is read and before the shared cache is asked, so this - // line reports the whole call. Name where the pipeline came from: a compile, the shared cache or - // its own journal file, which is what a compile cost has to be read from. - std::fprintf(stderr, - "[rt] d3d12: compute pipeline %s took %.1f s to obtain from %s (%zu B SPIR-V; hit %d," - " seeded %d, written %d)\n", - entry->name.c_str(), double(out.ms) / 1000.0, - out.journal_hit ? "its journal file" : out.from_shared ? "the shared cache" : "a compile", - bytes, hit_reported, int(journal.seeded), int(out.journaled)); + // The timer starts before the journal file is read and before the shared cache is asked, so this + // line reports the whole call. Name where the pipeline came from: a compile, the shared cache or + // its own journal file, which is what a compile cost has to be read from. + std::fprintf(stderr, + "[rt] d3d12: compute pipeline %s took %.1f s to obtain from %s (%zu B SPIR-V; hit %d," + " seeded %d, written %d)\n", + entry->name.c_str(), double(out.ms) / 1000.0, + out.journal_hit ? "its journal file" : out.from_shared ? "the shared cache" : "a compile", + bytes, hit_reported, int(journal.seeded), int(out.journaled)); + return out; } class PipelineState final