[PR #218] d3d12: persist the runtime Vulkan pipeline cache across launches #270

Open
opened 2026-11-26 20:17:20 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/218
Author: @Andretuta
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: old-pr/9953


📝 Commits (1)

  • 99cefc9 d3d12: persist the runtime Vulkan pipeline cache across launches (framed and checksummed file, saved after a cache miss and under 1 GiB, merged across sessions, never the build seed)

📊 Changes

14 files changed (+1328 additions, -35 deletions)

View changed files

📝 docs/d3d12_vulkan.md (+18 -0)
📝 runtime/CMakeLists.txt (+22 -0)
📝 runtime/shims/d3d12_com.h (+15 -0)
📝 runtime/shims/d3d12_vulkan_device.cpp (+279 -18)
📝 runtime/src/pipeline_cache_file.h (+21 -12)
📝 runtime/src/pipeline_cache_snapshot.h (+0 -0)
➕ runtime/src/pipeline_cache_store.h (+264 -0)
📝 runtime/src/vulkan_backend.h (+1 -1)
➕ runtime/test/d3d12_pipeline_cache_persist_test.cpp (+582 -0)
📝 runtime/test/pipeline_cache_file_test.cpp (+1 -1)
📝 runtime/test/pipeline_cache_snapshot_test.cpp (+1 -1)
➕ runtime/test/pipeline_cache_store_test.cpp (+120 -0)
📝 runtime/test/vk_pipeline_check.cpp (+2 -2)
📝 runtime/test/vk_test_device.h (+2 -0)

📄 Description

Carried over from old PR 9953 by tedin7 in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch old-pr/9953, exactly that PR's last commit. All carried-over PRs are listed in #17.
Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it.
tedin7: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one.


Original description (mentions and #N references are disabled; the numbers refer to the old repository):

Rebased cleanly on current main; supersedes #7396 closed during org migration.

What

The runtime's Vulkan pipeline cache now survives launches. Today main only reads a build-time pipeline_cache.bin seed, so every launch recompiles every PSO from scratch (the first-frame and PSO-creation stall).

  • The cache is saved at device teardown to a framed, checksummed file and the next session starts from it (runtime/src/pipeline_cache_store.h; pipeline_cache_file.h and pipeline_cache_snapshot.h move from test/ to src/).
  • It is saved only after a cache miss and while under 1 GiB; sessions merge into the same file, and the build seed is never overwritten. A corrupt, foreign-device or truncated file is ignored and the session starts empty.
  • LEONIDA_PIPELINE_CACHE=off turns it off (tests). PipelineCacheStats reports created / hits / time so a test can see the effect.

Why

PSO creation is the cold-boot cost before the first frame; the cache makes the second launch skip it. A checksum and size cap keep a damaged or huge file from breaking a launch.

Tested

On this base (current main, native g++):

  • pipeline_cache_store_test (new, framing, checksum, merge, size cap, rejection of damaged files): prints "pipeline cache store: ok", exit 0.
  • pipeline_cache_file_test and pipeline_cache_snapshot_test (moved to src/): exit 0 each.
  • Negative control: pipeline_cache_store_test does not build on origin/main (src/pipeline_cache_store.h does not exist there); the persistence behaviour is absent.

NOT run on this base (be aware): d3d12_pipeline_cache_persist_test (GPU test, Windows exe under Wine) and the compile of shims/d3d12_vulkan_device.cpp. The GPU pods are off and this host has no unpacked Windows SDK; mingw headers cannot parse the Windows code. The earlier version of this PR (#7396, older base) measured 26x faster PSO creation on the second launch on an RTX 4090. The merge needed three keep-both conflict resolutions (d3d12_com.h, d3d12_vulkan_device.cpp, vk_test_device.h; the host-pointer fields and create_buffer_at_host_address from main sit next to the new cache fields and pipeline_cache_stats); that second-launch speedup has not been reproduced here. Please run d3d12_pipeline_cache_persist on CI/maintainer hardware before merging.


🔄 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/218 **Author:** [@Andretuta](https://github.com/Andretuta) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `old-pr/9953` --- ### 📝 Commits (1) - [`99cefc9`](https://github.com/ubiquitarianism/leonida/commit/99cefc90d6545c0c204d12f1d3161f423939ed3f) d3d12: persist the runtime Vulkan pipeline cache across launches (framed and checksummed file, saved after a cache miss and under 1 GiB, merged across sessions, never the build seed) ### 📊 Changes **14 files changed** (+1328 additions, -35 deletions) <details> <summary>View changed files</summary> 📝 `docs/d3d12_vulkan.md` (+18 -0) 📝 `runtime/CMakeLists.txt` (+22 -0) 📝 `runtime/shims/d3d12_com.h` (+15 -0) 📝 `runtime/shims/d3d12_vulkan_device.cpp` (+279 -18) 📝 `runtime/src/pipeline_cache_file.h` (+21 -12) 📝 `runtime/src/pipeline_cache_snapshot.h` (+0 -0) ➕ `runtime/src/pipeline_cache_store.h` (+264 -0) 📝 `runtime/src/vulkan_backend.h` (+1 -1) ➕ `runtime/test/d3d12_pipeline_cache_persist_test.cpp` (+582 -0) 📝 `runtime/test/pipeline_cache_file_test.cpp` (+1 -1) 📝 `runtime/test/pipeline_cache_snapshot_test.cpp` (+1 -1) ➕ `runtime/test/pipeline_cache_store_test.cpp` (+120 -0) 📝 `runtime/test/vk_pipeline_check.cpp` (+2 -2) 📝 `runtime/test/vk_test_device.h` (+2 -0) </details> ### 📄 Description > Carried over from **old PR 9953** by `tedin7` in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch `old-pr/9953`, exactly that PR's last commit. All carried-over PRs are listed in #17. > Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it. > `tedin7`: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one. --- Original description (mentions and `#N` references are disabled; the numbers refer to the old repository): Rebased cleanly on current main; supersedes `#7396` closed during org migration. ## What The runtime's Vulkan pipeline cache now survives launches. Today main only reads a build-time `pipeline_cache.bin` seed, so every launch recompiles every PSO from scratch (the first-frame and PSO-creation stall). - The cache is saved at device teardown to a framed, checksummed file and the next session starts from it (`runtime/src/pipeline_cache_store.h`; `pipeline_cache_file.h` and `pipeline_cache_snapshot.h` move from test/ to src/). - It is saved only after a cache miss and while under 1 GiB; sessions merge into the same file, and the build seed is never overwritten. A corrupt, foreign-device or truncated file is ignored and the session starts empty. - `LEONIDA_PIPELINE_CACHE=off` turns it off (tests). `PipelineCacheStats` reports created / hits / time so a test can see the effect. ## Why PSO creation is the cold-boot cost before the first frame; the cache makes the second launch skip it. A checksum and size cap keep a damaged or huge file from breaking a launch. ## Tested On this base (current main, native g++): - `pipeline_cache_store_test` (new, framing, checksum, merge, size cap, rejection of damaged files): prints "pipeline cache store: ok", exit 0. - `pipeline_cache_file_test` and `pipeline_cache_snapshot_test` (moved to src/): exit 0 each. - Negative control: `pipeline_cache_store_test` does not build on origin/main (`src/pipeline_cache_store.h` does not exist there); the persistence behaviour is absent. NOT run on this base (be aware): `d3d12_pipeline_cache_persist_test` (GPU test, Windows exe under Wine) and the compile of `shims/d3d12_vulkan_device.cpp`. The GPU pods are off and this host has no unpacked Windows SDK; mingw headers cannot parse the Windows code. The earlier version of this PR (`#7396`, older base) measured 26x faster PSO creation on the second launch on an RTX 4090. The merge needed three keep-both conflict resolutions (`d3d12_com.h`, `d3d12_vulkan_device.cpp`, `vk_test_device.h`; the host-pointer fields and `create_buffer_at_host_address` from main sit next to the new cache fields and `pipeline_cache_stats`); that second-launch speedup has not been reproduced here. Please run `d3d12_pipeline_cache_persist` on CI/maintainer hardware before merging. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#270
No description provided.