Skip to content

Recompiler: direct DXIL cache entries change when its sources do - #1947

Merged
raylitebull merged 1 commit into
xcl-dev:mainfrom
pvfreis:dxil-cache-hash
Nov 25, 2026
Merged

raylitebull merged 1 commit into
xcl-dev:mainfrom
pvfreis:dxil-cache-hash

Conversation

@pvfreis

@pvfreis pvfreis commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

The on-disk translated cache is keyed by the HLSL path's sources (XCL_TRANSLATOR_SOURCE_ID), but of gpu/dxil only by TRANSLATOR_VERSION, which is bumped by hand. Unless something merged with it changes the HLSL path's sources, a gpu/dxil change that doesn't bump the number, or bumps it to one already used, leaves the old translator's containers in use under XCL_DIRECT_DXIL.

main has such a case now: #1900 (20cf130) puts the MSAA textureLoad before getDimensions, because AMD's driver compiler crashes on the other order, and doesn't bump it. For a program with an MSAA image load, a direct cache written at 689f2db still gives the old order at 20cf130 (see Tested).

This does for the direct path what bfb8133 (#1745) did for the per-lane sources, by listing the directory. MatyEjsr noted the gap on #1714 and IgorAntunes66 on #1741.

Related to #1269: it asks for shaders compiled directly into DXIL, and a direct-translator change tested over an existing cache can run and measure the old containers. If goal:world-load fits, please set it.

What is in it

  • build.rs: hashes every .rs file of gpu/dxil but the test files (*tests.rs) into XCL_DIRECT_DXIL_SOURCE_ID. Tests inside the other files are hashed with them. A new file (Direct DXIL: make multi-wave Compute and Mesh s_barrier early-exit-safe #1793 adds one) is not left out.
  • recomp/pso.rs: that hash is part of the direct entries' identity only (and the per-lane entries', which extend it). HLSL-path entries keep theirs. A unit test.
  • dxil/kernel.rs: the comment of TRANSLATOR_VERSION. The constant stays, for changes in pso.rs.

Cost

Tested

  • RTX 3060 12 GB (driver 617.14), Ryzen 9 5900XT, 32 GB, Windows 11 (26300), Rust 1.100.0, debug
  • cargo test --workspace --locked --no-fail-fast -- --test-threads=4 at 1831ec4a: 977 passed, 0 failed, 45 ignored (22 SKIPPED lines: 18 no wave64, 3 wave32 per-lane forms refused, 1 no heap windows)
  • direct_dxil_identity_tracks_its_sources fails with the source left out of direct_version and passes with it (cargo test -p xcl --lib shader_cache_tests: 13 passed, 1 failed / 14 passed; this diff on 689f2db)
  • dxil: emit MSAA textureLoad before getDimensions to avoid amdxc64 crash #1900's case, with a scratch test (not in the PR): the real direct translator on an MSAA IMAGE_LOAD program, through translated::cached with XCL_DIRECT_DXIL=1, builds run one after the other over one cache directory:
    • main: written at 689f2db; at 20cf130 the 689f2db container is served (getDimensions before textureLoad), while a fresh translation there has textureLoad first
    • with this diff: written at 689f2db + this diff; at 1831ec4a it is translated again (textureLoad first), and a rerun is a hit
  • build script output (this diff on 689f2db): editing dxil/module/opt.rs or adding a file changes only XCL_DIRECT_DXIL_SOURCE_ID; editing dxil/ops_tests.rs changes none

Regression run

main:

xcl-smoke v1
commit: 20cf13022f764208384c610c2ae6a3f4eed201a2
gpu: NVIDIA GeForce RTX 3060
title: b6ca0868
seconds: 60
exit: 0x0
frames shown: 1513 (PresentX 1513)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 20615 MB

PR:

xcl-smoke v1
commit: 1831ec4a5abb1c3ae0ca4ab3803776f7fafe30cb
gpu: NVIDIA GeForce RTX 3060
title: b6ca0868
seconds: 60
exit: 0x0
frames shown: 1530 (PresentX 1531)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 20446 MB

(the second of two pairs, run main, PR, main, PR; the first: main 1477 frames, peak 21803 MB; PR 1478 frames, 22433 MB; no removal or crash in either. Release builds.)

Not tested

  • the smoke runs take the HLSL path (default settings), so they don't reach the direct entries
  • a stale container in a title; AMD, so neither the driver crash dxil: emit MSAA textureLoad before getDimensions to avoid amdxc64 crash #1900 fixes nor its return from a cached container
  • that identity() passes the hash on is covered only by the scratch test, not by the unit test
  • direct_compute / direct_graphics in pso.rs stay outside the hash, as before: bump TRANSLATOR_VERSION for those (Shaders: guard wave64 graphics direct DXIL #1913 changes direct_graphics without one; it also edits hashed sources, which changes the identity anyway)
  • the build together with any of the PRs below

Overlaps (open PRs, merged in a scratch tree with this PR and with main 62265d3, 2026-11-24 23:45Z):

AI use

  • Claude Code (Claude Opus 5.5) wrote the fix and the test, ran the tests and wrote this text; a second Claude Opus 5.5 agent reviewed the diff. A Claude Fable 5.2 agent checked this text against the logs. I have read the diff and the text.

🤖 Generated with Claude Code

The translated cache's identity covers the HLSL path's sources
(XCL_TRANSLATOR_SOURCE_ID), but of gpu/dxil only TRANSLATOR_VERSION,
which is bumped by hand. Two changes that bump it to the same number,
or one that does not bump it (xcl-dev#1900), leave containers of the old
translator in use.

build.rs hashes every .rs file of gpu/dxil but the *tests.rs ones into
XCL_DIRECT_DXIL_SOURCE_ID, which only the direct entries' identity
includes (and the per-lane entries', which extend it). The HLSL path's
entries keep theirs, as with bfb8133 for the per-lane sources. The
directory is listed rather than named file by file, so that a new file
is not left out. TRANSLATOR_VERSION stays, for changes of pso.rs's
direct_compute / direct_graphics; edits of gpu/dxil no longer need it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pvfreis
pvfreis marked this pull request as ready for review November 24, 2026 23:49
anoyarou pushed a commit to anoyarou/xcl that referenced this pull request Nov 25, 2026
…-dev#1947)

The translated cache's identity covers the HLSL path's sources
(XCL_TRANSLATOR_SOURCE_ID), but of gpu/dxil only TRANSLATOR_VERSION,
which is bumped by hand. Two changes that bump it to the same number,
or one that does not bump it (xcl-dev#1900), leave containers of the old
translator in use.

build.rs hashes every .rs file of gpu/dxil but the *tests.rs ones into
XCL_DIRECT_DXIL_SOURCE_ID, which only the direct entries' identity
includes (and the per-lane entries', which extend it). The HLSL path's
entries keep theirs, as with bfb8133 for the per-lane sources. The
directory is listed rather than named file by file, so that a new file
is not left out. TRANSLATOR_VERSION stays, for changes of pso.rs's
direct_compute / direct_graphics; edits of gpu/dxil no longer need it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@futurepro62

futurepro62 commented Nov 25, 2026 •

Copy link
Copy Markdown

Full-suite run, since this PR has no test report yet. Tested exact head 1831ec4 (on its base 20cf130).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, DXC + dxil.dll 1.9.2602.17 (Windows SDK 10.0.26100), debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form --skip gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::const_and_null_mask_operands_agree_with_hlsl_on_the_gpu --skip gpu::dxil::fuzz_tests: 967 passed, 0 failed, 43 ignored. SKIPPED (no wave64): a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu, a_per_lane_2d_or_3d_group_runs_on_the_gpu, coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu, cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu, gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware, the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu.
  • The new tests ran and passed: direct_dxil_identity_tracks_its_sources.
  • Same head on the AMD Radeon integrated GPU (iGPU) of the Ryzen 7 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace -- --test-threads=4 --skip gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1: 976 passed, 0 failed, 45 ignored. SKIPPED: 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_programs_on_the_gpu (f16 arithmetic, wave64, 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_programs_on_the_gpu (f16 packed, wave32, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 packed, wave64, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f32_programs_on_the_gpu (f32 conversions, wave32, per-lane form: refused (unsupported V_CVT_F16_F32 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f32_programs_on_the_gpu (f32 conversions, wave64, per-lane form: refused (unsupported V_CVT_F16_F32 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • --skip leaves out tests that fail on main 80f4819 too, not because of this PR. On NVIDIA: heap_window_out_of_memory_falls_back_to_the_switch_form (Tests: heap_window_out_of_memory_falls_back_to_the_switch_form fails under XCL_REQUIRE_GPU=mesh (opt-in skip counted as missing coverage) #1651), the four gpu::recomp::lower_dxil::tests::*_programs_on_the_gpu tests and const_and_null_mask_operands_agree_with_hlsl_on_the_gpu (follow-up on #1651) fail because runner::skip_test turns their skips into failures under XCL_REQUIRE_GPU=mesh, and gpu::dxil::fuzz_tests seeds 70, 545, 1019 and 1507 fail CreateComputePipelineState with E_OUTOFMEMORY on this card (drivers 616.64 and 621.40). On AMD: fuzz_validate_and_gpu_1 fails on seed 540 (res[833] 0x7 vs CPU 0x6). The AMD run does not set XCL_REQUIRE_GPU.

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.

@upipibi

upipibi commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

RTX 3070 (Ampere, driver 616.56, Windows 11, debug) at 1831ec4: cargo test -p xcl --lib -- --skip gpu_ gives 817 passed, 0 failed, and the gpu_ tests with XCL_DIRECT_DXIL=1 give 110 passed, the same as main.

A live example of the "bumps it to one already used" case: three open PRs each bump TRANSLATOR_VERSION from 7 to 8 right now (#1946, #1950, #1952). Whichever two merge later would each need to renumber by hand. With this PR in, none of them needs a bump, since all three only change gpu/dxil files.

AI-assisted (Claude Code).

@anes66

anes66 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

CPU-only build-script validation on exact head 1831ec4a5abb1c3ae0ca4ab3803776f7fafe30cb passed. Optional regression companion d8dc190, directly on that head, adds one integration test; no runtime/build-script changes remain in the patch.

Tested

  • Windows 10 Pro 19045, Ryzen 7 9800X3D, Rust 1.100.0 MSVC, debug. No translator, DXC or GPU execution, no retail files.
  • The test copies Rust sources into a scratch tree, compiles this PR's actual build.rs against that tree, and checks all three emitted identity strings across 17 script invocations. It does not reimplement the hash.
  • Editing dxil/cfg.rs or dxil/module/opt.rs changes only the direct identity; editing recomp/lower.rs changes only per-lane; editing recomp/emit.rs changes only the common source identity. Restoring the bytes restores all identities.
  • New top-level/nested runtime files are included. Reversing their creation order preserves the identity; renaming a source changes it; deleting both probe files restores the baseline. Editing standalone ops_tests.rs or adding a non-Rust file changes none of the three.
  • Negative control: omitting recursive directory traversal from the real script makes the new test fail on the nested runtime source. The control was restored before the final passing run and commit.
  • cargo test --locked -p xcl --test direct_source_identity -- --nocapture --test-threads=1: 1 passed / 0 failed / 0 ignored, no skips.
  • cargo test --locked -p xcl --lib gpu::recomp::pso::shader_cache_tests:: -- --nocapture --test-threads=1: 14 passed / 0 failed / 0 ignored, no skips.

Not tested
Cargo's filesystem-change scheduling (the test invokes the compiled script itself), full workspace/GPU suite, release, retail cache reuse, or integration onto newer main. Compiling the script requires rustc and the normal MSVC build environment. No competing upstream PR.

AI use
Codex (GPT-6; exact variant unavailable) wrote the regression and temporary control, ran CPU validation and prepared this report.

@JJAutoCompare

Copy link
Copy Markdown

Tested

Clean PR head 1831ec4a5abb1c3ae0ca4ab3803776f7fafe30cb on an AMD Ryzen 7 3800X, Windows 11 Enterprise Evaluation 26200.9974, Rust 1.100.0 x86_64-pc-windows-msvc (debug). The host has an Intel Arc A770 (driver 32.0.101.9175). These checks were CPU-only. Cargo target, temporary files and the DXIL cache used private directories on L: with CARGO_INCREMENTAL=0.

cargo test --locked -p xcl --lib -j 2 -- --nocapture --test-threads=2 translated_identity_tracks_sources_and_dxc translated_namespace_tracks_every_request_input translations_on_disk_need_the_same_bytes_and_identity translated_v2_ignores_valid_entries_outside_its_namespace direct_dxil_identity_never_collides_with_hlsl direct_dxil_identity_tracks_its_sources direct_and_hlsl_disk_entries_are_separate

7 passed, 0 failed, 0 ignored, 0 skipped (946 filtered out). This exercised source and backend identities, cache hits and misses across namespaces and rejection of truncated entries.

I also ran cargo run --offline -j 2 -vv --bin xcl in five states of a scratch Cargo package that used the PR's unchanged build.rs and copied source inputs. All five runs exited 0 and matched their assertions. An unchanged rerun reused the build output. Editing src/gpu/dxil/module/opt.rs reran the build script and changed only the direct identity (8f217b15dfe94ce9 to 80f5ea9901858109). Restoring the bytes reran the script and restored the original value. Editing src/gpu/dxil/ops_tests.rs reran the script and preserved all three identities.

Not tested

Full workspace suite, release build, DXC or shader execution on the GPU, retail-title cache reuse or smoke runs.

AI use

Codex (gpt-6.2-sol) ran the tests, wrote the scratch probe and prepared this report.

@raylitebull
raylitebull merged commit 0f293be into xcl-dev:main Nov 25, 2026
4 checks passed
Royalflamejlh pushed a commit to Royalflamejlh/xcl that referenced this pull request Nov 25, 2026
…n the GPU

Two loop shapes (two returns to one head; a nested loop with returns to
either head), wave32 and split wave64, against HLSL + DXC and explicit
expected values. The test of anes66's companion commit b780cdd, taken
without its cache-version bump, which xcl-dev#1947 makes unnecessary.
luckyteagirl added a commit to luckyteagirl/xcl that referenced this pull request Nov 25, 2026
Track each memory write's pointer, value, and control block when computing
input-to-output dependencies for dx.viewIdState and PSV0. Preserve the
fixed-point traversal merged in xcl-dev#1966. The direct-DXIL source hash from
xcl-dev#1947 accounts for the changed output without a manual version bump.

Refs xcl-dev#1892
@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

Thanks!

mastrr9 added a commit to mastrr9/xcl that referenced this pull request Nov 25, 2026
`Module::optimize` replaces a phi only when it is trivial on its own
(every incoming value the phi itself or one other value). A loop whose
body sets a register back to the value it had before the loop (a copy,
a constant, or two copies of one expression that CSE merges) leaves a
cycle of phis that name each other plus that one value: the loop
header's phi takes the value and the join's phi, the join's phi takes
the header's phi and the value. Neither is trivial alone, so both were
written, with their uses.

Remove such groups as Braun et al. ("Simple and Efficient Construction
of Static Single Assignment Form", CC 2013) do: Tarjan's strongly
connected components over the phi operand graph, operands first; a
component whose operands outside it are all one value becomes that
value; a component with several outside values is a real merge, and
the phis in it that name only its members are searched again for such
a group. The step runs after the trivial phis (so CSE sees the
replacements) and once more after CSE (groups whose definitions CSE
merged). `XCL_DXIL_NO_OPT=scc` skips it. No TRANSLATOR_VERSION change:
the translation cache's identity includes a hash of the `gpu/dxil`
sources (xcl-dev#1947).

Tests build the IR by hand: a redundant two-phi loop cycle, the same
loop with a real second value (kept), a redundant inner group inside a
real outer merge, and a cycle that is redundant only after CSE.
Royalflamejlh pushed a commit to Royalflamejlh/xcl that referenced this pull request Nov 25, 2026
…n the GPU

Two loop shapes (two returns to one head; a nested loop with returns to
either head), wave32 and split wave64, against HLSL + DXC and explicit
expected values. The test of anes66's companion commit b780cdd, taken
without its cache-version bump, which xcl-dev#1947 makes unnecessary.
Royalflamejlh pushed a commit to Royalflamejlh/xcl that referenced this pull request Nov 25, 2026
…n the GPU

Two loop shapes (two returns to one head; a nested loop with returns to
either head), wave32 and split wave64, against HLSL + DXC and explicit
expected values. The test of anes66's companion commit b780cdd, taken
without its cache-version bump, which xcl-dev#1947 makes unnecessary.
Royalflamejlh pushed a commit to Royalflamejlh/xcl that referenced this pull request Nov 25, 2026
…n the GPU

Two loop shapes (two returns to one head; a nested loop with returns to
either head), wave32 and split wave64, against HLSL + DXC and explicit
expected values. The test of anes66's companion commit b780cdd, taken
without its cache-version bump, which xcl-dev#1947 makes unnecessary.
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.

7 participants