[PR #1950] [MERGED] d3d12: write the session pipeline cache when the run ends with the device alive (RT-SESSION-CACHE-AT-EXIT) #1956

Closed
opened 2026-11-26 21:19:32 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1950
Author: @kurrutako
Created: 11/25/2026
Status: ✅ Merged
Merged: 11/25/2026
Merged by: @aslan2142

Base: main ← Head: rt/session-cache-at-exit


📝 Commits (5)

  • f95b23e d3d12: write the session pipeline cache when the run ends with the device alive (RT-SESSION-CACHE-AT-EXIT)
  • 27a861a gta6rt: keep the exit-save filter when the title installs its own (RT-SESSION-CACHE-AT-EXIT)
  • a26b127 d3d12: the exit save writes the finished pipelines while a build runs, on a bounded thread (RT-SESSION-CACHE-AT-EXIT)
  • 98c457e gta6rt: threads that fault together wait for the first one's cache write (RT-SESSION-CACHE-AT-EXIT)
  • 2e61d40 docs: when the session pipeline cache is written at exit (RT-SESSION-CACHE-AT-EXIT)

📊 Changes

5 files changed (+155 additions, -13 deletions)

View changed files

📝 docs/d3d12_vulkan.md (+6 -1)
📝 runtime/shims/d3d12_compile_exit.h (+7 -0)
📝 runtime/shims/d3d12_vulkan_device.cpp (+73 -2)
📝 runtime/src/main.cpp (+48 -0)
📝 runtime/test/d3d12_compile_teardown_test.cpp (+21 -10)

📄 Description

RT-SESSION-CACHE-AT-EXIT, claimed in #1608.

What

pipeline_cache.session.bin was written only in ~Device. A title never releases its device, so a real boot kept none of what it compiled, and every boot built the world start again.

  • save_pipeline_caches_at_exit(wait_ms) (shims/d3d12_compile_exit.h) writes the session cache of every live device. The live devices are a list that the Device constructor and destructor maintain. It runs once per process, after stop_pipeline_compiles.
  • gta6rt calls it at the run's exit, at a console close (Ctrl+C, Ctrl+Break, close), and from an unhandled-exception filter: a fault in the title or one of its DLLs, or the int3 after a device loss. The filter then passes the exception on, so the exit code is the exception's, as before.
  • The retail title installs its own filter. It imports SetUnhandledExceptionFilter from api-ms-win-core-errorhandling-l1-1-0, which replaced the runtime's filter (measured: a title fault at 354 s wrote nothing). The runtime now serves that call: its own filter stays first and hands the exception to the title's, as Windows would.
  • Builds still running. A large build takes minutes, and at a crash the faulting thread may be inside one. A build still running gets wait_ms (1 s); then the cache is written with the pipelines finished so far. This is valid because the cache is not created EXTERNALLY_SYNCHRONIZED. Unlike at teardown, the previous file is not kept: the process is ending, so keeping it would throw away the whole run (measured: a 1,308 s boot ended with 2 builds running).
  • The write itself is bounded. It runs on its own thread and gets 3 s, so a driver that blocks the read cannot hold the ending process. CacheStagingFile publishes by rename, so a write cut off leaves the previous file whole.
  • Threads that fault together (measured: eight within a second) wait for the first one's write (std::call_once), so none reaches the title's filter, which may end the process, in the middle of it.

~Device and the checkpoints are unchanged. The size limit is #1886's subject; see below.

Measured

Retail boots on Windows 11, RTX 5070 12 GB, NVIDIA 621.01. Build: main + #1851, #1827, #1849, #1862 (shaders retranslated with it: 29/29 FSPX) + #1886, with LEONIDA_HOST_IMAGE_COPY=0 LEONIDA_ASYNC_PIPELINES=1 LEONIDA_DEVICE_TYPE=6 LEONIDA_ARENA_MB=2048 LEONIDA_TITLE_WATCHDOG=0 LEONIDA_DEVICE_FAULT=1, a person at the keyboard pad. Counted: the runtime's took N s to build lines.

boot how it ended session cache
before this change (dozen boots) title faults, device losses never written
A title fault at 652 s, 1 build running wrote 436563293 bytes
B (loads A's file: loaded 436563293 bytes) int3 at 687 s, 2 builds running wrote 510225527 bytes
  • A had 97 slow builds (550 s in all). In B, none of those 97 programs was slow again. B's 34 slow builds (647 s) are all programs A never reached, the largest 83 s.
  • Without #1886, a 345 MB cache stopped at the 256 MiB limit (over the 268435456-byte write limit). This change makes the write happen; #1886 lets it through at this size.

Tests

d3d12_compile_teardown_test, exit case: with the device still alive after stop_pipeline_compiles, save_pipeline_caches_at_exit writes the session file, and a second call does nothing. It passes on the RTX 5070 (MSVC 2022, RelWithDebInfo); on llvmpipe the file stays absent, as in the existing cache case. The exception-filter path is checked by the boots above. Counts, offsets and program names only; no game data; python -I scripts/check_no_game_data.py passes.

AI-assisted.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1950 **Author:** [@kurrutako](https://github.com/kurrutako) **Created:** 11/25/2026 **Status:** ✅ Merged **Merged:** 11/25/2026 **Merged by:** [@aslan2142](https://github.com/aslan2142) **Base:** `main` ← **Head:** `rt/session-cache-at-exit` --- ### 📝 Commits (5) - [`f95b23e`](https://github.com/ubiquitarianism/leonida/commit/f95b23e51864996b7a25a4cd4566ae24882efe2e) d3d12: write the session pipeline cache when the run ends with the device alive (RT-SESSION-CACHE-AT-EXIT) - [`27a861a`](https://github.com/ubiquitarianism/leonida/commit/27a861adc904fb42af043aafb99ddf2fbd9a0322) gta6rt: keep the exit-save filter when the title installs its own (RT-SESSION-CACHE-AT-EXIT) - [`a26b127`](https://github.com/ubiquitarianism/leonida/commit/a26b12760e6bef631949076261e21dba53f141db) d3d12: the exit save writes the finished pipelines while a build runs, on a bounded thread (RT-SESSION-CACHE-AT-EXIT) - [`98c457e`](https://github.com/ubiquitarianism/leonida/commit/98c457ec4f4bb6da6cdc685badd8019f0635cf4e) gta6rt: threads that fault together wait for the first one's cache write (RT-SESSION-CACHE-AT-EXIT) - [`2e61d40`](https://github.com/ubiquitarianism/leonida/commit/2e61d4080f65a70df1e6219537daa774449733eb) docs: when the session pipeline cache is written at exit (RT-SESSION-CACHE-AT-EXIT) ### 📊 Changes **5 files changed** (+155 additions, -13 deletions) <details> <summary>View changed files</summary> 📝 `docs/d3d12_vulkan.md` (+6 -1) 📝 `runtime/shims/d3d12_compile_exit.h` (+7 -0) 📝 `runtime/shims/d3d12_vulkan_device.cpp` (+73 -2) 📝 `runtime/src/main.cpp` (+48 -0) 📝 `runtime/test/d3d12_compile_teardown_test.cpp` (+21 -10) </details> ### 📄 Description RT-SESSION-CACHE-AT-EXIT, claimed in #1608. ## What `pipeline_cache.session.bin` was written only in `~Device`. A title never releases its device, so a real boot kept none of what it compiled, and every boot built the world start again. - `save_pipeline_caches_at_exit(wait_ms)` (`shims/d3d12_compile_exit.h`) writes the session cache of every live device. The live devices are a list that the `Device` constructor and destructor maintain. It runs once per process, after `stop_pipeline_compiles`. - `gta6rt` calls it at the run's exit, at a console close (Ctrl+C, Ctrl+Break, close), and from an **unhandled-exception filter**: a fault in the title or one of its DLLs, or the int3 after a device loss. The filter then passes the exception on, so the exit code is the exception's, as before. - **The retail title installs its own filter.** It imports `SetUnhandledExceptionFilter` from `api-ms-win-core-errorhandling-l1-1-0`, which replaced the runtime's filter (measured: a title fault at 354 s wrote nothing). The runtime now serves that call: its own filter stays first and hands the exception to the title's, as Windows would. - **Builds still running.** A large build takes minutes, and at a crash the faulting thread may be inside one. A build still running gets `wait_ms` (1 s); then the cache is written with the pipelines finished so far. This is valid because the cache is not created `EXTERNALLY_SYNCHRONIZED`. Unlike at teardown, the previous file is not kept: the process is ending, so keeping it would throw away the whole run (measured: a 1,308 s boot ended with 2 builds running). - **The write itself is bounded.** It runs on its own thread and gets 3 s, so a driver that blocks the read cannot hold the ending process. `CacheStagingFile` publishes by rename, so a write cut off leaves the previous file whole. - **Threads that fault together** (measured: eight within a second) wait for the first one's write (`std::call_once`), so none reaches the title's filter, which may end the process, in the middle of it. `~Device` and the checkpoints are unchanged. The size limit is #1886's subject; see below. ## Measured Retail boots on Windows 11, RTX 5070 12 GB, NVIDIA 621.01. Build: `main` + #1851, #1827, #1849, #1862 (shaders retranslated with it: 29/29 FSPX) + #1886, with `LEONIDA_HOST_IMAGE_COPY=0 LEONIDA_ASYNC_PIPELINES=1 LEONIDA_DEVICE_TYPE=6 LEONIDA_ARENA_MB=2048 LEONIDA_TITLE_WATCHDOG=0 LEONIDA_DEVICE_FAULT=1`, a person at the keyboard pad. Counted: the runtime's `took N s to build` lines. | boot | how it ended | session cache | |---|---|---| | before this change (dozen boots) | title faults, device losses | never written | | A | title fault at 652 s, 1 build running | `wrote 436563293 bytes` | | B (loads A's file: `loaded 436563293 bytes`) | int3 at 687 s, 2 builds running | `wrote 510225527 bytes` | - A had 97 slow builds (550 s in all). In B, **none of those 97 programs was slow again**. B's 34 slow builds (647 s) are all programs A never reached, the largest 83 s. - Without #1886, a 345 MB cache stopped at the 256 MiB limit (`over the 268435456-byte write limit`). This change makes the write happen; #1886 lets it through at this size. ## Tests `d3d12_compile_teardown_test`, exit case: with the device still alive after `stop_pipeline_compiles`, `save_pipeline_caches_at_exit` writes the session file, and a second call does nothing. It passes on the RTX 5070 (MSVC 2022, RelWithDebInfo); on llvmpipe the file stays absent, as in the existing cache case. The exception-filter path is checked by the boots above. Counts, offsets and program names only; no game data; `python -I scripts/check_no_game_data.py` passes. AI-assisted. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 21:19:32 +01:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#1956
No description provided.