D3D12.X: guard disk_stores removal on ShaderCacheSession SetDeleteOnDestroy #1601

Open
github-bot wants to merge 1 commit from github-bot/gh-1601 into main AGit
Owner

@⁠b3IKK on GitHub · 2026-11-24 18:07 UTC · original
b3IKK:d3d12x/shader-cache-delete-on-destroy-aba → main · +50 −1 · 1 files · 1 commits · open

In shader_cache_session::release, when delete_on_destroy was set on a disk-mode session, disk_stores().lock().unwrap().remove(&k) removed key k unconditionally. If two sessions S1 and S2 shared the same store Arc1 with SetDeleteOnDestroy(), releasing S1 removed k, S3 opened a fresh store Arc2 for k and cached shaders in it, and releasing S2 later evicted S3's newer Arc2 from disk_stores().

This removes k from disk_stores() only when the currently stored Arc is still Arc::ptr_eq to boxed.store.

What is in it

  • crates/xcl/src/hle/d3d12x/shader_cache_session.rs: check Arc::ptr_eq(cur, &boxed.store) before removing k from disk_stores(); add unit test stale_delete_on_destroy_does_not_evict_newer_disk_store (verified failing with DXGI_ERROR_NOT_FOUND before the fix).

Tested

  • hardware (GPU + driver, CPU), Windows build, Rust version, debug / release: NVIDIA GeForce RTX 5080 (driver 32.0.16.1088), AMD Ryzen 9 9950X3D, Windows 11 10.0.26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.9.2609.5, debug (scripts/test.ps1) and release (scripts/smoke.ps1)
  • .\scripts\test.ps1 (cargo build --workspace + cargo test --workspace -- --test-threads=4): 777 passed, 0 failed, 41 ignored (SKIPPED GPU tests: 2 no wave64 — gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask, gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware; 1 no heap windows — heap_window_out_of_memory_falls_back_to_the_switch_form)
  • cargo test -p xcl --lib shader_cache_session: 2 passed, 0 failed (stale_delete_on_destroy_does_not_evict_newer_disk_store failed before the fix)

Regression run

main:

xcl-smoke v1
commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1226 (PresentX 1226)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15341 MB

PR:

xcl-smoke v1
commit: 0003178b8c8bd642a8916b4687e8698a5afe99cc
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1642 (PresentX 1642)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14606 MB

Not tested

  • AMD GPUs and native wave64 hardware
  • other titles (Minecraft Preview, Unicorn Overlord, Fortnite, XDefiant) and Linux / Wine

AI use

  • OpenCode, Gemini 4 Neon: audited shader_cache_session.rs, wrote the fix and unit test, ran the test suite and scripts/smoke.ps1 regression runs, and drafted this PR description.
**@⁠b3IKK** on GitHub · 2026-11-24 18:07 UTC · [original](https://github.com/xcl-dev/xcl/pull/1601) `b3IKK:d3d12x/shader-cache-delete-on-destroy-aba` → `main` · +50 −1 · 1 files · 1 commits · open In `shader_cache_session::release`, when `delete_on_destroy` was set on a disk-mode session, `disk_stores().lock().unwrap().remove(&k)` removed key `k` unconditionally. If two sessions `S1` and `S2` shared the same store `Arc1` with `SetDeleteOnDestroy()`, releasing `S1` removed `k`, `S3` opened a fresh store `Arc2` for `k` and cached shaders in it, and releasing `S2` later evicted `S3`'s newer `Arc2` from `disk_stores()`. This removes `k` from `disk_stores()` only when the currently stored `Arc` is still `Arc::ptr_eq` to `boxed.store`. **What is in it** - `crates/xcl/src/hle/d3d12x/shader_cache_session.rs`: check `Arc::ptr_eq(cur, &boxed.store)` before removing `k` from `disk_stores()`; add unit test `stale_delete_on_destroy_does_not_evict_newer_disk_store` (verified failing with `DXGI_ERROR_NOT_FOUND` before the fix). **Tested** - hardware (GPU + driver, CPU), Windows build, Rust version, debug / release: NVIDIA GeForce RTX 5080 (driver 32.0.16.1088), AMD Ryzen 9 9950X3D, Windows 11 10.0.26300, Rust 1.100.0 (`stable-x86_64-pc-windows-msvc`), DXC 1.9.2609.5, debug (`scripts/test.ps1`) and release (`scripts/smoke.ps1`) - `.\scripts\test.ps1` (`cargo build --workspace` + `cargo test --workspace -- --test-threads=4`): 777 passed, 0 failed, 41 ignored (SKIPPED GPU tests: 2 `no wave64` — `gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware`; 1 `no heap windows` — `heap_window_out_of_memory_falls_back_to_the_switch_form`) - `cargo test -p xcl --lib shader_cache_session`: 2 passed, 0 failed (`stale_delete_on_destroy_does_not_evict_newer_disk_store` failed before the fix) **Regression run** main: ``` xcl-smoke v1 commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3 gpu: NVIDIA GeForce RTX 5080 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1226 (PresentX 1226) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15341 MB ``` PR: ``` xcl-smoke v1 commit: 0003178b8c8bd642a8916b4687e8698a5afe99cc gpu: NVIDIA GeForce RTX 5080 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1642 (PresentX 1642) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14606 MB ``` **Not tested** - AMD GPUs and native wave64 hardware - other titles (Minecraft Preview, Unicorn Overlord, Fortnite, XDefiant) and Linux / Wine **AI use** - OpenCode, Gemini 4 Neon: audited `shader_cache_session.rs`, wrote the fix and unit test, ran the test suite and `scripts/smoke.ps1` regression runs, and drafted this PR description.
In shader_cache_session::release, when `delete_on_destroy` was set on a
disk-mode session, `disk_stores().lock().unwrap().remove(&k)` removed
key `k` unconditionally. If two sessions S1 and S2 shared the same
store Arc1 with `SetDeleteOnDestroy()`, dropping S1 removed `k`, S3
opened a fresh store Arc2 for `k`, and then dropping S2 evicted S3's
newer Arc2 from `disk_stores()`.

Only remove `k` from `disk_stores()` when the currently mapped `Arc` is
still `Arc::ptr_eq` to `boxed.store`.

Assisted-by: OpenCode (Gemini 4 Neon)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:58:57 +00:00
Author
Owner

@⁠Aniseto on GitHub · 2026-11-24 18:14 UTC · original

Ran the shader_cache_session module at 0003178. The PR adds no test of its own, so this is a regression check:

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
2 passed; 0 failed; 0 ignored      (exit 0)

Both tests pass, and this machine takes the path the PR guards: the run logs CreateShaderCacheSession failed on the PC runtime (0x80070057) - using an in-memory session, so the in-memory session whose disk_stores registration the PR touches is the one in use here. That makes it a real path rather than a mocked one, though by itself it does not prove the set-delete-on-destroy ordering; that needs a driver that accepts the session.

Not tested: the destroy path on a driver that accepts the session (this one refuses it), RDNA2/RDNA4 and Intel GPUs, Wine, release profile.

AI-assisted (OpenCode), model: DeepSeek V4.1 Flash 1017 - built the PR's head commit from a clean tree and ran the tests on this machine; no local changes were made.

**@⁠Aniseto** on GitHub · 2026-11-24 18:14 UTC · [original](https://github.com/xcl-dev/xcl/pull/1601#issuecomment-7140368979) Ran the `shader_cache_session` module at `0003178`. The PR adds no test of its own, so this is a regression check: 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 2 passed; 0 failed; 0 ignored (exit 0) ``` Both tests pass, and this machine takes the path the PR guards: the run logs `CreateShaderCacheSession failed on the PC runtime (0x80070057) - using an in-memory session`, so the in-memory session whose `disk_stores` registration the PR touches is the one in use here. That makes it a real path rather than a mocked one, though by itself it does not prove the set-delete-on-destroy ordering; that needs a driver that accepts the session. Not tested: the destroy path on a driver that accepts the session (this one refuses it), RDNA2/RDNA4 and Intel GPUs, Wine, release profile. AI-assisted (OpenCode), model: **DeepSeek V4.1 Flash 1017** - built the PR's head commit from a clean tree and ran the tests on this machine; no local changes were made.
Author
Owner

@⁠b3IKK on GitHub · 2026-11-24 18:44 UTC · original

Thanks for testing @⁠Aniseto! Quick note: one of those 2 tests (\stale_delete_on_destroy_does_not_evict_newer_disk_store) is the regression test added by this PR — it directly exercises the fallback \SetDeleteOnDestroy\ / \disk_stores()\ ABA eviction path (which is only used by the fallback session itself) and fails without the \Arc::ptr_eq\ check.

**@⁠b3IKK** on GitHub · 2026-11-24 18:44 UTC · [original](https://github.com/xcl-dev/xcl/pull/1601#issuecomment-7141082658) Thanks for testing @⁠Aniseto! Quick note: one of those 2 tests (\stale_delete_on_destroy_does_not_evict_newer_disk_store\) is the regression test added by this PR — it directly exercises the fallback \SetDeleteOnDestroy\ / \disk_stores()\ ABA eviction path (which is only used by the fallback session itself) and fails without the \Arc::ptr_eq\ check.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 20:21 UTC · original

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

  • cargo test -p xcl --lib: all passed, 0 failed, ~22 ignored. (Intermittent 0xc0000005 abort under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified main.)

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-24 20:21 UTC · [original](https://github.com/xcl-dev/xcl/pull/1601#issuecomment-7143434026) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~22 ignored. (Intermittent 0xc0000005 abort under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified `main`.) Thanks!
Author
Owner

@⁠upipibi on GitHub · 2026-11-26 16:08 UTC · original

NVIDIA test report for 0003178: RTX 3070 8 GB (Ampere, driver 616.56), Windows 11 26100, Rust 1.100.0, debug. Head tested as-is on its base 9e3831e.

  • cargo test -p xcl --lib -- --skip hle::xaudio2 --test-threads=4: 719 passed, 0 failed, 21 ignored; 2 SKIPPED (no wave64: gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware), neither in a file this PR changes.
  • hle::d3d12x::shader_cache_session::tests::stale_delete_on_destroy_does_not_evict_newer_disk_store with --exact --test-threads=1 --nocapture, 3 runs: 3/3 passed, 0 SKIPPED.
    Lib tests only; no title run.
    AI-assisted (Claude Code, Claude Opus 5.5).
**@⁠upipibi** on GitHub · 2026-11-26 16:08 UTC · [original](https://github.com/xcl-dev/xcl/pull/1601#issuecomment-7197233563) NVIDIA test report for `0003178`: RTX 3070 8 GB (Ampere, driver 616.56), Windows 11 26100, Rust 1.100.0, debug. Head tested as-is on its base `9e3831e`. - `cargo test -p xcl --lib -- --skip hle::xaudio2 --test-threads=4`: 719 passed, 0 failed, 21 ignored; 2 SKIPPED (`no wave64`: gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware), neither in a file this PR changes. - `hle::d3d12x::shader_cache_session::tests::stale_delete_on_destroy_does_not_evict_newer_disk_store` with `--exact --test-threads=1 --nocapture`, 3 runs: 3/3 passed, 0 SKIPPED. Lib tests only; no title run. AI-assisted (Claude Code, Claude Opus 5.5).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1601/head:github-bot/gh-1601'
git switch 'github-bot/gh-1601'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1601'
git switch 'github-bot/gh-1601'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1601'
git switch 'github-bot/gh-1601'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1601'
git switch 'main'
git merge --squash 'github-bot/gh-1601'
git switch 'main'
git merge --ff-only 'github-bot/gh-1601'
git switch 'main'
git merge 'github-bot/gh-1601'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.