d3d12: rewrite a missed journal file from an empty cache when the seeded one kept its data (RT-JOURNAL-SEEDED-REWRITE) #2179

Open
github-bot wants to merge 2 commits from github-bot/gh-2179 into main AGit
Owner

@⁠Krashgamer on GitHub · 2026-11-26 02:38 UTC · original
Krashgamer:fix/journal-seeded-miss → main · +39 −1 · 1 files · 2 commits · open

Claimed in the coordination issue as: RT-JOURNAL-SEEDED-REWRITE (#1608)

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:

  • The same ~21 library compute pipelines missed in every boot (file loaded, creation feedback no hit, 2.4–9 s each, about 140 s per boot). Two boots in a row wrote byte-identical files for all of them.
  • With those files moved aside, one boot compiled them into empty caches and the next took all 21 from their files (40–60 ms each). So the files, not the pipelines, were the problem.
  • vk_pipeline_check alone 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 88479ff65 + #2138 + #1914 + #1886 with this change (the PR branch itself is this commit alone on current main; built with Ninja/MSVC, gta6rt links):

boot warm-up hits slow warm-up misses compile-gate stalls
before (3 boots) 1423 20–24 (~140 s) 21
with the change, 1st — 28 rebuilt, 15–78 ms extra each 26
2nd 28 of 28 rebuilt now hit 20 (further files, rebuilt) 18
3rd (300 s) 1770, 48 of 48 rebuilt hit 4 (33 s) 4

Each boot repairs the stale files it reaches; the count goes down as the warm-up gets further.

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

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a)

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

**@⁠Krashgamer** on GitHub · 2026-11-26 02:38 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2179) `Krashgamer:fix/journal-seeded-miss` → `main` · +39 −1 · 1 files · 2 commits · open Claimed in the coordination issue as: RT-JOURNAL-SEEDED-REWRITE (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ### 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: - The same ~21 library compute pipelines missed in every boot (file loaded, creation feedback no hit, 2.4–9 s each, about 140 s per boot). Two boots in a row wrote byte-identical files for all of them. - With those files moved aside, one boot compiled them into empty caches and the next took all 21 from their files (40–60 ms each). So the files, not the pipelines, were the problem. - `vk_pipeline_check` alone 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 88479ff65 + #2138 + #1914 + #1886 with this change (the PR branch itself is this commit alone on current main; built with Ninja/MSVC, `gta6rt` links): | boot | warm-up hits | slow warm-up misses | compile-gate stalls | |---|---|---|---| | before (3 boots) | 1423 | 20–24 (~140 s) | 21 | | with the change, 1st | — | 28 rebuilt, 15–78 ms extra each | 26 | | 2nd | 28 of 28 rebuilt now hit | 20 (further files, rebuilt) | 18 | | 3rd (300 s) | 1770, 48 of 48 rebuilt hit | 4 (33 s) | 4 | Each boot repairs the stale files it reaches; the count goes down as the warm-up gets further. 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 - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a) 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](https://claude.com/claude-code)
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 <[email protected]>
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 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:21:28 +00:00
Author
Owner

@⁠ecox982745 on GitHub · 2026-11-26 02:48 UTC · original

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 d3d12_compute_journal_test, on abbc1a4f8276c1dd84b5885ace81aa5e7e577592 (RTX 4090, Windows 11, NVIDIA 616.64, Khronos validation on).

Case What happened on this head
Normal driver, A’s journal under B’s key or vice versa Cache grew to 15,464 bytes. The next process reported a journal hit for the target shader.
Simulated unchanged-size miss, successful second create The replacement held the target shader. Both fresh processes reported journal hits and returned the expected counters.
Same miss, second create returns VK_ERROR_OUT_OF_HOST_MEMORY The first pipeline still dispatched correctly, but the 7,747- and 7,753-byte files were each overwritten with 36 bytes.

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 journal.finish gets built=true even when nothing was built into the replacement cache. The empty blob on this driver is larger than the 32-byte minimum. The change below keeps the usable pipeline and prevents publication on that path. With it, the old files kept their SHA-256 hashes in both failure cases, the successful retries still produced next-process hits, and all dispatches returned the expected (4,10) or (4,14).

AI-assisted with OpenAI Codex (gpt-6.2-astra).

Tested patch against abbc1a4f8
--- 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));
**@⁠ecox982745** on GitHub · 2026-11-26 02:48 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2179#issuecomment-7181142402) **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 `d3d12_compute_journal_test`, on `abbc1a4f8276c1dd84b5885ace81aa5e7e577592` (RTX 4090, Windows 11, NVIDIA 616.64, Khronos validation on). | Case | What happened on this head | |---|---| | Normal driver, A’s journal under B’s key or vice versa | Cache grew to 15,464 bytes. The next process reported a journal hit for the target shader. | | Simulated unchanged-size miss, successful second create | The replacement held the target shader. Both fresh processes reported journal hits and returned the expected counters. | | Same miss, second create returns `VK_ERROR_OUT_OF_HOST_MEMORY` | The first pipeline still dispatched correctly, but the 7,747- and 7,753-byte files were each overwritten with 36 bytes. | 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 `journal.finish` gets `built=true` even when nothing was built into the replacement cache. The empty blob on this driver is larger than the 32-byte minimum. The change below keeps the usable pipeline and prevents publication on that path. With it, the old files kept their SHA-256 hashes in both failure cases, the successful retries still produced next-process hits, and all dispatches returned the expected `(4,10)` or `(4,14)`. AI-assisted with OpenAI Codex (`gpt-6.2-astra`). <details><summary>Tested patch against abbc1a4f8</summary> ```diff --- 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)); ``` </details>
Author
Owner

@⁠Krashgamer on GitHub · 2026-11-26 02:50 UTC · original

Thanks, @⁠ecox982745, that's a real hole. Your change is in 4212cf5ab: a failed create against the empty cache now keeps the first pipeline and publishes nothing, so the old file stays. Rebuilt gta6rt and d3d12_compute_journal_test on the branch; the test passes on an RTX 3080 (NVIDIA 610.88, Windows 11). AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠Krashgamer** on GitHub · 2026-11-26 02:50 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2179#issuecomment-7181169750) Thanks, @⁠ecox982745, that's a real hole. Your change is in 4212cf5ab: a failed create against the empty cache now keeps the first pipeline and publishes nothing, so the old file stays. Rebuilt `gta6rt` and `d3d12_compute_journal_test` on the branch; the test passes on an RTX 3080 (NVIDIA 610.88, Windows 11). AI-assisted (Claude Code, Claude Opus 5.5).
Author
Owner

@⁠lixonik on GitHub · 2026-11-26 11:03 UTC · original · reviewed

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.

**@⁠lixonik** on GitHub · 2026-11-26 11:03 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2179#pullrequestreview-6072989792) · **reviewed** 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.
Author
Owner

@⁠Krashgamer on GitHub · 2026-11-26 15:22 UTC · original · edited 2026-11-26 23:08 UTC

CI note: all six red jobs come from main, not from this change (it only touches runtime/shims/d3d12_vulkan_device.cpp):

  • linux-gpu-tools: vk_null_descriptor_test.cpp:97 uses LEONIDA_TEST_NULL_DESCRIPTORS_SPV unguarded, but runtime/CMakeLists.txt only defines it when glslangValidator is found. Main has the same code, and #2055 is open for it.
  • macos: GPU test cs_imgatomic_ext fails (6 of 64 sint words), and vk_overlapping_occlusion now passes but is still in the expected failures. Neither touches the journal path.
  • windows: the job was canceled at about 35 minutes during the build, so it never reached the tests.
  • check, macos-python: Python test files fail on main as well (test_bink_names, test_opus_tags, test_world_names, test_mod_pack_output_alias, ...). They are tracked in #1608 with open PRs.
  • translator-tests: the two cs_dpp_cmp.asm cases fail with llvm-mc 21 ("dpp variant of this instruction is not supported"). Per #1608, main is green there since #1375 was merged.

I'll rebase once main is green.

**@⁠Krashgamer** on GitHub · 2026-11-26 15:22 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2179#issuecomment-7196189194) · edited 2026-11-26 23:08 UTC CI note: all six red jobs come from main, not from this change (it only touches `runtime/shims/d3d12_vulkan_device.cpp`): - **linux-gpu-tools**: `vk_null_descriptor_test.cpp:97` uses `LEONIDA_TEST_NULL_DESCRIPTORS_SPV` unguarded, but `runtime/CMakeLists.txt` only defines it when `glslangValidator` is found. Main has the same code, and #2055 is open for it. - **macos**: GPU test `cs_imgatomic_ext` fails (6 of 64 sint words), and `vk_overlapping_occlusion` now passes but is still in the expected failures. Neither touches the journal path. - **windows**: the job was canceled at about 35 minutes during the build, so it never reached the tests. - **check**, **macos-python**: Python test files fail on main as well (`test_bink_names`, `test_opus_tags`, `test_world_names`, `test_mod_pack_output_alias`, ...). They are tracked in #1608 with open PRs. - **translator-tests**: the two `cs_dpp_cmp.asm` cases fail with llvm-mc 21 ("dpp variant of this instruction is not supported"). Per #1608, main is green there since #1375 was merged. I'll rebase once main is green.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2179/head:github-bot/gh-2179'
git switch 'github-bot/gh-2179'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2179'
git switch 'github-bot/gh-2179'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2179'
git switch 'github-bot/gh-2179'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2179'
git switch 'main'
git merge --squash 'github-bot/gh-2179'
git switch 'main'
git merge --ff-only 'github-bot/gh-2179'
git switch 'main'
git merge 'github-bot/gh-2179'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.