d3d12: persist the runtime Vulkan pipeline cache across launches #218

Open
github-bot wants to merge 1 commit from github-bot/gh-218 into main AGit
Owner

@⁠Andretuta on GitHub · 2026-11-24 02:46 UTC · original
ubiquitarianism:old-pr/9953 → main · +1328 −35 · 14 files · 1 commits · draft

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.

**@⁠Andretuta** on GitHub · 2026-11-24 02:46 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/218) `ubiquitarianism:old-pr/9953` → `main` · +1328 −35 · 14 files · 1 commits · draft > 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 08:49:10 +00:00
This pull request has changes conflicting with the target branch.
  • runtime/shims/d3d12_com.h
  • runtime/shims/d3d12_vulkan_device.cpp
  • runtime/src/pipeline_cache_store.h
  • runtime/src/vulkan_backend.h
  • runtime/test/pipeline_cache_store_test.cpp
  • runtime/test/vk_pipeline_check.cpp
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

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