Skip to content

Recompiler: the translated cache keys on the HLSL emitter's switches - #2327

Draft
vakaobr wants to merge 1 commit into
xcl-dev:mainfrom
vakaobr:recompiler/translated-cache-emit-switches
Draft

vakaobr wants to merge 1 commit into
xcl-dev:mainfrom
vakaobr:recompiler/translated-cache-emit-switches

Conversation

@vakaobr

@vakaobr vakaobr commented Nov 25, 2026 •

Copy link
Copy Markdown

Addresses #1409, like #1413, which came first. Correction to what this said before: only XCL_SAFE_BARRIER has the bug. XCL_WAVE64_SPIN, XCL_X64_ALL_MASKS and XCL_RECOMP_NO_STRUCTURED are already in cache_allowed on main, which turns the memory and the disk cache off whenever one of them is set, so they never reuse a stale translation and the tags this adds for them never take effect.

XCL_SAFE_BARRIER=0 changes the HLSL emitted for s_barrier, but neither cache_allowed nor the cache identity knows it, so a run with it can load a translation cached without it, and the other way round. #1413 adds it to cache_allowed (no cache while it is set), the same way main handles the other three. This keys the disk cache on it instead (translated::identity() gets a tag when it is set), so a run with it set is still cached. That only matters where the barrier switch is a mode people run in rather than a debug switch, as on the Mac branch from #258, where the native barrier is the default and XCL_SAFE_BARRIER=1 brings back the spin barrier. For main, #1413 fits the existing pattern; if it is merged, I'll close this.

What is in it

  • crates/xcl/src/gpu/recomp/pso.rs: translated::with_emit_switches, applied at the end of identity() (rerouted entries derive from it, so they follow), and the test emit_switches_change_the_translated_identity.

Tested

  • Apple M5 Pro, macOS 27.2.1, CrossOver 26.3.0 with D3DMetal 3.0 (Rosetta 2), Rust 1.100.0 x86_64-pc-windows-gnu, debug, at e56c368 (on main 06c9f55).
  • gpu::recomp::pso::shader_cache_tests, all 7 tests (the new one + the 6 existing): 7 passed, 0 failed, each in its own process.
  • Mutation check: with XCL_SAFE_BARRIER left out of with_emit_switches, the new test fails (left: 4, right: 6).
  • Whole suite: not run on Windows.

Regression run

  • None: I have no title of my own to run scripts/smoke.ps1 on. Needs someone with a title, or the maintainer's call.

Not tested

  • Windows, AMD / NVIDIA, the whole suite, any title.
  • The change only adds to the cache identity when a switch is set: a run without these switches uses the same identity as main.

AI use

  • Claude Code, Claude Opus 5.5: found the gap, wrote the change and the test, ran the tests and wrote this description.

The on-disk translation cache folds the DXC toolchain, the backend and
the direct-DXIL switches into its identity, but not the switches the
HLSL emitter reads: XCL_SAFE_BARRIER=0, XCL_WAVE64_SPIN=0,
XCL_X64_ALL_MASKS and XCL_RECOMP_NO_STRUCTURED. A run with one of them
set loaded the translation an earlier run had cached without it, so
XCL_SAFE_BARRIER=0 still ran the spin barrier for every cached program
unless XCL_TRANSLATED_CACHE=0 was set too.

A non-default value of any of them now adds a tag to the identity
(rerouted entries derive from it and follow). Their defaults leave the
identity unchanged, so existing caches stay valid.
@nnonno91

Copy link
Copy Markdown

Independent Windows check of e56c368079bb51c1ceccf60fbcbb1e1860f3b3c5, using actual cache files across process boundaries.

Tested

  • Windows 11 25H2 build 26200.9974, Ryzen 7 9800X3D, Rust 1.100.0 MSVC, SDK DXC/DXIL 1.8.2502.11, unoptimized profile.
  • cargo test --locked -p xcl --lib gpu::recomp::pso::shader_cache_tests -- --nocapture --test-threads=1 gave 21 passed, 0 failed, 0 ignored and no skips.
  • A temporary test called translated::cached for the same key and trivial DXC-compiled compute shader in nine separate processes sharing one empty-at-start cache directory. Ran cargo test --locked -p xcl --lib local_emitter_switch_disk_cache -- --nocapture --test-threads=1 with XCL_DIRECT_DXIL=0. Each run gave 1 passed, 0 failed and 0 ignored.
  • The four switches (XCL_SAFE_BARRIER=0, XCL_WAVE64_SPIN=0, XCL_X64_ALL_MASKS=1, and XCL_RECOMP_NO_STRUCTURED=1) each missed the default entry and made a distinct entry. Defaults and the barrier-off setting both hit on repeat. Explicit defaults reused the default identity, and XCL_TRANSLATED_CACHE=0 compiled with identity zero. Five cache files remained. The temporary test was removed.

Not tested

GPU execution, the emitter output under each setting, the parent revision, retail smoke and the full workspace suite.

AI use

OpenAI Codex (GPT-6.2 Sol) wrote the temporary cache fixture, ran the tests and prepared this report.

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

Disclosure: the branch as fetched carries stacked unmerged content beyond the cache-key commit (title_list, dispatch_chain, split-restore work; 1780 insertions total). This row covers the branch as-is, same as any reviewer building it.

  • gpu_ suite (--release --locked, --test-threads=2): 142 passed / 3 failed / 1 ignored, identical to 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).
  • Targeted run of the cache/identity tests (gpu::recomp::dxc::cache_tests:: and gpu::recomp::pso::shader_cache_tests:: filters): all green on this lane, including cache_key_tracks_the_dxc_toolchain and the direct-vs-HLSL identity tests; no collisions with the XCL-patched vkd3d-proton toolchain fingerprint on the Wine lane.

Adds the Wine/vkd3d-proton data point next to the independent Windows check.

Not tested: retail titles (no title data on this lane, counts only).

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

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