Skip to content

gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL - #1426

Merged
raylitebull merged 34 commits into
xcl-dev:mainfrom
bmjask:shaders/direct-dxil-main
Nov 24, 2026
Merged

raylitebull merged 34 commits into
xcl-dev:mainfrom
bmjask:shaders/direct-dxil-main

Conversation

@bmjask

@bmjask bmjask commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

A backend that translates console RDNA2 programs straight to signed DXIL containers, with no HLSL text and no DXC at run time. It sits next to the HLSL path, is off by default, and is selected with XCL_DIRECT_DXIL=1: console compute shaders, the mesh pass and (with =all) VS/PS. Anything it can't translate falls back to the HLSL path and is logged. It is the base for the per-lane mode that @gefydev's team is building on it (#1269).

What is in it

  • crates/xcl/src/gpu/dxil/:
    • Bitcode writer: bitstream.rs and module.rs write LLVM 3.7 bitcode. Blocks are written in reverse post-order of the CFG, so a lowering may create blocks in any order; replace_all_uses is available.
    • Cleanup passes: module/opt.rs removes trivial phis, merges duplicate pure instructions along the dominator tree, and removes dead code. XCL_DXIL_NO_OPT=phi,cse,dce|all turns passes off for bisecting. There is no fast-math or float reassociation, and wave ops are only merged within one block.
    • DXIL layer: shader.rs and ops.rs cover dx.op calls, handles, resource metadata and shader flags. Every dx.op declaration's attributes are checked against DXC's table. The op library covers math, memory, atomics, typed/raw/structured buffers, textures/samplers, wave ops and derivatives.
    • Graphics: graphics.rs and container.rs write ISG1/OSG1/PSG1, PSV0 and the view-ID tables, and handle VS/PS/MS entries. The digest is computed in-tree and matches DXC byte for byte.
    • Translator: cfg.rs, ssa.rs, lanes.rs, lower*.rs, kernel.rs. It builds a CFG, constructs SSA on the fly, keeps lane masks and lowers every instruction, using the same EXEC model as the HLSL path. Lw::inst_guarded lets an external control-flow analysis reuse the per-instruction lowering.
    • Coverage: coverage.rs adds xcl shaders <pack> --direct [--sample N] [--validate] [--compare] to sweep a pack, and XCL_DIRECT_DXIL_STATS=1 prints live fallback statistics at exit.
    • Oracle: validate.rs wraps DXC's validator and disassembler, used in tests only. With a validator older than 1.8 only the validation step is skipped.
  • Hooks:
    • recomp/pso.rs: routing with HLSL fallback, and a separate on-disk cache identity per backend and TRANSLATOR_VERSION. HLSL cache entries are unchanged.
    • recomp/runner.rs: test-only additions.
    • recomp/tests.rs: backend switch.
  • Heap memory windows (XCL_HEAP_WINDOWS, merged from main) are not translated yet; those shaders take the HLSL path.
  • Fixed from reports in this thread:
    • AMD driver crash: !llvm.ident is now emitted.
    • AMD's 64-bit Bfrev miscompile: halves are now reversed separately.
    • WaveMultiPrefixBit* is now signed, as DXC emits it. The unsigned form removed the device on RDNA4.
    • waveGetLaneIndex is readonly (@Kalmarv).
    • VS/PS that branch before their exports (@Kalmarv).
    • The fuzzer no longer emits groupshared atomicrmw sub, which NVIDIA rejects.
    • Validator 1.7 handling, and draw tests skip on CI/WARP.
    • Fixtures are in tests/data/dxil/.
    • The test validator wrapper refuses input shorter than a container header, because DXC 1.8 read past it (patch by @upipibi, reported by @DavidM1911).
    • Builder misuse is recorded as an error and falls back to HLSL.
    • Irreducible console control flow. The console compiler emits loops entered in the middle. The CFG builder now splits nodes until every loop has one entry, so the DXIL is reducible, as DXIL requires. If that would grow the CFG past 4×, the program falls back to HLSL. This is the cause of the amdxc64.dll fault HKEY-Funk-Machine isolated on cs 62b584e061c05fc5: release builds skip the validator, and NVIDIA tolerated the irreducible CFG.
    • Countbits.i64 is emitted per 32-bit half, a workaround like the one for Bfrev.i64.
    • XCL_DXIL_DUMP=<hash|all> writes the direct DXIL of chosen programs. xcl shaders --direct --hash <h> --dump <dir> does the same in sweeps.
    • Translation time: a guarded region now merges only the registers it writes. On the sample, p50 is 29 ms, p95 0.38 s and max about 1 s, down from 64 ms / 1.6 s / 3.7 s.

Tested

  • RTX 4090 (wave32 only), NVIDIA driver, Windows 11, Rust 1.96 MSVC, debug, DXC 1.9.2602.17 (test oracle only), head 81d2ad5a9d06.

  • cargo test --workspace -- --test-threads=4: 858 passed, 0 failed, 42 ignored. SKIPPED GPU tests: gpu_geometry_wave32_prefix_count_over_a_mask (no wave64), gpu_wave32_program_in_wave64_hardware (no wave64), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).

  • XCL_DIRECT_DXIL=1 and =all, cargo test -p xcl --lib gpu::recomp: 194 passed, 0 failed, 18 ignored each. Every kernel/compute/mesh/VS/PS test goes through the direct path, with no fallback in tests.

  • Retail pack sample (xcl shaders shaders.rpf --direct --sample 200 --seed 1 --validate --compare):

    before the fixes in this round now
    translated (all validator-clean) 113 / 200 197 / 200 (the 3 left are ES+GS, not in this PR)
    translation time p50 / p95 605 ms / 10 s 29 ms / 0.38 s
    size vs HLSL+DXC 14.5× 1.25×
  • Also checked:

    • Signature and PSV0 parts match DXC byte for byte on 16+ references.
    • Randomised differential tests (2000 modules validated, about 1230 compared with a CPU interpreter on the GPU) ran on this code; they move to the stacked follow-up PR to keep this diff under GitHub's 20 000-line limit.
    • The same container is produced across runs and threads.
  • Testers on this PR:

    • Kalmarv (RTX 5070 Ti): whole suite with DXC 1.7 and 1.9; dxil.dll and dxil-spirv checks of 303 containers; smoke pairs.
    • mastrr9 (RTX 5080).
    • vitor127wt (RTX 5070 Ti, Linux).
    • ArturoWolff (RTX 4060, Proton).
    • emirduran707 (RX 9060 XT): no crash after !llvm.ident.
    • HKEY-Funk-Machine (RX 9070).
    • SlopTart (RX 7900 XT, RADV).

Regression run
The retail title, 60 s each, RTX 4090, release builds, back to back on an idle machine, XCL_DIRECT_DXIL unset, no uncommitted changes. PR (head 81d2ad5a9d06): 97 % of main's frames, 111 % of its peak commit (one earlier run on this head stalled near its end on a busy machine, 1400 frames; the rerun on an idle machine is the block below), no crash or device removal.

main:

xcl-smoke v1
commit: 9e3831e1f570d3646e53ab753b19ec07eb8f1485
gpu: NVIDIA GeForce RTX 4090
title: game
seconds: 60
exit: 0x0
frames shown: 1590 (PresentX 1590)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15360 MB

PR:

xcl-smoke v1
commit: 81d2ad5a9d06f6d11211f0c2524d5db9c3362bcf
gpu: NVIDIA GeForce RTX 4090
title: game
seconds: 60
exit: 0x0
frames shown: 1539 (PresentX 1539)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17128 MB

Not tested

  • AMD: the Bfrev and multi-prefix fixes come from testers' bisections and are not yet re-run on RDNA. The amdxc64.dll fault on one retail program is fixed (irreducible CFG, above) but not yet re-run on AMD. Fuzz seed 722 on RDNA4 looks like the driver moving a wave op into a divergent branch. RADV seeds 1003/1698 are a Mesa folding bug, traced in the thread.
  • Hardware: native wave64 hardware, and Intel.
  • Direct path in a title on this head (only the default path was smoke-tested here).
  • Not in this PR: geometry mode (ES+GS), MSAA, non-default f32 round modes, heap memory windows, and the randomised fuzz tests (kept out to stay under GitHub's 20 000-line diff limit). These exist on follow-up branches and will come as a stacked PR.

AI use

  • Claude Code (Claude Opus 5.5): designed and wrote the code and tests (several coordinated agents), ran the suites, the sample sweep and the regression runs on the RTX 4090, and drafted this description. Written from scratch. The references are the LLVM 3.7 bitcode format and DXC (NCSA licence), plus DXC's output for small HLSL programs. No code from GPL-3 projects was used.

🤖 Generated with Claude Code

bmjask and others added 10 commits November 24, 2026 09:54
…ages)

Emits signed DXIL containers without HLSL or DXC: LLVM 3.7 bitcode writer,
DXBC container with the retail digest, dx.op library (math, memory,
atomics, textures, wave ops), VS/PS/MS signatures and PSV0 matching DXC
byte for byte. DXC's validator is used as a test oracle only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
LLVM's reader only accepted 7 because unknown codes fall back to seq_cst.
Adds a test-only reader for our unabbreviated bitstream to check record
layouts the validator cannot distinguish.

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

The validator derives these flags from the code; kernels that built i64 or
double instructions with plain Module methods (rather than the Shader
helpers that call require) failed with "Flags must match usage". Both
finish paths now scan the entry for i64 / double operands and results,
and for double division and int <-> double conversions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Seeded xorshift generator of random-but-valid kernels (integer / float /
i64 / double arithmetic with guards, phis, diamonds, switches, loops with
back-edge phis, selects, dx.op integer ops, group-shared exchange and
atomics with barriers, wave reads, raw buffer I/O). 2000 modules pass the
validator; the exactly-comparable ones (~1200) run on the GPU against a
CPU interpreter. Includes the regression test for shader-flag inference.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Empty DXC blobs may report a null buffer, which slice::from_raw_parts
forbids (UB); error-buffer casts no longer unwrap, and blobs over 4 GiB
are an error instead of a truncated length. Adds a malformed-input test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Garbage above a half / float constant's width made equal constants
intern twice (and relied on the reader truncating the record).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Port of the translator from dxil/core (olympus-based) onto main:
CFG/SSA, the EXEC/ballot lane model, SALU/VALU/memory/image/cross-lane
lowering, compute/VS/PS/mesh entry points (gpu::dxil::kernel).

Hooks re-done against main's recomp: runner (direct_dxil, direct_kernel,
direct_kernel_full, switch in run_code/run_code_with), pso (direct compute,
VS/PS and mesh pass with logged HLSL fallback; the on-disk translation
cache is bypassed while the switch is on), tests (direct_or/direct_check),
constant_samplers pub(crate).

Translator fixes for tests only main has: f64/cvt output modifiers and
clamp, integer/packed/dot clamp, wave32 src_vccz/src_execz, b32 saveexec
with m0, SDWA f16 inline constants, cube T#s as cube arrays.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The translated cache identity now includes the backend (HLSL / direct
compute / direct all) and gpu::dxil::kernel::TRANSLATOR_VERSION when
XCL_DIRECT_DXIL is set; the HLSL identity is unchanged, so existing
entries stay valid. Caching is re-enabled for the direct path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Translator state is only looked up through hash maps (never iterated
into output), so no fix was needed; the test pins it.

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

gefydev commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

This overlaps with the direct DXIL work tracked in #1269. The two halves fit, so I'd rather build on this than finish a second writer.

What #1426 lists as future work is what gefydev/xcl recomp-lane-masks has:

  • Lane-mask analysis (gpu/recomp/lane_masks.rs). Each mask is followed as a per-lane boolean function, to work out which vector instructions still need an EXEC guard. On the retail pack, 25 695 of 26 698 programs are analysed and 37.1 % of 28.7 M vector instructions keep a guard, against 100 % today. It also exports the CFG and which branches are per-lane.
  • Lowering with per-lane control flow (gpu/recomp/ssa.rs, gpu/recomp/lower.rs). It keeps the console CFG, builds SSA over register dwords on the fly, and makes mask branches per-lane branches. It refuses, so the program falls back, where a mask written while some lanes were elsewhere is read after they meet again. Kernel and compute mode and memory are done. It writes through a small Ir trait, and its tests compare it with the HLSL path on the GPU: registers and memory agree (GTX 1650, wave32).

The proposal, also posted in #1269: this PR is the infrastructure, and I rebase onto it and implement the Ir trait on your module builder. The lowering then gives XCL_DIRECT_DXIL a per-lane mode as a follow-up on top of #1426, falling back to your per-instruction masking wherever the analysis refuses a program.

Two questions:

  1. Is module.rs / shader.rs meant as the API a second lowering can target? The Ir trait needs blocks, br / conditional br, phis with incoming values added later and trivial ones replaced, integer ops and compares, select, lane / thread / group ids, ballot, and raw buffer loads and stores.
  2. Would you take that per-lane mode as a follow-up PR once this one lands, or should it wait for review here first?

AI use: Claude Code (Claude Opus 5.5) wrote this comment for @gefydev.

@mastrr9

mastrr9 commented Nov 24, 2026

Copy link
Copy Markdown

RTX 5080 (Blackwell, wave32 / split-wave64) test report for head 065aef35c30f364d2a9be2431a1466cddf05e761 (Windows 11, DXC 1.9.2602.17, Rust MSVC, debug build, clean worktree):

  • cargo build --workspace: OK (0 new compiler warnings).
  • cargo test --workspace -- --test-threads=4: 768 passed, 4 failed, 23 ignored (stopped at xcl lib).
  • cargo test --workspace -- --test-threads=1: 768 passed, 4 failed, 23 ignored (identical deterministic failures).

gpu::dxil breakdown: 61 passed, 2 ignored, 4 failed — all four are deterministic fuzz seeds that pass validation and fail in the NVIDIA Blackwell driver at fuzz_tests.rs:1158:110 with GPU run: CreateComputePipelineState: Not enough memory resources are available (0x8007000E):

  • fuzz_tests::fuzz_validate_and_gpu_0 (seed 62)
  • fuzz_tests::fuzz_validate_and_gpu_1 (seed 545)
  • fuzz_tests::fuzz_validate_and_gpu_2 (seed 1019)
  • fuzz_tests::fuzz_validate_and_gpu_3 (seed 1507)

Happy to re-run on the RTX 5080 whenever a follow-up lands!

Not tested: AMD, Linux/Wine, retail smoke (scripts/smoke.ps1).
AI use: T3 Code (Antigravity / Claude Sonnet 5.5) built the worktree, ran both --test-threads=4 and --test-threads=1 on our RTX 5080, and drafted this report.

…guarded)

act() and the cross-lane instructions' wave mask can be overridden, so an
external control-flow analysis can reuse the per-instruction lowering while
deciding EXEC itself. Default behaviour unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@HKEY-Funk-Machine

Copy link
Copy Markdown

Test report: #1426 at 065aef3 on AMD RDNA4 (Windows): every GPU test of the emitted DXIL crashes the AMD driver

@bmjask @gefydev: an RDNA4 data point, since #1426 is now the base for the direct path. On this card, every DXIL container the backend emits crashes the AMD shader compiler (amdxc64.dll) on PSO creation. It reproduces from the PR's own tests, no game data needed.

Tested

  • RX 9070 (RDNA4, native wave64), AMD driver 32.0.32015.7029 · Ryzen 9 7945HX3D · 32 GB · Windows 11 Pro 26300 · Rust 1.100.0 · release · DXC 1.9.2602.17 (only as the test oracle)
  • Clean 065aef3 for the tests.

1. The PR's direct-DXIL tests, each run alone (xcl-*.exe --exact <test> --test-threads=1, all 67 tests under gpu::dxil):

  • 42 passed: every CPU-side test, including container::tests::digest_matches_dxc_signed_container and psv_matches_dxc_layout_for_compute_with_two_raw_uavs.
  • 25 crash the test process with 0xC0000005: every test that creates a pipeline from emitted DXIL and dispatches or draws it. That includes the smallest, tests::emitted_kernel_runs_on_the_gpu, plus all ops_tests::* (integer, float, wave, atomics, typed/raw buffers, textures, doubles, int64, half), all four fuzz_tests::fuzz_validate_and_gpu_*, graphics::tests::emitted_{vs_ps,ms_ps}_draw_a_triangle, emitted_ps_samples_a_texture_with_implicit_lod, emitted_ms_primitive_attribute_reaches_the_pixel_shader, and core_tests::direct_and_hlsl_graphics_stages_link.
  • cargo test --release -p xcl --lib -- gpu::dxil --test-threads=1 stops at the first of them (direct_and_hlsl_graphics_stages_link) with STATUS_ACCESS_VIOLATION.
  • Not counted: the rest of the workspace suite (not run on this tree).

2. Retail title, tree 065aef3 + #751 + #1288 + one local patch that skips InitializeApiImplEx2, XCL_NETWORK=0:

  • XCL_DIRECT_DXIL=1: crashes 3 s after start, 3 runs out of 3, always at amdxc64.dll+0x1ab0cf7 (read at 0x40), on three PSO threads at once. By then the direct path had translated only three compute programs, all tiny (128–368 B of console code, 12.5–35 KB of DXIL, wave64), with no HLSL fallbacks.
  • XCL_SPLIT_WAVE64=1 XCL_DIRECT_DXIL=1: same crash at the same address, so it is not the native-wave64 form.
  • Same build without XCL_DIRECT_DXIL: runs normally (410 compute PSOs in 60 s, no crash).

On @Kalmarv's open question (the in-tree digest on AMD): D3D12 accepts the containers here. There is no E_INVALIDARG at PSO creation; the fault comes later, inside the driver's compiler. For comparison, @mastrr9's RTX 5080 run above fails only the four fuzz_validate_and_gpu_* seeds (E_OUTOFMEMORY from the driver), where this card crashes on all 25 GPU tests.

So the digest matches DXC's, but something in the module or container that NVIDIA's compiler accepts makes AMD's crash, independent of the program and the wave size. I can run a build with more logging, or check a candidate fix on this card.

Not tested

  • Other AMD driver versions (emirduran707's RX 9060 XT runs 32.0.32029.2010, newer than mine), RDNA2/3, the debug layer's validator on the emitted containers, XCL_DIRECT_DXIL=all.
  • I added a local log line to name the translated programs in the title run; the tests above ran without it.

AI use: Claude Code (Claude Opus 5.5) built the trees, ran the tests and the title, classified the per-test results, and drafted this report.

Module records the first misuse (forward reference outside phis,
instruction after a terminator, GEP/extractvalue/load into wrong types,
function redeclared with another type, bad call arity, bad constants,
add_incoming to a non-phi, use of a void value) and carries on with a
placeholder. New additive API: Module::fail/error/try_to_bitcode,
Shader::try_finish, Shader::try_finish_graphics; existing finish /
finish_graphics / to_bitcode keep their signatures (panic on a recorded
error). The translator uses the try_ variants, so pso.rs routing falls
back to HLSL with a log. Regression tests for each former panic.

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

Kalmarv commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Test report for 065aef3 on an RTX 5070 Ti (NVIDIA 610.74, 32-lane waves), AMD Ryzen 9 9950X, Windows 11 Pro 26200, as @gefydev asked on #1269. I'll edit this comment as more runs finish.

Tests (debug, clean tree at 065aef3)

command Windows SDK DXC 1.7.2308 (XCL's default here) DXC 1.9.2609 (XCL_DXC_DIR)
cargo test -p xcl --lib gpu::dxil 14 passed, 51 failed, 2 ignored 61 passed, 4 failed, 2 ignored
XCL_DIRECT_DXIL=1 cargo test -p xcl --lib gpu::recomp::tests 40 passed, 78 failed, 17 ignored 118 passed, 0 failed, 17 ignored

SKIPPED in the second row, both DXCs: gpu_wave32_program_in_wave64_hardware, gpu_geometry_wave32_prefix_count_over_a_mask (no wave64).

  • With DXC 1.7, all 129 failures have one cause: the modules carry dx.valver 1.8 (gpu/dxil/shader.rs:471, gpu/dxil/graphics.rs:918), and the 1.7 validator refuses them: Validator version in metadata (1.8) is not supported; maximum: (1.7). None of them reaches the GPU.
  • With DXC 1.9, the 4 failures are fuzz_tests::fuzz_validate_and_gpu_0..3, each stopping at its first bad seed (62, 545, 1019, 1507): CreateComputePipelineState: Not enough memory resources are available to complete this operation. (0x8007000E) (fuzz_tests.rs:1158). The modules pass DXC 1.9's validator; the NVIDIA driver refuses them, the same seeds every run, also one test at a time with 38 GB of commit free.
    • Over all 2000 seeds, each run on its own: 1150 ran and matched the CPU, 768 are not run on the GPU by the fuzzer's own rule, and 82 fail this way. All 82 have an atomicrmw sub on group-shared memory, and none of the 1141 modules without one fails. It isn't the whole condition: 9 modules with atomicrmw sub ran and matched (5 of them subtract a constant 0).
    • The translator doesn't emit atomicrmw sub (lower_mem.rs:965-967 writes an add of the negated value; RmwOp::Sub is used only by fuzz_tests.rs:510), and DXC never does either. So this is a driver limit the fuzzer hits, not a path a title takes. Generating add of the negation in the fuzzer too would keep the test on the forms drivers see.
  • The emitted containers through dxil.dll: 303 containers dumped from these tests (gpu::dxil: 187 CS, 12 PS, 9 VS, 4 MS; the direct recompiler tests: 89 CS, 1 PS, 1 VS). dxil.dll 1.9's IDxcValidator accepts every one meant to be valid; the 11 it refuses are the ones double_unary_legality_matches_dxil_tables expects to be refused. dxil.dll 1.7 refuses all 303 for the validator version alone.
  • The same containers through dxil-spirv (2.79.0, the vkd3d-proton translator, run on Linux with --validate, with vkd3d-proton's compute options) and spirv-val (vulkan1.3): all 292 meant to be valid convert, and every SPIR-V passes spirv-val. VS / PS / MS (26 containers) pass everything. (One CS needs its typed RWBuffer at u3 left out of the root-descriptor option, and five with raw 64-bit loads need those options; neither is a container fault.) Not run inside vkd3d-proton or on a Vulkan driver.

Regression run (60 s each, scripts/smoke.ps1, release builds, no uncommitted changes; main at 930e8b4, this PR's base, then this PR's head; XCL_DIRECT_DXIL unset). 100 % of main's frames, 107 % of its peak commit.

main 930e8b4:

xcl-smoke v1
commit: 930e8b49c1c2ec683d22c724a398b39111cd0e56
gpu: NVIDIA GeForce RTX 5070 Ti
title: GTA VI
seconds: 60
exit: 0x0
frames shown: 1323 (PresentX 1323)
presents per 2 s (last 3): 14 18 47
device removals: 0
crashes: 0
peak commit: 26231 MB

this PR, 065aef3:

xcl-smoke v1
commit: 065aef35c30f364d2a9be2431a1466cddf05e761
gpu: NVIDIA GeForce RTX 5070 Ti
title: GTA VI
seconds: 60
exit: 0x0
frames shown: 1321 (PresentX 1321)
presents per 2 s (last 3): 47 54 13
device removals: 0
crashes: 0
peak commit: 28081 MB

Title run with XCL_DIRECT_DXIL=1 (the same head, title and 60 s; no main counterpart): 1269 frames, no crash or device removal, peak commit 26751 MB. The log has no direct DXIL … HLSL path line, and the DXIL sizes differ from the HLSL path's (the first two programs: 6600 and 6572 B without the switch, 12928 and 12900 B with it), so the 79 compute pipelines it built went through the direct path. Compared with the pair's run of the same head without the switch (102 compute pipelines, 13 of them from the driver's blobs of an earlier build):

DXIL size, median DXIL size, largest total DXIL pipeline creation, median / largest
HLSL path 23 KB 1.2 MB 6.8 MB 1 ms / 106 ms
direct path 73 KB 14.7 MB 39.4 MB 106 ms / 24.2 s

The sizes compare like for like. The times likely don't: the HLSL path's programs had been built by the driver in earlier runs on this machine (median 1 ms), while every direct one was new to it.

Not tested

  • AMD and Intel, native wave64, vkd3d-proton itself (only its dxil-spirv translator, above).
  • The whole suite (running now), and XCL_DIRECT_DXIL=all.
  • Driver times on a cold driver cache for both paths.

AI use: Claude Code (Claude Opus 5.5, Claude Fable 5.2)

@ArturoWolff

ArturoWolff commented Nov 24, 2026 •

Copy link
Copy Markdown

RTX 4060 / Proton: direct compute dispatch passed on 065aef35c30f364d2a9be2431a1466cddf05e761, with fallback excluded. One synthetic wave32 group, 32 lanes, one memory window. Different EXEC masks controlled a register update (0xa5a5a5a5) and a global store (0xcccccccc). Each backend matched an independent CPU oracle on all 64 output words: 16 stores (eight updated values, eight preserved) and 48 untouched sentinels, including all 16 masked-off destinations.

Tested: Windows-target release build on Linux, Ryzen 5 5600, RTX 4060, NVIDIA 620.73.04, GE-Proton11-14, vkd3d-proton 4522cc1a8b1347f+. Separate Wine processes ran the exact direct and hlsl tests with --exact --nocapture --test-threads=1; each had 1 passed, 0 failed, 0 ignored, 0 skipped, 1 filtered. The direct probe calls gpu::dxil::kernel::translate_compute, fails on refusal and submits its returned bytes directly to CreateComputePipelineState. DXC was disabled in that process; dxcompiler.dll was not loaded before or after translation. The control used recomp::translate then dxc::compile. Both dispatched and read back the same buffer layout.

One observation per backend, not a speed benchmark: direct conversion 1,297 µs, first PSO 5,446 µs; control 97 µs to HLSL + 15,676 µs in DXC, first PSO 5,584 µs. No supplied cached PSO; not proof of a fully cold driver. Not tested: live hook/fallback selection, native Windows or AMD, wave64, the separate per-lane lowering, full suite, retail loading. AI use: Hermes Agent (gpt-6.2-astra), probe, execution, output verification and report.

Paired timing follow-up on the same head and RTX 4060

Skipping DXC saved time even after the first CreateComputePipelineState on two synthetic, all-active wave32 arithmetic shaders. Each size had four direct/HLSL pairs (two direct-first, two HLSL-first), one fresh Wine process per arm. Median within-pair differences in milliseconds; the last column is the median of the paired sums, not a sum of column medians:

Mixing rounds Conversion saved by direct Extra first-PSO time for direct Net saved, conversion + first PSO
32 31.70 0.18 31.51
256 153.43 5.96 149.165

Direct won the sum in all eight pairs. At 256 rounds its PSO was slower in every pair; its executable bitcode was 16,516 bytes vs 11,984 from DXC. The arithmetic survived both compilers (1,288 vs 1,287 LLVM binary-op records). All 16 dispatches matched a separate integer CPU oracle: 32 lane results and 32 untouched guard words per run; no refusal or skip. Both paths got identical ISA and runtime user data. The direct probe failed on refusal, with DXC disabled. Stock used recomp::translate + dxc::compile (cs_6_6, no extra flags).

Commands: private Windows-target release probe, probe.exe direct --exact --nocapture --test-threads=1 / probe.exe hlsl --exact --nocapture --test-threads=1, at each size. No supplied PSO blob; fresh per-arm cache directories and disk shader caches disabled, not a guarantee of a cold driver. These are conversion and PSO API timings, not GPU execution or retail startup timings. This compares this PR's per-instruction emitter to HLSL/DXC, not the coordinated per-lane emitter to this PR. AI use: Hermes Agent (gpt-6.2-astra), fixtures, measurements, verification and report.

CPU-only regression fixture for the writer-order request. At bc93a3a6f1d5ce2f5836135b231bd5e09e8d1658 (the same module.rs and bitstream.rs as a7cf0784c0eeb2e372b9cce48b1cf7f03f083e4a), I compiled those two unmodified modules with rustc --edition=2021 order.rs -o probe on Linux x86-64. The graph, values, phi incoming edges and order of all instruction-building calls are fixed. Only new_block() order changes. abc (head, body, exit) serializes; acb, bac, bca, cab, cba all report a non-phi forward reference. LLVM opt -passes=verify -disable-output accepted the independently reordered textual IR for all six, and rejected a negative control adding an entry→exit edge bypassing the definition. Reproducer function below; call once per order using a fresh module, and require all six to return Ok after the writer fix. No adapter workaround proposed. Writer test only, not shader validation, dispatch or timing. Hermes Agent (gpt-6.2-astra) wrote and ran the fixture.

Writer fixture (uses the existing module types)
fn loop_case(order: &str) -> Result<Vec<u8>, String> {
    let mut m=Module::new();m.define_entry("main"); let entry=m.entry_block();
    let mut ids=[Block(0);3];for c in order.bytes(){ids[(c-b'a') as usize]=m.new_block();}
    let [head,body,exit]=ids;let ty=m.i32();let zero=m.i32c(0);let one=m.i32c(1);let three=m.i32c(3);
    m.br(head);m.set_block(head);let i=m.phi(ty);m.add_incoming(i,zero,entry);m.br(body);
    m.set_block(body);let next=m.bin(BinOp::Add,i,one);let more=m.cmp(Pred::Ne,next,three);m.cond_br(more,head,exit);m.add_incoming(i,next,body);
    m.set_block(exit);let _=m.bin(BinOp::Xor,next,one);m.ret();
    m.try_to_bitcode("x86_64-unknown-linux-gnu","")
}

@gefydev

gefydev commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

@HKEY-Funk-Machine @bmjask a likely candidate for the AMD crash: #1426 never emits !llvm.ident (no occurrence in gpu/dxil/; Shader::finish writes dx.version, dx.valver, dx.shaderModel, dx.resources and dx.entryPoints only).

@Sr-0w measured exactly this on an RX 7800 XT (Windows driver) while testing the text path (#1269, #1269 (comment)). A module without !llvm.ident validates and signs, but CreateComputePipelineState faults inside the AMD driver with an access violation instead of returning an error. Any value works, e.g. !llvm.ident = !{!0} / !0 = !{!"xcl"}. That fits what you see: it hits every container, whatever the program or wave size, and NVIDIA and WARP don't mind.

The fix to try is one named metadata node in Shader::finish, next to the others. With the builder's API, roughly:

let ident = m.md_str("xcl");
let node = m.md_node(&[Some(ident)]);
m.named_md("llvm.ident", &[node]);

I can't run it on AMD here (GTX 1650). @HKEY-Funk-Machine, could you check tests::emitted_kernel_runs_on_the_gpu with that change on your RX 9070? If it isn't the cause, the shader flags are the next suspect: Sr-0w also found that they must match what the validator computes.

AI use: Claude Code (Claude Opus 5.5) wrote this comment for @gefydev.

@emirduran707

emirduran707 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Root cause of the AMD crash above: the emitted module has no !llvm.ident. With it, the direct path runs on RDNA4.

@bmjask @gefydev, following @HKEY-Funk-Machine's report: same crash here (amdxc64.dll 32.0.31044.16, 0xC0000005 at offset 0xf879d0, the same 25 gpu::dxil tests). I narrowed it down on tests::emitted_kernel_runs_on_the_gpu against DXC's output for the same program (testdata/dxc_cs_raw_uav.hlsl, compiled with cs_6_6, [WaveSize(64)]):

container result
DXC's runs
DXC's without HASH, or without STAT, signed with container::hash runs
emitted, plus a HASH part crashes
DXC's parts with the emitted DXIL part crashes
emitted parts with DXC's DXIL part runs
emitted IR (DXC disassembly) assembled by DXC's IDxcAssembler (#1373's assemble) crashes
same, function body replaced by DXC's crashes
DXC's IR, function body replaced by the emitted one runs
emitted IR plus !llvm.ident = !{!11}, !11 = !{!"xcl direct dxil"} runs

So the in-tree digest, the other parts and the bitcode writer are fine on AMD (SFI0/ISG1/OSG1/PSV0 are byte-identical to DXC's); only the missing named metadata llvm.ident crashes the driver's compiler, whatever string it holds. The difference between the two module headers is otherwise the declaration order (no effect) and dx.valver 1.8 / 1.9 (no effect).

With these three lines before m.named_md("dx.version", …) in both shader.rs and graphics.rs (local only, not pushed):

let ident = m.md_str("xcl direct dxil");
let ident = m.md_node(&[Some(ident)]);
m.named_md("llvm.ident", &[ident]);
  • nothing crashes any more
  • XCL_DIRECT_DXIL=1 cargo test -p xcl --lib gpu::recomp::tests: 118 passed, 0 failed; the same with XCL_DIRECT_DXIL=all: 118 passed, 0 failed
  • cargo test -p xcl --lib gpu::dxil (65 run, 2 ignored), the failing ones rerun alone: 59 pass; still failing on this card:
    • ops_tests::wave_ops_match_cpu: CreateComputePipelineState → 0x887A0005 (device removed); run together, the other GPU tests after it fail the same way
    • ops_tests::half_precision_overloads_run: got(0) (half max) 5.0, expected 10.5
    • fuzz_tests::fuzz_validate_and_gpu_0..3: GPU against CPU at seeds 328 (res[257] 0xe0000000 / 0x0), 662 (res[576] 0xf9999999 / 0xcccccccc), 1206 (res[320] 0xfffffffe / 0xfffffffc), 1599 (res[193] 0x1 / 0x0)

Tested

  • gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 at 065aef35c30f364d2a9be2431a1466cddf05e761, clean except the three lines above for the second half
  • AMD Radeon RX 9060 XT (RDNA4), driver 32.0.31044.16, Ryzen 5 5600, Windows 11 Pro 26300, Rust 1.100.0, debug, DXC 1.9.2602.17 (as oracle)
  • without the change: default path cargo test --workspace -- --skip gpu::dxil: 750 passed, 0 failed, 41 ignored

Not tested

  • other AMD drivers, the title with XCL_DIRECT_DXIL=1 and the fix, NVIDIA with the fix (llvm.ident should be harmless there; DXC always writes it)

AI use: Claude Code (Claude Opus 5.5) ran the tests and the experiments and wrote this report.

@gefydev

gefydev commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

@Kalmarv thank you for the test report on 065aef3, and for asking the right question about the validator: the dx.valver 1.8 failures on DXC 1.7, the four fuzz seeds that the NVIDIA driver refuses, the clean smoke pair and the title run with XCL_DIRECT_DXIL=1 are all useful for what we build on top.

The size gap you measured (39.4 MB direct against 6.8 MB for the HLSL path in total, largest 14.7 MB) is what the per-lane mode on #1269 targets: it drops most of the per-instruction EXEC guards. On the retail pack the lane-mask analysis leaves 37.1 % of the vector instructions guarded.

AI use: Claude Code (Claude Opus 5.5) wrote this reply for @gefydev.

@Kalmarv

Kalmarv commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Review notes on 065aef3, each shown with a local probe test (uncommitted, printing the validator's verdict and DXC's listing) under DXC 1.9.2609 and the SDK's 1.7.2308; no GPU needed.

  1. VS / PS with a branch or a memory load before their exports fall back to HLSL. kernel.rs:296 creates the exit block before the program's blocks, lower_gfx.rs:262-279 (finish_gfx) emits the bitcasts and storeOutput calls into it, and module.rs:884-888 asserts on a non-phi reference to a later value. With the VS and PS of core_tests::direct_and_hlsl_graphics_stages_link plus one forward S_CBRANCH_SCC1 or one GLOBAL_LOAD_DWORD before the exports: the direct DXIL translator panicked: forward reference to value 104 at instruction 70 (blocks must be in dominance order) (PS; VS: value 129 at 85). pso.rs:275-279 then takes the HLSL path, so under XCL_DIRECT_DXIL=all it is lost coverage, not a crash. Kernel mode translates the same branch.
  2. dx.valver is 1.8 (shader.rs:471-472, graphics.rs:918-919), which the Windows SDK's DXC 1.7.2308 refuses (Validator version in metadata (1.8) is not supported; maximum: (1.7)), even for an empty compute shader. kernel.rs:349-353 validates in test and debug builds, so with that DXC every direct translation returns Err there. The README still lists DXC 1.7 as usable.
  3. No !llvm.ident (shader.rs:503-509, graphics.rs:1008): DXC's output has !llvm.ident = !{!0}. Both validators accept it without; @Sr-0w reports an RX 7800 XT faulting in CreateComputePipelineState without it (not tried here, no AMD card).
  4. dx.op.waveGetLaneIndex is readnone (shader.rs:335); DXC 1.9.2609 declares it readonly (1.7.2308 declared it readnone). dxil.dll 1.7 and 1.9 accept either. The other 71 dx.op declarations match DXC 1.9.2609's table in name and attribute.

Builder API only (the translator doesn't reach these at 065aef3):
5. Nine raw_uavs: DXC 1.9 says Flags must match usage. Flags declared=16, actual=32784; the "64 UAV slots" flag (bit 15) isn't in shader.rs:38-58.
6. Module::unreachable (module.rs:639-642): Instructions must be of an allowed type. at 'unreachable'.
7. shader.rs:15's data layout is used with Feature::NativeLowPrecision too; DXC with -enable-16bit-types writes …i16:16…f16:16…. DXC 1.9 accepts it anyway.

Not checked: AMD, mesh mode for point 1, DXC 1.8.

AI use: Claude Code (Claude Fable 5.2, Claude Opus 5.5)

@thehollowedone

Copy link
Copy Markdown

One size opportunity on 065aef3. The current SSA builder can hand the bitcode writer phi nodes whose incoming values are identical once self-references are ignored.

In a scratch prototype I redirected those uses before assigning serialized value IDs and omitted the redundant phi records. The GPU loop fixture gpu_scalar_loop_and_scc dropped 65 phi nodes and still matched its expected results on an RTX 3080 Ti (621.35), Windows 11 build 26300, DXC 1.8.2502.11, Rust 1.99.1 MSVC. The prototype conservatively keeps cycles.

XCL_DIRECT_DXIL=1 cargo test --offline --locked -p xcl --lib gpu_scalar_loop_and_scc -- --nocapture --test-threads=1 passed 1/1. The broader DXIL test group did not pass on this setup. An isolated rerun of fuzz_validate_and_gpu_2 rejected seed 1495 with Flags must match usage on both the unchanged head and the prototype.

AI-assisted. Codex (GPT-6 family, exact variant unavailable) wrote the scratch prototype, ran the tests and drafted this report.

bmjask and others added 2 commits November 24, 2026 11:16
The PR check only accepts binaries under tests/data/.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On the no-GPU CI runner (WARP / Basic Render Driver) even a DXC-compiled
VS/PS draw through runner::draw removes the device, which then fails every
later GPU test in the process (mesh_dispatch included). Gate the draw tests
the way recomp's gpu_ready() does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@raylitebull
raylitebull requested a review from ivall November 24, 2026 16:16
@raylitebull raylitebull added the enhancement New feature or request label Nov 24, 2026
@LucasHoepfner

Copy link
Copy Markdown
Contributor

Test report for 065aef3 with DXC 1.8, the case @Kalmarv's notes leave open: RTX 3060 Ti (Ampere, 32-lane waves), NVIDIA 621.01, Intel Core i7-14700KF, Windows 11 Pro 26200, rustc 1.99.1 MSVC, debug, clean tree. DXC is the Windows SDK 10.0.26100.0's dxcompiler / dxil 1.8.2502.11, XCL's default here.

gpu::dxil::validate::tests::malformed_containers_are_errors kills the whole lib test process with DXC 1.8 (0xc0000005, 3 of 3 runs alone). Every test after it in the binary then doesn't run. Running each of its five inputs alone (2 runs each): only b"DXBC" crashes, inside IDxcValidator::Validate. The other four pass, and Disassemble survives all of them. CI's DXC 1.9.2602.17 passes the test, so it looks like an out-of-bounds read in 1.8's validator on a buffer shorter than a container header. Dropping that input, or having validate() refuse anything shorter than the 32-byte header before it calls DXC, would keep 1.8 machines running the suite.

With that one test skipped (--skip malformed_containers_are_errors):

command result
cargo test -p xcl --lib gpu::dxil -- --test-threads=4 64 passed, 0 failed, 2 ignored
cargo test -p xcl --lib gpu::recomp::tests -- --test-threads=4 118 passed, 0 failed, 17 ignored
the same with XCL_DIRECT_DXIL=1 118 passed, 0 failed, 17 ignored
cargo test --workspace --no-fail-fast -- --test-threads=4 815 passed, 0 failed, 43 ignored

SKIPPED: gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware (no wave64).

  • DXC 1.8 accepts the modules' dx.valver 1.8, so none of 1.7's 129 failures happen here.
  • The fuzz seeds that @Kalmarv's 5070 Ti refuses run on this card and match the CPU. 1 232 of the 2 000 seeds were run on the GPU here, all matching: the same 1 232 as the 1 150 + 82 of the 5070 Ti run (same generator, same rule for which seeds go to the GPU), so this includes all 82 with atomicrmw sub on group-shared memory. I checked the four first-failing seeds (62, 545, 1019, 1507) one by one with a local print in run_seeds. So the 0x8007000E refusal on the 5070 Ti and the 5080 looks specific to those Blackwell cards or their drivers, not to the modules.
  • XCL_DIRECT_DXIL=1 over all of gpu::recomp failed once in 26 runs, in gpu_sparse_vram_descriptors_buffers_and_xmem, with submit 1 lane 0 mismatch (0 vs 1077). That's the message of the order-dependent failure in Tests: gpu_sparse_vram_descriptors_buffers_and_xmem fails beside the title-texture tests since #288 #343, and it passes alone on both paths. The other 25 runs passed, as did 5 on the HLSL path, so I can't pin it on either path.

Not tested: a title or smoke run (I have no title), XCL_DIRECT_DXIL=all, release, AMD, native wave64.

AI use: Claude Code (Claude Opus 5.5) ran the tests and the probes and drafted this; I checked it before posting.

@brainhay5

Copy link
Copy Markdown

Adding the part @Kalmarv's 60 s run could not reach: same card, same head (this PR merged onto 930e8b4, merge 53ae66b), XCL_DIRECT_DXIL=1, but 120 s with input (A every 3 s).

  • No [SHADER] direct DXIL: … – HLSL path line in the run, so no fallbacks.
  • The overlay's DXC counters read 0 running / 0 done throughout, so DXC was not invoked.
  • FPS 29.7 at 30 s → 7.9 at 60 s → 0.0 at 90 s, queue 57,793 → 58,712 → 57,889.

Then the usual end:

[100.649] unhandled exception 0xc0000005 in game_scarlett_master.exe+0x23cf683 (write at address 0x0)

Same fault, same point as the HLSL path on this title (100.6 s against ~98–103 s). So the switch is safe and does route compute away from DXC, but it does not move this title's stall.

@Kalmarv's sizes explain why, and are the part of his report I would put first: the direct path's DXIL is 73 KB median / 14.7 MB largest / 39.4 MB total, against 23 KB / 1.2 MB / 6.8 MB on the HLSL path. The driver was already the bottleneck; being handed 3× the DXIL for the same work makes that side worse, which is exactly what the per-lane mode on recomp-lane-masks is meant to offset (37.1 % of vector instructions still guarded).

One request that would make live runs auditable: a success line per routed program, or an end-of-run count ("N compute programs direct, M fell back"). With zero fallbacks and no success line, "the switch reached the PSO path" and "the switch never applied" are indistinguishable in the log — Kalmarv and I both had to infer it from DXIL sizes.

Not tested: XCL_DIRECT_DXIL=all, AMD, wave64, cold driver cache.

AI use: OpenCode, DeepSeek V4.1 Flash 1017.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.