Skip to content

D3D12.X: share fallback memory shader cache sessions - #2878

Draft
andrewDoing wants to merge 2 commits into
xcl-dev:mainfrom
andrewDoing:fix/shared-memory-shader-cache
Draft

andrewDoing wants to merge 2 commits into
xcl-dev:mainfrom
andrewDoing:fix/shared-memory-shader-cache

Conversation

@andrewDoing

@andrewDoing andrewDoing commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Fallback D3D12 MEMORY shader-cache sessions with the same identifier and version previously used separate stores. A second live session could not find a value written by the first. Share the store while any matching session remains alive, then discard it after the last session closes, matching the native behavior measured on this machine.

What is in it

  • crates/xcl/src/hle/d3d12x/shader_cache_session.rs: share matching memory-session stores, serialize creation and last-session cleanup, reject duplicate stores without replacing existing bytes, and test lifetime, isolation and duplicate handling.

Tested

  • NVIDIA RTX 5070, driver 616.92; Ryzen 7 5700X3D; Windows build 26300.10075; Rust 1.100.0 MSVC, debug; SDK DXC/DXIL 1.8.2502.11.
  • At the previous head c1a8ecc7, a local native-D3D12 versus fallback probe: before the fix, a live second fallback session returned DXGI_ERROR_NOT_FOUND where native returned the 13-byte value. After the fix, both returned the value and a fresh session after the final release missed it. An early SetDeleteOnDestroy did not prevent the live peer reading the value. One post-fix parity run passed; this probe is not included in the PR.
  • On the updated head 1f4cf9ef, both focused fallback tests passed with zero skips. The original session and a second live session each received DXGI_ERROR_ALREADY_EXISTS when trying to replace a key. The surviving session read the original bytes.
  • A separate native D3D12 probe explicitly selected the RTX 5070. The original session and its same-ID peer both returned 0x887a0036 on duplicate StoreValue, and the peer read back the original byte. This is also relevant to the replacement assumptions in the independently proposed capacity fix. Native results on #2332
  • Fresh full workspace runs with separate writable DXIL caches and debug targets, cargo test --workspace --locked --offline --no-fail-fast -- --test-threads=4: head 1f4cf9ef had 1,442 passed, 5 failed, 47 ignored. Base 8b957bec had 1,441 passed, 5 failed, 47 ignored. Each logged 26 GPU skips (21 wave64, three unsupported per-lane forms, one driver-cache option, one heap-windows feature).
  • Both revisions failed the same four RTX 50 DXIL fuzz batches (DXIL GPU fuzz tests reproducibly fail with E_OUTOFMEMORY on RTX 5060 #1905) and the synthetic-title DRED test. The pipeline-submit test that failed on the earlier head passed in both fresh suites.

Regression run

The same game image and requested 60-second duration were used with clean release builds, separate empty data and shader cache directories, and networking disabled. Both processes exited during startup with zero presents. The retail regression gate remains outstanding and the PR remains a draft.

Main:

xcl-smoke v1
commit: 8b957bec6f82495aec940944c6bf47faa02db590
gpu: NVIDIA GeForce RTX 5070
title: cc96ddfb
seconds: 60
exit: 0xc0000005
frames shown: none logged (the run did not reach its end)
presents per 2 s (last 3): 0
device removals: 1
crashes: 2
peak commit: 1753 MB

PR:

xcl-smoke v1
commit: 1f4cf9ef8b560974f0abc7d07f800af3f61d121c
gpu: NVIDIA GeForce RTX 5070
title: cc96ddfb
seconds: 60
exit: 0xc0000005
frames shown: none logged (the run did not reach its end)
presents per 2 s (last 3): 0
device removals: 1
crashes: 2
peak commit: 761 MB

Not tested

  • Rendered retail gameplay, other GPU vendors, conflicting-version behavior, and long-running title performance.

AI use

  • OpenAI Codex with GPT-6.2 Astra investigated, implemented and tested the change, and a second GPT-6.2 Astra agent reviewed it. Codex coordinated and prepared the PR. OpenAI Codex addressed the duplicate-key review and reran the matched suites and retail attempts. GPT-6.2 Sol ran the native duplicate-key probe and updated the results.

@Aniseto

Aniseto commented Nov 26, 2026

Copy link
Copy Markdown

Ran the shader-cache session tests at c1a8ecc7 (draft PR) on an NVIDIA Blackwell desktop part:

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 shader_cache_session -- --test-threads=1
2 passed; 0 failed; 0 ignored; 0 measured; 1344 filtered out      (exit 0)

Both tests pass: memory_sessions_share_entries_until_the_last_release and rejected_create_shader_cache_session_falls_back_to_working_in_memory_session. They are CPU-side tests of the fallback store and do not open a D3D12 device. The author ran the same two tests on an RTX 5070 (driver 616.92, DXC 1.8.2502.11); this adds a desktop RTX 5070 Ti on driver 32.0.16.2124 with DXC 1.9.2609.5. I did not repeat the author's native-vs-fallback probe or the full-suite comparison.

Not tested: the native D3D12 comparison probe, the full workspace suite and its known failures, a paired smoke run, AMD and Intel GPUs, native wave64 hosts, Wine, release profile, game data.

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

rootw0rm pushed a commit to rootw0rm/xcl that referenced this pull request Nov 26, 2026

@luckyteagirl luckyteagirl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the shared MEMORY store reject duplicate keys before modifying the value? Native ID3D12ShaderCacheSession::StoreValue specifies DXGI_ERROR_ALREADY_EXISTS for an existing key. The fallback already overwrote same-session duplicates, but sharing the store makes a second live session able to replace the first session's cached bytes.

I compiled the exact parent and PR fallback modules into a Windows CPU harness and opened two same-ID MEMORY sessions in each. A stored byte A in the first session, then a store of B under the same key in the second, gave S_OK for the second store on both revisions. Reading through the first session returned A on the parent and B on the PR head. The native API contract calls for rejection of the duplicate and preservation of A in the shared cache. The harness used no native D3D12 device.

Shared-store lookup · Insertion · D3D12 shader cache contract

AI-assisted review (GPT-6.2 Sol).

Rogeriomatador added a commit to CaveiraBoone/NexusVI that referenced this pull request Nov 27, 2026
Import public XCL PR xcl-dev#2878, by @andrewDoing.
Source: xcl-dev#2878
Original head: c1a8ecc
GPL-2.0-only; original attribution retained. Imported for authorized synthetic test validation; not yet independently tested.

Assisted-by: ChatGPT (GPT-6.2)
@andrewDoing

Copy link
Copy Markdown
Contributor Author

Addressed the duplicate-key review in 1f4cf9ef. The fallback checks for an existing key while holding the shared store mutex and returns DXGI_ERROR_ALREADY_EXISTS before changing the bytes or the store's size accounting.

The lifetime regression now tries to replace the first value both through its original session and through a second live session with the same ID and version. Both calls returned the expected HRESULT. After the first session closed, the second still read the original six bytes. The two focused shader-cache tests passed on Windows/Ryzen 7 5700X3D with no skips, including the device-backed forced-fallback path. This revision has focused test coverage only; the draft is still awaiting the required clean retail smoke comparison.

AI assistance: OpenAI Codex (GPT-6) implemented and tested the correction.

@andrewDoing

Copy link
Copy Markdown
Contributor Author

The duplicate-key review is addressed in 1f4cf9ef. The focused tests passed there, including writes from a second live session, and the matched local suites had the same failure set.

The outstanding item is the runtime regression check. Our paired smoke attempts both stopped during title startup before the first present. If someone has a title that renders on current main, could you run scripts/smoke.ps1 on clean main and this draft's clean head using the same title, GPU and run duration, and share both generated xcl-smoke blocks here? A compatible title is enough for the regression check, even if it never opens a fallback memory shader-cache session.

@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:shaders Shader cache, PSO compilation, pipeline libraries, precompilation gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) labels Nov 29, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head 1f4cf9e

The first commit, sharing MEMORY-mode fallback stores between live sessions with the same identifier and version, is not in any other PR or on main.
The second commit (1f4cf9e, Store::insert returning DXGI_ERROR_ALREADY_EXISTS without replacing the value) makes the same duplicate-key change as #2332, which was opened first. #2332 also returns DXGI_ERROR_CACHE_FULL, where this PR still returns S_OK and drops the entry. Agree with #2332 on which PR keeps that part, and drop it from the other.
The second commit's subject has no area prefix ('D3D12.X: ...').
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:shaders Shader cache, PSO compilation, pipeline libraries, precompilation gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants