d3d12: say when the driver's pipeline cache stops keeping new pipelines (RT-PIPELINE-CACHE-GROWTH-STALL) #2062

Merged
thegalaxydev merged 2 commits from upstream-pr/2062 into main 2026-11-30 17:38:27 +00:00
thegalaxydev commented 2026-11-25 19:15:11 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by thegalaxydev on 2026-11-25T19:15:11Z.


RT-PIPELINE-CACHE-GROWTH-STALL, claimed in #1608 after the finding just above it.

What

The runtime says once, in the log, when the title's pipeline builds keep compiling but the driver's VkPipelineCache has stopped growing (the numbers below show the format, not a run):

[rt] d3d12: the Vulkan pipeline cache grew 0 bytes (to 1346482377) over 23 pipeline builds that compiled: the driver no longer keeps new pipelines, so the next run compiles them again. A large pipeline_cache.bin or pipeline_cache.session.bin can cause it (docs/d3d12_vulkan.md, pipeline caches)
  • pipeline_profile::DriverCall (it already wraps both title vkCreate*Pipelines calls) always times the call and counts successful builds of at least 200 ms in compiled_builds(). A cache hit takes a few milliseconds, also while the title loads every core. Printing still needs LEONIDA_PSO_PROFILE=1.
  • pipeline_cache_store::GrowthWatch (pure, no Vulkan) compares two cache sizes with the builds that compiled between them: 16 or more compiled and less than 64 KiB of growth reports once.
  • The device takes the size when it creates the cache (after the seed and the session are loaded) and at every session save, checkpoint or teardown, including a save skipped for being over LEONIDA_PIPELINE_CACHE_BYTES. The size query is the one the save already makes.
  • docs/d3d12_vulkan.md records the measurements under "Pipeline caches".

Why

A driver can stop adding to a large cache without an error, and then a session file stops helping without anything saying so. Measured on an RTX 5060 Ti, NVIDIA 610.88, Windows 11 23H2:

cache before one ~2 s compute compile (vk_pipeline_check named gta6rt.exe) file afterwards next process
empty +~210 KiB 0.01 s from the file, also with __GL_SHADER_DISK_CACHE=0
1.23 GB (library and main-set compute) same size to the byte hit only through the driver's own disk cache
1.35 GB (the above plus what the game added) same size to the byte compiled again

In the game (main fe1553456 + #1886): seeded with the 1.23 GB file, 68 of the ~110 builds over 200 ms in one run were over 200 ms again in the next; started with no seed, 5 of 164 were. An older cache of mostly main-set graphics pipelines stopped growing at 4.9 GB, so there is no fixed size to test against, hence a growth check instead of a size limit. #1886 measured a 1,285 MB session on an RTX 5080, still growing.

Tested

  • RTX 5060 Ti 16 GB, NVIDIA 610.88, Windows 11 23H2, MSVC via scripts/build_runtime.ps1.
  • pipeline_cache_store_test gains test_growth (no Vulkan, no GPU): no reference at creation, a growing cache at any size, too few builds, report once, counting from the previous save, a count that went backwards.
  • ctest -R "pipeline_cache|compile_teardown|pipeline_workers|pso_profile|d3d12_pipeline": 10/10 pass.
  • Full ctest -j 8: everything passes except root_sig, d3d12_state_sweep and d3d12_pso_validation, which fail the same way on main fe1553456 without this change on this machine.
  • scripts/check_no_game_data.py on the changed files: clean.

Related: #1886 (raises the save limit, so sessions reach this size), #1756 (checkpoint scheduling; both touch save_session_pipeline_cache, the overlap is one added line).

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5497576964 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2062). Originally posted by [thegalaxydev](https://github.com/thegalaxydev) on 2026-11-25T19:15:11Z. --- RT-PIPELINE-CACHE-GROWTH-STALL, claimed in [#1608](https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7171729880) after the finding [just above it](https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7171729435). ## What The runtime says once, in the log, when the title's pipeline builds keep compiling but the driver's `VkPipelineCache` has stopped growing (the numbers below show the format, not a run): ``` [rt] d3d12: the Vulkan pipeline cache grew 0 bytes (to 1346482377) over 23 pipeline builds that compiled: the driver no longer keeps new pipelines, so the next run compiles them again. A large pipeline_cache.bin or pipeline_cache.session.bin can cause it (docs/d3d12_vulkan.md, pipeline caches) ``` - `pipeline_profile::DriverCall` (it already wraps both title `vkCreate*Pipelines` calls) always times the call and counts successful builds of at least 200 ms in `compiled_builds()`. A cache hit takes a few milliseconds, also while the title loads every core. Printing still needs `LEONIDA_PSO_PROFILE=1`. - `pipeline_cache_store::GrowthWatch` (pure, no Vulkan) compares two cache sizes with the builds that compiled between them: 16 or more compiled and less than 64 KiB of growth reports once. - The device takes the size when it creates the cache (after the seed and the session are loaded) and at every session save, checkpoint or teardown, including a save skipped for being over `LEONIDA_PIPELINE_CACHE_BYTES`. The size query is the one the save already makes. - `docs/d3d12_vulkan.md` records the measurements under "Pipeline caches". ## Why A driver can stop adding to a large cache without an error, and then a session file stops helping without anything saying so. Measured on an RTX 5060 Ti, NVIDIA 610.88, Windows 11 23H2: | cache before one ~2 s compute compile (`vk_pipeline_check` named `gta6rt.exe`) | file afterwards | next process | |---|---|---| | empty | +~210 KiB | 0.01 s from the file, also with `__GL_SHADER_DISK_CACHE=0` | | 1.23 GB (library and main-set compute) | same size to the byte | hit only through the driver's own disk cache | | 1.35 GB (the above plus what the game added) | same size to the byte | compiled again | In the game (main fe1553456 + #1886): seeded with the 1.23 GB file, 68 of the ~110 builds over 200 ms in one run were over 200 ms again in the next; started with no seed, 5 of 164 were. An older cache of mostly main-set graphics pipelines stopped growing at 4.9 GB, so there is no fixed size to test against, hence a growth check instead of a size limit. #1886 measured a 1,285 MB session on an RTX 5080, still growing. ## Tested - RTX 5060 Ti 16 GB, NVIDIA 610.88, Windows 11 23H2, MSVC via `scripts/build_runtime.ps1`. - `pipeline_cache_store_test` gains `test_growth` (no Vulkan, no GPU): no reference at creation, a growing cache at any size, too few builds, report once, counting from the previous save, a count that went backwards. - `ctest -R "pipeline_cache|compile_teardown|pipeline_workers|pso_profile|d3d12_pipeline"`: 10/10 pass. - Full `ctest -j 8`: everything passes except `root_sig`, `d3d12_state_sweep` and `d3d12_pso_validation`, which fail the same way on main fe1553456 without this change on this machine. - `scripts/check_no_game_data.py` on the changed files: clean. Related: #1886 (raises the save limit, so sessions reach this size), #1756 (checkpoint scheduling; both touch `save_session_pipeline_cache`, the overlap is one added line).
MSedgeMC commented 2026-11-25 19:53:20 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MSedgeMC on 2026-11-25T19:53:20Z.

Review: APPROVED


Verified on the PR branch: python3 -m unittest discover -s tests -p 'test_docs_*.py' -> 47 tests OK; the new GrowthWatch logic is backed by runtime/src/pipeline_cache_store.h:78 and runtime/src/pipeline_profile.h:46, and the standalone C++ unit test compiles and passes (g++ -std=c++20 runtime/test/pipeline_cache_store_test.cpp -> exit 0). The new docs describe the watch condition and remedy consistently with the source. Caveat: the NVIDIA 610.88 growth-stall measurements in the docs are GPU-specific observations I cannot reproduce on this host; I verified their consistency with the code, not the numbers. Advisory: branch carries 7 older commits not on main.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6064041156 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2062#pullrequestreview-6064041156). Originally posted by [MSedgeMC](https://github.com/MSedgeMC) on 2026-11-25T19:53:20Z. **Review:** APPROVED --- Verified on the PR branch: python3 -m unittest discover -s tests -p 'test_docs_*.py' -> 47 tests OK; the new GrowthWatch logic is backed by runtime/src/pipeline_cache_store.h:78 and runtime/src/pipeline_profile.h:46, and the standalone C++ unit test compiles and passes (g++ -std=c++20 runtime/test/pipeline_cache_store_test.cpp -> exit 0). The new docs describe the watch condition and remedy consistently with the source. Caveat: the NVIDIA 610.88 growth-stall measurements in the docs are GPU-specific observations I cannot reproduce on this host; I verified their consistency with the code, not the numbers. Advisory: branch carries 7 older commits not on main.
qhukz13 commented 2026-11-25 23:15:58 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by qhukz13 on 2026-11-25T23:15:58Z.


Review at 869319b55 (code reading plus a native run on a GTX 1050 Ti, see the end). The check itself reads right: GrowthWatch reports once, re-bases at every observation, and treats a count that went backwards as "no stall". One thing about scope, and one data point.

  • The watch and the build count are process-wide, the cache is per device. pipeline_cache_handle is a DeviceState member created in its own call_once, so two D3D12 devices have two VkPipelineCaches (the tests make two, e.g. d3d12_rebound_second_device; a title can too). pipeline_cache_growth() and pipeline_profile::compiled_builds() are single statics. With two live devices, device A's creation observe()s A's size, then device B's save compares B's size against it and against builds that both devices compiled, which can report a stall that is not one (B's cache is smaller than A's) or hide one. Keeping a GrowthWatch (and the compiled count at the last observation) per DeviceState, or keyed by the VkPipelineCache handle, would make it per cache. With one device, which is the retail case so far, it is fine as is.
  • The 200 ms line on a slower CPU. With LEONIDA_PSO_PROFILE=1 on a Xeon E5-2670 v3 (2.3 GHz) + GTX 1050 Ti, the pipeline tests below made 1,447 title builds: 1,443 succeeded with median 0.7 ms, p90 2.3 ms, p99 15.6 ms; 5 took 201-206 ms (all result=0), the rest under 16 ms. So cache-hit-sized builds stay far below 200 ms here too, while a real compile of a small test shader sits right at the line on this CPU (on a faster one it would fall under it and not count). That direction only makes the watch report less, so it is safe; it may be worth saying in the comment that compiled_builds() undercounts on fast CPUs rather than counting every compile.

Run: this head merged onto main 8564bb48b (clean), GTX 1050 Ti, Windows 10 Pro 19045, NVIDIA 582.66, MSVC RelWithDebInfo. pipeline_cache_store (with test_growth), pipeline_cache_file, pipeline_cache_seed, pipeline_cache_snapshot, pipeline_workers, d3d12_pipeline_library, d3d12_pipeline_library_host, d3d12_pipeline_workers, d3d12_pipeline_workers_eager, d3d12_compile_teardown, d3d12_rebound_second_device: 11/11, 3 runs each, plain and with LEONIDA_VK_VALIDATION=1, and again with LEONIDA_PSO_PROFILE=1. No validation messages, and no growth-stall line in any of them (none reaches 16 compiled builds).

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7177333780 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2062#issuecomment-7177333780). Originally posted by [qhukz13](https://github.com/qhukz13) on 2026-11-25T23:15:58Z. --- Review at `869319b55` (code reading plus a native run on a GTX 1050 Ti, see the end). The check itself reads right: `GrowthWatch` reports once, re-bases at every observation, and treats a count that went backwards as "no stall". One thing about scope, and one data point. - **The watch and the build count are process-wide, the cache is per device.** `pipeline_cache_handle` is a `DeviceState` member created in its own `call_once`, so two D3D12 devices have two `VkPipelineCache`s (the tests make two, e.g. `d3d12_rebound_second_device`; a title can too). `pipeline_cache_growth()` and `pipeline_profile::compiled_builds()` are single statics. With two live devices, device A's creation `observe()`s A's size, then device B's save compares B's size against it and against builds that both devices compiled, which can report a stall that is not one (B's cache is smaller than A's) or hide one. Keeping a `GrowthWatch` (and the compiled count at the last observation) per `DeviceState`, or keyed by the `VkPipelineCache` handle, would make it per cache. With one device, which is the retail case so far, it is fine as is. - **The 200 ms line on a slower CPU.** With `LEONIDA_PSO_PROFILE=1` on a Xeon E5-2670 v3 (2.3 GHz) + GTX 1050 Ti, the pipeline tests below made 1,447 title builds: 1,443 succeeded with median 0.7 ms, p90 2.3 ms, p99 15.6 ms; 5 took 201-206 ms (all `result=0`), the rest under 16 ms. So cache-hit-sized builds stay far below 200 ms here too, while a real compile of a small test shader sits right at the line on this CPU (on a faster one it would fall under it and not count). That direction only makes the watch report less, so it is safe; it may be worth saying in the comment that `compiled_builds()` undercounts on fast CPUs rather than counting every compile. Run: this head merged onto main `8564bb48b` (clean), GTX 1050 Ti, Windows 10 Pro 19045, NVIDIA 582.66, MSVC RelWithDebInfo. `pipeline_cache_store` (with `test_growth`), `pipeline_cache_file`, `pipeline_cache_seed`, `pipeline_cache_snapshot`, `pipeline_workers`, `d3d12_pipeline_library`, `d3d12_pipeline_library_host`, `d3d12_pipeline_workers`, `d3d12_pipeline_workers_eager`, `d3d12_compile_teardown`, `d3d12_rebound_second_device`: 11/11, 3 runs each, plain and with `LEONIDA_VK_VALIDATION=1`, and again with `LEONIDA_PSO_PROFILE=1`. No validation messages, and no growth-stall line in any of them (none reaches 16 compiled builds). AI-assisted (Claude Code).
MoonEyes commented 2026-11-28 17:57:15 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T17:57:15Z.


Hi @thegalaxydev, thanks for this pull request. It currently conflicts with main (conflicting file(s): docs/d3d12_vulkan.md, runtime/shims/d3d12_vulkan_device.cpp), so it carries the needs rebase label. CONTRIBUTING.md asks authors to rebase their branch on main; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here.

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7243415354 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2062#issuecomment-7243415354). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T17:57:15Z. --- Hi @thegalaxydev, thanks for this pull request. It currently conflicts with `main` (conflicting file(s): `docs/d3d12_vulkan.md`, `runtime/shims/d3d12_vulkan_device.cpp`), so it carries the `needs rebase` label. CONTRIBUTING.md asks authors to rebase their branch on `main`; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here. AI-assisted (Claude Code, Claude Opus 5.5).
OreoFR commented 2026-11-30 13:40:35 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-30T13:40:35Z.


Carried as #2737 because of the conflict with main after #2566; @thegalaxydev, if you come back, say so and the carry is dropped.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7280191601 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2062#issuecomment-7280191601). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-30T13:40:35Z. --- Carried as #2737 because of the conflict with main after #2566; @thegalaxydev, if you come back, say so and the carry is dropped.
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!2062
No description provided.