Repository navigation
d3d12: rewrite a missed journal file from an empty cache when the seeded one kept its data (RT-JOURNAL-SEEDED-REWRITE) - #2179
Conversation
|
If the optional second compilation fails, the dispatch still works, but this head replaces the existing journal entry with a 36-byte empty NVIDIA cache. I reproduced this in both directions with the two authored modules from
For the last two cases I changed the first post-build cache-size query to return the size loaded from disk. For the failure case only, the test shim also returned the error on the second pipeline create. All other driver calls and GPU readbacks were real. The unmodified driver grew the cache in this synthetic test. The first create produced a valid pipeline, so AI-assisted with OpenAI Codex ( Tested patch against abbc1a4--- a/runtime/shims/d3d12_vulkan_device.cpp
+++ b/runtime/shims/d3d12_vulkan_device.cpp
@@ -10405,6 +10405,7 @@
auto& compiling = leonida::driver_compile;
VkResult created = VK_ERROR_UNKNOWN;
bool from_shared = false, probe_compiled = false;
+ bool journal_retry_failed = false;
ULONGLONG probe_ms = 0, driver_ms = 0;
{
// Every driver call of the build (shader module, journal cache, pipeline) in one turn through the compile
@@ -10455,7 +10456,8 @@
const ULONGLONG at_again = GetTickCount64();
const VkResult again_result = vk.vkCreateComputePipelines(dev, journal.cache, 1, &pipeline_info, nullptr, &again);
const ULONGLONG again_ms = GetTickCount64() - at_again;
- if (again_result == VK_SUCCESS && again) {
+ journal_retry_failed = again_result != VK_SUCCESS || !again;
+ if (!journal_retry_failed) {
vk.vkDestroyPipeline(dev, built, nullptr);
built = again;
}
@@ -10467,7 +10469,7 @@
}
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);
+ journal.finish(!from_shared && !journal_retry_failed && created == VK_SUCCESS && built, trace.hit(), driver_ms);
}
std::vector<std::uint32_t>().swap(words);
profile.finish(int(created)); |
|
Thanks, @ecox982745, that's a real hole. Your change is in 4212cf5: a failed create against the empty cache now keeps the first pipeline and publishes nothing, so the old file stays. Rebuilt |
lixonik
left a comment
There was a problem hiding this comment.
Built d3d12_compute_journal_test at this head with MSVC on Windows 11. The authored overlay scenario passed: cold A and new B both produced journal entries, external A was a driver hit with zero local entries, and the follow-up B was a local hit. Readbacks matched in all four processes. GPU: NVIDIA GeForce RTX 5070, driver 610.88. This covers the normal cold, seeded-hit and local-hit paths. The synthetic fixture did not trigger a same-size seeded miss, so it did not verify the new retry path.
AI-assisted.
|
CI note: all six red jobs come from main, not from this change (it only touches
I'll rebase once main is green. |
|
Independently verified head Verification Results
Important Cross-PR Interaction Catch with Open PR
|
|
The retry also misses external seeds on this PR by itself. If the writable entry is missing, I tested
What was simulated. The table covers an unchanged-size cache miss. A test-only hook substituted the size Vulkan originally accepted for the single post-build size observation in I also rebuilt the patched standalone tree without the hook. The CPU Patch for git amSave the block as From d8a5b7bc6572695ead478e4e6ba3696111a1c8a4 Mon Sep 17 00:00:00 2001
From: OpenAI Codex <codex@localhost.invalid>
Date: Sun, 29 Nov 2026 12:05:29 +1000
Subject: [PATCH] d3d12: compare journal retries with the loaded driver payload
The writable file can be absent or invalid when a pipeline cache is initialized from an external seed. Remember the size Vulkan accepted, and keep the on-disk byte count for replacement accounting.
AI-assisted with OpenAI Codex (GPT-6).
---
runtime/shims/d3d12_vulkan_device.cpp | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/runtime/shims/d3d12_vulkan_device.cpp b/runtime/shims/d3d12_vulkan_device.cpp
index 72cf1f2cb..fe096fcce 100644
--- a/runtime/shims/d3d12_vulkan_device.cpp
+++ b/runtime/shims/d3d12_vulkan_device.cpp
@@ -10124,6 +10124,7 @@ public:
file_.data.empty() ? nullptr : file_.data.data()};
if (!file_.data.empty() && vk.vkCreatePipelineCache(device_.info.device, &info, nullptr, &cache) == VK_SUCCESS) {
seeded = true;
+ seeded_bytes_ = info.initialDataSize;
} else {
cache = VK_NULL_HANDLE; // no file, or one the driver declined: start empty, and the build rewrites it
info.initialDataSize = 0;
@@ -10141,7 +10142,7 @@ public:
if (!cache || !seeded) return false;
const auto& vk = device_.context->vk;
std::size_t size = 0;
- if (vk.vkGetPipelineCacheData(device_.info.device, cache, &size, nullptr) != VK_SUCCESS || size != file_.bytes)
+ if (vk.vkGetPipelineCacheData(device_.info.device, cache, &size, nullptr) != VK_SUCCESS || size != seeded_bytes_)
return false; // it took the pipeline (or cannot say): rewritten from it as before
vk.vkDestroyPipelineCache(device_.info.device, cache, nullptr);
cache = VK_NULL_HANDLE;
@@ -10229,6 +10230,7 @@ private:
leonida::SubmitMutex* submits_ = nullptr; // null: compute_driver_turn, for a build outside the submit lock
const char* trigger_ = "";
const char* name_;
+ std::size_t seeded_bytes_ = 0; // Driver payload, which may come from outside the writable journal.
bool enabled_ = false;
bool built_ = false;
bool write_ = false;Retest of the adopted fix. I merged head I repeated the two-shader matrix with the same test-only substitution of the single post-build size observation. All six simulated unchanged-size misses retried, covering a valid local entry, a missing local entry with an external seed, and a seven-byte invalid local entry with an external seed. All six unmodified-size controls skipped the retry because the driver's cache grew. Every fresh-process check found the rewritten entry, both shaders returned the expected words, and the external seeds kept their hashes and timestamps. These runs tested #2179 on its own. Author's update AI-assisted with OpenAI Codex (GPT-6.2 Sol). |
timbot103
left a comment
There was a problem hiding this comment.
Static review of 4212cf5ab only. I ran no builds or GPU tests.
[MAJOR] runtime/shims/d3d12_vulkan_device.cpp:10144 — A same-size miss from an external seed bypasses the empty-cache retry. runtime/src/pipeline_cache_journal.h:176 can load a compatible external payload while retaining zero bytes for a missing writable file or the size of an invalid writable file. When Vulkan reports the same size as the payload it loaded, restart_empty() compares that size with the writable file's byte count and skips the retry. The miss can then publish the unchanged payload locally, causing the next launch to prefer that stale entry and miss again.
Save info.initialDataSize after successful seeded cache creation and compare the returned size with that value. Keep file_.bytes for the disk budget. The existing overlay probe in scripts/check_compute_journal_overlay.py:41 covers cold creation, an external hit, and a local hit. Add a forced same-size external miss with a missing or invalid writable entry, and check that the local rewrite hits in a fresh process and leaves the seed intact.
The driver calls stay within the build's existing driver turn, and each build owns its journal cache. With a valid local seed, a size increase or decrease follows the existing rewrite path. An equal size attempts the empty-cache retry. The seeded cache is destroyed before replacement creation. A failed replacement creation or retry preserves the first pipeline and skips publication. If the replacement cache was created, finish() destroys it even when the retry fails. Publication uses the existing staged rename and accounts bytes only after a successful write. Concurrent publishers still share the existing best-effort budget check. The changed shim is part of the Windows runtime target. The portable journal tests and file writer are unchanged.
AI-assisted.
|
Thanks, @zmasi, @ecox982745 and @timbot103. You are right: Tested on Windows 11, RTX 3080, NVIDIA 610.88: |
|
AGENT-MSG | 2026-11-29 13:46 UTC | merzleckeier | AI-assisted: Codex BASE: I put the first synthetic shader's driver cache under the second shader's key. Both drivers reported a miss and grew the cache (NVIDIA 7,947 → 15,864 bytes, RADV 904 → 1,776). To exercise the unchanged-size branch, the wrapper substitutes the accepted input byte count for the first post-build size query only. Initial pipeline creation and dispatch used the real driver.
The unchanged CPU journal test and the two ordinary GPU dispatch readbacks also passed. Host Khronos validation reported the same device-creation VUID |
|
TAKEN by OreoFR (Windows, RTX 4070 8 GB) |
|
Verified by OreoFR — NO RED (no test)
AI-assisted (Claude Code, Claude Opus 5.5), run for OreoFR. |
|
Thanks, @OreoFR. The test is in now (
RTX 3080 10 GB, NVIDIA 610.88, Windows 11. Details are in the description. AI-assisted (Claude Code, Claude Opus 5.5). |
…ded one kept its data (RT-JOURNAL-SEEDED-REWRITE) A compute pipeline that missed its journal file was rewritten from the cache made from that file. On NVIDIA (RTX 3080, 610.88) that cache came back exactly as loaded, without the pipeline just compiled, so the rewrite gave the same file and the same multi-second miss on every boot. After a seeded miss whose cache is still the loaded size, the pipeline is built once more against an empty cache (15-78 ms: the driver still has it) and that is written. A seeded cache that took the pipeline is rewritten as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…fails Found by ecox982745 in review: a failed second create left an empty cache that finish() still wrote over the old file (36 bytes on NVIDIA). The first pipeline is kept and nothing is published on that path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…made from restart_empty() compared the cache's size with file_.bytes, the writable file's size. That is zero or wrong when the payload came from the external seed (missing or invalid local file), and 24 bytes too many once ProjectLeonida#2511 strips its stamp. The retry was then skipped and the same miss came back on every boot. create() now records the size Vulkan took; file_.bytes stays for the disk budget. Found by zmasi, ecox982745 and timbot103 in review; the change follows ecox982745's patch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ompute_journal_seeded_miss) d3d12_compute_journal_test gets a test-only layer between the runtime and the driver (--keep-seeded-cache-data): a pipeline cache made from initial data answers vkGetPipelineCacheData with exactly that data, as NVIDIA 610.88 did on an RTX 3080 after a seeded miss. Other drivers grow the cache instead, so the layer makes the case reproducible on any GPU; pipelines, dispatches and readbacks stay the real driver's. --fail-cache-retry also fails the create against the empty cache. scripts/check_compute_journal_seeded_miss.py runs each case in its own process with A's journal data under B's key: a stale local file, the same data only in the seed folder, seven invalid local bytes with the seed, and a failed retry. The file has to be rewritten with B's pipeline (and hit in a fresh process when the driver reports hits), the seed has to keep its bytes and last-write time, and a failed retry has to leave the file alone. Registered in CTest as d3d12_compute_journal_seeded_miss. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
c9777e3 to
f230da5
Compare
|
Rebased on |
|
Independent native Windows red/green check of the new stock seeded-miss fixture. The tested merge of
The fixture forces the seeded cache to report its original data to exercise the retry. GPU pipeline creation and readback were native. AI-assisted with OpenAI Codex (GPT-6.2 Sol). |
Claimed in the coordination issue as: RT-JOURNAL-SEEDED-REWRITE (#1608 (comment))
What and why
The compute pipeline journal (#2098) rewrites a pipeline's file after a miss. When the file was loaded (the cache was seeded from it) and the pipeline still missed, the rewrite came from that seeded cache. On NVIDIA that cache came back exactly as loaded, without the pipeline just compiled, so the file never changed and the same pipelines missed and compiled in the driver on every boot, holding the compile gate while the title waited to submit.
Measured on an RTX 3080 10 GB, NVIDIA 610.88:
vk_pipeline_checkalone does not reproduce it: a cache seeded with another pipeline grows and gives a hit the next run. Where the stale files first came from is not determined.Change: after a seeded miss,
JournalCache::restart_empty()asks the cache for its data size. If it is still the loaded size, the cache is swapped for an empty one and the pipeline is created once more against it; that pipeline is kept and its cache is written. The second create took 15–78 ms (mean ~41 ms over 28), since the driver still has the pipeline. A seeded cache that did take the pipeline (a different size) is rewritten as before, so drivers without this behaviour are unchanged. One log line per rebuild:pipeline journal: <name> missed its journal file (N ms); built again against an empty cache in M ms.Tested
Boots of 180–300 s on Windows 11,
LEONIDA_COMPILE_HELPER=1 LEONIDA_ASYNC_PIPELINES=1 LEONIDA_TITLE_WATCHDOG=0 LEONIDA_CONSOLE_FIX_US=0, on main 88479ff + #2138 + #1914 + #1886 with this change (the PR branch itself is this commit alone on current main; built with Ninja/MSVC,gta6rtlinks):Each boot repairs the stale files it reaches; the count goes down as the warm-up gets further.
Changes since the first version
c5bc7b0c5(from ecox982745's review): when the create against the empty cache fails, the first pipeline is kept and nothing is published, so the old file stays as it was.7a70814b6(from the reviews of zmasi, ecox982745 and timbot103):restart_empty()compares the cache's size with the payload Vulkan was given (info.initialDataSize, recorded increate()), not with the writable file's size. The two differ when the data came from the read-only seed folder (local file missing or invalid) and, with d3d12: stamp compute journal files with the writing build and device-create config; precompile re-checks other writers' files (RT-PIPELINE-JOURNAL-BUILD-ID) #2511, by its 24-byte stamp.file_.bytesstays for the disk budget.main8f41d7d01(conflict inbuild_compute_pipeline:main'shit_reportedand this PR'sjournal_retry_failedboth kept). The commits above had other IDs before the rebase (abbc1a4f8,4212cf5ab,49b8998de); the changes are the same.Test:
d3d12_compute_journal_seeded_miss(f230da518)d3d12_compute_journal_testgets a test-only layer between the runtime and the driver (--keep-seeded-cache-data): a pipeline cache made from initial data answersvkGetPipelineCacheDatawith exactly that data, as NVIDIA 610.88 did here. Other drivers grow the cache instead, so the layer makes the case reproducible on any GPU, the way merzleckeier's wrapper did. Pipelines, dispatches and readbacks stay the real driver's, and no production code changes for the test.--fail-cache-retryalso fails the create against the empty cache.scripts/check_compute_journal_seeded_miss.py(registered in CTest) runs each case in its own process and cache folder, with shader A's journal data under shader B's key:Red and green, Windows 11 (26200), RTX 3080 10 GB, NVIDIA 610.88, Ninja RelWithDebInfo:
mainad36782c6(c9777e386, before the rebase): all four cases pass, 5 runs in a row; also withLEONIDA_VK_VALIDATION=1(0 validation errors). The runtime logs the retry (built again against an empty cache ... (VkResult 0)).mainad36782c6with only the test applied:ERROR: stale-local: the journal file was rewritten with the data it was read from. Run by hand onmain, all four cases fail: B's local file ends with A's bytes in the three rewrite cases, and in failed-retry no retry happens and the file is rewritten.file_.bytes(as in the first two commits): stale-local passes, external-seed fails. So the test covers both fixes separately.Full suite (
ctest -j 6, 577 tests each),c9777e386againstmainad36782c6+ the test: no new failure.xbox_presentfails on both (as onmainin OreoFR's run);d3d12_compute_journal_seeded_missfails only onmain;d3d12_state_sweepanddxgi_waitable_latencyfailed once in the parallel run on the PR tree and pass 3 of 3 alone on both trees. After the rebase onto8f41d7d01(no commit sincead36782c6touches this PR's files)gta6rtbuilds, the three journal tests pass 3 runs in a row, and the seeded-miss script passes withLEONIDA_VK_VALIDATION=1.GPUs tested: NVIDIA GeForce RTX 3080 10 GB, driver 610.88, Windows 11 Pro 26200
AI-assisted: yes (Claude Code, Claude Opus 5.5)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a: no translator change; this PR only changes the runtime's pipeline journal)Related: HasiKe's finding in #1608 that the NVIDIA session cache keeps its loaded size across checkpoints may be the same driver behaviour for the shared cache; this PR does not touch that path.
🤖 Generated with Claude Code