Skip to content

Shaders: cache refused shaders and DXC failures by capability (#1412) - #1472

Open
KarolKurzyna wants to merge 2 commits into
xcl-dev:mainfrom
KarolKurzyna:shaders/negative-cache-capability-markers
Open

KarolKurzyna wants to merge 2 commits into
xcl-dev:mainfrom
KarolKurzyna:shaders/negative-cache-capability-markers

Conversation

@KarolKurzyna

@KarolKurzyna KarolKurzyna commented Nov 24, 2026 •

Copy link
Copy Markdown

Fixes #1412.

What is in it

  • Caches deterministic DXC compilation failures (dxc: ...) in <key>.fail markers alongside <key>.dxil (crates/xcl/src/gpu/recomp/dxc.rs), storing the formatted failure text and a capability digest (XCLFAIL1, package version, XCL_TRANSLATOR_SOURCE_ID, and toolchain_identity()).
    • Subsequent hits replay the exact formatted error into CacheCounters::cached_failure (CacheStats::cached_failures) without incrementing compilations or compilation_failures or triggering CACHED_ONLY deferrals.
    • Transient DXC errors (Compile: ..., DXC: ..., missing DLL, invalid container) are never negative-cached.
  • Caches upstream translator refusals and deterministic DXC refusals in <stem>.fail (XCLTRNF1 + ident, capability digest over ident/stage/sampler_base/windows/split, blob size and hash2) inside translated (crates/xcl/src/gpu/recomp/pso.rs), short-circuiting before re-lowering on subsequent runs while skipping cached_only deferrals (has_missed()) and transient DXC errors.
  • Skips negative markers and deletes any matching .fail file on disk whenever capability-changing or debug env overrides are active (XCL_SAFE_BARRIER, XCL_SPLIT_WAVE64, XCL_WAVE64_SPIN, XCL_NEGATIVE_CACHE, XCL_RECOMP_*, XCL_DEBUG_*), and deletes stale or mismatched markers when a capability digest drifts or a shader later succeeds.
  • Rebased onto main (1a0bbe3, PR gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 Direct DXIL + PR Direct DXIL: memory windows through the descriptor heap (XCL_HEAP_WINDOWS) #1693): translated::identity() stays wired through identity_with(..., Backend::current(), crate::gpu::dxil::kernel::TRANSLATOR_VERSION), isolating Direct DXIL refusal markers from HLSL ones and invalidating them on TRANSLATOR_VERSION bumps.

Tested

  • Hardware: Intel Core i5-14600K; NVIDIA GeForce RTX 3070 Ti (8017 MiB VRAM, driver 32.0.16.2124); Rust 1.100.0; DXC 1.9.2602.17.
  • cargo build --release -p xcl: passed. Two existing Atomic::fetch_update deprecation warnings are in untouched files/lines.
  • Focused test translated_refusals_are_cached_and_invalidated_by_capability_digest: passed on head 9e1a79e47915.
  • cargo test --workspace -- --test-threads=4 on head 9e1a79e47915: xcl library had 1186 passed, 1 failed, 26 ignored. The failure is gpu::recomp::pso::shader_cache_tests::console_mesh_caches_hlsl_compute_pass_in_memory_and_on_disk (DXIL not compiled yet); it reproduces on base 1a0bbe3a2ba9 as well.

Regression run

Fresh main baseline (warm cache):

xcl-smoke v1
commit: 1a0bbe3a2ba91ea8f5b6fc29130a053868d3c9e6
gpu: NVIDIA GeForce RTX 3070 Ti
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1604 (PresentX 1604)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14428 MB

This PR head (warm cache):

xcl-smoke v1
commit: 9e1a79e4791597607c1cb9048687c05be8294141
gpu: NVIDIA GeForce RTX 3070 Ti
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1610 (PresentX 1610)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14367 MB

Not tested

  • Remaining workspace/integration targets were not reached because Cargo stopped at the library test failure above.
  • A live refused shader or DXC failure did not occur during this 60-second run; cache behavior and capability invalidation are covered by unit tests. AMD and Intel GPUs were not available locally.

AI use

Original implementation and initial evidence were prepared with Google Antigravity (Gemini 4 Neon). Codex (GPT-6) rebased/reviewed the branch, corrected the test's synthetic marker byte index, and ran the current build, tests, and smoke checks.

@pickles976

Copy link
Copy Markdown

Reviewed the diff — this implements #1412's acceptance faithfully, and two choices go beyond the letter of it in the right direction: the master kill switch inside the override list (XCL_NEGATIVE_CACHE presence ⇒ markers off, so the feature is testable in both directions without a rebuild) and the determinism gate (dxc:-prefixed failures only — correctly excludes driver-side rejections, which are capability-dependent and would poison exactly like the class we were trying to avoid). XCLFAIL1/XCLTRNF1 magic + reason-length bound + digest-in-header with miss-then-overwrite recovery is the right file shape; reason replay keeps log-tail comparability.

One edge worth a documented limitation (or a follow-up line in the digest), because negative entries poison asymmetrically where positive entries merely serve a stale variant: the capability digest folds translator-source-id + toolchain + extra flags, but not the device-derived wave decision — split_wave64 comes from the device wave range at PSO time, and laptops with iGPU+dGPU (or users swapping adapters) share one cache directory. Run on the wave64-capable adapter ⇒ a shader refusals-free… precisely: a shader whose refusal depends on the non-split path gets a marker; the same cache on the 32-lane adapter, where the split lowering would translate it fine, is now permanently refused — wrong-in-a-way-the-positive-cache never was (positive staleness costs perf, negative staleness costs content). The positive cache's single-device assumption is pre-existing, so this is not a merge blocker — but either fold a device-capability bit (split-vs-native wave64 is enough; full LUID would overfit to docks/eGPU churn) into both digests, or state the single-adapter-per-cache assumption in the module docs and in the #1412 close note so the next iGPU-laptop "why is everything magenta-refused" report is a grep instead of a mystery.

@KarolKurzyna

Copy link
Copy Markdown
Author

@pickles976 Thanks for the quick review!

One helpful detail already in the diff: in pso.rs, translated::fail_file and translated::capability_digest already include split (split_wave64) alongside ident, stage, sampler_base, and windows (both in the filename ..._{split as u8}.fail and in the XCLTRNF1 capability digest), so a wave64-native adapter and a split-wave64 adapter sharing one cache directory will not poison each other's translator refusal markers.

In dxc.rs, <key>.fail is keyed on the full emitted HLSL src (plus entry, profile, toolchain_identity(), and XCL_TRANSLATOR_SOURCE_ID), so wave-dependent lowering differences already produce different HLSL and separate <key>.fail entries; I agree the single-adapter-per-cache assumption still applies if two adapters somehow produce identical HLSL or share graphics wave knobs, and I am happy to add a short module doc note (or fold a wave-mode bit into dxc.rs as well) if you want that before merge.

@nnonno91

Copy link
Copy Markdown

Independent Windows/AMD test of a56a7c7aeb694ff9645d2f923430c731ded3da7f for #1412.

Tested

  • Windows 11 25H2 (26200.9974), Ryzen 7 9800X3D, AMD Radeon(TM) Graphics (32.0.21042.62), Rust 1.100.0 x86_64-pc-windows-msvc, debug builds. The workspace suite used DXC 1.8.2502.11.
  • cargo build --workspace --locked passed. cargo test --locked -p xcl --lib cache_tests -- --test-threads=4 passed all 27 tests. cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --show-output had 776 passed, 0 failed, 41 ignored, and no SKIPPED messages. The bundled test title passed.
  • A temporary integration test called dxc::compile_cached with float4 main() : SV_Target { return xcl_undefined_value; } (main, ps_6_6). Each invocation of cargo test --locked -p xcl --test dxc_refusal_probe -- --exact real_dxc_refusal_probe --nocapture --test-threads=1 started a fresh process. All five passed using a single initially empty XCL_DXIL_CACHE directory.
Run DXC calls Cached failures .fail files after run
DXC 1.8.2502.11, empty cache 1 0 1
DXC 1.8.2502.11, same input 0 1 1
DXC 1.9.2609.5, same input 1 0 2
DXC 1.8.2502.11, XCL_NEGATIVE_CACHE=0 1 0 1
DXC 1.8.2502.11, override unset 1 0 2

The cold and warm 1.8 runs returned identical error text. The override removed the 1.8 marker, and the next run with the override unset recreated it.

Not tested

Retail-title smoke runs, startup performance, and cross-process replay of translator refusals. The five-process probe exercised the DXC path.

AI use

OpenAI Codex (GPT-6 family, exact variant unavailable) wrote and ran the temporary probe and drafted this report.

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

@KarolKurzyna
KarolKurzyna force-pushed the shaders/negative-cache-capability-markers branch from a56a7c7 to e96f516 Compare November 24, 2026 19:52
@KarolKurzyna

Copy link
Copy Markdown
Author

Rebased onto main (9039900, #1426 Direct DXIL + #1693) — new head is e96f516.

@DavidM1911 Thank you for verifying on RTX 3060 Ti!

Direct DXIL interop on e96f516

  • Preserved gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426's translated::identity_with(..., Backend::current(), crate::gpu::dxil::kernel::TRANSLATOR_VERSION) inside translated::identity() (crates/xcl/src/gpu/recomp/pso.rs), so XCL_DIRECT_DXIL refusal markers stay isolated from HLSL entries and invalidate whenever TRANSLATOR_VERSION bumps.
  • Added Direct DXIL Backend / TRANSLATOR_VERSION isolation assertions to translated_refusals_are_cached_and_invalidated_by_capability_digest.

Re-verified on e96f516 (RTX 3070 Ti, DXC 1.9.2602.17)

  • .\scripts\test.ps1: 864 passed, 0 failed, 42 ignored across 20 runs (unittests src\lib.rs: 815 passed, 0 failed, 22 ignored; GPU tests skipped on this adapter: 2 (no wave64), 1 (no heap windows)).
  • Release build (cargo build --release -p xcl) + 60 s scripts/smoke.ps1: exit: 0x0, 1630 frames (PresentX 1630), 60 60 60, 0 device removals/crashes, 14522 MB peak commit.

@speed-y

speed-y commented Nov 24, 2026

Copy link
Copy Markdown

Independent Windows/NVIDIA verification of head e96f516 (A18 / #1412).

Tested

  • RTX 5080 (driver 621.24), Windows 10.0.26200, rustc 1.100.0 MSVC, DXC 1.9.2602.17 (Windows SDK 10.0.26100.0); unit tests debug, smoke release.
  • Negative-cache unit tests (8): all passed (dxc_deterministic_failures_are_cached_and_replayed, dxc_negative_marker_invalidates_on_capability_change_and_env_override, dxc_transient_failures_are_not_negative_cached, translated_refusals_are_cached_and_invalidated_by_capability_digest, translated_negative_markers_skip_and_delete_under_env_overrides, translated_deferred_and_transient_errors_are_not_negative_cached, direct_dxil_identity_never_collides_with_hlsl, direct_and_hlsl_disk_entries_are_separate).
  • .\scripts\test.ps1: 864 passed, 0 failed, 42 ignored; SKIPPED GPU: 2 (no wave64), 1 (no heap windows).

Regression run (warm not required; single 60 s smoke of this head)

xcl-smoke v1
commit: e96f5163ee1e4d6f34bb84bc255c002e334a3bb8
gpu: NVIDIA GeForce RTX 5080
title: GTAVI.exe
seconds: 60
exit: 0x0
frames shown: 1577 (PresentX 1577)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15631 MB

Not tested

AI use

  • Cursor (Composer): fetched the branch, ran the tests and smoke, drafted this report.

…v#1412)

Deterministic DXC failures and upstream translator refusals are
currently re-run from scratch on every boot, even though `report.json`
logs the exact same refusal set across launches.

Add capability-keyed negative cache markers across both layers without
poisoning caches across recompiler/DXC fixes or debug overrides:

- `dxc.rs`: write `<key>.fail` (`XCLFAIL1` + capability digest of version,
  `XCL_TRANSLATOR_SOURCE_ID`, and DXC toolchain) only on deterministic
  DXC refusals (`"dxc: ..."`), replay exact error strings via
  `CacheCounters::cached_failure` (`cached_failures`), and skip DXC and
  `CACHED_ONLY` deferrals on hit without bumping `compilations`.
- `pso.rs`: write `<stem>.fail` (`XCLTRNF1` + `ident`, capability digest
  covering stage/sampler_base/windows/split, blob len + hash2) in
  `translated` for deterministic upstream translator and DXC refusals,
  skipping transient errors and `cached_only` deferrals.
- Skip and delete stale/mismatched markers whenever capability-changing
  or debug env overrides are active (`XCL_SAFE_BARRIER`, `XCL_SPLIT_WAVE64`,
  `XCL_WAVE64_SPIN`, `XCL_NEGATIVE_CACHE`, `XCL_RECOMP_*`, `XCL_DEBUG_*`).

Fixes xcl-dev#1412.

Assisted-by: Google Antigravity (Gemini 4 Neon)
@KarolKurzyna
KarolKurzyna force-pushed the shaders/negative-cache-capability-markers branch from b970224 to 899c509 Compare November 25, 2026 11:47
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

6 participants