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

Copy link
Copy Markdown

The fallback shader cache copied keys and values before checking its 32 MiB limit, then reported S_OK even when it discarded the entry. Reject oversized inputs before copying, check remaining capacity under the store lock, and return DXGI_ERROR_CACHE_FULL without losing a previous value.

What is in it

  • Capacity checks in shader_cache_session.rs, four regression tests, and README documentation. This affects the fallback used when the host refuses CreateShaderCacheSession.
  • No measured world-loading benefit or claim to fix a retail-title issue.

Tested

  • Head ab861b8196779f65209de31eef1e5f97ee1eb6d8, base 06c9f5505f63f10c5ec49ef932d75b2c28177324. Windows 11 Pro build 26300, Ryzen 7 8840HS, Radeon 780M (driver 32.0.31033.3), rustc 1.100.0 MSVC, debug.
  • cargo build --locked --workspace --jobs 2: passed.
  • cargo test --locked --workspace --no-fail-fast --jobs 2 -- --test-threads=4: 1268 passed, 1 failed, 46 ignored. All four new tests and the existing fallback-session GPU test pass. The failure is gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 (seed 722), reproduced on unchanged main before the rebase too.
  • Three regression tests were first run against unchanged production code: all failed because StoreValue returned S_OK instead of DXGI_ERROR_CACHE_FULL, then passed with the fix. The fourth checks accounting while replacing and shrinking entries at capacity.
  • A separate local integration branch at ab2ff4dc8d82e524ac5230dc58c2fcdc2989766a, additionally carrying upstream PRs Shaders: preserve first active lane reads across divergent switches #2192, Direct DXIL: lower i64 min/max as compare/select #1946 and Shaders: reverse the halves of an i64 Bfrev with shifts and masks on AMD #2237, builds and passes the full command above: 1271 passed, 0 failed, 46 ignored. Those commits are NOT included in this PR.
  • Both final full runs report 10 SKIPPED events: six unsupported direct-DXIL f16/conversion cases, a driver-cache benchmark requiring Developer Mode, two debug-layer tests and a heap-window test. These are not coverage. git diff --check passes.

Regression run
Not run: no unpacked retail title is available. The required main/head smoke pair is still needed before merge.

Not tested
Retail titles, Wine/vkd3d-proton, other GPUs, ignored tests and optional XCL_SAMPLE_* inputs (unset). No measured peak-memory or world-load improvement. The PR branch's complete suite is not green until the independent shader failure is resolved upstream.

AI use
This PR was created with AI assistance from OpenAI Codex (gpt-6-astra).

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

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants