Repository navigation
Conversation
Device teardown now writes the device's VkPipelineCache to pipeline_cache_runtime_<vendor>_<device>.bin beside the executable (or in LEONIDA_PIPELINE_CACHE_DIR), and the next device's first PSO takes it in under the same header check as ItsNotRexed#367's seed, merged into the seed's cache with vkMergePipelineCaches. - The save goes through the pipeline checker's atomic writer (temporary file, then rename): a failed save leaves the previous file as it was. - Nothing is written when the cache did not grow since it was loaded, or holds only the header. - A truncated, foreign or junk file is logged and left out; the device starts without it and replaces it at teardown. - LEONIDA_PIPELINE_CACHE_PERSIST=0 neither reads nor writes the file. Tests: pipeline_cache_persist_test (header checks, teardown writes, no GPU) and d3d12_pipeline_cache_persist_test (round trip on a device). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Independent Windows + GPU test of Setup: Windows 11 x64, MSVC 19.44.35220 (
AI-assisted review/test. |
|
Independent native Windows check of 3223295 applied to main 1924c8f. Windows 11 Pro build 26300, MSVC 19.44.35223 x64 RelWithDebInfo, Vulkan Headers 1.4.363, glslang 16.6.0.
Both devices passed the unchanged-cache, malformed-cache replacement, failed-save and opt-out checks. This was a small synthetic cold/warm round trip, with no full-corpus seed or game files. AI-assisted (Codex). |
|
Code read of 3223295 (not run). On the size note in the description (the saved file contains the seed's entries, no cap): one way to avoid the duplicate without a cap is to create new pipelines against a second, empty VkPipelineCache, merge it into the seed's cache for lookups, and save only the second one at teardown, so the runtime file holds just what this machine compiled and a corpus seed is never rewritten. (Merging is one-way, so lookups would need care; a direction, not a drop-in.) Smaller: d3d12_vulkan_device.cpp now includes runtime/test/pipeline_cache_file.h and pipeline_cache_snapshot.h, so the runtime depends on files in the test folder; moving them to runtime/src would keep that direction clean. AI-assisted (Claude Code). |
|
Of the three PRs for D3D-704 (#7360, #7384, #7396), this one looks like the one to keep: it is claimed under the D3D-704 ID in #7231, it is mergeable, and it has been checked independently on native Windows + MSVC (RTX 3080, RTX 5070 Ti, AMD iGPU). Worth porting from #7396 before it lands: the framed/hashed session file, the save gated on creation feedback rather than cache size, and the merge with another session's save. One open point: the saved file includes the seed, so with the 3.8 GB corpus seed every session that adds a pipeline rewrites ~3.8 GB. @Envyre's suggestion above (a second, empty cache saved on its own) would fix that. |
|
Side-by-side check of #7396 ( Tests: #7396 Damaged file after a valid header (the case #7360 passes to the driver and #7396's Differences that matter more:
The last-but-one row in both is the open problem: because the cache is saved whole, the seed's entries go into every session file, so with a full-corpus seed one PR saves nothing and the other rewrites gigabytes. Keeping the session's own misses in a small cache of their own (and merging it with the seed at load) would give a file the size of what the session learned. AI-assisted. Synthetic shaders only, no game files. |
|
Independent Windows 11 / RTX 5070 Ti (621.24) observation on the retail boot stack: the debugger-bounded loading runs can end before device teardown. A local checkpoint of the real runtime cache (not this PR’s teardown code) grew from the 399,382,983-byte build seed to 698,588,474 bytes, with the same Vulkan header identity. A fresh |
…(D3D-704) A run that never reaches device teardown (killed by a debugger, crashed, timed out) kept nothing with a teardown-only save. Each device now has one checkpoint worker thread that saves the cache through the same atomic temporary-file-and-rename path while the device lives. - A checkpoint runs only when pipelines were created since the last one (a counter over every compute and graphics pipeline created with the cache, draw-time graphics variants included), and at most once per LEONIDA_PIPELINE_CACHE_CHECKPOINT_S seconds (default 60; 0 turns checkpoints off, and teardown still saves). - Counting a creation is a short lock that wakes the worker; creation never waits for a write. Only the worker writes; teardown stops it, waiting for a write in progress, before its own final save. - vkGetPipelineCacheData runs on the worker with no lock: its pipelineCache is not externally synchronized, and vkCreate*Pipelines' is only with VK_PIPELINE_CACHE_CREATE_EXTERNALLY_SYNCHRONIZED_BIT, which this cache does not use. - A checkpoint over a cache that did not grow writes nothing; a failed one is tried again an interval later. The first checkpoint is logged, then at most one line per 5 minutes. - LEONIDA_PIPELINE_CACHE_PERSIST=0 turns all of it off. Tests: pipeline_cache_persist_test (interval parsing, rate limit and counter on an injected clock, log limiter, the worker on short intervals) and d3d12_pipeline_cache_persist_test (a checkpoint written and taken by Vulkan before teardown and loaded by the next device; no write when nothing new; no checkpoint with 0 or with PERSIST=0). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks @Yoshi-OOF. Runs that end before device teardown are a gap a teardown-only save can't cover, and your 399 MB → 699 MB checkpoint shows how much those runs lose. Commit c31c8ca adds checkpoints while the device lives:
Tests (RADV gfx1036 under Wine 11.22, cross-built with clang for mingw, plus Linux native):
Not measured: how long a checkpoint of a several-hundred-MB cache takes on the worker. A run on your setup with the default 60 s would show that. AI-assisted (Claude Code, Claude Opus 5.5). |
|
Tested c31c8ca on RTX 4070 SUPER, NVIDIA 621.01, Windows 11 Pro: pass
|
Claimed in the coordination issue as D3D-704: #7231 (comment).
What and why
VkPipelineCachewas destroyed at teardown without being saved. A PSO compiled in one session was compiled again in the next.cherryinbubbles-opsreported this in Coordinating who works on what (41) (moved to #7231) #7049 (comment). On an RTX 5050 Laptop, 64 synthetic compute PSOs took 16.67 ms to create with an empty application cache and 1.37 ms with a saved one.pipeline_cache.bin) and does not replace it.Design
pipeline_cache_runtime_<vendor>_<device>.bin(hex IDs, e.g.pipeline_cache_runtime_1002_164e.bin).LEONIDA_PIPELINE_CACHE_DIRputs it somewhere else, and a missing folder is created.VkPipelineCacheHeaderVersionOnematches this device:headerSize,headerVersion,vendorID,deviceIDandpipelineCacheUUID.vkMergePipelineCaches.~Device, aftervkDeviceWaitIdleand beforevkDestroyPipelineCache):vkGetPipelineCacheDatasize is the same as at the last save, or right after loading. An in-memory cache only grows, so the same size means nothing was added.pipeline_cache_snapshot(which handlesVK_INCOMPLETE) and written with the existingwrite_pipeline_cache_file. That writes a temporary file in the same folder and then renames it over the old one.LEONIDA_PIPELINE_CACHE_CHECKPOINT_Sseconds (default 60).0turns checkpoints off; teardown still saves.vkGetPipelineCacheDataruns with no lock while other threads create pipelines. ItspipelineCacheis not externally synchronized (spec, "Threading Behavior"; noexternsyncinvk.xml).vkCreate*Pipelines'pipelineCacheis externally synchronized only withVK_PIPELINE_CACHE_CREATE_EXTERNALLY_SYNCHRONIZED_BIT, which this cache does not use.LEONIDA_PIPELINE_CACHE_PERSIST=0neither reads nor writes the file, checkpoints included. The seed is still used.runtime/src/pipeline_cache_persist.h, so it can be tested without a GPU or Windows.runtime/test/. I did not move them, because open PRs (runtime(pipeline_cache_snapshot): guard headroom capacity addition against size_t overflow #6238, vk_pipeline_check: a progress line with a rough ETA every 5 minutes, and the cache save time #5028) edit them.rt::d3d12::pipeline_cache_sources()reports what the cache loaded and how many checkpoints ran, for tests.vkGetPipelineCacheDataandvkMergePipelineCacheswere added to the device function table.Tests
pipeline_cache_persist_testneeds no GPU and runs on every OS.headerSizeorheaderVersion; junk.vkGetPipelineCacheDatafailing; the snapshot throwing.FILE_SHARE_DELETE.LEONIDA_PIPELINE_CACHE_CHECKPOINT_Sparsing: whole seconds and0; empty, signed, fractional, non-numeric and over-long values fall back to 60.0.stop()waits for a save in progress and none starts after it;d3d12_pipeline_cache_persist_testruns on a device, through the Xbox proxy, withcs_user_data.comp. Each session creates a layer device and a compute PSO, then releases them.saved_bytesequals the file size). The same PSO adds nothing, so the file is not rewritten (same bytes and modification time).LEONIDA_PIPELINE_CACHE_PERSIST=0, the file is neither read nor written, also with 1 s checkpoints and the device kept alive for 2.5 s.LEONIDA_PIPELINE_CACHE_CHECKPOINT_S=1, a checkpoint writes the file while the device lives. Its header matches,vkCreatePipelineCachetakes it on the test's device, and teardown leaves it alone.LEONIDA_PIPELINE_CACHE_CHECKPOINT_S=0, nothing is written during 2.5 s with the device alive, and teardown still saves.SKIPand returns 77.pipeline_cache.bin. Both loaded (seed 1552 saved 1552), the merge succeeded and the PSO was created. That variant is not committed, because the seed path is fixed beside the executable.main: the header andpipeline_cache_sourcesdon't exist there, andmainwrites no file.GPU and driver
1002:164e), Mesa 26.3.1, under Wine 11.22. The tests were cross-built with mingw-w64 and selected withMESA_VK_DEVICE_SELECT=1002:164e MESA_VK_DEVICE_SELECT_FORCE_DEFAULT_DEVICE=1.d3d12_pipeline_cache_persist_test: passed (1552-byte cache saved, loaded and left unchanged).d3d12_compute_test: passed.MESA_VK_DEVICE_SELECT=1002:164e!:d3d12_pipeline_cache_persist_test: sessions 1 to 5 passed before the checkpoint commit; all 8 sessions pass after it. The checkpoint wrote 1552 bytes before teardown.pipeline_cache_persist_test: passed before and after.VUID-vkCreateDevice-ppEnabledExtensionNames-01387. No windows were opened.d3d12_pipeline_cache_persist_test: SKIP, because llvmpipe stores nothing.d3d12_compute_test: passed.VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validationon the host, because the layer is not visible to Wine otherwise.VUID-vkCreateDevice-ppEnabledExtensionNames-01387, which every run under Wine shows.pipeline_cache_persist,pipeline_cache_fileandpipeline_cache_snapshotpass inctest.ctest.pipeline_cache_persist_testis also clean under ThreadSanitizer (clang) and passed 8 repeated runs.test_docs_env_vars,test_docs_repeated_lines,test_docs_table_idsandtest_build_runtime_cmakepass.test_text_write_line_endingsfails ontools/leonida_tui.pyandtools/wave_diff.py. This PR doesn't touch them.Not tested
/W4 /permissive-); CI will show it.Relation to other work
VkPipelineCacheis not written to disk" as still open. Its section (d) expects 0 cache hits on the first creation. With this PR, a cache file saved beside the test executable by an earlier run would answer that creation. That test should setLEONIDA_PIPELINE_CACHE_PERSIST=0or a scratchLEONIDA_PIPELINE_CACHE_DIR.pipeline_cache_runtime_*.binin the build folder when the driver stores cache data. Parallelctestruns are safe, because each write uses a uniquely named temporary file followed by a rename.docs/d3d12_vulkan.md: the pipeline cache paragraph now describes the saved file and the checkpoints. I left the README sentence about the seed alone; README: the runtime loads the pipelines stage's pipeline_cache.bin #4679 and README: the runtime seeds its VkPipelineCache from pipeline_cache.bin #5720 edit it.Checklist
cs_user_data.compand hand-built FSSM marker words.pipeline_cache_persist,d3d12_pipeline_cache_persist).docs/d3d12_vulkan.md).AI-assisted (Claude Code, Claude Opus 5.5).