Skip to content

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

Open
b3IKK wants to merge 1 commit into
xcl-dev:mainfrom
b3IKK:d3d12x/shader-cache-delete-on-destroy-aba
Open

b3IKK wants to merge 1 commit into
xcl-dev:mainfrom
b3IKK:d3d12x/shader-cache-delete-on-destroy-aba

Conversation

@b3IKK

@b3IKK b3IKK commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

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.

…estroy

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)
@Aniseto

Aniseto commented Nov 24, 2026

Copy link
Copy Markdown

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.

@b3IKK

b3IKK commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

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.

@DavidM1911

Copy link
Copy Markdown
Contributor

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!

@upipibi

upipibi commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

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

@thehollowedone

thehollowedone commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

merge-check
base: 9dfbe3e
head: 0003178
merge: clean (local merge tree 16667840d8df2e49d4476d7626c7272873ec7fa0)
build: cargo build --workspace --offline --locked -> ok
tests: cargo test --workspace --offline --locked --no-fail-fast -- --test-threads=4 -> 2885 passed, 2 failed, 51 ignored; SKIPPED: 24 (22 no wave64; 2 no heap windows, one requires XCL_HEAP_WINDOWS=1); failing: gpu::dxil::msaa_tests::gpu_direct_image_get_resinfo_d16 and gpu::recomp::pso::shader_cache_tests::console_mesh_caches_hlsl_compute_pass_in_memory_and_on_disk; both also fail in exact-base filtered runs.
review: The one-file change removes the shared key only when its current Arc still matches the releasing session’s store. The regression recreates the replacement-store sequence and confirms the newer value remains readable. The store lock is released before taking the registry lock. No default frame-path work added.
performance: Reasoned cost is limited to session release. Matched 60-second RTX 3080 Ti smokes held 60 presents per 2-second interval with zero device removals or crashes. Base/merge tree: 1662/1692 frames; peak commit 16288/16341 MB (single-run delta, not attributed to this change).
verdict: safe to merge — clean merge, successful build, no new test failures, and matched smoke runs passed.
hardware / tool and model: RTX 3080 Ti, driver 32.0.16.2140; Ryzen 7 9800X3D; Windows 11 Pro build 26300; rustc 1.99.1 / Codex GPT-6.2 Sol.

Regression run

main:

xcl-smoke v1
commit: 9dfbe3ea6653a9c76ef3ea0d66187a4b5407483b
gpu: NVIDIA GeForce RTX 3080 Ti
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1662 (PresentX 1662)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16288 MB

merged PR tree:

xcl-smoke v1
commit: 16667840d8df2e49d4476d7626c7272873ec7fa0
gpu: NVIDIA GeForce RTX 3080 Ti
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1692 (PresentX 1692)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16341 MB

@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) needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU labels Nov 30, 2026
@SzczepanGrela

SzczepanGrela commented Nov 30, 2026 •

Copy link
Copy Markdown

merge-check
base: 9dfbe3e
head: 0003178
merge: clean; staged merge tree 8df2ff5de0244d00548123970d13cc7d5156c6a1, no local production edits.
build: cargo build --workspace --release --target x86_64-pc-windows-gnu --offline --locked -j 3 --message-format=json-render-diagnostics -> ok on base and merge.
tests: cargo test --workspace --release --target x86_64-pc-windows-gnu --offline --locked -j 3 --no-fail-fast -- --test-threads=4 --nocapture -> exit 101 on both. On each, 41 of 42 harnesses completed with 136 passed, 12 failed, 20 ignored; the library harness exited 5 without a summary. These are completed-harness counts, not full-suite totals. Four SKIPPED notices on each: three missing D3D12 debug layer and one disabled heap-window path.
review: Read the complete one-file diff and current module. Registry lookup, Arc::ptr_eq and removal share one lock; the store-clear guard is released before that lock. Targeted stale-store regression is red on base and green on merge, as below. No blocking finding in this change itself.
performance: One pointer comparison on delete-on-destroy session release; no added draw/dispatch work. Reasoned, not timed.
verdict: not yet: this Wine run cannot establish full-suite non-regression because both library harnesses abort. Targeted fix verified; no PR-specific failure observed among the completed harnesses. A complete independent merge check remains needed.
hardware / tool and model: RX 9070 16 GB, RADV GFX1201 / Mesa 26.3.1-arch3.5; Ryzen 7 7700, 30 GiB RAM; CachyOS 7.3.6-3-cachyos; GE-Proton11-12 / Wine 11.0 Staging, vkd3d-proton 8293130ebe370b1+; Rust 1.97.1, Windows GNU release executables. Codex, GPT-6 (exact serving variant not exposed).

Tested

Targeted runner: Wine <unit.exe> hle::d3d12x::shader_cache_session::tests:: --nocapture --test-threads=1, then --test-threads=4.

Source / filter Threads 1, per run Threads 4, per run Repeats per setting
Unmodified base, existing cache-session module 1 passed, 0 failed 1 passed, 0 failed 1
Base plus verbatim PR regression, that test alone with --exact 0 passed, 1 failed 0 passed, 1 failed 3
Merged PR, cache-session module 2 passed, 0 failed 2 passed, 0 failed 3

Zero targeted skips. Negative controls fail at FindValue with 0x887A0002; the unchanged base production code loses the replacement store. The device/session test also exercises XCL's actual fallback after vkd3d-proton returns 0x80004001.

The same 12 completed-harness failures occur on both sides in d3d12_resource_and_sync, e2e, gpu_compute_e2e (six), gpu_two_pass_cache_e2e, pls_quota, predication_e2e and sparse_reinit. Both library runs report gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_2 failed before exiting 5; neither produces library totals. No cause or PR attribution claimed for those interruptions.

Separate source worktrees and final target directories; source hashes, test inventories and distinct executable hashes verified. An initial shared-target attempt reused the base executable; it was rejected and excluded from all PR results above.

Not tested

Native Windows/MSVC, retail titles, scripts/smoke.ps1, timing/FPS, or the library tests left unexecuted after the abort. XCL_SAMPLE_* unset; XCL_NETWORK=0.

AI use

Codex (GPT-6, exact serving variant not exposed) reviewed the diff, prepared the verbatim-test negative control, ran the comparisons, verified source/binary provenance and drafted this report. Publication authorized by the account owner.

@github-actions github-actions Bot added checks-disagree Merge-checks disagree (safe vs not yet); needs maintainer/3rd look and removed needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) labels Nov 30, 2026
@Pipodi

Pipodi commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

merge-check claim
head: 0003178

@Pipodi

Pipodi commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

merge-check
base: 9dfbe3e
head: 0003178
merge: clean (local merge tree 5dcb48bc75218a0a547cceb1b9823963b1b8be8b)
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> first run: the library harness aborted (0xc0000409, STATUS_STACK_BUFFER_OVERRUN, no summary), the other harnesses 148 passed, 0 failed, 20 ignored. The library harness alone rerun: 2738 passed, 1 failed, 31 ignored, so 2886 passed, 1 failed, 51 ignored in all; failing: gpu::dxil::msaa_tests::gpu_direct_image_get_resinfo_d16 (also fails on main 9dfbe3e, fixed by #3513). New test shader_cache_session::tests::stale_delete_on_destroy_does_not_evict_newer_disk_store passes on the merge and fails with the production hunk reverted (uncommitted; FindValue returns 0x887A0002). 24 SKIPPED: 22 "no wave64", two_pass_binds_set_the_shared_view_heap (no heap windows) and pso_measurement_compiles_an_exact_synthetic_record (cannot disable the driver cache).
disagreement of the two earlier checks: thehollowedone lists console_mesh_caches_hlsl_compute_pass_in_memory_and_on_disk as failing on the merge and on base; SzczepanGrela (Wine, RADV) could not get library totals because the library harness aborts. Here console_mesh_caches_hlsl_compute_pass_in_memory_and_on_disk passes (in the library rerun, and also on the merge for #1781), so it is not caused by this PR and is not a failure on this setup. The library-harness abort is not specific to this PR: it did not repeat on the rerun of the same binary and was reported on unmodified main by DavidM1911 on this PR (0xc0000005 under parallel scheduling); the PR changes only the release path of a fallback shader cache session. The Wine run therefore does not block: its targeted result (test red on base, green on merge) matches mine.
review: read the whole diff (crates/xcl/src/hle/d3d12x/shader_cache_session.rs, +50 -1). release() now removes the shared disk_stores key only when the entry is still this session store (Arc::ptr_eq), under one lock held for the get and the remove; the store lock is dropped before it. This closes the sequence where an older session, released late, evicts a newer store of the same (id, version). No blocker.
performance: one pointer comparison when a delete-on-destroy session is released; nothing in the frame path.
verdict: safe to merge
hardware / tool and model: NVIDIA RTX 4090, driver 621.40; i9-13900K; Windows 11 Pro 10.0.26300; rustc 1.100.0; debug. Claude Code, Claude Opus 5.5.

@brainhay5

Copy link
Copy Markdown

merge-check claim
head: 0003178

Claiming for a tie-break: the three checks on this head disagree because one was run under Wine (x86_64-pc-windows-gnu), where both library harnesses abort. A native Windows run on the same head should settle whether that verdict reflects the PR or the environment.

@brainhay5

Copy link
Copy Markdown

merge-check
base: d0832e6
head: 0003178
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2890 passed, 1 failed, 51 ignored; 29 SKIPPED lines; failing: test_title_runs_and_game_folder_is_untouched — also fails on the base alone with the same command, verified by running it there
review: one file (+50), and the change is the right shape: release now removes the disk store only when the entry is still the same Arc (Arc::ptr_eq), so a session that is stale (its store already replaced by a newer session for the same identifier/version) can no longer evict the newer one. The lock is taken once and the check and removal happen under it, so there is no window between them. The added test builds exactly that ordering — s1 and s2 delete-on-destroy, s1 dropped, s3 opens a fresh store and writes, s2 dropped — and asserts s3's value survives; that test fails without the change. Contained, no unrelated edits, no new dependency.
performance: none in a hot path — the guard runs once per session release, and ptr_eq is a pointer comparison. No per-frame or per-draw cost.
verdict: safe to merge
comment on the disagreement above: this head has three checks and two verdicts. The not yet came from a run under Wine with --target x86_64-pc-windows-gnu, where the check itself reports that both library harnesses abort — so it could not establish non-regression, which is a statement about that environment rather than this PR. On native Windows the full suite completes (2,774 lib tests present, 2,890 passed overall) and the only failure is the one that fails on base regardless. That matches the two safe to merge verdicts above.
hardware / tool and model: RTX 5070 Ti 16 GB, driver 610.88 (32.0.16.1088); Ryzen 7 5800X3D, 64 GB; Windows 11 22631; OpenCode agent, DeepSeek V4.1 Flash 1017

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head 0003178

No open or merged PR makes the same change: main's release in shader_cache_session.rs still removes the disk_stores() entry by key alone. #2878 and #2332 edit the same file (shared memory-mode sessions, StoreValue capacity) but keep that removal as it is. The new test fails without the Arc::ptr_eq guard (stale s2 evicts s3's store).
No problems found in the diff.
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 checks-disagree Merge-checks disagree (safe vs not yet); needs maintainer/3rd look gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) needs:amd-test Needs a test report or merge-check on an AMD GPU

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants