d3d12: write the session pipeline cache when the run ends with the device alive (RT-SESSION-CACHE-AT-EXIT) #1950
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!1950
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1950/head"
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?
@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 UTCRT-SESSION-CACHE-AT-EXIT, claimed in #1608.
What
pipeline_cache.session.binwas 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 theDeviceconstructor and destructor maintain. It runs once per process, afterstop_pipeline_compiles.gta6rtcalls 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.SetUnhandledExceptionFilterfromapi-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.wait_ms(1 s); then the cache is written with the pipelines finished so far. This is valid because the cache is not createdEXTERNALLY_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).CacheStagingFilepublishes by rename, so a write cut off leaves the previous file whole.std::call_once), so none reaches the title's filter, which may end the process, in the middle of it.~Deviceand 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, withLEONIDA_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'stook N s to buildlines.wrote 436563293 bytesloaded 436563293 bytes)wrote 510225527 bytesover 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 afterstop_pipeline_compiles,save_pipeline_caches_at_exitwrites 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.pypasses.AI-assisted.
🤖 Generated with Claude Code
@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:
mainfe1553456(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 passspirv-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).
ActivateRays,ActivateProbesandActivateProbesTargetprograms of indirect diffuse lighting.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_DIRpointing at the offline cache. Host image copy:off (auto: NVIDIA)from #1851. One run per row.LEONIDA_TITLE_WATCHDOG=0)game_scarlett_master.exe+0x23cf683)main42537e7b6+ #1631; my run table of 07:54 in #1608).AI-assisted (Claude Code).
@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).
@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
98c457ec4plus the documentation commit, onto main73cc1a2baand 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.
@aslan2142 on GitHub · 2026-11-25 19:15 UTC · original
Merged, thanks! Reviewed at
2e61d408: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.d3d12_compile_teardownpasses and writes the file on RADV.main490f5b9ec+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.pyis clean on the 5 changed files.AI-assisted (Claude Code, Claude Opus 5.5).
@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.
@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:EXTERNALLY_SYNCHRONIZED, sovkGetPipelineCacheDatawhile another thread'svkCreateComputePipelinesuses the same cache is valid. The exit path counts on that:save_pipeline_caches_at_exitwaits up to 1 s foractive_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.vkCreateComputePipelines(in the Intel driver or in the layer), that thread never leaves the build.active_compilesstays 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.call_oncethe first thread holds. The first thread stops waiting after 3 s (kExitCacheWriteMs) and hands the original exception to the title's filter. The previouspipeline_cache.session.binstays 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.