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

Closed
Andretuta wants to merge 1 commit from upstream-pr/218 into main
Andretuta commented 2026-11-24 02:46:37 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Andretuta on 2026-11-24T02:46:37Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5465119382 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/218). Originally posted by [Andretuta](https://github.com/Andretuta) on 2026-11-24T02:46:37Z. --- > 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.
DadaCap commented 2026-11-28 10:34:13 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by DadaCap on 2026-11-28T10:34:13Z.


Thanks for the contribution! This PR was reviewed by the maintainers and is being closed as part of a large batch of closures.

Reason: superseded by main.

If this looks like a mistake, mention @DadaCap here at any time and it will be looked at again.

AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7237981813 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/218#issuecomment-7237981813). Originally posted by [DadaCap](https://github.com/DadaCap) on 2026-11-28T10:34:13Z. --- Thanks for the contribution! This PR was reviewed by the maintainers and is being closed as part of a large batch of closures. Reason: superseded by main. If this looks like a mistake, mention @DadaCap here at any time and it will be looked at again. AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
ProjectLeonida/mandy!218
No description provided.