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

Merged
ksanjeev284 merged 1 commit from upstream-pr/1211 into main 2026-11-24 15:58:37 +00:00
ksanjeev284 commented 2026-11-24 13:17:36 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by ksanjeev284 on 2026-11-24T13:17:36Z.


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.
<!-- greyfinch-sync:ivall/xcl:issue:6582666098 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1211). Originally posted by [ksanjeev284](https://github.com/ksanjeev284) on 2026-11-24T13:17:36Z. --- 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.
copilot-pull-request-reviewer[bot commented 2026-11-24 14:06:04 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-24T13:17:46Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

<!-- greyfinch-sync:ivall/xcl:review:6039872435 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1211#pullrequestreview-6039872435). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/copilot-pull-request-reviewer%5Bbot%5D) on 2026-11-24T13:17:46Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
DavidM1911 commented 2026-11-24 14:06:40 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T13:47:10Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7133333620 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/1211#issuecomment-7133333620). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-24T13:47:10Z. --- 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.
upstream-sync closed this pull request 2026-11-24 16:06:02 +00:00
Aniseto commented 2026-11-24 16:06:54 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Aniseto on 2026-11-24T15:08:41Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7135530388 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/1211#issuecomment-7135530388). Originally posted by [Aniseto](https://github.com/Aniseto) on 2026-11-24T15:08:41Z. --- 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.
DavidM1911 commented 2026-11-26 04:07:45 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-26T03:52:47Z.


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

<!-- greyfinch-sync:ivall/xcl:comment:7182102130 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1211#issuecomment-7182102130). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-26T03:52:47Z. --- 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
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
xcl-dev/xcl!1202
No description provided.