Repository navigation
d3d12: persist the pipeline cache across launches (D3D-704) - #7384
ddaikodaiko wants to merge 1 commit into
Conversation
PSOs a session built were compiled again by the next one. The layer already read the `pipelines` stage's pipeline_cache.bin beside gta6rt.exe (ItsNotRexed#367), but never wrote anything back. Now the runtime keeps its own cache in pipeline_cache.session.bin beside it: vkGetPipelineCacheData on device teardown, then vkMergePipelineCaches into the cache at the next launch. Vulkan takes one blob per create, so the offline seed and the session file are two caches merged together rather than one file. They are deliberately separate files, so a run can never replace the multi-GB corpus cache with the handful of pipelines it compiled. The write is capped at 256 MiB (LEONIDA_PIPELINE_CACHE_BYTES=<bytes>, 0 turns it off): a cache seeded from the corpus comes back as the whole union, which is not worth rewriting at every exit; past the cap the previous session file is left alone. A foreign or truncated session file is ignored with one line, and so is a failed write (a read-only install directory). The header check moves to runtime/src/pipeline_cache_store.h, shared with the offline seed and tested without Vulkan (runtime/test/pipeline_cache_store_test.cpp: the limit parser and the 32-byte VkPipelineCacheHeaderVersionOne comparison). write_pipeline_cache_file moves from runtime/test to runtime/src so the runtime and vk_pipeline_check use the same staged write. Not run: this machine has neither MSVC nor the Windows SDK, so the shim itself is compiled by the Windows job. The portable test passes here (23/23 ctest on Linux). The end-to-end check needs a Vulkan GPU: run d3d12_vulkan_device_test twice and look for "wrote N bytes to pipeline_cache.session.bin", then "merged N bytes" on the second run.
|
I checked this PR at
The Windows helper test holds the destination open without delete sharing, forces replacement to fail, then checks that the previous bytes survive. Overlapping successful writers are a separate case. If A and B load the same session before either saves, this PR merges the file only at first use. B can therefore publish a valid cache that drops entries A saved in the meantime. Held-file test and assertions · First-use merge For comparison, #7396 checks for an intervening save at teardown. Its two-session test explicitly releases A before B, so the assertion covers B seeing A's completed save. I verified these behaviors against the source and committed assertions. Runtime cap enforcement and simultaneous saves were outside this review. #7396 teardown check · Order in the two-session test |
|
Tested AI-assisted (Claude Code), no game files. |
|
Tested
AI-assisted (Claude Code). |
|
Coordinator note: D3D-704 already has an open PR, #7360 by @aslan2142 (opened 16:37 UTC), so this looks like a duplicate. Please compare the two and either close this one or say here what it adds. The maintainer decides which one is merged. |
|
Tested
On main alone, on this GPU, the full ctest fails these: Ran the full |
|
Compared the three D3D-704 PRs as asked (#7360, #7396, this one) on What the three share: none of them writes the What #7396 already has that this PR was written for:
#7360 is the one with independent Windows + MSVC runs (RTX 3080, RTX 5070 Ti, an AMD iGPU) and, per @skorex and The branch stays at |
Claimed in #7231 (comment).
What
PSOs a session compiled were compiled again by the next one. The layer already read the
pipelinesbuild stage'spipeline_cache.binbesidegta6rt.exe(#367), but never wrote anything back.D3D-704 closes that: the runtime keeps its own cache in
pipeline_cache.session.binbeside the executable.vkDeviceWaitIdleand the resource drain,vkGetPipelineCacheDatafills a buffer andwrite_pipeline_cache_filepublishes it through a staged file + rename (the helpervk_pipeline_checkalreadyused, moved from
runtime/testtoruntime/src).VkPipelineCacheCreateInfo(Vulkan reads one blob), so the cache is created from the seed as before, the session file becomes a second cache
and
vkMergePipelineCachesfolds it in.The two files are deliberately separate, so a run can never replace the multi-GB corpus cache with the handful of
pipelines it happened to compile.
Limits, deliberately
LEONIDA_PIPELINE_CACHE_BYTES=<bytes>(0turns the session file off). A cacheseeded from the corpus file comes back as the whole union (3.8 GB on the measured corpus), and rewriting that at
every exit costs more than it saves. Past the cap the previous session file is left alone rather than replaced
with one the next launch would also refuse to write.
VkPipelineCacheHeaderVersionOnenames another vendor, device orpipelineCacheUUIDisignored with one line, as the seed already did. A truncated file (< 32 bytes) is "no cache".
bad_allocon the teardown buffer is logged, not thrown out of a destructor.vkGetPipelineCacheData/vkMergePipelineCaches(not expected: both are Vulkan 1.0 core), no session file.Tests
New portable test, no Vulkan and no GPU:
runtime/test/pipeline_cache_store_test.cppcovers the limit parser(absent, empty,
0, leading zeros,SIZE_MAX,-1,"1 ",0x10, overflow) and the 32-byte header comparison(match, extra payload, short, null, each of headerSize/headerVersion/vendor/device/UUID changed). Both it and the
existing
pipeline_cache_filetest pass here:23/23 cteston Linux (portable subset).The shim itself has not been compiled here — this machine has no MSVC, no Windows SDK and no Vulkan GPU. The
Windows job of
runtime.ymlis the compile check, and the end-to-end check is: rund3d12_vulkan_device_testtwice on a Vulkan GPU; the first says
wrote N bytes to pipeline_cache.session.bin, the secondmerged N bytes from pipeline_cache.session.bin.Checklist
docs/d3d12_vulkan.md(§4.5, "Pipeline caches") describes the two files, the merge, the cap and theenvironment variable.
AI-assisted (Claude), and the run planned on Windows 11 + MSVC + a Vulkan GPU (RADV/AMD on Linux is available for
the portable tests, not for the layer).