d3d12: a pipeline cache for the offline cache's misses, written while the game runs (RT-HEAVY-PIPELINE-CACHE) #1914
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs rebase
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!1914
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1914"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@kawaii-shakal on GitHub · 2026-11-25 15:41 UTC · original
kawaii-shakal:heavy-pipeline-cache→main· +439 −5 · 9 files · 5 commits · merged 2026-11-26 14:41 UTCClaimed in the coordination issue as RT-HEAVY-PIPELINE-CACHE: #1608
Problem
The builds the offline
pipeline_cache.binmisses are compiled again on every boot. On an RTX 5070 Ti these are the pipeline library's compute programs, 3 to 7 s each and about 40 per boot before the world starts, and they are what keeps the render thread waiting at the title's hang watchdog.pipeline_cache.session.bincan't keep them for two reasons:LEONIDA_STARTUP_CACHE_CHECKPOINTShas the same problem.Change
VK_PIPELINE_CREATE_FAIL_ON_PIPELINE_COMPILE_REQUIRED_BIT(DeviceState::create_pipeline).pipeline_cache.heavy.bin, next topipeline_cache.bin. That cache holds only the corpus's misses, so it stays small.LEONIDA_HEAVY_PIPELINE_CACHE_MS(500 by default) marks the cache dirty. A thread of its own writes it 3 s after the newest slow build and no later than 20 s after the first unwritten one, through the existing staging file and rename (CacheStagingFile), so the file on disk is always complete. A crash loses at most the last 20 s of slow builds. At teardown the thread stops and writes what is left.LEONIDA_HEAVY_PIPELINE_CACHE_MS=0turns it off, and with itpipelineCreationCacheControlunlessLEONIDA_PIPELINE_COMPILE=cache-onlyasks for it. A cache-only create (cache-only) is left exactly as it was.runtime/src/heavy_pipeline_cache.h, withheavy_pipeline_cache_test.vk_test_device.htakes the heavy path whenLEONIDA_HEAVY_PIPELINE_CACHE_MSis set, andd3d12_mesh_heavy_cacheruns the mesh test's draws through it.docs/d3d12_vulkan.mddescribes it next to the session cache.Measured (Windows 11 Pro 26300, RTX 5070 Ti, NVIDIA 617.42, VS 2026 RelWithDebInfo)
vk_pipeline_checkand a local probe that adds the flag (not part of this PR), against an empty cache. Four library compute programs the corpus lacks returnVK_PIPELINE_COMPILE_REQUIREDin under 1 ms, so the heavy path is taken for them. The mesh test's small shaders come backVK_SUCCESSfrom a cache-only create even into an empty cache, because the driver's own shader cache already holds them. That is why the CTest case checks correctness, not the file.heavy_pipeline_cache,pipeline_cache_store,pipeline_cache_file,d3d12_msaa_draw,d3d12_meshandd3d12_mesh_heavy_cacheall pass, 6 of 6.Not done here
🤖 Generated with Claude Code
@Tyrannys on GitHub · 2026-11-25 19:11 UTC · original
Data point for this PR and for thegalaxydev's RT-PIPELINE-CACHE-GROWTH-STALL. With a complete offline cache, the session cache can't be saved at all under the current limit. Counts only.
mainfe1553456+ #1886 + #1950 (plus #674, #1662, #1851, #1849, #1905, #1957, #1894, which don't touch the cache).pipeline_cache.binfrom a fullmake_game.py --stages pipelinesrun, every module of the 26,503-shader set including the three ScreenProbes compute shaders (each built on its own, about 30-40 min apiece; three at once crashed the driver compiler with "NVVM compilation failed: 3"). About 9.6 GB on disk.LEONIDA_PIPELINE_CACHE_DIR. At exit the session save was refused: the driver's cache data was 9.72 GB, over the 4 GiB save limit. So nothing the boot compiled was kept, even though the run ended cleanly.The session snapshot is the whole driver cache, seed included, so once the seed alone is over the limit, every session save is refused. A separate cache for the builds the seed misses, as this PR does, avoids that. So does a limit that is measured against what the run added rather than against the total.
AI-assisted (Claude Code).
@lixonik on GitHub · 2026-11-25 19:27 UTC · original · reviewed
Independent CPU check at
e4c413a3a:heavy_pipeline_cache_testpasses. A failure-injection harness using the current writer and teardown methods exposed one remaining issue with saving during a run. No GPU or game files.AI-assisted.
@lixonik on GitHub · 2026-11-25 19:27 UTC · original
On
runtime/shims/d3d12_vulkan_device.cppline 2133 (outdated):[P2] Retry unsuccessful periodic saves while the device is live
The writer ignores the save result and marks the captured generation written. If staging or publication fails briefly and no further slow compile occurs, the writer goes idle with the cache still unsaved. With the exact methods at this head, a mocked first save failure followed by 30 s on the clock produced one attempt while live and a second only at normal teardown. A crash in that interval still loses the cache. Keep the generation dirty on a failed save and retry after a bounded delay so persistent failures do not spin.
@Snooozs on GitHub · 2026-11-25 20:01 UTC · original
One difference to the session saver, from the code at this head (
save_heavy_pipeline_cache): it acceptsVK_INCOMPLETE, andpublishthen replacespipeline_cache.heavy.bin; the session saver (save_session_pipeline_cache) wantsVK_SUCCESSand keeps the previous file. A compile that adds to the cache between the size query and the data query givesVK_INCOMPLETE, so the file can be the partial snapshot (valid as a seed, but without the entries that did not fit). Keeping the previous file and letting the next write do it costs nothing: the cache stays dirty.Also a measurement about size, RTX 5060 Ti 16 GB, NVIDIA 621.01: the file was 1.09 GB, and with about 640 more programs 1.60 GB. The writes are whole, so each of them was that size, one every 10 to 20 s while compiles ran (
wrote ... to pipeline_cache.heavy.bin in 0.4-0.7 s). With thegalaxydev's finding about large caches (#1608, 7171729435) several smaller caches, chosen by the module's hash, would keep each small and write only what changed. I have not built that.AI-assisted (Claude Code, Claude Opus 5.5).
@kawaii-shakal on GitHub · 2026-11-25 22:19 UTC · original
These changes were made by Claude Code (AI-assisted) in
aab76535, after the review:WriteSchedule::failed()keeps the cache dirty and retries 5 s later. The delay doubles with each failure in a rowand is capped at 2 min, so a save that keeps failing does not spin. Once a save succeeds, the backoff is cleared.
heavy_pipeline_cache_testhas a newtest_failed_writethat covers the backoff, the cap, a compile during thebackoff and the reset after a success.
save_heavy_pipeline_cachenow requiresVK_SUCCESSandwritten <= size, the same asthe session saver. A truncated snapshot never replaces the previous file. With the retry above, the next try
queries a fresh size.
this PR. The file holds only the offline cache's misses. If the size becomes a problem, I'd rather do that as a
follow-up.
Tested:
heavy_pipeline_cache_test, built with g++ 13 on Linux. The shim (d3d12_vulkan_device.cpp) is Windows-onlyand was not built here, so it still needs a Windows CI or local run.
Generated by Claude Code
@OreoFR on GitHub · 2026-11-25 23:52 UTC · original
Real boots with this PR (earlier head, before
aab76535) on an RTX 4070 Laptop 8 GB, NVIDIA 621.40, main + #2077 + the mesh-indirect branch:pipeline_cache.heavy.binloads at start (~100 MB) and is rewritten during the run in about 0.1 s each time (e.g. "3 slow builds and 364 other builds past the offline cache so far"). Across runs it does its job: the mesh pipeline builds that missed the offline cache went from 135 in the first run to 13 in the next ones. No crash or corrupt cache file in ~15 runs, including runs that ended in a device loss.@kawaii-shakal on GitHub · 2026-11-26 00:27 UTC · original
Merged main (
c50ed94b3) ina42bffdc3; the PR had a conflict with it.main now has its own crash-safe store for compute pipelines: the per-pipeline journal (
pipeline_cache.d/cs-<hash>.bin,src/pipeline_cache_journal.h), written right after each compile. So in the merge the compute build is main'sbuild_compute_pipelineunchanged, and the heavy cache keeps graphics pipelines only (create_pipelineis used by the graphics variant build). Two effects:The docs section and the
create_pipelinecomment say this now.Tested (Windows 11, MSVC RelWithDebInfo, RTX 5070 Ti, NVIDIA 617.42), including the
aab76535review fixes on Windows for the first time:xbox_presentandd3d12_set_descriptor_heaps, fail the same way on a clean build of mainc50ed94b3and withLEONIDA_HEAVY_PIPELINE_CACHE_MS=0, so they are not from this PR. Both tests were changed in main recently, by #671 and #2141.heavy_pipeline_cache,d3d12_mesh,d3d12_mesh_heavy_cache,pipeline_cache_journal,d3d12_compute_journaland the other cache, journal and mesh tests: 10 repeats, all pass.AI-assisted (Claude Code, Claude Opus 5.5).
@aslan2142 on GitHub · 2026-11-26 14:41 UTC · original
Thank you, @kawaii-shakal. This went into
mainthrough #2350 (RT-LINUX-AMD-WORLD), merged at your heada42bffdc3with your commits and authorship kept. The only conflict was the session-cache paragraph indocs/d3d12_vulkan.mdagainst #1886: main's cap and your heavy-cache text were both kept. GitHub shows this PR as merged for that reason, so nothing needs closing.AI-assisted (Claude Code, Claude Opus 5.5 and Claude Fable 5.2)