Skip to content

Direct DXIL: XCL_DXIL_DIFF=1 differential kernel runs (both backends) - #1934

Draft
mastrr9 wants to merge 1 commit into
xcl-dev:mainfrom
mastrr9:feat/dxil-diff-kernel-mode
Draft

mastrr9 wants to merge 1 commit into
xcl-dev:mainfrom
mastrr9:feat/dxil-diff-kernel-mode

Conversation

@mastrr9

@mastrr9 mastrr9 commented Nov 24, 2026

Copy link
Copy Markdown

XCL_DXIL_DIFF=1 runs the recompiler's kernel tests through both HLSL + DXC and the direct DXIL translator and fails on any difference. XCL_DXIL_DIFF_TABLE=<path> also records each paired program, for a per-opcode parity table. This is the proof the direct DXIL spec asks for before phase 7 (default-on). With the variable unset the tests run as before.

Draft: the head commit has not been built or tested yet.

What is in it

  • gpu/recomp/diff_kernel.rs: pairing, comparison and mismatch report, with tests
  • gpu/recomp/diff_table.rs: the per-program log and per-opcode summary, with tests
  • gpu/recomp/runner.rs, mod.rs: early returns taken only when the mode is on or a container was paired
  • gpu/recomp/tests.rs: pairs the tests that compile their own HLSL
  • docs/specs/2026-11-24-direct-dxil.md: 9 lines describing the switch (can be dropped if you prefer the spec untouched)

Tested
These runs are from before the final rebase, on a combined branch (376f968, based on main 689f2db; it holds this change, the other half of the differential mode, and six direct-translator parity fixes), not on this PR's head commit.

  • Windows 11 x64, NVIDIA GeForce RTX 5080 16 GB, cargo test debug build. Driver, CPU and Rust versions were not recorded.
  • cargo test -p xcl --lib recomp::diff_kernel -- --nocapture --test-threads=1: passed.
  • XCL_DXIL_DIFF=1 (with XCL_DXIL_DIFF_TABLE, XCL_DIRECT_DXIL unset), cargo test -p xcl --lib recomp:: -- --test-threads=1: 285 tests ran, 279 passed, 6 reported HLSL / direct mismatches. Not all of the 285 run both backends (some only translate). The combined tree had direct-translator fixes that this PR does not, so this PR alone may report differently.
  • Kernel-side mismatches: gpu_compute_tg_size_counts_a_partial_last_wave (HLSL 2, direct 1) and two 1–5 ULP floating-point differences in BVH ray intersection. Three more were wave64 VS / PS draws, found by the graphics half (separate PR).
  • Per-opcode table from that sweep: 71 rows, 69 matched, 2 mismatched.

Regression run
Not run: there are no xcl-smoke blocks for this change.

Not tested

  • The head commit (rebased onto main f5136a6) has not been built or tested: it was rebased on macOS, with no Rust toolchain.
  • cargo test --workspace was not run for this change on its own.
  • AMD and Intel GPUs; release build.
  • The early-exited-wave barrier program of gpu_safe_s_barrier_multi_warp_and_early_endpgm is deliberately not paired (see Direct DXIL: make multi-wave Compute and Mesh s_barrier early-exit-safe #1793).

AI use

  • Code and tests: written by Claude Opus 5.5 in an agent session (Duet) with no Windows or GPU.
  • RTX 5080 test runs above: a Claude Sonnet 5.5 agent.
  • Overlap check, rebase and this description: Claude Code, Claude Sonnet 5.5.

The direct DXIL spec's testing strategy asks for every recompiler kernel
test to run through both backends with identical results; the runner
picked one backend by XCL_DIRECT_DXIL. With XCL_DXIL_DIFF=1,
runner::run_code, run_code_with and run_program (through run_code)
translate the program with HLSL + DXC and with the direct translator,
run both kernels with the same inputs and compare SGPRs, SCC, every
lane's VGPRs, exports, flat memory and the UAV test textures. A
difference is an error naming the field, the first 8 differing slots
(lane/register decoded, HLSL and direct value in hex) and the count; a
program the direct translator refuses keeps the HLSL result (counted,
each distinct reason logged once), so the existing suite runs unchanged
in this mode. Panics, validation and builder failures of the direct
translator are errors, not refusals.

Tests that compile the HLSL kernel themselves (kernel_wave, run_wave and
kernel-mode direct_or in recomp/tests.rs) pair the container with its
direct translation (diff_kernel::pair); every later runner::run* of
that container on the same thread runs both and compares, so a test
that runs one kernel from many states is compared for each. Compute-mode
programs from direct_or are paired too: runner::dispatch then compares
the flat memory both dispatches leave (dispatch_timed stays one run).

Each backend stores only the registers it uses, so a register one side
leaves unstored (0) while the other stores its unchanged input value is
not a difference: an SGPR on its own, a VGPR only when that holds in
every lane that ran.

The comparison lives in the new recomp/diff_kernel.rs; runner.rs gains
early returns in run_code, run_code_with, run_with_statics and
dispatch, tests.rs one pairing line in kernel_wave, kernel- and
compute-mode branches in direct_or, and diff_pair for two compute
tests that compile their own HLSL (the safe-barrier test's multi-warp
loop only: main's direct s_barrier does not handle early-exited waves).
Without the variable nothing changes.

With XCL_DXIL_DIFF_TABLE=<path> as well, each paired program appends one
line to <path> (test thread name, FNV-1a hash of the program, matched /
mismatched / refused / failed, its distinct RDNA2 mnemonics), one
append-mode write per line and once per program and outcome, so the
per-opcode parity table needs no exit hook. The new recomp/diff_table.rs
holds the recording and summarise/table, which count per opcode the
distinct programs containing it by their worst outcome; with
XCL_DXIL_DIFF_SUMMARY=<path> its summary test prints that table and
writes it to <path>.summary.tsv.
@upipibi

upipibi commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Built and ran, since the description says the head wasn't yet: RTX 3070 8 GB (32-lane waves, split wave64), driver 616.56, Windows 11, debug, d2758cb merged onto main 20cf130 (clean).

  • diff_kernel / diff_table unit tests: 13 passed.
  • XCL_DXIL_DIFF=1 cargo test -p xcl --lib -- gpu::recomp::tests --test-threads=4: 119 passed, 4 differ, 17 ignored. The mode does what it says and found these:
Test Difference Reading
gpu_compute_tg_size_counts_a_partial_last_wave 96 words: HLSL 2, direct 1 a direct-DXIL bug: dxil/kernel.rs sets TG_SIZE's wave count to total / lanes; the test (and the HLSL path) want total.div_ceil(lanes) (96 threads in wave64 are 2 waves). The test compiles only HLSL, so it never saw this
gpu_format_stores_atomics_global_lds 97 VGPRs, e.g. lane 1 v16 HLSL 0x64 vs direct 0xa3, v26 0x1 vs 0x44 not traced yet; the test's own checks pass on both
gpu_built_bvh_nodes_match_the_cpu_node_test, gpu_triangle_pair_and_box16_nodes 2–3 values, 1–2 ulp (0xc0dd6761 vs …63) float contraction / rounding between the backends; both within the tests' own tolerance

I'll open a small PR for the TG_SIZE one. The ulp cases might want a tolerance option in the comparison, so a known-inexact op doesn't hide a real difference in the same test.

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

raylitebull pushed a commit that referenced this pull request Nov 25, 2026
The direct translator set TG_SIZE's wave count to threads / lanes, so a
group of 96 threads in wave64 read 1 wave where the console (and the HLSL
path) give 2. It is now threads.div_ceil(lanes). The existing test
gpu_compute_tg_size_counts_a_partial_last_wave now runs through
direct_or, so XCL_DIRECT_DXIL=1 covers this path; it fails without the
fix (left: 1, right: 2 for 96 threads in wave64).

Found with #1934's XCL_DXIL_DIFF=1.

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

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11): merge conflict with current main — needs a rebase before it can be tested.

@upipibi

upipibi commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Second run with XCL_DXIL_DIFF=1: RTX 3070, driver 616.56, debug. I merged d2758cb with main 568e7db; one hunk in tests.rs conflicts, and I kept main's direct_or(...) line, which also pairs in this mode. gpu_ tests, --test-threads=1: 130 passed, 5 differ.

Test Difference Reading
gpu_compute_tg_size_counts_a_partial_last_wave none now fixed by #1950
gpu_format_stores_atomics_global_lds, gpu_atomic_fcmpswap_x2 returned values of atomics (e.g. buffer_atomic_umax GLC old value: HLSL 0, 0x64, 0x65, …, direct 0xa3 on every lane; ds_add_rtn_u32 old values in another order) false positives. The lane order of one atomic across a wave is unspecified: direct's umax values are what you get when lane 63 goes first. The test's own checks accept any order. With XCL_DIRECT_DXIL=1 the test passes 5 of 5 runs, and in diff mode it differed in 4 runs and matched in 1.
gpu_f64_math_random lanes 14 and 22, v_rsq_f64 high dword: HLSL 0x7ff00000, direct 0x7ff80000 (low dword equal) a NaN payload: HLSL returns the input signalling NaN unchanged, and direct quiets it (closer to RDNA's IEEE mode). The test treats every NaN as equal. Reproduces in 3 of 3 runs.
gpu_built_bvh_nodes_match_the_cpu_node_test, gpu_triangle_pair_and_box16_nodes 1–2 ulp as before
gpu_image_get_resinfo_1d_array 64 values the known direct failure on main

For the comparison, it might help to compare the destinations of returning atomics as multisets, or let a test mark them as unordered. Compare NaNs by class or by payload, as a test chooses. Otherwise the noise hides a real difference in the same test.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants