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

Caches deterministic translator refusals and DXC compile failures on disk in capability-scoped .err markers so repeated boots do not re-lower refused programs or re-invoke DXC on deterministically failing HLSL.

Fixes #1412.

What is in it

  • crates/xcl/src/gpu/recomp/dxc.rs:
    • Persist deterministic DXC compiler rejections (raw errors from compile starting with "dxc: ") in {key:016x}.err (atomic write-to-tmp + rename, tagged with magic XCLDXCE1, key, src.len(), and the formatted error message). Because key already hashes CARGO_PKG_VERSION, toolchain_identity() (dxcompiler.dll + dxil.dll size/mtime), profile, entry, and src, updating DXC or changing the generated HLSL automatically invalidates prior markers.
    • Check {key:016x}.err both on the fast path (before CACHED_ONLY) and inside the flight + process lock after waiting, returning the exact original error text with zero additional DXC invocations (compilations and compilation_failures remain flat on subsequent runs).
    • Never negatively cache transient/missing-DLL/validation errors or cached_only deferrals; expose cached_only_missed() for pso.rs.
    • Add unit test dxc_compile_failure_is_cached_and_skips_recompilation.
  • crates/xcl/src/gpu/recomp/pso.rs:
    • In mod translated, persist translator refusals and compile errors in translated/v2/{ident:016x}/{fnv64}_{stage}_{sampler_base}_{windows}_{split}.err (tagged with magic XCLTERR1, ident, blob.len(), hash2(blob), and the exact refusal reason string).
    • Because ident hashes XCL_TRANSLATOR_SOURCE_ID (all translator/recompiler sources in build.rs) and dxc::toolchain_identity(), and the filename encodes stage, sampler_base, windows, and split_wave64, any translator/spec update, DXC update, or wave-mode change automatically invalidates prior markers. Debug/capability env overrides continue to bypass the cache completely via cache_allowed, and cached_only deferrals or transient errors are never cached.
    • Add unit test translated_cache_caches_refusals_by_capability_identity.

Regression run

Baseline (main, warm shader/PSO cache):

xcl-smoke v1
commit: 09940bb87fa11bc394fd9e5de570c2b7cfd16323
gpu: AMD Radeon RX 6800
title: YouKnowWho
seconds: 60
exit: 0x0
frames shown: 405 (PresentX 405)
presents per 2 s (last 3): 11 12 11
device removals: 0
crashes: 0
peak commit: 15870 MB

This PR (perf/cache-shader-refusals, warm shader/PSO cache):

xcl-smoke v1
commit: 3db920c6102e009a0d2a841f39e179e9bc2dccc5
gpu: AMD Radeon RX 6800
title: YouKnowWho
seconds: 60
exit: 0x0
frames shown: 556 (PresentX 557)
presents per 2 s (last 3): 18 20 19
device removals: 0
crashes: 0
peak commit: 15859 MB

Tested

Hardware: Windows 11 Pro for Workstations (Build 26300), Intel Core i9-9900K, 32 GB RAM, AMD Radeon RX 6800 (16337 MiB VRAM, Driver 32.0.21045.29003), rustc 1.100.0 (0ef1bc386 2026-11-09).

  • cargo test -p xcl --lib gpu::recomp::dxc::: 15 passed; 0 failed; 0 ignored; 0 skipped.
  • cargo test -p xcl --lib gpu::recomp::pso::: 12 passed; 0 failed; 1 ignored; 0 skipped.
  • XCL_REQUIRE_GPU=wave64,mesh cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4: 769 passed; 3 failed; 41 ignored; 0 skipped. All 3 failures are the pre-existing RDNA2 placed_title_textures_share_vram_and_preserve_pixels + 2 VRAM_TEST_LOCK PoisonError cascades on unmodified main (tracked in D3D12.X: map a one-slice title texture's packed mips where D3D12 addresses them #470).
  • .\scripts\smoke.ps1 -Game '<game folder>\YouKnowWho' on 3db920c6102e009a0d2a841f39e179e9bc2dccc5 (see Regression run above).

Not tested

  • Non-AMD GPUs and Linux / Wine.
  • Multi-launch refusal timing benchmark on a mesh-heavy corpus with high refusal counts (unit tests verify zero re-lowering / zero DXC invocations on second hit and capability invalidation).

AI use

Antigravity (Gemini 4 Neon) implemented the capability-scoped negative cache markers and unit tests in crates/xcl/src/gpu/recomp/dxc.rs and crates/xcl/src/gpu/recomp/pso.rs, and ran the full test suite and smoke run.

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

…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 451ae68 to 3db920c Compare November 24, 2026 18:39
@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.

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

7 participants