[PR #1914] [MERGED] d3d12: a pipeline cache for the offline cache's misses, written while the game runs (RT-HEAVY-PIPELINE-CACHE) #1921

Closed
opened 2026-11-26 21:19:25 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1914
Author: @kawaii-shakal
Created: 11/25/2026
Status: ✅ Merged
Merged: 11/26/2026
Merged by: @aslan2142

Base: main ← Head: heavy-pipeline-cache


📝 Commits (5)

  • 9f1f5bf d3d12: a pipeline cache for the offline cache's misses, written while the game runs (RT-HEAVY-PIPELINE-CACHE)
  • e4c413a heavy pipeline cache: a write covers what was noted before it started, counted, not timed; teardown keeps fast builds too
  • c3b8520 Merge upstream main into heavy-pipeline-cache
  • aab7653 d3d12: retry a failed heavy cache write and never publish a VK_INCOMPLETE snapshot
  • a42bffd Merge origin/main into heavy-pipeline-cache

📊 Changes

9 files changed (+439 additions, -5 deletions)

View changed files

📝 docs/d3d12_vulkan.md (+19 -0)
📝 runtime/CMakeLists.txt (+8 -0)
📝 runtime/shims/d3d12_com.h (+3 -0)
📝 runtime/shims/d3d12_vulkan_device.cpp (+196 -3)
➕ runtime/src/heavy_pipeline_cache.h (+94 -0)
📝 runtime/test/d3d12_mesh_test.cpp (+1 -0)
📝 runtime/test/d3d12_translated_draw_test.cpp (+1 -0)
➕ runtime/test/heavy_pipeline_cache_test.cpp (+109 -0)
📝 runtime/test/vk_test_device.h (+8 -2)

📄 Description

Update (a42bffdc3, merged with main c50ed94b3): main now persists compute pipelines in its per-pipeline journal (src/pipeline_cache_journal.h), so the heavy cache here covers graphics pipelines only; compute builds use main's build_compute_pipeline unchanged. The text below describes the original version, where it covered both.

Claimed in the coordination issue as RT-HEAVY-PIPELINE-CACHE: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7167207402

Problem

The builds the offline pipeline_cache.bin misses are compiled again on every boot. On an RTX 5070 Ti these are the pipeline library's compute programs, 3 to 7 s each and about 40 per boot before the world starts, and they are what keeps the render thread waiting at the title's hang watchdog. pipeline_cache.session.bin can't keep them for two reasons:

  • It is written at device teardown only, and a boot that ends in a crash never gets there.
  • A cache seeded from the corpus returns the whole corpus (9.2 GB here), so even a clean teardown is over the 256 MiB write limit and writes nothing. LEONIDA_STARTUP_CACHE_CHECKPOINTS has the same problem.

Change

  • Corpus first, without compiling. Every graphics and compute build first asks the corpus cache with VK_PIPELINE_CREATE_FAIL_ON_PIPELINE_COMPILE_REQUIRED_BIT (DeviceState::create_pipeline).
  • A miss goes to a cache of its own. It is built against a second cache seeded from pipeline_cache.heavy.bin, next to pipeline_cache.bin. That cache holds only the corpus's misses, so it stays small.
  • Written while the game runs. A build of at least LEONIDA_HEAVY_PIPELINE_CACHE_MS (500 by default) marks the cache dirty. A thread of its own writes it 3 s after the newest slow build and no later than 20 s after the first unwritten one, through the existing staging file and rename (CacheStagingFile), so the file on disk is always complete. A crash loses at most the last 20 s of slow builds. At teardown the thread stops and writes what is left.
  • Off switch. LEONIDA_HEAVY_PIPELINE_CACHE_MS=0 turns it off, and with it pipelineCreationCacheControl unless LEONIDA_PIPELINE_COMPILE=cache-only asks for it. A cache-only create (cache-only) is left exactly as it was.
  • Pure logic, tested on its own. The threshold parsing and the write schedule are in runtime/src/heavy_pipeline_cache.h, with heavy_pipeline_cache_test.
  • Test devices. vk_test_device.h takes the heavy path when LEONIDA_HEAVY_PIPELINE_CACHE_MS is set, and d3d12_mesh_heavy_cache runs the mesh test's draws through it.
  • Docs. docs/d3d12_vulkan.md describes it next to the session cache.

Measured (Windows 11 Pro 26300, RTX 5070 Ti, NVIDIA 617.42, VS 2026 RelWithDebInfo)

  • Does the driver honour cache-only for the heavy programs? Checked with vk_pipeline_check and a local probe that adds the flag (not part of this PR), against an empty cache. Four library compute programs the corpus lacks return VK_PIPELINE_COMPILE_REQUIRED in under 1 ms, so the heavy path is taken for them. The mesh test's small shaders come back VK_SUCCESS from a cache-only create even into an empty cache, because the driver's own shader cache already holds them. That is why the CTest case checks correctness, not the file.
  • CTest: heavy_pipeline_cache, pipeline_cache_store, pipeline_cache_file, d3d12_msaa_draw, d3d12_mesh and d3d12_mesh_heavy_cache all pass, 6 of 6.

Not done here

  • No real boot yet. I haven't run this PR in a real boot, so the next one will measure how much of the inline compile time goes away on the second boot.
  • Graphics variants share the same path. They are only slow when the corpus misses them.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1914 **Author:** [@kawaii-shakal](https://github.com/kawaii-shakal) **Created:** 11/25/2026 **Status:** ✅ Merged **Merged:** 11/26/2026 **Merged by:** [@aslan2142](https://github.com/aslan2142) **Base:** `main` ← **Head:** `heavy-pipeline-cache` --- ### 📝 Commits (5) - [`9f1f5bf`](https://github.com/ubiquitarianism/leonida/commit/9f1f5bf9a653d6cd4568a879887b4483f37ad465) d3d12: a pipeline cache for the offline cache's misses, written while the game runs (RT-HEAVY-PIPELINE-CACHE) - [`e4c413a`](https://github.com/ubiquitarianism/leonida/commit/e4c413a3a5fe18b99ede727d02b9a561fc8ca56e) heavy pipeline cache: a write covers what was noted before it started, counted, not timed; teardown keeps fast builds too - [`c3b8520`](https://github.com/ubiquitarianism/leonida/commit/c3b8520683b1ed19c1af9f0061b48ceb57bad928) Merge upstream main into heavy-pipeline-cache - [`aab7653`](https://github.com/ubiquitarianism/leonida/commit/aab7653566e4ecf80a8026cfbd48e74966a4d04c) d3d12: retry a failed heavy cache write and never publish a VK_INCOMPLETE snapshot - [`a42bffd`](https://github.com/ubiquitarianism/leonida/commit/a42bffdc3e0d30347eedb3c433405e9a141cc06b) Merge origin/main into heavy-pipeline-cache ### 📊 Changes **9 files changed** (+439 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `docs/d3d12_vulkan.md` (+19 -0) 📝 `runtime/CMakeLists.txt` (+8 -0) 📝 `runtime/shims/d3d12_com.h` (+3 -0) 📝 `runtime/shims/d3d12_vulkan_device.cpp` (+196 -3) ➕ `runtime/src/heavy_pipeline_cache.h` (+94 -0) 📝 `runtime/test/d3d12_mesh_test.cpp` (+1 -0) 📝 `runtime/test/d3d12_translated_draw_test.cpp` (+1 -0) ➕ `runtime/test/heavy_pipeline_cache_test.cpp` (+109 -0) 📝 `runtime/test/vk_test_device.h` (+8 -2) </details> ### 📄 Description > **Update (a42bffdc3, merged with main c50ed94b3):** main now persists compute pipelines in its per-pipeline journal (`src/pipeline_cache_journal.h`), so the heavy cache here covers **graphics pipelines only**; compute builds use main's `build_compute_pipeline` unchanged. The text below describes the original version, where it covered both. Claimed in the coordination issue as RT-HEAVY-PIPELINE-CACHE: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7167207402 ### Problem The builds the offline `pipeline_cache.bin` misses are compiled again on every boot. On an RTX 5070 Ti these are the pipeline library's compute programs, 3 to 7 s each and about 40 per boot before the world starts, and they are what keeps the render thread waiting at the title's hang watchdog. `pipeline_cache.session.bin` can't keep them for two reasons: - It is written at device teardown only, and a boot that ends in a crash never gets there. - A cache seeded from the corpus returns the whole corpus (9.2 GB here), so even a clean teardown is over the 256 MiB write limit and writes nothing. `LEONIDA_STARTUP_CACHE_CHECKPOINTS` has the same problem. ### Change - **Corpus first, without compiling.** Every graphics and compute build first asks the corpus cache with `VK_PIPELINE_CREATE_FAIL_ON_PIPELINE_COMPILE_REQUIRED_BIT` (`DeviceState::create_pipeline`). - **A miss goes to a cache of its own.** It is built against a second cache seeded from `pipeline_cache.heavy.bin`, next to `pipeline_cache.bin`. That cache holds only the corpus's misses, so it stays small. - **Written while the game runs.** A build of at least `LEONIDA_HEAVY_PIPELINE_CACHE_MS` (500 by default) marks the cache dirty. A thread of its own writes it 3 s after the newest slow build and no later than 20 s after the first unwritten one, through the existing staging file and rename (`CacheStagingFile`), so the file on disk is always complete. A crash loses at most the last 20 s of slow builds. At teardown the thread stops and writes what is left. - **Off switch.** `LEONIDA_HEAVY_PIPELINE_CACHE_MS=0` turns it off, and with it `pipelineCreationCacheControl` unless `LEONIDA_PIPELINE_COMPILE=cache-only` asks for it. A cache-only create (`cache-only`) is left exactly as it was. - **Pure logic, tested on its own.** The threshold parsing and the write schedule are in `runtime/src/heavy_pipeline_cache.h`, with `heavy_pipeline_cache_test`. - **Test devices.** `vk_test_device.h` takes the heavy path when `LEONIDA_HEAVY_PIPELINE_CACHE_MS` is set, and `d3d12_mesh_heavy_cache` runs the mesh test's draws through it. - **Docs.** `docs/d3d12_vulkan.md` describes it next to the session cache. ### Measured (Windows 11 Pro 26300, RTX 5070 Ti, NVIDIA 617.42, VS 2026 RelWithDebInfo) - **Does the driver honour cache-only for the heavy programs?** Checked with `vk_pipeline_check` and a local probe that adds the flag (not part of this PR), against an empty cache. Four library compute programs the corpus lacks return `VK_PIPELINE_COMPILE_REQUIRED` in under 1 ms, so the heavy path is taken for them. The mesh test's small shaders come back `VK_SUCCESS` from a cache-only create even into an empty cache, because the driver's own shader cache already holds them. That is why the CTest case checks correctness, not the file. - **CTest:** `heavy_pipeline_cache`, `pipeline_cache_store`, `pipeline_cache_file`, `d3d12_msaa_draw`, `d3d12_mesh` and `d3d12_mesh_heavy_cache` all pass, 6 of 6. ### Not done here - **No real boot yet.** I haven't run this PR in a real boot, so the next one will measure how much of the inline compile time goes away on the second boot. - **Graphics variants share the same path.** They are only slow when the corpus misses them. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 21:19:25 +01:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#1921
No description provided.