Skip to content

D3D12.X: check shader cache capacity before copying entries - #2332

Draft
storrmzz wants to merge 1 commit into
xcl-dev:mainfrom
storrmzz:shaders/cache-capacity-check
Draft

storrmzz wants to merge 1 commit into
xcl-dev:mainfrom
storrmzz:shaders/cache-capacity-check

Conversation

@storrmzz

@storrmzz storrmzz commented Nov 25, 2026 •

Copy link
Copy Markdown

Keep the fallback shader-cache store within its 32 MiB key/value budget before allocating or copying either input. Address the native StoreValue feedback: existing keys return DXGI_ERROR_ALREADY_EXISTS, without replacing their values or changing capacity accounting.

What is in it

  • Borrow inputs until duplicate and overflow-safe capacity checks pass. Duplicate detection, capacity accounting and insertion run under the same store lock; no replacement/shrinking path remains.
  • Regression tests for oversized new entries, exact capacity, duplicate values and duplicates in a full fallback store; README behavior updated.
  • The previous early size rejection now follows duplicate detection, matching the native measurements below. Scope remains capacity guarding, not cache session lifetime or eviction policy.

Tested

  • Windows 11 Pro build 26300, AMD Radeon 780M driver 32.0.31033.3, Ryzen 7 8840HS, Rust 1.100.0 MSVC, debug builds.
  • PR 225c039ab26c025944091419dafc900a02b33cc9, unchanged main 53e85fb124eae624641e9884517e4f3c4a7d8794.
  • cargo build --workspace --jobs 2: passed on PR.
  • cargo test -p xcl --lib shader_cache_session --jobs 2 -- --test-threads=1 --nocapture: 5 passed, 0 failed, 0 ignored, 0 skipped on PR.
  • Red check: the corrected four capacity tests on prior head b2f681a157028116009dfcc4ef94671c80a960f4 produced 2 passed / 2 failed. Both duplicate regressions failed before the fix.
  • cargo test --workspace --no-fail-fast --jobs 2 -- --test-threads=4 --nocapture: PR 2793 passed, 4 failed, 49 ignored; 12 distinct explicit SKIPPED messages; unchanged main 2789 passed, 4 failed, 49 ignored; 12 distinct explicit SKIPPED messages. All 41 Cargo test/doc-test targets completed on each revision. Explicit skips are not GPU coverage.
  • git diff --check: passed.

The same four failed tests were reproduced on unchanged main, with the same assertions. The initial parallel main run additionally aborted in the UMA coherent-window restore path (Windows error 487, process exit 130088963); its library target was incomplete. Its other 40 targets finished with 138 passed, 1 failed and 20 ignored; 11 distinct SKIPPED messages were recorded across that partial run. The main counts above come from the subsequent complete repeat, not that partial run. The PR run completed without this abort; this change does not claim to fix it.

Full-suite failures (see paired results above):

  • gpu::dxil::compact_tests::gpu_compact_form_with_micro_blocks_and_literal_table_runs_as_the_plain_form
  • gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1
  • hle::d3d12x::standin::tests::concurrent_shell_miss_reuses_winner_and_releases_loser_pipeline
  • two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs

Native D3D12 probe, directly using D3D12CreateDevice / ID3D12Device9::CreateShaderCacheSession, without XCL hooks: with a 32 MiB MEMORY cache and a 32 MiB DISK cache, a duplicate with a nonempty oversized value returned 0x887a0036. With DISK filled until another 1 MiB entry returned 0x887a0034, the same-sized duplicate still returned 0x887a0036; the original bytes remained readable. A new oversized key returned 0x887a0034. This agrees with the Microsoft StoreValue contract. Native MEMORY eviction differs from the fallback's fixed total budget: a failed large new insertion could evict an earlier key. No identical eviction behavior is claimed.

Compatibility with #2878
Reviewed #2878 at 1f4cf9ef8b560974f0abc7d07f800af3f61d121c. Both reject duplicate keys. Their insert edits overlap and need a textual conflict resolution retaining this PR's capacity error; session-sharing/lifetime changes are not included here.

A temporary local combination of this PR with #2878's session-sharing file, resolving the overlap to retain the capacity checks and both sets of tests, passed the same focused shader_cache_session command: 6 passed, 0 failed, 0 ignored, 0 skipped. This is an uncommitted integration check, not the published PR or a full integration-suite result; the original PR tree was restored afterward.

Explicit SKIPPED messages from the paired full runs

Regression run
Not run: no owned, runnable retail title is available. This PR remains a draft; no xcl-smoke blocks are fabricated.

Not tested

  • Retail-title startup, rendered frames, performance or memory-use improvements; no retail compatibility or FPS claim.
  • NVIDIA, Wine/vkd3d-proton, or a full integration suite with D3D12.X: share fallback memory shader cache sessions #2878.
  • Broader native argument-validation parity: native rejects zero-length values; the fallback's existing zero-length acceptance is outside this capacity fix and remains unchanged. An explicit 1 KiB native MEMORY descriptor was rejected with E_INVALIDARG; native measurements above used valid 32 MiB descriptors.

AI use
Created with AI assistance from OpenAI Codex (GPT-6).

@SlopTart

Copy link
Copy Markdown

Tested: current PR head merged onto current origin/main (clean), Linux (Arch, kernel 7.2.15), Mesa 26.2.5 RADV, Radeon RX 7900 XT (NAVI31), cargo target x86_64-pc-windows-gnu run under wine-11.0 (Proton), rustc 1.94.0, vkd3d-proton 3.1 with the XCL patch, official MS DXC (binaries 2026-09-29).

  • gpu_ suite (--release --locked, --test-threads=2): 144 passed / 3 failed / 1 ignored, same three baseline failures as plain origin/main on this rig (rig's known baseline: fuzz seed 1003 of DXIL fuzz tests: fuzz_validate_and_gpu_1 fails on AMD (seed 722 and others, RDNA2-4), so the default suite is red there #2115, gpu_nonfused_mad_and_mac_prevent_fma_contraction, gpu_depth_buffer_created_for_unordered_access_is_placed).
  • The four new tests hle::d3d12x::shader_cache_session::tests::cache_capacity_* (oversized entry rejected, exact-limit accepted then next key rejected, failed replacement preserves previous value, replacements accounted in a full store): all 4 pass on this lane (--exact module filter, --test-threads=1), including through the real vkd3d-proton D3D12_GPU_PRIVATE_VIRTUAL_ADDRESS session path this driver provides.

Caveat, one-off: the very first suite run on this head died mid-suite with radv/amdgpu: The CS has been rejected (-14) and D3D12 device removed: 0x887a0005 (test process exit 5, no individual failure recorded, no GPU reset in dmesg). A second full suite run on the same head was fully clean, and this rig has produced the same kernel-side CS reject under heavy host memory pressure (it co-hosts an ~80 GB pinned model server). No crash reproduces; mentioning it only for completeness, evidence leans environmental rather than this change.

AI use: Hermes agent (local Qwen-class) ran both machines and drafted this; I checked it before posting.

@luckyteagirl

Copy link
Copy Markdown
Contributor

Independent focused verification of exact PR head ab861b8196779f65209de31eef1e5f97ee1eb6d8 on Windows 11 build 26200, AMD Radeon RX 6800M (driver 30.0.13002.13003), Rust 1.99 MSVC, DXC/DXIL 1.9.2609.5.

Tested

  • Clean checkout: cargo test --locked -p xcl --lib shader_cache_session::tests:: -- --test-threads=1 --show-output: 5 passed, 0 failed, 0 ignored, 0 explicit skips. The four capacity tests cover an oversized entry, exact-limit insertion, failed replacement preserving the old value, and replacement/shrinking accounting.
  • The fifth test used a D3D12 device and logged CreateShaderCacheSession failed on the PC runtime (0x80070057) – using an in-memory session; it checked miss handling, store and exact readback, buffer-too-small behavior, parent-device identity, and delete-on-destroy cleanup. The clean fixture uses the default device, so this run does not identify which adapter it used.
  • Local test-only selector change: XCL_ADAPTER=6800M chose and printed shader cache test adapter: AMD Radeon RX 6800M; the same five tests passed with 0 failures and 0 explicit skips. I restored the selector change; the PR checkout is clean.

I did not reproduce a host cache-session refusal beyond the fixture's deliberately invalid flags, run a full workspace suite, or run a title smoke pair on this PR.

AI use: OpenAI Codex (GPT-6) ran the tests and prepared this report.

@DavidM1911

Copy link
Copy Markdown
Contributor

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

Thanks!

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

@Prime1997 Prime1997 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Good within the targeted test scope; retain for integration. Checks the capacity before copying shader-cache entries, preserves a previous value when replacement cannot fit, and accounts for replacements correctly.

Reviewed PR head ab861b8196779f65209de31eef1e5f97ee1eb6d8. Tested an isolated, uncommitted merge-tree integration with latest main b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7, tree 2c318f747df7b6edd4d82517db51991d57374d37; this is not a clean PR-head run. Integration source overlay SHA-256: eeeb73b447215fc122aff8186c907d88cc4ba0562448502f1012bd6769c666d5.

Measured: 4 passed, 0 failed, 0 ignored, 0 skipped. Exact selected filters, each run in a fresh process:

  • hle::d3d12x::shader_cache_session::tests::cache_capacity_rejects_an_oversized_entry
  • hle::d3d12x::shader_cache_session::tests::cache_capacity_accepts_exact_limit_and_rejects_another_key
  • hle::d3d12x::shader_cache_session::tests::cache_capacity_failed_replacement_preserves_the_previous_value
  • hle::d3d12x::shader_cache_session::tests::cache_capacity_accounts_for_replacements_in_a_full_store

Build: cargo test --locked --offline -p xcl --lib --no-run --message-format=json --target-dir <isolated-target>. Run each: <test-exe> <exact-filter> --exact --test-threads=1 --nocapture. Private target/executable paths are placeholders. Windows 11 Pro 26200, i5-10400, 32 GiB, Rust 1.100.0 MSVC debug; private temporary/cache paths, two low-priority build jobs, 90-second per-test bound.

Scope: Four CPU boundary and replacement-accounting fixtures. No actual title cache workload or whole-process memory bound was measured. No full suite, retail run, sustained memory pressure or performance benefit is established. Passing these fixtures is not merge certification.

AI use: Codex (GPT-6) inspected the changes and fixtures, ran the checks and verified raw receipts. Optional temporary Discord for coordinating contributor work, testing and comparing results.

@Prime1997 Prime1997 mentioned this pull request Nov 26, 2026
@storrmzz
storrmzz force-pushed the shaders/cache-capacity-check branch from ab861b8 to b2f681a Compare November 29, 2026 14:38
@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:docs-ci Documentation, scripts, workflows, repo governance 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-pr-check Failing the PR description check (CONTRIBUTING.md) labels Nov 29, 2026
@andrewDoing

Copy link
Copy Markdown
Contributor

Tested on an RTX 5070 (616.92), Ryzen 7 5700X3D, Windows 11 26300.10075, using a standalone native D3D12 probe. I opened two simultaneous MEMORY sessions with the same identifier and version. The initial StoreValue succeeded. A second store of the same key with different bytes returned DXGI_ERROR_ALREADY_EXISTS (0x887a0036) both through the original session and through its peer. The peer then read back the original byte. This matches the documented StoreValue contract. Microsoft's D3D12 shader-cache spec

On the current #2332 head b2f681a1, the fallback capacity tests expect an existing value to be replaced or shrunk. That expectation conflicts with the native result and with the duplicate-key behavior in #2878. The capacity guard can still be tested on new keys without expecting a live entry to be replaced.

Not tested on the #2332 runtime, Wine, AMD or a retail title. OpenAI Codex with GPT-6.2 Sol ran the native probe and prepared the report.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head 225c039

#2878 also changes Store::insert in shader_cache_session.rs so a duplicate key returns DXGI_ERROR_ALREADY_EXISTS instead of replacing the value, so the two PRs will conflict there. The approaches differ: this PR also returns DXGI_ERROR_CACHE_FULL when the 32 MiB cap is exceeded, while #2878 still returns S_OK and drops the entry, and #2878 additionally shares MEMORY-mode sessions. The HRESULT values (0x887A0034, 0x887A0036) match the DXGI definitions, and the tests cover the exact-limit, oversized and duplicate-in-full-store cases. No other 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:docs-ci Documentation, scripts, workflows, repo governance 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-pr-check Failing the PR description check (CONTRIBUTING.md)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants