d3d12: the session pipeline cache is saved up to 4 GiB, checkpoints included (RT-SESSION-CACHE-LIMIT) #1886

Manually merged
github merged 3 commits from github-bot/gh-1886 into main 2026-11-26 12:52:34 +00:00 AGit
Owner

@⁠DadaCap on GitHub · 2026-11-25 14:27 UTC · original
DadaCap:session-cache-limit → main · +38 −15 · 4 files · 3 commits · merged 2026-11-26 12:52 UTC

RT-SESSION-CACHE-LIMIT, claimed and found in #1608.

What

The session pipeline cache's default save limit (LEONIDA_PIPELINE_CACHE_BYTES) goes from 256 MiB to 4 GiB, and a checkpoint uses the same limit instead of its own 512 MiB.

Why

Past the limit nothing is written, so every later build is lost and the next run repeats it. The world phase exceeds it on NVIDIA:

RTX 5080, NVIDIA 621.24, main + #1756 + #1849 + #1827, LEONIDA_DEVICE_TYPE=6, the two later runs with LEONIDA_SERIAL_BIG_COMPILES=0 session file
four runs with the default stuck at 267.7 MB; log pipeline cache is 350948938 bytes, over the 268435456-byte write limit
next run, limit and checkpoint cap raised (30 min) 867 MB
the run after (25 min) 1,285 MB

The effect on the next run: 353 of 362 builds that were slow (2 s or more) in one run came from the cache in the following one (5 rebuilt, probably in flight when the run was stopped; 4 not reached when I counted). The later run passed in about 80 s what had taken the earlier one its whole 30 minutes. Those two runs got to the fifth world frame, a point my runs never reached before.

Cost, measured on the same machine: loading 867 MB takes 0.35 s (driver_us), a checkpoint 0.35 s at 681 MB and 0.50 s at 1,102 MB, on the compile worker. Whether that disturbs a frame is not measured yet.

What the limit is for: the comment says it keeps a cache seeded from a multi-GB offline corpus from being rewritten at every exit. With 4 GiB a corpus file below that is rewritten, at teardown and with LEONIDA_STARTUP_CACHE_CHECKPOINTS=1 at each checkpoint. If that is a concern, a lower default (above about 1.5 GB) plus an exemption for a seeded cache would be an alternative; tell me and I'll change it.

Tests

pipeline_cache_store, d3d12_compile_teardown, d3d12_pipeline_workers and its eager variant pass on main 98c2f7777, RTX 5080, Windows 11, VS 18 RelWithDebInfo. No new test: the parsing is covered by pipeline_cache_store_test, and this changes a constant and removes a second cap. Textual overlap with #1756 in save_session_pipeline_cache (both touch the same function); I'll merge main when that lands. Not run: the whole ctest set, other GPUs.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

**@⁠DadaCap** on GitHub · 2026-11-25 14:27 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1886) `DadaCap:session-cache-limit` → `main` · +38 −15 · 4 files · 3 commits · merged 2026-11-26 12:52 UTC RT-SESSION-CACHE-LIMIT, claimed and found in [#1608](https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608). ## What The session pipeline cache's default save limit (`LEONIDA_PIPELINE_CACHE_BYTES`) goes from 256 MiB to 4 GiB, and a checkpoint uses the same limit instead of its own 512 MiB. ## Why Past the limit nothing is written, so every later build is lost and the next run repeats it. The world phase exceeds it on NVIDIA: | RTX 5080, NVIDIA 621.24, `main` + #1756 + #1849 + #1827, `LEONIDA_DEVICE_TYPE=6`, the two later runs with `LEONIDA_SERIAL_BIG_COMPILES=0` | session file | |---|---| | four runs with the default | stuck at 267.7 MB; log `pipeline cache is 350948938 bytes, over the 268435456-byte write limit` | | next run, limit and checkpoint cap raised (30 min) | 867 MB | | the run after (25 min) | 1,285 MB | The effect on the next run: 353 of 362 builds that were slow (2 s or more) in one run came from the cache in the following one (5 rebuilt, probably in flight when the run was stopped; 4 not reached when I counted). The later run passed in about 80 s what had taken the earlier one its whole 30 minutes. Those two runs got to the fifth world frame, a point my runs never reached before. **Cost, measured on the same machine:** loading 867 MB takes 0.35 s (`driver_us`), a checkpoint 0.35 s at 681 MB and 0.50 s at 1,102 MB, on the compile worker. Whether that disturbs a frame is not measured yet. **What the limit is for:** the comment says it keeps a cache seeded from a multi-GB offline corpus from being rewritten at every exit. With 4 GiB a corpus file below that is rewritten, at teardown and with `LEONIDA_STARTUP_CACHE_CHECKPOINTS=1` at each checkpoint. If that is a concern, a lower default (above about 1.5 GB) plus an exemption for a seeded cache would be an alternative; tell me and I'll change it. ## Tests `pipeline_cache_store`, `d3d12_compile_teardown`, `d3d12_pipeline_workers` and its eager variant pass on `main` 98c2f7777, RTX 5080, Windows 11, VS 18 RelWithDebInfo. No new test: the parsing is covered by `pipeline_cache_store_test`, and this changes a constant and removes a second cap. Textual overlap with #1756 in `save_session_pipeline_cache` (both touch the same function); I'll merge `main` when that lands. Not run: the whole `ctest` set, other GPUs. AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review of #1886: the seed the driver hands back with the session's builds no longer counts against
LEONIDA_PIPELINE_CACHE_BYTES (pipeline_cache_store::over_save_limit, with a unit test), the stale 512 MiB
checkpoint sentence is gone from docs/d3d12_vulkan.md, and kExitCacheWriteMs is 6 s with the measured
write times (1.87 GB in 1.4 s, 2.9 GB in 1.3-1.6 s; about 2.2 s at the 4 GiB default).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Gt9hwRYcpySx4P4ncQ3wD5
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:09:57 +00:00
Author
Owner

@⁠Snooozs on GitHub · 2026-11-25 14:44 UTC · original

Answering the question in the description with one measured size: my offline pipeline_cache.bin from the pipelines stage is 2,096,191,412 bytes (RTX 5060 Ti, NVIDIA 621.01; the runtime loads it: loaded 2096191412 bytes from pipeline_cache.bin). So a corpus file below 4 GiB is a real case on NVIDIA, not only a theoretical one.

By reading, what changes for such a setup: today both writes stop at the limit (256 MiB at teardown; scripts/windows-boot/boot.ps1 raises LEONIDA_PIPELINE_CACHE_BYTES to 4 GiB and turns checkpoints on, but the 512 MiB checkpoint cap still stopped those). With this change a seeded run writes the whole union, 2.1 GB and up, at each checkpoint and again at teardown, and the next start loads the seed and then merges a session file that already contains it.

Two ways that keep your gain: count only what the session added (size minus the seed's size) against the limit, which leaves the write large but stops a seed alone from triggering it; or, once a session file exists that was written by a seeded run, skip loading the seed. I have not measured the cost of a 2.1 GB checkpoint. Not a blocker from my side: losing every build past 256 MiB is worse.

The PR builds and its neighbours pass together with six other world-start pull requests (counts in #1608); it conflicts with #1756. AI-assisted (Claude Code).

**@⁠Snooozs** on GitHub · 2026-11-25 14:44 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1886#issuecomment-7165751826) Answering the question in the description with one measured size: my offline `pipeline_cache.bin` from the `pipelines` stage is **2,096,191,412 bytes** (RTX 5060 Ti, NVIDIA 621.01; the runtime loads it: `loaded 2096191412 bytes from pipeline_cache.bin`). So a corpus file below 4 GiB is a real case on NVIDIA, not only a theoretical one. By reading, what changes for such a setup: today both writes stop at the limit (256 MiB at teardown; `scripts/windows-boot/boot.ps1` raises `LEONIDA_PIPELINE_CACHE_BYTES` to 4 GiB and turns checkpoints on, but the 512 MiB checkpoint cap still stopped those). With this change a seeded run writes the whole union, 2.1 GB and up, at each checkpoint and again at teardown, and the next start loads the seed and then merges a session file that already contains it. Two ways that keep your gain: count only what the session added (`size` minus the seed's size) against the limit, which leaves the write large but stops a seed alone from triggering it; or, once a session file exists that was written by a seeded run, skip loading the seed. I have not measured the cost of a 2.1 GB checkpoint. Not a blocker from my side: losing every build past 256 MiB is worse. The PR builds and its neighbours pass together with six other world-start pull requests (counts in [#1608](https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608)); it conflicts with #1756. AI-assisted (Claude Code).
Author
Owner

@⁠DadaCap on GitHub · 2026-11-25 14:51 UTC · original

Thank you @⁠Snooozs, that is the size I did not have: 2.1 GB is a real seed, so with this change a seeded run writes the whole union at each checkpoint. Extrapolating my own checkpoints (0.35 s at 681 MB, 0.61 s at 1,357 MB: fill_us 394,793 + publish_us 217,088) that would be about 1 s of the compile worker every time; not measured at that size.

Of your two ways I prefer counting only what the session added against the limit: a seed alone then never triggers a write, and the builds a session adds are still saved. I'd rather not add it to this pull request without a maintainer saying which they want, since it needs the seed's size kept beside the cache. Whoever merges: is the plain limit fine for now, or shall I add that here? AI-assisted (Claude Code).

**@⁠DadaCap** on GitHub · 2026-11-25 14:51 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1886#issuecomment-7165916456) Thank you @⁠Snooozs, that is the size I did not have: 2.1 GB is a real seed, so with this change a seeded run writes the whole union at each checkpoint. Extrapolating my own checkpoints (0.35 s at 681 MB, 0.61 s at 1,357 MB: `fill_us` 394,793 + `publish_us` 217,088) that would be about 1 s of the compile worker every time; not measured at that size. Of your two ways I prefer counting only what the session added against the limit: a seed alone then never triggers a write, and the builds a session adds are still saved. I'd rather not add it to this pull request without a maintainer saying which they want, since it needs the seed's size kept beside the cache. Whoever merges: is the plain limit fine for now, or shall I add that here? AI-assisted (Claude Code).
Author
Owner

@⁠Tyrannys on GitHub · 2026-11-25 18:12 UTC · original · edited 2026-11-25 18:55 UTC

Test report from a combined build on a second NVIDIA machine. Counts only.

Machine: Windows 11, RTX 4070 SUPER, NVIDIA 621.01, 64 GB, own 1.0.2.1 copy.

Build: main fe1553456 (already contains #1827 and #1893), plus #674, #1662, #1851, #1849, #1905, #1957, #1950, #1886 and #1894. All of them merged without conflicts.

Shaders: translated on 3de22a190 + #674 + #1662 with --wave64-emulate. 29,279 of 29,280 translated, and all 29,279 pass spirv-val. That is 2,683 library programs and 29 of 29 FSPX. main's translator changes since then are correctness fixes only.

Pipeline cache: warm and complete, 26,503 of 26,503 (9.6 GB).

  • Three library compute programs took 30 to 32 minutes each to build alone: the ScreenProbes ActivateRays, ActivateProbes and ActivateProbesTarget programs of indirect diffuse lighting.
  • Building all three at once crashed the NVIDIA compiler ("NVVM compilation failed: 3", after 22 minutes).

Recipe: scripts/windows-boot/boot.ps1 -Seconds 480, LEONIDA_KEYBOARD_PAD=1 LEONIDA_SKIP_INT3=1 LEONIDA_TITLE_WINDOWS_MB=1024 LEONIDA_MAP_READBACK=1, LEONIDA_PIPELINE_CACHE_DIR pointing at the offline cache. Host image copy: off (auto: NVIDIA) from #1851. One run per row.

run 1 run 2 (+ LEONIDA_TITLE_WATCHDOG=0)
end 344 s: the title's hang watchdog (null write at game_scarlett_master.exe+0x23cf683) full 484 s, stopped by the script
device loss / fault report none none
D3D12 calls 330,487 375,686
ExecuteCommandLists 5,490 6,017
Dispatch / DrawIndexedInstanced 2,435 / 2,726 2,779 / 6,026
PresentX 1,358 ok, 0 failed 1,465 ok, 0 failed
captures 23, all non-black 25, all non-black
indirect draws recorded / emitted / skipped 64 / 0 / 5,092 128 / 34 / 9,244 (#429 not included)
  • WRITE_INVALID: the world-start WRITE_INVALID did not happen in either run. On this machine it ended an earlier run with host image copies on (main 42537e7b6 + #1631; my run table of 07:54 in #1608).
  • #1950 / #1886: in run 1 the exit filter ran on the title's fatal exception: "1 pipeline build(s) still running at exit; writing the pipelines finished so far". It then refused the write: "pipeline cache is 9722912321 bytes, over the 4294967296-byte write limit". With a seeded offline cache, the union is past 4 GiB, so nothing from the session was kept. This is the seeded case raised on #1886. No session file was written in either run.

AI-assisted (Claude Code).

**@⁠Tyrannys** on GitHub · 2026-11-25 18:12 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1886#issuecomment-7170581999) · edited 2026-11-25 18:55 UTC Test report from a combined build on a second NVIDIA machine. Counts only. **Machine:** Windows 11, RTX 4070 SUPER, NVIDIA 621.01, 64 GB, own 1.0.2.1 copy. **Build:** `main` `fe1553456` (already contains #1827 and #1893), plus #674, #1662, #1851, #1849, #1905, #1957, #1950, #1886 and #1894. All of them merged without conflicts. **Shaders:** translated on `3de22a190` + #674 + #1662 with `--wave64-emulate`. 29,279 of 29,280 translated, and all 29,279 pass `spirv-val`. That is 2,683 library programs and 29 of 29 FSPX. `main`'s translator changes since then are correctness fixes only. **Pipeline cache:** warm and complete, 26,503 of 26,503 (9.6 GB). - Three library compute programs took 30 to 32 minutes each to build alone: the ScreenProbes `ActivateRays`, `ActivateProbes` and `ActivateProbesTarget` programs of indirect diffuse lighting. - Building all three at once crashed the NVIDIA compiler ("NVVM compilation failed: 3", after 22 minutes). **Recipe:** `scripts/windows-boot/boot.ps1 -Seconds 480`, `LEONIDA_KEYBOARD_PAD=1 LEONIDA_SKIP_INT3=1 LEONIDA_TITLE_WINDOWS_MB=1024 LEONIDA_MAP_READBACK=1`, `LEONIDA_PIPELINE_CACHE_DIR` pointing at the offline cache. Host image copy: `off (auto: NVIDIA)` from #1851. One run per row. | | run 1 | run 2 (+ `LEONIDA_TITLE_WATCHDOG=0`) | |---|---|---| | end | 344 s: the title's hang watchdog (null write at `game_scarlett_master.exe+0x23cf683`) | full 484 s, stopped by the script | | device loss / fault report | none | none | | D3D12 calls | 330,487 | 375,686 | | ExecuteCommandLists | 5,490 | 6,017 | | Dispatch / DrawIndexedInstanced | 2,435 / 2,726 | 2,779 / 6,026 | | PresentX | 1,358 ok, 0 failed | 1,465 ok, 0 failed | | captures | 23, all non-black | 25, all non-black | | indirect draws recorded / emitted / skipped | 64 / 0 / 5,092 | 128 / 34 / 9,244 (#429 not included) | - **WRITE_INVALID:** the world-start WRITE_INVALID did not happen in either run. On this machine it ended an earlier run with host image copies on (`main` `42537e7b6` + #1631; my run table of 07:54 in #1608). - **#1950 / #1886:** in run 1 the exit filter ran on the title's fatal exception: "1 pipeline build(s) still running at exit; writing the pipelines finished so far". It then refused the write: "pipeline cache is 9722912321 bytes, over the 4294967296-byte write limit". With a seeded offline cache, the union is past 4 GiB, so nothing from the session was kept. This is the seeded case raised on #1886. No session file was written in either run. AI-assisted (Claude Code).
Author
Owner

@⁠HasiKe on GitHub · 2026-11-25 20:08 UTC · original

Tested together with #1756 and #1950: on my PC the session cache now persists and a second boot reuses it. AI-assisted test.

Setup: RTX 2070 SUPER, NVIDIA 616.56, Windows 11. main 490f5b9ec + #1756 + #1886 + #1950 (two small conflicts in save_session_pipeline_cache resolved by keeping both sides). LEONIDA_STARTUP_CACHE_CHECKPOINTS=1, LEONIDA_CONSOLE_FIX_US=0, no offline pipeline_cache.bin next to the exe.

run result
main alone, 2 h 0 session writes. The checkpoint never found a moment with no build active: the submitting thread built one dispatch pipeline after another, 6,373 s of the 7,200 s (227 builds, 101 over 1 MiB)
with the three PRs, run 1 (ended by a host crash at 46 min) 21 checkpoints written, the last one 117 MB, after ScreenProbes_ActivateRays (1,925 s build)
run 2 on that file loaded 117 MB in 56 ms; 817 of 1,075 builds hit, 188 s of compiling in all; the world-start phase took ~200 s instead of being held for half an hour

#1950's exit path wrote too: after the device loss in run 2 (0x80000003), pipeline-cache op=exit bytes=119019741 ok=1.

Run 2 then hit a device loss at ~203 s, before the cache was even needed for the big builds. I'm narrowing that down with the crash-diagnostic layer and will report it separately in #1608.

**@⁠HasiKe** on GitHub · 2026-11-25 20:08 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1886#issuecomment-7173250778) Tested together with #1756 and #1950: on my PC the session cache now persists and a second boot reuses it. AI-assisted test. Setup: RTX 2070 SUPER, NVIDIA 616.56, Windows 11. `main` 490f5b9ec + #1756 + #1886 + #1950 (two small conflicts in `save_session_pipeline_cache` resolved by keeping both sides). `LEONIDA_STARTUP_CACHE_CHECKPOINTS=1`, `LEONIDA_CONSOLE_FIX_US=0`, no offline `pipeline_cache.bin` next to the exe. | run | result | |---|---| | `main` alone, 2 h | 0 session writes. The checkpoint never found a moment with no build active: the submitting thread built one dispatch pipeline after another, 6,373 s of the 7,200 s (227 builds, 101 over 1 MiB) | | with the three PRs, run 1 (ended by a host crash at 46 min) | 21 checkpoints written, the last one 117 MB, after `ScreenProbes_ActivateRays` (1,925 s build) | | run 2 on that file | loaded 117 MB in 56 ms; 817 of 1,075 builds hit, 188 s of compiling in all; the world-start phase took ~200 s instead of being held for half an hour | #1950's exit path wrote too: after the device loss in run 2 (0x80000003), `pipeline-cache op=exit bytes=119019741 ok=1`. Run 2 then hit a device loss at ~203 s, before the cache was even needed for the big builds. I'm narrowing that down with the crash-diagnostic layer and will report it separately in #1608.
Author
Owner

@⁠aslan2142 on GitHub · 2026-11-26 01:26 UTC · original

Raising the limit is right, and making checkpoints follow it fixes boot.ps1 and boot.sh, whose 4 GiB setting was being capped at 512 MiB. Three points before merging:

  • docs/d3d12_vulkan.md:2423 still says checkpoints have "an additional 512 MiB ceiling". Please drop that sentence.
  • The comment on default_save_limit still says the cap stops a seeded cache being rewritten at every exit. With 4 GiB it doesn't for the 2.1 GB and 3.81 GB seeds, and a 9.7 GB union saves nothing. Your suggestion to count only size minus the seed's size against the limit sounds good to us; please add it here.
  • kExitCacheWriteMs (3 s) was sized from a 77 MiB cache. A line about the exit time at about 4 GiB, or a measurement, would help.

Wine suite (lavapipe and RDNA2 iGPU): no regressions from this PR.

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

**@⁠aslan2142** on GitHub · 2026-11-26 01:26 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1886#issuecomment-7179773510) Raising the limit is right, and making checkpoints follow it fixes `boot.ps1` and `boot.sh`, whose 4 GiB setting was being capped at 512 MiB. Three points before merging: - `docs/d3d12_vulkan.md:2423` still says checkpoints have "an additional 512 MiB ceiling". Please drop that sentence. - The comment on `default_save_limit` still says the cap stops a seeded cache being rewritten at every exit. With 4 GiB it doesn't for the 2.1 GB and 3.81 GB seeds, and a 9.7 GB union saves nothing. Your suggestion to count only `size` minus the seed's size against the limit sounds good to us; please add it here. - `kExitCacheWriteMs` (3 s) was sized from a 77 MiB cache. A line about the exit time at about 4 GiB, or a measurement, would help. Wine suite (lavapipe and RDNA2 iGPU): no regressions from this PR. AI-assisted (Claude Code, Claude Opus 5.5).
Author
Owner

@⁠DadaCap on GitHub · 2026-11-26 01:36 UTC · original

@⁠aslan2142 thank you, all three are in 66e96ccea (with main merged first, no conflict):

  • Doc: the "additional 512 MiB ceiling" sentence is gone, and the LEONIDA_PIPELINE_CACHE_BYTES line now says the limit is on what a session adds.
  • Seed: the size of an offline pipeline_cache.bin the device cache was created from is no longer counted. The check is pipeline_cache_store::over_save_limit(size, seed, limit) (size minus seed over the limit), and the comment on default_save_limit now says this. pipeline_cache_store_test has cases for no seed, a 9 GB seed plus 1 GB of new builds (saved), 5 GB added (refused), a cache smaller than its seed, and the exact edge. A session file loaded as the seed still counts whole, since that is what gets rewritten.
  • Exit time: measured here (RTX 5080, NVIDIA 621.24, Windows 11, NVMe), fill plus publish: 1.87 GB in 1.4 s, 2.9 GB in 1.3-1.6 s, so about 2.2 s at 4 GiB. That is under 3 s with little margin, so kExitCacheWriteMs is now 6 s; the wait still ends as soon as the write does.

Tested: pipeline_cache_store, pipeline_cache_file, pipeline_cache_seed, pipeline_cache_journal, pipeline_cache_snapshot (5/5) and a gta6rt build. AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠DadaCap** on GitHub · 2026-11-26 01:36 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1886#issuecomment-7179949177) @⁠aslan2142 thank you, all three are in 66e96ccea (with main merged first, no conflict): - **Doc:** the "additional 512 MiB ceiling" sentence is gone, and the `LEONIDA_PIPELINE_CACHE_BYTES` line now says the limit is on what a session adds. - **Seed:** the size of an offline `pipeline_cache.bin` the device cache was created from is no longer counted. The check is `pipeline_cache_store::over_save_limit(size, seed, limit)` (size minus seed over the limit), and the comment on `default_save_limit` now says this. `pipeline_cache_store_test` has cases for no seed, a 9 GB seed plus 1 GB of new builds (saved), 5 GB added (refused), a cache smaller than its seed, and the exact edge. A session file loaded as the seed still counts whole, since that is what gets rewritten. - **Exit time:** measured here (RTX 5080, NVIDIA 621.24, Windows 11, NVMe), fill plus publish: 1.87 GB in 1.4 s, 2.9 GB in 1.3-1.6 s, so about 2.2 s at 4 GiB. That is under 3 s with little margin, so `kExitCacheWriteMs` is now 6 s; the wait still ends as soon as the write does. Tested: `pipeline_cache_store`, `pipeline_cache_file`, `pipeline_cache_seed`, `pipeline_cache_journal`, `pipeline_cache_snapshot` (5/5) and a `gta6rt` build. AI-assisted (Claude Code, Claude Opus 5.5).
github manually merged commit 73516a2902 into main 2026-11-26 12:52:34 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.