D3D12.X: fall back to an in-memory shader cache session (#1108) #1211

Manually merged
github merged 1 commit from gh-pr/1211/head into gh-pr/1211/base 2026-11-26 04:47:13 +00:00
Owner

@⁠ksanjeev284 on GitHub · 2026-11-24 13:17 UTC · original
ksanjeev284:pr-1108-shader-cache-session → main · +360 −0 · 3 files · 1 commits · merged 2026-11-24 15:58 UTC

When ID3D12Device9::CreateShaderCacheSession fails on the PC runtime (such as returning E_INVALIDARG or E_NOTIMPL under vkd3d-proton / GE-Proton, or when a title passes flags the host runtime rejects), titles like the retail RAGE build hit a fatal int3 breakpoint immediately after checking the HRESULT. Hook CreateShaderCacheSession on adopted devices so native PC sessions continue to be used whenever they succeed, and fall back to an in-memory ID3D12ShaderCacheSession implementation when the host runtime refuses the call.

Fixes #1108.

What is in it

  • crates/xcl/src/hle/d3d12x/shader_cache_session.rs: in-memory ID3D12ShaderCacheSession COM object implementing IUnknown / ID3D12Object / ID3D12DeviceChild, GetDevice, two-step FindValue (DXGI_ERROR_NOT_FOUND, size query, E_NOT_SUFFICIENT_BUFFER, copy-out), StoreValue (capped at 32 MiB per store), SetDeleteOnDestroy, GetDesc, and shared (Identifier, Version) stores for D3D12_SHADER_CACHE_MODE_DISK, plus a GPU unit test exercising the fallback path through ID3D12Device9::CreateShaderCacheSession.
  • crates/xcl/src/hle/d3d12x/real.rs & crates/xcl/src/hle/d3d12x/mod.rs: override CreateShaderCacheSession on Kind::Device to call the PC method first and fall back to shader_cache_session::create_fallback on failure with a one-time log entry.

Tested

  • NVIDIA GeForce RTX 3070 Ti (driver 32.0.16.1742), AMD Ryzen 5 5600X, Windows 11, rustc 1.88.0 (6b00bc388 2025-06-23), debug + release.
  • cargo +1.88.0 test -p xcl --lib shader_cache_session: 1 passed, 0 failed (D3D12.X: CreateShaderCacheSession failed on the PC runtime (0x80070057) – using an in-memory session).
  • cargo +1.88.0 test --workspace --no-fail-fast -- --test-threads=4 --skip test_title_runs_and_game_folder_is_untouched: 740 passed, 1 failed (hle::kernelx::tests::xmem_virtual_query_marks_cpu_readable_memory, pre-existing sandbox VirtualQuery failure on unmodified main), 41 ignored (SKIPPED GPU tests: 2 no wave64).

Regression run

main:

xcl-smoke v1
commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3
gpu: NVIDIA GeForce RTX 3070 Ti
title: retail_title_smoke
seconds: 35
exit: 0x0
frames shown: 292 (PresentX 293)
presents per 2 s (last 3): 2 29 60
device removals: 0
crashes: 0
peak commit: 15625 MB

PR:

xcl-smoke v1
commit: 560216ba9e46b9ec06abbd02fa5ff1f457af77fa
gpu: NVIDIA GeForce RTX 3070 Ti
title: retail_title_smoke
seconds: 35
exit: 0x0
frames shown: 342 (PresentX 342)
presents per 2 s (last 3): 41 60 61
device removals: 0
crashes: 0
peak commit: 15656 MB

Not tested

  • Live title run under Linux / GE-Proton / vkd3d-proton where #1108 reproduces end-to-end (tested on Windows 11 by forcing CreateShaderCacheSession rejection with unsupported flags in the unit test, plus retail title regression smoke on Windows).
  • AMD GPUs.

AI use

  • Antigravity (Gemini): assisted with implementing the ID3D12ShaderCacheSession fallback COM table, unit test, and PR description; reviewed and verified locally against the test suite and retail smoke runs.
**@⁠ksanjeev284** on GitHub · 2026-11-24 13:17 UTC · [original](https://github.com/xcl-dev/xcl/pull/1211) `ksanjeev284:pr-1108-shader-cache-session` → `main` · +360 −0 · 3 files · 1 commits · merged 2026-11-24 15:58 UTC When `ID3D12Device9::CreateShaderCacheSession` fails on the PC runtime (such as returning `E_INVALIDARG` or `E_NOTIMPL` under vkd3d-proton / GE-Proton, or when a title passes flags the host runtime rejects), titles like the retail RAGE build hit a fatal `int3` breakpoint immediately after checking the `HRESULT`. Hook `CreateShaderCacheSession` on adopted devices so native PC sessions continue to be used whenever they succeed, and fall back to an in-memory `ID3D12ShaderCacheSession` implementation when the host runtime refuses the call. Fixes #1108. **What is in it** - `crates/xcl/src/hle/d3d12x/shader_cache_session.rs`: in-memory `ID3D12ShaderCacheSession` COM object implementing `IUnknown` / `ID3D12Object` / `ID3D12DeviceChild`, `GetDevice`, two-step `FindValue` (`DXGI_ERROR_NOT_FOUND`, size query, `E_NOT_SUFFICIENT_BUFFER`, copy-out), `StoreValue` (capped at 32 MiB per store), `SetDeleteOnDestroy`, `GetDesc`, and shared `(Identifier, Version)` stores for `D3D12_SHADER_CACHE_MODE_DISK`, plus a GPU unit test exercising the fallback path through `ID3D12Device9::CreateShaderCacheSession`. - `crates/xcl/src/hle/d3d12x/real.rs` & `crates/xcl/src/hle/d3d12x/mod.rs`: override `CreateShaderCacheSession` on `Kind::Device` to call the PC method first and fall back to `shader_cache_session::create_fallback` on failure with a one-time log entry. **Tested** - NVIDIA GeForce RTX 3070 Ti (driver 32.0.16.1742), AMD Ryzen 5 5600X, Windows 11, `rustc 1.88.0 (6b00bc388 2025-06-23)`, debug + release. - `cargo +1.88.0 test -p xcl --lib shader_cache_session`: 1 passed, 0 failed (`D3D12.X: CreateShaderCacheSession failed on the PC runtime (0x80070057) – using an in-memory session`). - `cargo +1.88.0 test --workspace --no-fail-fast -- --test-threads=4 --skip test_title_runs_and_game_folder_is_untouched`: 740 passed, 1 failed (`hle::kernelx::tests::xmem_virtual_query_marks_cpu_readable_memory`, pre-existing sandbox `VirtualQuery` failure on unmodified `main`), 41 ignored (SKIPPED GPU tests: 2 `no wave64`). **Regression run** main: ``` xcl-smoke v1 commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3 gpu: NVIDIA GeForce RTX 3070 Ti title: retail_title_smoke seconds: 35 exit: 0x0 frames shown: 292 (PresentX 293) presents per 2 s (last 3): 2 29 60 device removals: 0 crashes: 0 peak commit: 15625 MB ``` PR: ``` xcl-smoke v1 commit: 560216ba9e46b9ec06abbd02fa5ff1f457af77fa gpu: NVIDIA GeForce RTX 3070 Ti title: retail_title_smoke seconds: 35 exit: 0x0 frames shown: 342 (PresentX 342) presents per 2 s (last 3): 41 60 61 device removals: 0 crashes: 0 peak commit: 15656 MB ``` **Not tested** - Live title run under Linux / GE-Proton / vkd3d-proton where `#1108` reproduces end-to-end (tested on Windows 11 by forcing `CreateShaderCacheSession` rejection with unsupported flags in the unit test, plus retail title regression smoke on Windows). - AMD GPUs. **AI use** - Antigravity (Gemini): assisted with implementing the `ID3D12ShaderCacheSession` fallback COM table, unit test, and PR description; reviewed and verified locally against the test suite and retail smoke runs.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:47:09 +00:00
github manually merged commit 560216ba9e into gh-pr/1211/base 2026-11-26 04:47:13 +00:00
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 13:47 UTC · original

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib shader_cache tests: 13 passed (see note), 0 failed.

Note: the full d3d12x lib filter currently aborts with 0xc0000005 on unmodified main too (pre-existing, unrelated to this PR); the PR's own tests were run by name and pass.

**@⁠DavidM1911** on GitHub · 2026-11-24 13:47 UTC · [original](https://github.com/xcl-dev/xcl/pull/1211#issuecomment-7133333620) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - cargo test -p xcl --lib shader_cache tests: 13 passed (see note), 0 failed. Note: the full `d3d12x` lib filter currently aborts with 0xc0000005 on unmodified `main` too (pre-existing, unrelated to this PR); the PR's own tests were run by name and pass.
Author
Owner

@⁠Aniseto on GitHub · 2026-11-24 15:08 UTC · original

Ran the PR's own test at 560216b:

Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, wave32 only, 16 GB) driver 32.0.16.2124, Intel Core i5-12400F, 64 GB RAM, rustc 1.100.0 (0ef1bc386 2026-11-09) MSVC 14.44.35207, DXC 1.9.2609.5, debug build.

XCL_ADAPTER=nvidia cargo test -p xcl --lib rejected_create_shader_cache_session
1 passed; 0 failed; 0 ignored      (exit 0)

rejected_create_shader_cache_session_falls_back_to_working_in_memory_session passes here. I ran the test by name for the reason the earlier report gives: the whole d3d12x lib filter aborts with 0xc0000005 on unmodified main on this machine too, so it is not attributable to this PR.

This adds a Blackwell part (RTX 5070 Ti, driver 32.0.16.2124) on Windows 11 build 26200 to the RTX 3060 Ti report above.

Not tested: a title run that reaches the fallback (no unpacked title here), RDNA2/RDNA4 and Intel GPUs, Wine, release profile.

AI-assisted (OpenCode), model: DeepSeek V4.1 Flash 1017 - checked out the PR's head commit in a detached worktree, built it, ran the test, wrote this report; the worktree was not modified.

**@⁠Aniseto** on GitHub · 2026-11-24 15:08 UTC · [original](https://github.com/xcl-dev/xcl/pull/1211#issuecomment-7135530388) Ran the PR's own test at `560216b`: Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, wave32 only, 16 GB) driver 32.0.16.2124, Intel Core i5-12400F, 64 GB RAM, rustc 1.100.0 (0ef1bc386 2026-11-09) MSVC 14.44.35207, DXC 1.9.2609.5, debug build. ``` XCL_ADAPTER=nvidia cargo test -p xcl --lib rejected_create_shader_cache_session 1 passed; 0 failed; 0 ignored (exit 0) ``` `rejected_create_shader_cache_session_falls_back_to_working_in_memory_session` passes here. I ran the test by name for the reason the earlier report gives: the whole `d3d12x` lib filter aborts with 0xc0000005 on unmodified `main` on this machine too, so it is not attributable to this PR. This adds a Blackwell part (RTX 5070 Ti, driver 32.0.16.2124) on Windows 11 build 26200 to the RTX 3060 Ti report above. Not tested: a title run that reaches the fallback (no unpacked title here), RDNA2/RDNA4 and Intel GPUs, Wine, release profile. AI-assisted (OpenCode), model: **DeepSeek V4.1 Flash 1017** - checked out the PR's head commit in a detached worktree, built it, ran the test, wrote this report; the worktree was not modified.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-26 03:52 UTC · original

Re-verification on RTX 3060 Ti (Windows 11), new head merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.

Thanks!

— Devin

**@⁠DavidM1911** on GitHub · 2026-11-26 03:52 UTC · [original](https://github.com/xcl-dev/xcl/pull/1211#issuecomment-7182102130) Re-verification on RTX 3060 Ti (Windows 11), new head merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved. Thanks! — Devin
This discussion has been locked. Commenting is limited to contributors.
No description provided.