Repository navigation
dxil: eliminate giant-shader IR and CFG blowup in FormatLoad and multi-window memory - #1748
Conversation
|
Independent Windows GPU test of Tested
Not tested Retail-title behavior, cold driver compilation time, and the full workspace on the baseline. AI use OpenAI Codex (GPT-6 family, exact variant unavailable) wrote the temporary probe, ran and checked the tests, and wrote this report. |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Test report for Tested: AMD RDNA4 (native wave64), Windows, DXC 1.8.2502.11. Suite (debug):
The three largest compute programs (validated, not built by the driver):
Compile times, retail compute programs, release, 4 switch windows, one program at a time, sums per row. "Front" is translation, plus DXC on the HLSL path:
How to read the numbers: one run each, the driver's own cache was not disabled, and the "HLSL" and "direct before" columns are from I also read the whole diff. The format descriptors are hoisted to the block that defines the descriptor word. Every detached phi is placed before a read returns, so Not tested: a title run with AI use: Claude Code (Claude Opus 5.5) ran the tests and measurements, read the diff and wrote this report. |
Brings local fork into 100% parity with upstream/main (commit 4178e88), incorporating PR xcl-dev#1748: - Direct DXIL: eliminate giant-shader IR and CFG blowup in FormatLoad and multi-window memory (xcl-dev#1748). Optimizes SSA lowering in crates/xcl/src/gpu/dxil/lower_mem.rs and module/opt.rs, bounding IR node allocations and control-flow graph complexity for massive compute shaders. (by raylitebull) Assisted-by: Antigravity
…in Direct DXIL)
|
NVIDIA numbers for the open points above (RTX 4090 24 GB, driver 617.14, Windows 11, DXC 1.8.2502.11, release, 1. The direct-vs-HLSL driver gap at 33–85 KB does not show on NVIDIA. On 13 retail compute programs from 0.6 to 81 KB of console code, both with 4 switch windows, the driver is faster on the direct form in every one: median ratio 0.70, and 0.89 on the 81 KB program (28.3 s vs 31.7 s). Its DXIL has fewer blocks and phi operands than the HLSL form's (median 0.74× / 0.65×, counted from 2. Heap windows matter more than the backend on NVIDIA. 14 programs with all four forms timed:
3. Driver builds of the largest programs (direct, heap windows): all build, peak ~3.5 GB.
Not tested: the HLSL form of these five (over 4 MB of HLSL, DXC skipped), a title run with AI use: Claude Code (Claude Opus 5.5) ran the measurements and drafted this. |
|
@ivall the title run with Tested
Not tested
AI use: Claude Code (Claude Opus 5.5) ran the runs and the memory sampling, read the logs and wrote this comment. |
|
Independent synthetic performance and output check on RTX 4070 Ti SUPER (617.14), i5-13600KF, Windows build 28000.3501, DXC 1.9.2602.17 and Rust 1.100.0 gnullvm, optimized test builds. Exact base I generated Wave32 shaders with repeated dynamic
Translation is the median of five calls after an untimed call in each process, then across three processes. For PSO creation I timed the first creation in each fresh process and alternated the order of both revisions and binding modes. The D3D12 implicit-cache disable request succeeded in every process. Microsoft documents the driver-managed cache flag as a hint. These figures cover pipeline creation for the synthetic inputs. They do not measure frame rate, GPU shader execution time or a whole application. PortBridge preflight found this exact PR. Codex (GPT-6 family) wrote and ran the harness, with a separate review of the correctness and timing controls. Source fixture and reproductionSave as // SPDX-License-Identifier: GPL-2.0-only
// Synthetic cold-PSO and output comparison for XCL #1748.
use std::mem::ManuallyDrop;
use std::time::{Duration, Instant};
use windows::core::Interface;
use windows::Win32::Graphics::{Direct3D::D3D_FEATURE_LEVEL_12_0, Direct3D12::*, Dxgi::*};
use xcl::gpu::dxil::kernel::{translate, KernelOptions};
use xcl::gpu::rdna2::encode;
use xcl::gpu::recomp::{pso, runner, HEAP_WINDOWS};
use xcl::gpu::{adapter, agility, uma::Uma};
const BASE: usize = 0x100;
const WINDOWS: usize = 4;
const LANES: usize = 32;
fn program(loads: usize) -> Vec<u8> {
let mut code = Vec::new();
for i in 0..loads {
code.extend(encode("BUFFER_LOAD_FORMAT_X", "ENC_MUBUF", &[
("VDATA", (16 + i) as u64), ("VADDR", 0), ("SRSRC", (3 + i % WINDOWS) as u64),
("SOFFSET", 128), ("IDXEN", 1), ("OFFSET", (16 * i) as u64),
], None).unwrap());
}
code.extend(encode("S_ENDPGM", "ENC_SOPP", &[], None).unwrap());
code
}
fn half_mantissa(window: usize, index: usize) -> u32 {
((3 * index + 211 * window + 1) & 1023) as u32
}
fn check_output(dxil: &[u8], loads: usize) {
let arena = Uma::with_windows(WINDOWS, 1 << 20).unwrap();
let mut state = runner::KernelState::default();
for (lane, regs) in state.vgpr.iter_mut().enumerate() {
regs[0] = lane as u32;
}
let dwords = loads * 4 + LANES;
for window in 0..WINDOWS {
let address = arena.window(window).0 + BASE;
// 16_16_FLOAT with identity selection and a 4-byte stride.
let desc = [address as u32, ((address >> 32) as u32 & 0xffff) | 4 << 16,
dwords as u32, 29 << 12 | 7 << 9 | 6 << 6 | 5 << 3 | 4];
state.sgpr[12 + 4 * window..16 + 4 * window].copy_from_slice(&desc);
for index in 0..dwords {
let half = 0x3c00 | half_mantissa(window, index);
// The arena owns a committed 1 MiB region. These aligned writes stay
// within its first 4 KiB and finish before the GPU reads the regions.
unsafe { ((address + 4 * index) as *mut u32).write(half) };
}
}
let output = runner::run_in_arena(dxil, &state, &arena).unwrap();
for lane in 0..LANES {
for i in 0..loads {
let expected = 0x3f80_0000 | half_mantissa(i % WINDOWS, 4 * i + lane) << 13;
assert_eq!(output.vgpr[lane][16 + i], expected, "lane {lane}, load {i}");
}
}
}
fn cache_off_device() -> ID3D12Device {
let selector = adapter::Selector::from_env_or("auto");
let factory: IDXGIFactory6 = unsafe { CreateDXGIFactory2(DXGI_CREATE_FACTORY_FLAGS(0)) }.unwrap();
let (gpu, _) = adapter::candidates(&factory, &selector).into_iter().next().unwrap();
let device = agility::create_device(&gpu, D3D_FEATURE_LEVEL_12_0).unwrap();
let device9 = device.cast::<ID3D12Device9>().unwrap();
let kinds = D3D12_SHADER_CACHE_KIND_FLAG_IMPLICIT_DRIVER_MANAGED
| D3D12_SHADER_CACHE_KIND_FLAG_IMPLICIT_D3D_CACHE_FOR_DRIVER;
unsafe { device9.ShaderCacheControl(kinds, D3D12_SHADER_CACHE_CONTROL_FLAG_DISABLE) }
.expect("cold timing needs process shader-cache control");
device
}
fn pso_time(device: &ID3D12Device, dxil: &[u8]) -> Duration {
let mut desc = D3D12_COMPUTE_PIPELINE_STATE_DESC {
pRootSignature: ManuallyDrop::new(Some(pso::abi_root_signature(device, false).unwrap())),
CS: D3D12_SHADER_BYTECODE { pShaderBytecode: dxil.as_ptr().cast(), BytecodeLength: dxil.len() },
..Default::default()
};
let start = Instant::now();
let pipeline = unsafe { device.CreateComputePipelineState::<ID3D12PipelineState>(&desc) };
let elapsed = start.elapsed();
drop(unsafe { ManuallyDrop::take(&mut desc.pRootSignature) });
drop(pipeline.unwrap());
elapsed
}
#[test]
fn formatted_load_pipeline_cost_and_output() {
let name = runner::adapter().unwrap();
assert!(runner::wave32_supported().unwrap(), "Wave32 unavailable on {name}");
let device = cache_off_device();
println!("adapter={name} implicit cache disable request accepted");
let loads = match std::env::var("PORTBRIDGE_FORMAT_LOADS") {
Ok(raw) => raw.parse::<usize>().expect("load count"),
Err(_) => 64,
};
assert!((4..=192).contains(&loads) && loads % WINDOWS == 0);
let code = program(loads);
let mode = std::env::var("PORTBRIDGE_FORMAT_MEMORY").unwrap_or_else(|_| "switch".to_owned());
let flags = match mode.as_str() {
"switch" => 0,
"heap" => HEAP_WINDOWS,
_ => panic!("unknown memory mode {mode}"),
};
let options = KernelOptions {
wave64: false, split: false, mem_windows: WINDOWS as u32 | flags, sampler_base: 0,
};
let dxil = translate(&code, options).unwrap();
let mut translation = (0..5).map(|_| {
let start = Instant::now();
let output = translate(&code, options).unwrap();
let elapsed = start.elapsed();
assert_eq!(output, dxil);
elapsed.as_secs_f64() * 1e3
}).collect::<Vec<_>>();
let compilation = pso_time(&device, &dxil).as_secs_f64() * 1e3;
check_output(&dxil, loads);
translation.sort_by(f64::total_cmp);
println!("mode={mode} loads={loads} code_bytes={} dxil_bytes={} translation_ms={:.3} pso_ms={compilation:.3} checked_values={}",
code.len(), dxil.len(), translation[translation.len() / 2], loads * LANES);
} |
|
Verification on RTX 3060 Ti (Windows 11), branch merged with current
Thanks! |
… verdict The driver's refusal of a translated compute pipeline reached only note_translation_error: the report's translation_errors, or the notes of a cached-only attempt, which are dropped when a shader was missing. On an RX 7800 XT a retail title's 13.8 MB compute program (xcl-dev#1332 in the form of xcl-dev#1321) took the driver 15 - 23 s and ~15 GB of commit in every run and was refused with E_OUTOFMEMORY; xcl.log showed its `driver compile finish` and, a millisecond later, the title's dispatch with that pipeline skipped - and nothing in between. The same with the 3.9 MB form of the direct DXIL backend (xcl-dev#1748). The verdict had to be taken from `xcl shaders --measure-pso`. A huge program (`huge_pso_bytes` and up) the driver refuses is now logged with its record hash, DXIL size, HRESULT and the time the driver took, next to the compile lines it already has. Logging only; no behaviour changes. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Eliminates giant-shader IR and CFG blowup in the direct RDNA2 -> DXIL backend for
FormatLoadand multi-window memory accesses, cuttingActivateProbes(56c0cd3b82a00c6e) from 14.77 MB to 3.76 MB (-74.5%) andActivateRays(95cc13288a27a96e) from 10.73 MB to 3.73 MB (-65.2%).Why this exceeds ~800 lines (
+1136/-362): the size reduction requires landing three co-dependent pieces together—hoisting and caching decoded format descriptors (FmtDesc/FmtComp1) ind3's defining block, unifying multi-window memory/format dispatch (with_mem_many_tys, which replaceslower_window::with_heap_memacross both heap-window and switch paths), and folding constant global pointers inmodule/opt.rs—alongsidecore_tests.rsvalidation tests.What is in it
crates/xcl/src/gpu/dxil/kernel.rs&lower.rs: bumpTRANSLATOR_VERSIONto6; addfmt_desc_cache,fmt_comp1_cache, anduma_base_valonLw.crates/xcl/src/gpu/dxil/lower_window.rs: hoistuma_base()(IO_UMA_BASE_HI) once to the entry block and remove the duplicatedwith_heap_memhelper.crates/xcl/src/gpu/dxil/lower_mem.rs&lower_image.rs: addwith_mem_many_tys/with_mem_i32s/with_mem_void(guarding and dispatching heap-window or switch windows per multi-dword op), hoistFmtDesc/FmtComp1, and compact small-float / component decoding (uf_small_bits,fmt_comp,fmt_comp_dyn).crates/xcl/src/gpu/dxil/module.rs&module/opt.rs: adddef_block/set_insert_before_terminsertion helpers and constant-global pointer simplification (is_const_global_ptr,simplify_op).crates/xcl/src/gpu/dxil/core_tests.rs: adduf_small_ieee_bit_math_matches_exact_formulaandmulti_window_mem_format_and_bvh_validate.Tested
10.0.22631.0),rustc 1.99.1 (58cf8f9c3 2026-10-13), release & debug builds.cargo test -p xcl --lib gpu::dxil::: 80 passed, 0 failed onb9b6ea6(gpu::recomp::: 107 passed, 0 failed;cargo check --workspacegreen).shaders.rpf):56c0cd3b82a00c6e14.77 MB -> 3.76 MB(3,939,588 B, -74.5%, validated in897 ms);95cc13288a27a96e10.73 MB -> 3.73 MB(3,914,652 B, -65.2%, validated in940 ms).Regression run
main:
PR:
Not tested
cargo test --workspacerun; also the 60 ssmoke.ps1regression run uses defaultXCL_DIRECT_DXIL=0on the Account Picker UI and does not exercise coldXCL_DIRECT_DXIL=1runtime driver compiles across the full world shader set.AI use