Skip to content

Shaders: cache translator refusals and DXC compile failures by capability - #1474

Open
AlpPesen wants to merge 1 commit into
xcl-dev:mainfrom
AlpPesen:perf/cache-shader-refusals
Open

AlpPesen wants to merge 1 commit into
xcl-dev:mainfrom
AlpPesen:perf/cache-shader-refusals

Conversation

@AlpPesen

@AlpPesen AlpPesen commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1412.

Repeated boots re-attempt the same deterministic translator refusals and DXC compile errors on every run because only successful .dxil / translated blobs are persisted on disk.

What is in it

  • Persist capability-keyed negative cache markers (.err) for deterministic translator refusals in crates/xcl/src/gpu/recomp/pso.rs (translated::cached_in and translated::cached_rerouted, keyed by capability/source/rerouted identity so any translator, DXC, wave-mode, or direct-DXIL update invalidates them).
  • Persist deterministic DXC compile errors (: dxc: , excluding Internal Compiler error:) in crates/xcl/src/gpu/recomp/dxc.rs while keeping transient failures (E_OUTOFMEMORY 0x8007000E from Compile or GetStatus, Internal Compiler error:, cross-process mutex lock errors DXIL cache: ..., missing/old dxcompiler.dll, cached_only deferrals, invalid DXIL containers) uncached and retryable.
  • Add unit tests in pso.rs (including direct translated::cached_rerouted coverage) and dxc.rs covering capability/version invalidation, cached_only deferral isolation, cross-process lock errors, and transient vs deterministic DXC errors.

Tested

  • Hardware: Intel Core i9-9900K, 32 GB RAM, AMD Radeon RX 6800 (16337 MiB VRAM, RDNA2, driver 32.0.21045.29003), Windows 11 Pro build 26300, rustc 1.100.0, DXC 1.9.2602.17.
  • cargo test -p xcl --lib gpu::recomp::pso: 22 passed, 0 failed, 1 ignored, 0 skipped.
  • cargo test -p xcl --lib gpu::recomp::dxc: 16 passed, 0 failed, 0 ignored, 0 skipped.
  • Previously verified across RTX 5070 Ti, RTX 5070 Laptop, RTX 3070, RTX 3060 Ti, and RDNA2 iGPU before rebasing onto 06c9f55.

Not tested

  • Linux/Wine or NVIDIA GPUs after rebase onto 06c9f55.

Regression run

xcl-smoke v1
commit: 06c9f5505f63f10c5ec49ef932d75b2c28177324
gpu: AMD Radeon RX 6800
title: 6ca5cab7
seconds: 60
exit: 0x0
frames shown: 1521 (PresentX 1521)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14974 MB
xcl-smoke v1
commit: f51058f787a62d3a4964029f0279335a1832da68
gpu: AMD Radeon RX 6800
title: 6ca5cab7
seconds: 60
exit: 0x0
frames shown: 1391 (PresentX 1391)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14974 MB

AI use

  • Antigravity (Gemini 4 Neon): implemented the capability-keyed negative cache and unit tests, addressed review feedback from @GonZiin and @pvfreis on transient DXC/lock/internal errors and cached_rerouted test coverage, rebased onto 06c9f55, ran the tests and paired scripts/smoke.ps1 runs, and drafted this PR description.

@futurepro62

Copy link
Copy Markdown

Full-suite run, since this PR has no test report yet. Tested exact head 451ae68 (on its base b7aa9f3). Passes on both GPUs.

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4, run alone: 772 passed, 0 failed, 41 ignored. SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.
  • An earlier run, done while another suite was using the machine, failed only fine_timer_makes_short_sleeps_short (Sleep(1) took 6.71 ms), a timing check this PR doesn't touch. It passed when run alone.
  • The new tests ran and passed on both GPUs: dxc_compile_failure_is_cached_and_skips_recompilation, translated_cache_caches_refusals_by_capability_identity.
  • Same head on the AMD Radeon iGPU of the 9800X3D (RDNA2, XCL_ADAPTER=radeon): 772 passed, 0 failed, 41 ignored, nothing skipped.

Note

Not tested

  • A release build, a game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.

@GonZiin GonZiin left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The translated-shader cache can persist a transient DXC error and prevent a retry. The lower DXIL cache excludes a failed compiler invocation such as Compile: … (0x8007000E). The outer translated::cached_in receives the formatted error, treats it as cacheable and writes an .err marker. The next call for that shader returns the saved error before calling the translator or compiler.

Tested

  • Windows 11 Pro build 26300, Ryzen 7 7800X3D, Rust 1.100.0 MSVC, debug. I ran cargo test -p xcl --lib review_a_transient_dxc_error_allows_retry -- --nocapture with one temporary probe appended to pso.rs in an isolated checkout. The probe injects the formatted DXC out-of-memory error on the first call and supplies a successful compile result on the second.
  • Base b7aa9f3bd212088e0d927439284dc5ed325ce3c7 retried once and returned the successful result. Head 451ae68ed5e1493b663a65064cb4b6976efdd097 returned the original error with zero retry calls.

The outer cache should persist deterministic translator refusals and let the lower cache handle compiler errors, or carry retryability through the result type. This would keep transient or invalid-output errors retryable even after the outer cache sees them.

Not tested

Real system memory exhaustion, GPU behavior and retail titles. The probe injected the error at the translated-cache boundary.

AI use

Codex (gpt-6.2-sol) reviewed the error path, wrote and ran the probe, and drafted this review.

@upipibi

upipibi commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Duplicate note: #1472 (opened two minutes earlier) also fixes #1412, in the same two files (dxc.rs, pso.rs). It has a review and an AMD Windows test on its head (a56a7c7). The two use different on-disk markers: .err with XCLDXCE1 there, .fail with XCLFAIL1 here. A cache directory would then hold one or the other depending on which lands, so it is worth choosing before either merges. Comparison only: I haven't run either.

AI use: Claude Code (Claude Opus 5.5) compared the diffs and wrote this.

@AlpPesen

Copy link
Copy Markdown
Contributor Author

Thanks @GonZiin for the catch! Updated ranslated::is_cacheable_error in 3db920c so errors formatted by the lower DXIL cache (DXIL cache ...) are only cached when DXC itself deterministically rejected the HLSL (: dxc: ), keeping transient failures like Compile: ... (0x8007000E) or invalid-container outputs retryable. Added unit test coverage for both cases in ranslated_cache_caches_refusals_by_capability_identity and reran scripts/smoke.ps1 on 3db920c.

@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, ~21 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified main.)

Thanks!

@kais7654

Copy link
Copy Markdown

Ran on the PR's head (3db920c): RTX 5070 Laptop (Blackwell, driver 616.87),
Windows 11 26H2, rustc 1.100.0.

cargo build --workspace: ok
cargo test -p xcl --lib gpu::recomp: 191 passed, 0 failed, 18 ignored
(includes shader_cache_retries_failed_and_deferred_compiles and the dxc cache
statistics tests)

One design question: every raw error from compile() that starts with "dxc: " is
treated as deterministic and cached for the toolchain identity's lifetime. Are
all "dxc: " failures really deterministic? An out-of-memory inside DXC
mid-compile would produce the same prefix and then be cached until the DXC
version changes, so a transient failure would never be retried. Does something
exclude those (or should only defined refusal classes be cached)?

Not tested: the runtime effect across repeated boots (no retail pack here),
and no Windows-path check of the .err invalidation on a DXC upgrade.
AI use: my local Mistral Vibe agent fetched the branch, ran the build/tests
above and drafted this comment; I checked the diff.

kacper-serewis pushed a commit to kacper-serewis/xcl that referenced this pull request Nov 24, 2026
…lity

Adapt Alp Pesen's xcl-dev#1474 to staging 7209e87.
Preserve direct backend and adapter identities. Carry typed failures across
translation, compilation and caching. Persist only deterministic refusals.
Ignore legacy rejection markers. Bypass caches for shader diagnostic overrides.

Original-commit: 3db920c
Assisted-by: Antigravity (Gemini 4 Neon)
Assisted-by: Codex (gpt-6.2-astra)
@ivall ivall added the goal:world-load Bears on the retail title getting past world loading label Nov 24, 2026
@upipibi

upipibi commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Test report at the current head 3db920c: RTX 3070 (Ampere, driver 616.56), Windows 11, debug.

  • cargo test -p xcl --lib -- --test-threads=4: 723 passed, 1 failed, 21 ignored. The failure is hle::xaudio2::tests::xma2_source_voice_decodes_and_manages_lifetime (no samples played within its fixed wait while the machine was loaded). This PR doesn't touch XAudio2; Tests: the XAudio2 voice tests wait 30 s for playback and skip a slow audio device (#1487) #1600 gives those voice tests a longer wait.
  • XCL_DIRECT_DXIL=1 cargo test -p xcl --lib -- gpu_ --skip gpu_sparse_vram: 98 passed, 0 failed.

(This PR is in duplicate group D7 with #1472 in #1607.)

AI-assisted (Claude Code). Synthetic tests only.

@AlpPesen
AlpPesen force-pushed the perf/cache-shader-refusals branch 2 times, most recently from ad4fbe5 to 7f97ba3 Compare November 25, 2026 11:34
@pvfreis

pvfreis commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Two errors that can be transient are kept as refusals at 7f97ba3. Tested on its base 426a5a7 (main has not touched dxc.rs or pso.rs since).

  1. Lock errors. process_cache_lock(&file)? (dxc.rs:873) returns "DXIL cache: cannot create the cross-process mutex" as it is, and is_cacheable_error (pso.rs:360) treats only a text with starts_with("DXIL cache "), with a space, as an error of the lower cache. So cached_rerouted writes the .err marker, and later calls return it before translating, until the marker is deleted or the translator or DXC changes. The comment above the check says lock errors stay retryable. starts_with("DXIL cache") would cover both forms.
  2. An internal error of DXC (an answer to @kais7654's question). DXC's Compile catches hlsl::Exception and returns a successful call whose status is the exception's HRESULT, with the text "Internal Compiler error: " plus its message (dxcompilerobj.cpp, the catch after SetStatusAndPrimaryResult). One of them is transient: IFT(CreateMemoryStream(...)) throws E_OUTOFMEMORY this way. XCL formats any failing status as dxc: ... (dxc.rs:533) and drops the code, so this becomes dxc: Internal Compiler error: and the DXIL layer caches it (tested), as does the translated layer (by reading). Ordinary HLSL errors have status E_FAIL, so keeping the status and not caching E_OUTOFMEMORY would separate them. I don't know how often a title hits it: the out-of-memory errors in Shaders: a DXC compile out of memory runs again with no other compile #1710 were the other form ("Compile: ... (0x8007000E)"), which is not cached.

The refusal tests in pso.rs all go through cached_in, which is test-only since #2120, so the marker branch of cached_rerouted, the one a title runs, is not checked by any test. Calling cached_rerouted there would cover it.

cargo test --workspace --locked --offline --no-fail-fast -- --test-threads=4, debug, RTX 3060, passed / failed / ignored
main 426a5a7 + two tests 1244 / 1 / 46
this PR + the same two tests 1244 / 3 / 46, both red

Test 1 calls cached_rerouted with a real compile_cached_in while an event holds the mutex's name, so CreateMutexW really fails; then the event is closed and the same call is made again. On main the second call compiles; here it returns the mutex error without running the closure. Test 2 gives compile_cached_in_observed the internal error's text and then a good result. The failure the rows share is the e2e title test (presents is 0 in my sandbox); 24 SKIPPED lines in both logs. #1472 (its duplicate) has the same two filters, by reading its head 9e1a79e.

Not tested: a real DXC internal error, a title. I can post the tests.

AI use: Claude Code (Claude Opus 5.5) read the change, wrote and ran the tests; checked with Claude Fable 5.2.

…lity

Persist deterministic negative cache markers (.err) alongside positive shader cache entries so repeated boots do not re-lower refused programs or re-invoke DXC on deterministically failing HLSL:

- dxc.rs: cache deterministic DXC compiler rejections (raw error starting with 'dxc: ') in {key:016x}.err (keyed by crate version, DXC toolchain identity, profile, entry, and HLSL source). Subsequent runs return the identical error text with zero DXC invocations. Transient/missing-DLL errors and cached_only deferrals are never cached.
- pso.rs: cache translator refusals and compile errors in translated/v2/{ident:016x}/...err (keyed by XCL_TRANSLATOR_SOURCE_ID, DXC toolchain identity, blob hashes/length, stage, sampler_base, windows, and split_wave64). Updating translator sources, DXC DLLs, or wave mode automatically invalidates prior markers; debug/capability env overrides bypass the cache via cache_allowed.

Fixes xcl-dev#1412.

Assisted-by: Antigravity (Gemini 4 Neon)
@AlpPesen
AlpPesen force-pushed the perf/cache-shader-refusals branch from 7f97ba3 to f51058f Compare November 25, 2026 14:00
@AlpPesen

Copy link
Copy Markdown
Contributor Author

Thanks @pvfreis for the detailed review and tests! All three points are fixed in f51058f (rebased onto 06c9f55):

  1. Lock errors: pso::translated::is_cacheable_error now matches reason.starts_with("DXIL cache") (covering both "DXIL cache " and "DXIL cache: cannot create the cross-process mutex"), so cross-process mutex errors stay retryable.
  2. DXC Internal Compiler error: / E_OUTOFMEMORY: dxc::compile now preserves E_OUTOFMEMORY (dxc (0x8007000E): ...) instead of formatting it as dxc: ..., and both dxc::is_cacheable_dxc_error and pso::translated::is_cacheable_error reject "Internal Compiler error:".
  3. cached_rerouted coverage: Added translated_cache_rerouted_caches_refusals_and_skips_transient_errors in pso.rs covering cached_rerouted refusal caching, direct-translator version invalidation, cross-process mutex lock errors, and DXC internal compiler errors, plus an internal-error case in dxc.rs.

Verified on AMD RX 6800 (gpu::recomp::pso: 22 passed, gpu::recomp::dxc: 16 passed, plus fresh paired 60 s smoke.ps1 runs).

@thehollowedone

Copy link
Copy Markdown

Independent check of f51058f on Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti / 621.35, Rust 1.99.1 MSVC and DXC 1.8.2502.11.

The clean head built with cargo build --offline --locked --workspace -j 6. cargo test --offline --locked --workspace -j 6 --no-fail-fast -- --test-threads=4 --nocapture finished with 1,268 passed, 0 failed, 46 ignored, including 26 runtime skips in the pass count. The stock rerouted-cache tests covered cross-process lock errors and DXC internal errors staying retryable.

I also exercised the production DXC disk cache from four fresh test processes with one synthetic HLSL input and a private cache directory. The first process made one compiler attempt and wrote one refusal marker. The next process replayed the diagnostic in normal and cached-only modes with zero compiler attempts and no deferral. Corrected HLSL compiled once and passed DXIL validation. Deleting the refusal marker made the original input reach DXC again. All four runs passed with zero skips using cargo test --offline --locked -p xcl --lib -j 6 local_dxc_cache_persists_across_processes -- --test-threads=1 --nocapture with a test-only fixture.

Synthetic inputs only. No retail run or induced DXC out-of-memory failure.

AI-assisted. Codex (GPT-6, exact variant unavailable) wrote the temporary fixture, ran the tests and drafted this report.

@S1m0ne1997

Copy link
Copy Markdown

Test report for f51058f787a62d3a4964029f0279335a1832da68 (this PR's head), for #1607.

Tested

  • NVIDIA GeForce RTX 4090 24 GB (driver 621.40), AMD Ryzen 9 9950X3D, 47 GB RAM, Windows 11 Home 10.0.26300, rustc 1.100.0 (0ef1bc386 2026-11-09) x86_64-pc-windows-msvc, debug.
  • cargo build --workspace, then cargo test --workspace -- --test-threads=4 at the head: 1268 passed, 0 failed, 46 ignored.
  • SKIPPED (18): dispatch_chain_native_wave64_builds_whole (no wave64), a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu (no wave64), coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu (no wave64), cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu (no wave64), the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu (no wave64), a_per_lane_2d_or_3d_group_runs_on_the_gpu (no wave64), const_and_null_mask_operands_agree_with_hlsl_on_the_gpu (const_mask, wave64: no wave64), f16_programs_on_the_gpu (f16 arithmetic, wave32, per-lane form: refused (unsupported V_MUL_F16 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's)); f16 arithmetic, wave64: no wave64), f32_programs_on_the_gpu (f32 arithmetic, wave64: no wave64; f32 compares, wave64: no wave64), f64_programs_on_the_gpu (f64, wave64: no wave64), integer_programs_on_the_gpu (integer arithmetic, wave64: no wave64; integer carries, wave64: no wave64), mask_ff0_and_flbit_agree_with_hlsl_on_the_gpu (mask_ff0_flbit, wave64: no wave64), gpu_geometry_wave32_prefix_count_over_a_mask (no wave64), gpu_wave32_program_in_wave64_hardware (no wave64), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows), pso_measurement_compiles_an_exact_synthetic_record (cannot disable the driver cache (Windows Developer Mode is required): L'applicazione ha richiesto un'operazione che dipende da un componente SDK mancante o non corrispondente. (0x887A002D)), test_title_draws_with_a_root_signature_under_the_debug_layer (no d3d12SDKLayers.dll), uploads_start_from_each_subresources_state (no D3D12 debug layer (L'applicazione ha richiesto un'operazione che dipende da un componente SDK mancante o non corrispondente. (0x887A002D))).

Regression run (retail title, scripts/smoke.ps1 -Seconds 60, release; main built from the commit in its block, this PR from its head with no changes to crates/, both run with the scripts/smoke.ps1 of main, which hashes the name of the game folder)

main:

xcl-smoke v1
commit: 06c9f5505f63f10c5ec49ef932d75b2c28177324
gpu: NVIDIA GeForce RTX 4090
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1599 (PresentX 1599)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16384 MB

this PR:

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

Not tested

  • AMD, other NVIDIA cards and drivers, Linux. I did not review the diff; this report is the build, the suite and the regression run only.

AI use: Claude Code with Claude Opus 5.5 ran the build, the suite and the regression run and wrote this report at my request.

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

Labels

goal:world-load Bears on the retail title getting past world loading

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cache refused programs and failed compiles — boot pays for the same refusals every run; markers must be capability-keyed

10 participants