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

Open
andrewDoing wants to merge 2 commits from upstream-pr/2878 into main
andrewDoing commented 2026-11-26 20:43:48 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by andrewDoing on 2026-11-26T20:43:48Z.


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 (#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.
<!-- greyfinch-sync:ivall/xcl:issue:5516896189 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2878). Originally posted by [andrewDoing](https://github.com/andrewDoing) on 2026-11-26T20:43:48Z. --- 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](https://github.com/xcl-dev/xcl/pull/2332#issuecomment-7258940600) - 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 (#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 commented 2026-11-26 21:13:51 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Aniseto on 2026-11-26T21:13:51Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7203519363 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2878#issuecomment-7203519363). Originally posted by [Aniseto](https://github.com/Aniseto) on 2026-11-26T21:13:51Z. --- 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.
luckyteagirl commented 2026-11-27 06:29:07 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by luckyteagirl on 2026-11-27T06:29:07Z.

Review: COMMENTED


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).

<!-- greyfinch-sync:ivall/xcl:review:6084371926 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2878#pullrequestreview-6084371926). Originally posted by [luckyteagirl](https://github.com/luckyteagirl) on 2026-11-27T06:29:07Z. **Review:** COMMENTED --- 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](https://github.com/xcl-dev/xcl/blob/c1a8ecc7f15a0493ed5f270e0a1d7ad972611557/crates/xcl/src/hle/d3d12x/shader_cache_session.rs#L108-L117) · [Insertion](https://github.com/xcl-dev/xcl/blob/c1a8ecc7f15a0493ed5f270e0a1d7ad972611557/crates/xcl/src/hle/d3d12x/shader_cache_session.rs#L29-L39) · [D3D12 shader cache contract](https://microsoft.github.io/DirectX-Specs/d3d/ShaderCache.html#id3d12shadercachesession) AI-assisted review (GPT-6.2 Sol).
andrewDoing commented 2026-11-28 19:03:37 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by andrewDoing on 2026-11-28T19:03:37Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7244257855 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2878#issuecomment-7244257855). Originally posted by [andrewDoing](https://github.com/andrewDoing) on 2026-11-28T19:03:37Z. --- 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 commented 2026-11-29 16:03:12 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by andrewDoing on 2026-11-29T16:03:12Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7258578276 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2878#issuecomment-7258578276). Originally posted by [andrewDoing](https://github.com/andrewDoing) on 2026-11-29T16:03:12Z. --- 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.
Foniass commented 2026-12-01 09:06:45 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T09:06:45Z.


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 (1f4cf9ef, 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.

<!-- greyfinch-sync:ivall/xcl:comment:7306231805 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2878#issuecomment-7306231805). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T09:06:45Z. --- **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 (1f4cf9ef, 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.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2878:upstream-pr/2878'
git switch 'upstream-pr/2878'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/2878'
git switch 'upstream-pr/2878'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2878'
git switch 'upstream-pr/2878'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2878'
git switch 'main'
git merge --squash 'upstream-pr/2878'
git switch 'main'
git merge --ff-only 'upstream-pr/2878'
git switch 'main'
git merge 'upstream-pr/2878'
git push origin 'main'
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!2878
No description provided.