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

Manually merged
github merged 5 commits from gh-pr/1950/head into gh-pr/1950/base 2026-11-26 10:12:29 +00:00
Owner

@⁠kurrutako on GitHub · 2026-11-25 16:33 UTC · original
kurrutako:rt/session-cache-at-exit → main · +155 −13 · 5 files · 5 commits · merged 2026-11-25 19:15 UTC

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

**@⁠kurrutako** on GitHub · 2026-11-25 16:33 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1950) `kurrutako:rt/session-cache-at-exit` → `main` · +155 −13 · 5 files · 5 commits · merged 2026-11-25 19:15 UTC 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)
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: not
after a normal exit, a console close or a crash, and every boot built the
world start again.

save_pipeline_caches_at_exit writes the session cache of every live device
(a registry the Device constructor and destructor keep), once per process,
after stop_pipeline_compiles. A build still running on another thread is
given wait_ms, then the previous file is kept, as at teardown. gta6rt calls
it at the run's exit, at a console close, and from an unhandled-exception
filter (a fault in the title or its DLLs, the int3 after a device loss),
which then passes the exception on, so the exit code is unchanged.

d3d12_compile_teardown_test's exit case checks that the file is written
with the device alive, and only once.

AI-assisted.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The retail title calls SetUnhandledExceptionFilter (from
api-ms-win-core-errorhandling-l1-1-0), which replaced the runtime's filter:
a title fault at 354 s ended the process without the cache write. The
title's call is now served by the runtime, which keeps its filter
installed and passes the exception on to the title's.

AI-assisted.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A 1,308 s boot ended in a title fault with 2 builds still running, and the
exit save kept the old file, so the run's pipelines were lost again. At
exit there is no later moment to wait for: after wait_ms the cache is
written with the pipelines finished so far (it is not created
EXTERNALLY_SYNCHRONIZED, so reading it during a build is valid). The write
runs on its own thread and is given 3 s, so a driver that blocks the read
cannot hold the ending process; the file is published by a rename, so a
write cut off leaves the previous one whole.

AI-assisted.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A boot ended with eight title threads faulting within a second. Each
entered the filter; the ones after the first returned at once and went on
to the title's filter, which can end the process during the write. The
write now runs under std::call_once, so they wait for it.

AI-assisted.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
AI-assisted.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:12:26 +00:00
github manually merged commit 2e61d4080f into gh-pr/1950/base 2026-11-26 10:12:29 +00:00
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/1950#issuecomment-7170581400) · 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

@⁠kurrutako on GitHub · 2026-11-25 18:44 UTC · original

Thanks for the test. Run 1 is the case this PR is for: the title's fatal exception went through the exit filter, the save ran while a build was still going, and it set out to write only the pipelines that had finished.

The write was then refused by the 4 GiB cap from #1886, not by this PR. With an offline seed loaded, the driver's cache data is the seed plus the session, so a 9.7 GB seed is over the cap before the session adds anything. That is the seeded case already raised on #1886, so I will leave the fix there and not change it here.

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

**@⁠kurrutako** on GitHub · 2026-11-25 18:44 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1950#issuecomment-7171320741) Thanks for the test. Run 1 is the case this PR is for: the title's fatal exception went through the exit filter, the save ran while a build was still going, and it set out to write only the pipelines that had finished. The write was then refused by the 4 GiB cap from #1886, not by this PR. With an offline seed loaded, the driver's cache data is the seed plus the session, so a 9.7 GB seed is over the cap before the session adds anything. That is the seeded case already raised on #1886, so I will leave the fix there and not change it here. AI-assisted (Claude Code, Claude Opus 5.5).
Author
Owner

@⁠GGandCo on GitHub · 2026-11-25 19:12 UTC · original

Intel integration verification (AI-assisted: OpenAI Codex): Windows 11, MSVC RelWithDebInfo, Intel UHD Graphics / i5-1334U, driver 32.0.101.6314. Applied the four implementation commits through 98c457ec4 plus the documentation commit, onto main 73cc1a2ba and an existing private integration tree.

14/14 targeted tests passed: d3d12_compile_teardown (including the once-only live-device session-cache write), list_value_wait_budget, all nine xs_proxy_mock modes, d3d12_xmem_placed, d3d12_m2_textured, replay_copy_offset.

Also checked the actual gta6rt import/filter path with two synthetic, CRT-free guest PEs, one importing SetUnhandledExceptionFilter from KERNEL32.dll and one through api-ms-win-core-errorhandling-l1-1-0.dll. Each registers two filters, verifies the previous guest filter is returned, then raises a deliberate noncontinuable exception; the final guest filter exits with code 42. Both fixed-runtime runs log the cache-exit filter and then exit 42. The preceding runtime failed the filter-chain check (exit 43). These tiny fixtures create no graphics device; actual cache publication is covered by d3d12_compile_teardown, not by the PE fixtures.

This is a combined-tree, targeted result, not a full-suite or playability claim. No title data is included.

**@⁠GGandCo** on GitHub · 2026-11-25 19:12 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1950#issuecomment-7171977609) Intel integration verification (AI-assisted: OpenAI Codex): Windows 11, MSVC RelWithDebInfo, Intel UHD Graphics / i5-1334U, driver 32.0.101.6314. Applied the four implementation commits through 98c457ec4 plus the documentation commit, onto main 73cc1a2ba and an existing private integration tree. 14/14 targeted tests passed: d3d12_compile_teardown (including the once-only live-device session-cache write), list_value_wait_budget, all nine xs_proxy_mock modes, d3d12_xmem_placed, d3d12_m2_textured, replay_copy_offset. Also checked the actual gta6rt import/filter path with two synthetic, CRT-free guest PEs, one importing SetUnhandledExceptionFilter from KERNEL32.dll and one through api-ms-win-core-errorhandling-l1-1-0.dll. Each registers two filters, verifies the previous guest filter is returned, then raises a deliberate noncontinuable exception; the final guest filter exits with code 42. Both fixed-runtime runs log the cache-exit filter and then exit 42. The preceding runtime failed the filter-chain check (exit 43). These tiny fixtures create no graphics device; actual cache publication is covered by d3d12_compile_teardown, not by the PE fixtures. This is a combined-tree, targeted result, not a full-suite or playability claim. No title data is included.
Author
Owner

@⁠aslan2142 on GitHub · 2026-11-25 19:15 UTC · original

Merged, thanks! Reviewed at 2e61d408:

  • Cache: the format and location are unchanged, so existing session files stay valid. An oversized or cut-off write keeps the previous file.
  • Merges: clean with main, including #1887 and #1798, which landed in between (the console-fix default stays 0). Also clean with #1889, #1886 and #1914; one trivial signature conflict with #1756, for whichever merges second.
  • Windows suite under Wine (llvmpipe + RADV iGPU): no regressions. d3d12_compile_teardown passes and writes the file on RADV.
  • Checked on main 490f5b9ec + 2e61d4080: it merges cleanly; the semantic suite passes (490 files, 6,310 tests, 0 files failed); the 15 docs and writer tests pass; check_no_game_data.py is clean on the 5 changed files.
  • Non-blocking: no test covers handing the exception on to the title's own filter. A tiny-game test that installs a filter and faults would cover it.

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

**@⁠aslan2142** on GitHub · 2026-11-25 19:15 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1950#issuecomment-7172038070) Merged, thanks! Reviewed at `2e61d408`: - **Cache:** the format and location are unchanged, so existing session files stay valid. An oversized or cut-off write keeps the previous file. - **Merges:** clean with `main`, including #1887 and #1798, which landed in between (the console-fix default stays 0). Also clean with #1889, #1886 and #1914; one trivial signature conflict with #1756, for whichever merges second. - **Windows suite under Wine** (llvmpipe + RADV iGPU): no regressions. `d3d12_compile_teardown` passes and writes the file on RADV. - **Checked on `main` `490f5b9ec` + `2e61d4080`:** it merges cleanly; the semantic suite passes (490 files, 6,310 tests, 0 files failed); the 15 docs and writer tests pass; `check_no_game_data.py` is clean on the 5 changed files. - **Non-blocking:** no test covers handing the exception on to the title's own filter. A tiny-game test that installs a filter and faults would cover it. AI-assisted (Claude Code, Claude Opus 5.5).
Author
Owner

@⁠GGandCo on GitHub · 2026-11-25 20:43 UTC · original

Additional Intel diagnostic finding after the positive targeted tests above: with Khronos GPU-assisted validation enabled, a fatal shutdown while compute compilation was still active was followed by a driver access violation inside vkGetPipelineCacheData. Host symbols resolve the caller to save_session_pipeline_cache (d3d12_vulkan_device.cpp, the data query) from the bounded save_pipeline_caches_at_exit worker. The initial fatal exception occurred before this secondary driver failure; this does not explain or fix the initial shutdown.

Windows 11, Intel UHD Graphics / i5-1334U, driver 32.0.101.6314, Vulkan SDK 1.4.363.1, current-main integration including #1950. An earlier non-GPUAV run successfully saved the session cache at exit. No minimal standalone concurrency reproducer yet, so this is an observed GPUAV/driver interaction, not a confirmed general cache synchronization bug. A useful follow-up would be a synthetic active-compilation plus exit-cache-query stress test on Intel with GPUAV. No game logs or data included. AI-assisted with OpenAI Codex.

**@⁠GGandCo** on GitHub · 2026-11-25 20:43 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1950#issuecomment-7174094593) Additional Intel diagnostic finding after the positive targeted tests above: with Khronos GPU-assisted validation enabled, a fatal shutdown while compute compilation was still active was followed by a driver access violation inside vkGetPipelineCacheData. Host symbols resolve the caller to save_session_pipeline_cache (d3d12_vulkan_device.cpp, the data query) from the bounded save_pipeline_caches_at_exit worker. The initial fatal exception occurred before this secondary driver failure; this does not explain or fix the initial shutdown. Windows 11, Intel UHD Graphics / i5-1334U, driver 32.0.101.6314, Vulkan SDK 1.4.363.1, current-main integration including #1950. An earlier non-GPUAV run successfully saved the session cache at exit. No minimal standalone concurrency reproducer yet, so this is an observed GPUAV/driver interaction, not a confirmed general cache synchronization bug. A useful follow-up would be a synthetic active-compilation plus exit-cache-query stress test on Intel with GPUAV. No game logs or data included. AI-assisted with OpenAI Codex.
Author
Owner

@⁠kurrutako on GitHub · 2026-11-25 21:52 UTC · original

Thanks, that's useful, and the caller you resolved is the expected one. Notes from the code at 2e61d408:

  • The read is allowed by Vulkan. The session cache is not created EXTERNALLY_SYNCHRONIZED, so vkGetPipelineCacheData while another thread's vkCreateComputePipelines uses the same cache is valid. The exit path counts on that: save_pipeline_caches_at_exit waits up to 1 s for active_compiles, then reads the pipelines finished so far. A driver that faults on that read in a valid call is a driver (or GPU-AV) problem, not missing locking on our side. That fits your clean non-GPU-AV exit save.
  • GPU-AV changes the call. It hooks pipeline creation and builds instrumented copies, so the driver sees different pipelines, and more of them, going into the same cache. The race window is therefore not the same as in a normal run.
  • Where did the first exception happen? This is the question that matters. If the first fatal exception was on a thread inside vkCreateComputePipelines (in the Intel driver or in the layer), that thread never leaves the build. active_compiles stays above zero, and the driver's cache can be left half-updated when we read it. A secondary access violation would then be likely, whatever the locking. A module and offset for the first exception, or just whether its stack shows a pipeline create, would settle it.
  • The secondary fault can't hang the exit. The write runs on its own detached thread. Its access violation goes back into the fatal filter, which waits on the call_once the first thread holds. The first thread stops waiting after 3 s (kExitCacheWriteMs) and hands the original exception to the title's filter. The previous pipeline_cache.session.bin stays whole, because it is only ever replaced by a rename.

If the first exception turns out to be inside a pipeline create, a narrow follow-up would be to skip the exit write when the faulting thread is in a build (a thread-local mark set by CompileActivity). The cost is losing that run's cache, not risking a second fault. I'd hold that until the first exception's location is known, and I agree a synthetic stress test (active compile plus exit-cache query, Intel, GPU-AV) is the way to tell a general race from this layer/driver combination.

**@⁠kurrutako** on GitHub · 2026-11-25 21:52 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1950#issuecomment-7175648870) Thanks, that's useful, and the caller you resolved is the expected one. Notes from the code at `2e61d408`: - **The read is allowed by Vulkan.** The session cache is not created `EXTERNALLY_SYNCHRONIZED`, so `vkGetPipelineCacheData` while another thread's `vkCreateComputePipelines` uses the same cache is valid. The exit path counts on that: `save_pipeline_caches_at_exit` waits up to 1 s for `active_compiles`, then reads the pipelines finished so far. A driver that faults on that read in a valid call is a driver (or GPU-AV) problem, not missing locking on our side. That fits your clean non-GPU-AV exit save. - **GPU-AV changes the call.** It hooks pipeline creation and builds instrumented copies, so the driver sees different pipelines, and more of them, going into the same cache. The race window is therefore not the same as in a normal run. - **Where did the first exception happen?** This is the question that matters. If the first fatal exception was on a thread inside `vkCreateComputePipelines` (in the Intel driver or in the layer), that thread never leaves the build. `active_compiles` stays above zero, and the driver's cache can be left half-updated when we read it. A secondary access violation would then be likely, whatever the locking. A module and offset for the first exception, or just whether its stack shows a pipeline create, would settle it. - **The secondary fault can't hang the exit.** The write runs on its own detached thread. Its access violation goes back into the fatal filter, which waits on the `call_once` the first thread holds. The first thread stops waiting after 3 s (`kExitCacheWriteMs`) and hands the original exception to the title's filter. The previous `pipeline_cache.session.bin` stays whole, because it is only ever replaced by a rename. If the first exception turns out to be inside a pipeline create, a narrow follow-up would be to skip the exit write when the faulting thread is in a build (a thread-local mark set by `CompileActivity`). The cost is losing that run's cache, not risking a second fault. I'd hold that until the first exception's location is known, and I agree a synthetic stress test (active compile plus exit-cache query, Intel, GPU-AV) is the way to tell a general race from this layer/driver combination.
This discussion has been locked. Commenting is limited to contributors.
No description provided.