Repository navigation
gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL - #1426
Conversation
…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>
|
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
The proposal, also posted in #1269: this PR is the infrastructure, and I rebase onto it and implement the Two questions:
AI use: Claude Code (Claude Opus 5.5) wrote this comment for @gefydev. |
|
RTX 5080 (Blackwell, wave32 / split-wave64) test report for head
Happy to re-run on the RTX 5080 whenever a follow-up lands! Not tested: AMD, Linux/Wine, retail smoke ( |
…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>
|
Test report: #1426 at @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 ( Tested
1. The PR's direct-DXIL tests, each run alone (
2. Retail title, tree
On @Kalmarv's open question (the in-tree digest on AMD): D3D12 accepts the containers here. There is no 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
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>
|
Test report for Tests (debug, clean tree at
SKIPPED in the second row, both DXCs:
Regression run (60 s each,
this PR, Title run with
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
AI use: Claude Code (Claude Opus 5.5, Claude Fable 5.2) |
|
RTX 4060 / Proton: direct compute dispatch passed on Tested: Windows-target release build on Linux, Ryzen 5 5600, RTX 4060, NVIDIA 620.73.04, GE-Proton11-14, vkd3d-proton 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 4060Skipping DXC saved time even after the first
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 Commands: private Windows-target release probe, CPU-only regression fixture for the writer-order request. At 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","")
} |
|
@HKEY-Funk-Machine @bmjask a likely candidate for the AMD crash: #1426 never emits @Sr-0w measured exactly this on an RX 7800 XT (Windows driver) while testing the text path (#1269, #1269 (comment)). A module without The fix to try is one named metadata node in 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 AI use: Claude Code (Claude Opus 5.5) wrote this comment for @gefydev. |
|
Root cause of the AMD crash above: the emitted module has no @bmjask @gefydev, following @HKEY-Funk-Machine's report: same crash here (
So the in-tree digest, the other parts and the bitcode writer are fine on AMD ( With these three lines before let ident = m.md_str("xcl direct dxil");
let ident = m.md_node(&[Some(ident)]);
m.named_md("llvm.ident", &[ident]);
Tested
Not tested
AI use: Claude Code (Claude Opus 5.5) ran the tests and the experiments and wrote this report. |
|
@Kalmarv thank you for the test report on 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. |
|
Review notes on
Builder API only (the translator doesn't reach these at Not checked: AMD, mesh mode for point 1, DXC 1.8. AI use: Claude Code (Claude Fable 5.2, Claude Opus 5.5) |
|
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
AI-assisted. Codex (GPT-6 family, exact variant unavailable) wrote the scratch prototype, ran the tests and drafted this report. |
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>
|
Test report for
With that one test skipped (
SKIPPED:
Not tested: a title or smoke run (I have no title), AI use: Claude Code (Claude Opus 5.5) ran the tests and the probes and drafted this; I checked it before posting. |
|
Adding the part @Kalmarv's 60 s run could not reach: same card, same head (this PR merged onto
Then the usual end: 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 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: AI use: OpenCode, DeepSeek V4.1 Flash 1017. |
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/:bitstream.rsandmodule.rswrite 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_usesis available.module/opt.rsremoves trivial phis, merges duplicate pure instructions along the dominator tree, and removes dead code.XCL_DXIL_NO_OPT=phi,cse,dce|allturns passes off for bisecting. There is no fast-math or float reassociation, and wave ops are only merged within one block.shader.rsandops.rscover 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.rsandcontainer.rswrite 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.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_guardedlets an external control-flow analysis reuse the per-instruction lowering.coverage.rsaddsxcl shaders <pack> --direct [--sample N] [--validate] [--compare]to sweep a pack, andXCL_DIRECT_DXIL_STATS=1prints live fallback statistics at exit.validate.rswraps DXC's validator and disassembler, used in tests only. With a validator older than 1.8 only the validation step is skipped.recomp/pso.rs: routing with HLSL fallback, and a separate on-disk cache identity per backend andTRANSLATOR_VERSION. HLSL cache entries are unchanged.recomp/runner.rs: test-only additions.recomp/tests.rs: backend switch.XCL_HEAP_WINDOWS, merged from main) are not translated yet; those shaders take the HLSL path.!llvm.identis now emitted.Bfrevmiscompile: halves are now reversed separately.WaveMultiPrefixBit*is now signed, as DXC emits it. The unsigned form removed the device on RDNA4.waveGetLaneIndexis readonly (@Kalmarv).atomicrmw sub, which NVIDIA rejects.tests/data/dxil/.amdxc64.dllfault HKEY-Funk-Machine isolated oncs 62b584e061c05fc5: release builds skip the validator, and NVIDIA tolerated the irreducible CFG.Countbits.i64is emitted per 32-bit half, a workaround like the one forBfrev.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.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=1and=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):Also checked:
Testers on this PR:
!llvm.ident.Regression run
The retail title, 60 s each, RTX 4090, release builds, back to back on an idle machine,
XCL_DIRECT_DXILunset, no uncommitted changes. PR (head81d2ad5a9d06): 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:
PR:
Not tested
amdxc64.dllfault 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.AI use
🤖 Generated with Claude Code