From e359f6eb6e958e42b105bf2a061f207d189baa02 Mon Sep 17 00:00:00 2001 From: Raghav314 <71544502+Raghav314@users.noreply.github.com> Date: Wed, 25 Nov 2026 02:48:51 +0530 Subject: [PATCH 1/5] Shaders: xcl shaders --time-forms times the compute forms one at a time, driver cache off For each compute program: the per-lane form, #1426's per-instruction form and the HLSL path with W and with heap windows, each made into a compute pipeline one at a time with the driver's own shader cache off for the process (ShaderCacheControl, developer mode; --warm keeps it). One CSV row per program: translation, DXC, DXIL bytes, driver ms. --all N takes a size-spread sample plus the 10 largest; --max-hlsl / --max-dxil cap the giants (sizes still recorded); --heap gives the direct forms heap windows; --no-hlsl skips the HLSL columns; --dump DIR writes each form's DXIL. --- crates/xcl/src/gpu/recomp/pso.rs | 6 + crates/xcl/src/shaders.rs | 204 +++++++++++++++++++++++++++++++ 2 files changed, 210 insertions(+) diff --git a/crates/xcl/src/gpu/recomp/pso.rs b/crates/xcl/src/gpu/recomp/pso.rs index da4b25e5fb..fa5459481c 100644 --- a/crates/xcl/src/gpu/recomp/pso.rs +++ b/crates/xcl/src/gpu/recomp/pso.rs @@ -1009,6 +1009,12 @@ fn direct_graphics(blob: &[u8], stage: Stage, sampler_base: u32, windows: u32) - Ok(Compiled { dispatch_chain: None, dxil: k.dxil, samplers: k.static_samplers }) } +/// The HLSL path's translation of a console compute shader, without DXC (`xcl shaders +/// --time-forms` times translation and DXC apart). +pub fn console_translation_compute(blob: &[u8], windows: u32, split_wave64: bool) -> Result<(super::Translation, &'static str), String> { + console_translation(blob, Stage::Compute, 0, windows, split_wave64) +} + pub(crate) fn console_translation(blob: &[u8], stage: Stage, sampler_base: u32, windows: u32, split_wave64: bool) -> Result<(super::Translation, &'static str), String> { if let Some(f) = fspx(blob) { if stage != Stage::Compute { diff --git a/crates/xcl/src/shaders.rs b/crates/xcl/src/shaders.rs index 0cd2ed7b3a..563f8d276c 100644 --- a/crates/xcl/src/shaders.rs +++ b/crates/xcl/src/shaders.rs @@ -983,6 +983,9 @@ pub fn run(path: &Path, args: &[String]) -> i32 { let windows = runtime_windows(); return precompile(&input, opts.limit, windows, opts.split, opts.only.as_deref(), opts.pipelines, used.as_ref(), t0); } + if args.iter().any(|a| a == "--time-forms") { + return time_forms(&input, args, t0); + } if opts.direct { return direct_sweep(&input, &opts, t0); } @@ -2419,6 +2422,207 @@ fn direct_sweep(input: &Input, opts: &ShadersOptions, t0: std::time::Instant) -> 0 } +/// `--time-forms [--windows W] [--heap] [--split 0|1] [--timeout S] [--limit N] [--threads T] +/// [--warm] [--all N] [--max-hlsl MB] [--max-dxil KB] [--no-hlsl] [--dump DIR] [--out FILE]`: for each +/// compute program the per-lane form translates, the same program in four forms, each made +/// into a compute pipeline one at a time (no XCL cache, no concurrency): the per-lane form, +/// #1426's per-instruction form, the HLSL path with W windows and the HLSL path with heap +/// windows. Per form: translation time (+ DXC for HLSL), DXIL bytes and +/// `CreateComputePipelineState` time. One CSV row per program, by index only (no names). +/// The driver's own shader cache is turned off for the process (`ShaderCacheControl`, needs +/// Windows developer mode; `--warm` keeps it). The first row includes the driver's warm-up. +/// `--heap`: the two direct forms with heap windows instead of W. `--no-hlsl`: the HLSL +/// columns stay empty. `--dump DIR`: each form's DXIL as `DIR/_.dxil`. +fn time_forms(input: &Input, args: &[String], t0: std::time::Instant) -> i32 { + use std::time::{Duration, Instant}; + use windows::Win32::Graphics::Direct3D12::*; + let opt = |name: &str| args.iter().position(|a| a == name).and_then(|i| args.get(i + 1)).and_then(|v| v.parse::().ok()); + let windows = opt("--windows").unwrap_or(4) as u32; + let split = opt("--split").map(|v| v != 0).unwrap_or(true); + let timeout = Duration::from_secs(opt("--timeout").unwrap_or(120)); + let limit = opt("--limit").map(|v| v as usize).unwrap_or(usize::MAX); + let out_path = args.iter().position(|a| a == "--out").and_then(|i| args.get(i + 1)).cloned(); + let threads = opt("--threads").map(|v| v.max(1) as usize).unwrap_or(8); + // `--all N`: a size-spread sample of N compute programs of every size (the 10 largest + // always in), not only the ones the per-lane form takes (its columns are empty where it + // refuses one) + let all = opt("--all").map(|v| v as usize); + let heap = args.iter().any(|a| a == "--heap"); + let no_hlsl = args.iter().any(|a| a == "--no-hlsl"); + let dump_dir = args.iter().position(|a| a == "--dump").and_then(|i| args.get(i + 1)).map(std::path::PathBuf::from); + if let Some(d) = &dump_dir { + let _ = std::fs::create_dir_all(d); + } + let dump = |idx: usize, form: &str, dxil: &[u8]| { + if let Some(d) = &dump_dir { + let _ = std::fs::write(d.join(format!("{idx}_{form}.dxil")), dxil); + } + }; + // caps for the giants: no DXC above `--max-hlsl` MB of HLSL, no driver build above + // `--max-dxil` KB of DXIL (sizes are still recorded) + let max_hlsl = opt("--max-hlsl").unwrap_or(16) as usize * (1 << 20); + let max_dxil = opt("--max-dxil").unwrap_or(4096) as usize * 1024; + std::panic::set_hook(Box::new(|_| {})); + + // phase 1 (parallel): the compute programs and whether the per-lane form takes them + struct Prog { + idx: usize, + blob: Vec, + code: Vec, + cs: recomp::CsInterface, + o: crate::gpu::dxil::kernel::KernelOptions, + } + let run_timed = |f: Box Result + Send>| -> (Result, Duration) { + let t = Instant::now(); + let (tx, rx) = std::sync::mpsc::channel(); + std::thread::spawn(move || { + let _ = tx.send(std::panic::catch_unwind(std::panic::AssertUnwindSafe(f)).unwrap_or_else(|_| Err("panic".into()))); + }); + let r = rx.recv_timeout(timeout).unwrap_or_else(|_| Err("timeout".into())); + (r, t.elapsed()) + }; + let next = AtomicUsize::new(0); + let tried = AtomicUsize::new(0); + let covered: Mutex> = Mutex::new(Vec::new()); + std::thread::scope(|s| { + for _ in 0..threads { + s.spawn(|| loop { + let ri = next.fetch_add(1, Ordering::Relaxed); + if ri >= input.len() { + break; + } + let (_, Some(blob)) = input.get(ri) else { continue }; + let Some(sh) = xbox::parse(&blob) else { continue }; + let Some(f) = sh.fssm.iter().find(|f| f.stages.first().is_some_and(|s| s.hw == 6)) else { continue }; + let Some(recomp::Mode::Compute(cs)) = recomp::interface(&blob, &sh, f) else { continue }; + let Some(p) = f.programs.first() else { continue }; + let code = f.data[p.offset..p.offset + p.len].to_vec(); + tried.fetch_add(1, Ordering::Relaxed); + let wave64 = recomp::detect_wave64(&code); + let mem_windows = if heap { windows | recomp::HEAP_WINDOWS } else { windows }; + let o = crate::gpu::dxil::kernel::KernelOptions { wave64, split: wave64 && split, mem_windows, sampler_base: 0 }; + if all.is_some() { + covered.lock().unwrap().push(Prog { idx: ri, blob, code, cs, o }); + continue; + } + let (c2, cs2) = (code.clone(), cs.clone()); + let (r, _) = run_timed(Box::new(move || recomp::lower_dxil::compute_with(&c2, &cs2, o))); + if r.is_ok() { + covered.lock().unwrap().push(Prog { idx: ri, blob, code, cs, o }); + } + }); + } + }); + let mut progs = covered.into_inner().unwrap(); + if let Some(n) = all { + // evenly spaced over the programs ranked by size, plus the 10 largest + progs.sort_by_key(|p| (p.code.len(), p.idx)); + let len = progs.len(); + let mut keep: std::collections::BTreeSet = (0..n.min(len)).map(|i| i * len / n.max(1)).collect(); + keep.extend(len.saturating_sub(10)..len); + progs = progs.into_iter().enumerate().filter(|(i, _)| keep.contains(i)).map(|(_, p)| p).collect(); + eprintln!("time-forms: --all: {} of {len} compute programs, by size", progs.len()); + } + progs.sort_by_key(|p| p.idx); + if all.is_none() { + eprintln!("time-forms: per-lane form takes {} of {} compute programs ({:.0} s)", progs.len(), tried.load(Ordering::Relaxed), t0.elapsed().as_secs_f64()); + } + eprintln!("time-forms: timing {} programs one at a time", progs.len().min(limit)); + progs.truncate(limit); + + // phase 2 (serial): every form of every covered program, translated then made + let pipelines = match Pipelines::new() { + Ok(p) => p, + Err(e) => { + eprintln!("time-forms: no D3D12 device: {e}"); + return 1; + } + }; + // cold driver builds: the driver's own shader cache off for this process (developer mode) + if args.iter().all(|a| a != "--warm") { + use windows::core::Interface; + let r = pipelines.dev.cast::().and_then(|d9| unsafe { + d9.ShaderCacheControl(D3D12_SHADER_CACHE_KIND_FLAG_IMPLICIT_DRIVER_MANAGED, D3D12_SHADER_CACHE_CONTROL_FLAG_DISABLE) + }); + match r { + Ok(()) => eprintln!("time-forms: the driver's shader cache is off for this process"), + Err(e) => { + eprintln!("time-forms: cannot turn the driver's shader cache off ({e}); needs Windows developer mode, or pass --warm"); + return 1; + } + } + } + let make = |dxil: &[u8], samplers: &[recomp::pso::StaticSampler]| -> Option { + let rs = recomp::pso::abi_root_signature_with(&pipelines.dev, true, samplers).ok()?; + let desc = D3D12_COMPUTE_PIPELINE_STATE_DESC { + pRootSignature: std::mem::ManuallyDrop::new(Some(rs)), + CS: D3D12_SHADER_BYTECODE { pShaderBytecode: dxil.as_ptr() as *const _, BytecodeLength: dxil.len() }, + ..Default::default() + }; + let t = Instant::now(); + let r = unsafe { pipelines.dev.CreateComputePipelineState::(&desc) }; + let ms = t.elapsed().as_secs_f64() * 1000.0; + drop(std::mem::ManuallyDrop::into_inner(desc.pRootSignature)); + r.ok().map(|_| ms) + }; + let fmt = |v: Option| v.map_or(String::new(), |v| format!("{v:.1}")); + let mut csv = String::from("idx,wave64,code_bytes,pl_tr_ms,pl_dxil,pl_pso_ms,pi_tr_ms,pi_dxil,pi_pso_ms,hl_tr_ms,hl_src,hl_dxc_ms,hl_dxil,hl_pso_ms,hh_tr_ms,hh_src,hh_dxc_ms,hh_dxil,hh_pso_ms\n"); + for (n, p) in progs.iter().enumerate() { + let mut row = vec![p.idx.to_string(), (p.o.wave64 as u8).to_string(), p.code.len().to_string()]; + // per-lane and per-instruction forms + for per_lane in [true, false] { + let (c, cs, o) = (p.code.clone(), p.cs.clone(), p.o); + let (r, tr) = run_timed(Box::new(move || if per_lane { recomp::lower_dxil::compute_with(&c, &cs, o) } else { crate::gpu::dxil::kernel::translate_compute(&c, o, &cs) })); + if let Ok(k) = &r { + dump(p.idx, if per_lane { "pl" } else { "pi" }, &k.dxil); + } + match r { + Ok(k) => row.extend([fmt(Some(tr.as_secs_f64() * 1000.0)), k.dxil.len().to_string(), fmt((k.dxil.len() <= max_dxil).then(|| make(&k.dxil, &k.static_samplers)).flatten())]), + Err(_) => row.extend([String::new(), String::new(), String::new()]), + } + } + // the HLSL path: W windows, then heap windows + for w in [windows, windows | recomp::HEAP_WINDOWS] { + if no_hlsl { + row.extend(std::iter::repeat_n(String::new(), 5)); + continue; + } + let t = Instant::now(); + let tr = recomp::pso::console_translation_compute(&p.blob, w, p.o.split); + let tr_ms = t.elapsed().as_secs_f64() * 1000.0; + match tr { + Ok((t_, _)) if t_.hlsl.len() > max_hlsl => row.extend([fmt(Some(tr_ms)), t_.hlsl.len().to_string(), String::new(), String::new(), String::new()]), + Ok((t_, profile)) => { + let t = Instant::now(); + let d = recomp::dxc::compile(&t_.hlsl, "main", profile, &[]); + let dxc_ms = t.elapsed().as_secs_f64() * 1000.0; + if let Ok(d) = &d { + dump(p.idx, if w & recomp::HEAP_WINDOWS != 0 { "hh" } else { "hl" }, d); + } + match d { + Ok(d) => row.extend([fmt(Some(tr_ms)), t_.hlsl.len().to_string(), fmt(Some(dxc_ms)), d.len().to_string(), fmt((d.len() <= max_dxil).then(|| make(&d, &t_.static_samplers)).flatten())]), + Err(_) => row.extend([fmt(Some(tr_ms)), t_.hlsl.len().to_string(), fmt(Some(dxc_ms)), String::new(), String::new()]), + } + } + Err(_) => row.extend(std::iter::repeat_n(String::new(), 5)), + } + } + csv.push_str(&row.join(",")); + csv.push('\n'); + if let Some(path) = &out_path { + let _ = std::fs::write(path, &csv); + } + if all.is_some() || (n + 1) % 10 == 0 { + eprintln!(" {} / {} ({:.0} s)", n + 1, progs.len(), t0.elapsed().as_secs_f64()); + } + } + if out_path.is_none() { + print!("{csv}"); + } + eprintln!("time-forms: done, {} programs, {:.0} s", progs.len(), t0.elapsed().as_secs_f64()); + 0 +} + /// A survey reason without its program's numbers: registers as `sN`, other numbers as `N` /// (an `s_setreg`'s hardware register is kept), at most eight words. fn survey_key(r: &str) -> String { From 8a72557be3a74c383e7541ce5ed657ae3b271e8c Mon Sep 17 00:00:00 2001 From: Raghav314 <71544502+Raghav314@users.noreply.github.com> Date: Wed, 25 Nov 2026 04:29:01 +0530 Subject: [PATCH 2/5] time-forms: pipeline builds under --timeout on their own thread, a hash column From the Linux review on #1830: a CreateComputePipelineState that never returned (the driver's compiler out of the tool thread's 2 MB stack under Wine) ended the sweep without a row. Builds and translations now run on threads with a 256 MB stack under --timeout; a cell that runs out of time reads timeout and the sweep goes on. Rows also carry the record hash (shader::fnv64, as runtime logs name a record). The message when ShaderCacheControl is refused says vkd3d-proton does not implement it. --- crates/xcl/src/shaders.rs | 71 +++++++++++++++++++++++++++------------ 1 file changed, 50 insertions(+), 21 deletions(-) diff --git a/crates/xcl/src/shaders.rs b/crates/xcl/src/shaders.rs index 563f8d276c..cdb35edc8f 100644 --- a/crates/xcl/src/shaders.rs +++ b/crates/xcl/src/shaders.rs @@ -2428,13 +2428,19 @@ fn direct_sweep(input: &Input, opts: &ShadersOptions, t0: std::time::Instant) -> /// into a compute pipeline one at a time (no XCL cache, no concurrency): the per-lane form, /// #1426's per-instruction form, the HLSL path with W windows and the HLSL path with heap /// windows. Per form: translation time (+ DXC for HLSL), DXIL bytes and -/// `CreateComputePipelineState` time. One CSV row per program, by index only (no names). +/// `CreateComputePipelineState` time. One CSV row per program, by record index and record hash +/// (`shader::fnv64` of the record, as runtime logs name it; no names). Translations and pipeline +/// builds run on threads of their own (256 MB stack) under `--timeout`: a cell that ran out of +/// time reads `timeout` and the sweep goes on (the stuck build keeps its thread). /// The driver's own shader cache is turned off for the process (`ShaderCacheControl`, needs -/// Windows developer mode; `--warm` keeps it). The first row includes the driver's warm-up. +/// Windows developer mode; vkd3d-proton does not implement it); `--warm` keeps it. The first +/// row includes the driver's warm-up. /// `--heap`: the two direct forms with heap windows instead of W. `--no-hlsl`: the HLSL /// columns stay empty. `--dump DIR`: each form's DXIL as `DIR/_.dxil`. fn time_forms(input: &Input, args: &[String], t0: std::time::Instant) -> i32 { use std::time::{Duration, Instant}; + // driver compilers recurse deeply on big programs (a 2 MB stack overflowed under Wine) + const BIG_STACK: usize = 256 << 20; use windows::Win32::Graphics::Direct3D12::*; let opt = |name: &str| args.iter().position(|a| a == name).and_then(|i| args.get(i + 1)).and_then(|v| v.parse::().ok()); let windows = opt("--windows").unwrap_or(4) as u32; @@ -2475,9 +2481,12 @@ fn time_forms(input: &Input, args: &[String], t0: std::time::Instant) -> i32 { let run_timed = |f: Box Result + Send>| -> (Result, Duration) { let t = Instant::now(); let (tx, rx) = std::sync::mpsc::channel(); - std::thread::spawn(move || { + let spawned = std::thread::Builder::new().stack_size(BIG_STACK).spawn(move || { let _ = tx.send(std::panic::catch_unwind(std::panic::AssertUnwindSafe(f)).unwrap_or_else(|_| Err("panic".into()))); }); + if let Err(e) = spawned { + return (Err(format!("no thread: {e}")), t.elapsed()); + } let r = rx.recv_timeout(timeout).unwrap_or_else(|_| Err("timeout".into())); (r, t.elapsed()) }; @@ -2547,28 +2556,48 @@ fn time_forms(input: &Input, args: &[String], t0: std::time::Instant) -> i32 { match r { Ok(()) => eprintln!("time-forms: the driver's shader cache is off for this process"), Err(e) => { - eprintln!("time-forms: cannot turn the driver's shader cache off ({e}); needs Windows developer mode, or pass --warm"); + eprintln!("time-forms: cannot turn the driver's shader cache off ({e}): it needs Windows developer mode, and vkd3d-proton does not implement it; pass --warm to time with the driver's cache as it is (turn it off yourself for cold builds)"); return 1; } } } - let make = |dxil: &[u8], samplers: &[recomp::pso::StaticSampler]| -> Option { - let rs = recomp::pso::abi_root_signature_with(&pipelines.dev, true, samplers).ok()?; - let desc = D3D12_COMPUTE_PIPELINE_STATE_DESC { - pRootSignature: std::mem::ManuallyDrop::new(Some(rs)), - CS: D3D12_SHADER_BYTECODE { pShaderBytecode: dxil.as_ptr() as *const _, BytecodeLength: dxil.len() }, - ..Default::default() - }; - let t = Instant::now(); - let r = unsafe { pipelines.dev.CreateComputePipelineState::(&desc) }; - let ms = t.elapsed().as_secs_f64() * 1000.0; - drop(std::mem::ManuallyDrop::into_inner(desc.pRootSignature)); - r.ok().map(|_| ms) - }; let fmt = |v: Option| v.map_or(String::new(), |v| format!("{v:.1}")); - let mut csv = String::from("idx,wave64,code_bytes,pl_tr_ms,pl_dxil,pl_pso_ms,pi_tr_ms,pi_dxil,pi_pso_ms,hl_tr_ms,hl_src,hl_dxc_ms,hl_dxil,hl_pso_ms,hh_tr_ms,hh_src,hh_dxc_ms,hh_dxil,hh_pso_ms\n"); + // a pipeline build on a thread of its own under `--timeout`: its ms, "" if refused, "timeout" + struct Dev(ID3D12Device); + // SAFETY: ID3D12Device is free-threaded + unsafe impl Send for Dev {} + let make = |dxil: &[u8], samplers: &[recomp::pso::StaticSampler]| -> String { + let (dev, dxil, samplers) = (Dev(pipelines.dev.clone()), dxil.to_vec(), samplers.to_vec()); + let (tx, rx) = std::sync::mpsc::channel(); + let spawned = std::thread::Builder::new().stack_size(BIG_STACK).spawn(move || { + let dev = dev; + let built = (|| { + let rs = recomp::pso::abi_root_signature_with(&dev.0, true, &samplers).ok()?; + let desc = D3D12_COMPUTE_PIPELINE_STATE_DESC { + pRootSignature: std::mem::ManuallyDrop::new(Some(rs)), + CS: D3D12_SHADER_BYTECODE { pShaderBytecode: dxil.as_ptr() as *const _, BytecodeLength: dxil.len() }, + ..Default::default() + }; + let t = Instant::now(); + let r = unsafe { dev.0.CreateComputePipelineState::(&desc) }; + let ms = t.elapsed().as_secs_f64() * 1000.0; + drop(std::mem::ManuallyDrop::into_inner(desc.pRootSignature)); + r.ok().map(|_| ms) + })(); + let _ = tx.send(built); + }); + if spawned.is_err() { + return String::new(); + } + match rx.recv_timeout(timeout) { + Ok(ms) => fmt(ms), + Err(std::sync::mpsc::RecvTimeoutError::Timeout) => "timeout".into(), + Err(_) => String::new(), + } + }; + let mut csv = String::from("idx,hash,wave64,code_bytes,pl_tr_ms,pl_dxil,pl_pso_ms,pi_tr_ms,pi_dxil,pi_pso_ms,hl_tr_ms,hl_src,hl_dxc_ms,hl_dxil,hl_pso_ms,hh_tr_ms,hh_src,hh_dxc_ms,hh_dxil,hh_pso_ms\n"); for (n, p) in progs.iter().enumerate() { - let mut row = vec![p.idx.to_string(), (p.o.wave64 as u8).to_string(), p.code.len().to_string()]; + let mut row = vec![p.idx.to_string(), format!("{:016x}", shader::fnv64(&p.blob)), (p.o.wave64 as u8).to_string(), p.code.len().to_string()]; // per-lane and per-instruction forms for per_lane in [true, false] { let (c, cs, o) = (p.code.clone(), p.cs.clone(), p.o); @@ -2577,7 +2606,7 @@ fn time_forms(input: &Input, args: &[String], t0: std::time::Instant) -> i32 { dump(p.idx, if per_lane { "pl" } else { "pi" }, &k.dxil); } match r { - Ok(k) => row.extend([fmt(Some(tr.as_secs_f64() * 1000.0)), k.dxil.len().to_string(), fmt((k.dxil.len() <= max_dxil).then(|| make(&k.dxil, &k.static_samplers)).flatten())]), + Ok(k) => row.extend([fmt(Some(tr.as_secs_f64() * 1000.0)), k.dxil.len().to_string(), if k.dxil.len() <= max_dxil { make(&k.dxil, &k.static_samplers) } else { String::new() }]), Err(_) => row.extend([String::new(), String::new(), String::new()]), } } @@ -2600,7 +2629,7 @@ fn time_forms(input: &Input, args: &[String], t0: std::time::Instant) -> i32 { dump(p.idx, if w & recomp::HEAP_WINDOWS != 0 { "hh" } else { "hl" }, d); } match d { - Ok(d) => row.extend([fmt(Some(tr_ms)), t_.hlsl.len().to_string(), fmt(Some(dxc_ms)), d.len().to_string(), fmt((d.len() <= max_dxil).then(|| make(&d, &t_.static_samplers)).flatten())]), + Ok(d) => row.extend([fmt(Some(tr_ms)), t_.hlsl.len().to_string(), fmt(Some(dxc_ms)), d.len().to_string(), if d.len() <= max_dxil { make(&d, &t_.static_samplers) } else { String::new() }]), Err(_) => row.extend([fmt(Some(tr_ms)), t_.hlsl.len().to_string(), fmt(Some(dxc_ms)), String::new(), String::new()]), } } From 6f9462cd8c23bd77f14f4074b55f24f7a36f27eb Mon Sep 17 00:00:00 2001 From: Raghav314 <71544502+Raghav314@users.noreply.github.com> Date: Wed, 25 Nov 2026 05:09:55 +0530 Subject: [PATCH 3/5] time-forms: timeout can also be a build whose thread died From the Wine review on #1830: dxil-spirv's endless recursion overflows even a 256 MB stack, so the build's thread is gone and its cell reads timeout. --- crates/xcl/src/shaders.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/xcl/src/shaders.rs b/crates/xcl/src/shaders.rs index cdb35edc8f..7ace76cf59 100644 --- a/crates/xcl/src/shaders.rs +++ b/crates/xcl/src/shaders.rs @@ -2430,8 +2430,10 @@ fn direct_sweep(input: &Input, opts: &ShadersOptions, t0: std::time::Instant) -> /// windows. Per form: translation time (+ DXC for HLSL), DXIL bytes and /// `CreateComputePipelineState` time. One CSV row per program, by record index and record hash /// (`shader::fnv64` of the record, as runtime logs name it; no names). Translations and pipeline -/// builds run on threads of their own (256 MB stack) under `--timeout`: a cell that ran out of -/// time reads `timeout` and the sweep goes on (the stuck build keeps its thread). +/// builds run on threads of their own (256 MB stack) under `--timeout`: a cell with no result +/// in that time reads `timeout` and the sweep goes on. That is a build still running (it keeps +/// its thread) or one whose thread died without unwinding: under Wine, dxil-spirv's endless +/// recursion on some programs overflows even the 256 MB stack (#1805). /// The driver's own shader cache is turned off for the process (`ShaderCacheControl`, needs /// Windows developer mode; vkd3d-proton does not implement it); `--warm` keeps it. The first /// row includes the driver's warm-up. From 28667db2db4d72aa52b54f46cd77df41baa1f1b8 Mon Sep 17 00:00:00 2001 From: Raghav314 <71544502+Raghav314@users.noreply.github.com> Date: Wed, 25 Nov 2026 05:58:21 +0530 Subject: [PATCH 4/5] time-forms: turn off the D3D runtime's caches for the driver too ShaderCacheControl on IMPLICIT_DRIVER_MANAGED alone left the D3D runtime's own caches on: a second process got a 1.4 MB program back in 10 ms (19.7 s cold). With IMPLICIT_D3D_CACHE_FOR_DRIVER and IMPLICIT_D3D_CONVERSIONS off as well, two processes in a row build it cold (20.8 s and 20.1 s). --- crates/xcl/src/shaders.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/xcl/src/shaders.rs b/crates/xcl/src/shaders.rs index 7ace76cf59..8b629e2792 100644 --- a/crates/xcl/src/shaders.rs +++ b/crates/xcl/src/shaders.rs @@ -2553,7 +2553,7 @@ fn time_forms(input: &Input, args: &[String], t0: std::time::Instant) -> i32 { if args.iter().all(|a| a != "--warm") { use windows::core::Interface; let r = pipelines.dev.cast::().and_then(|d9| unsafe { - d9.ShaderCacheControl(D3D12_SHADER_CACHE_KIND_FLAG_IMPLICIT_DRIVER_MANAGED, D3D12_SHADER_CACHE_CONTROL_FLAG_DISABLE) + d9.ShaderCacheControl(D3D12_SHADER_CACHE_KIND_FLAG_IMPLICIT_DRIVER_MANAGED | D3D12_SHADER_CACHE_KIND_FLAG_IMPLICIT_D3D_CACHE_FOR_DRIVER | D3D12_SHADER_CACHE_KIND_FLAG_IMPLICIT_D3D_CONVERSIONS, D3D12_SHADER_CACHE_CONTROL_FLAG_DISABLE) }); match r { Ok(()) => eprintln!("time-forms: the driver's shader cache is off for this process"), From 6423b67d9d42c87096f5d1e5d67304ebd306f7e5 Mon Sep 17 00:00:00 2001 From: Raghav314 Date: Thu, 26 Nov 2026 00:45:18 +0530 Subject: [PATCH 5/5] time-forms: options through xcl shaders' parser (#2266) `xcl shaders` now rejects unknown options, so --time-forms and its options (--heap, --no-hlsl, --warm, --all N, --max-hlsl MB, --max-dxil KB, --out FILE) are ShadersOptions fields, and time_forms reads them from there instead of scanning the arguments. --timeout becomes optional so each mode keeps its own default (--direct 10 s, --time-forms 120 s). shaders_e2e checks the new options' missing and mistyped values. Assisted-by: Claude Code (Claude Opus 5.5) --- crates/xcl/src/shaders.rs | 66 ++++++++++++++++++++++----------- crates/xcl/tests/shaders_e2e.rs | 4 ++ 2 files changed, 49 insertions(+), 21 deletions(-) diff --git a/crates/xcl/src/shaders.rs b/crates/xcl/src/shaders.rs index 8b629e2792..ce1c875f87 100644 --- a/crates/xcl/src/shaders.rs +++ b/crates/xcl/src/shaders.rs @@ -823,10 +823,19 @@ struct ShadersOptions { threads: Option, trace: bool, max_bytes: usize, - timeout: u64, + /// `--timeout S`: `--direct` (default 10) and `--time-forms` (default 120) + timeout: Option, lanes: bool, hash: Option, dump: Option, + time_forms: bool, + heap: bool, + no_hlsl: bool, + warm: bool, + all: Option, + max_hlsl_mb: usize, + max_dxil_kb: usize, + out: Option, } fn parse_args(args: &[String]) -> Result { @@ -858,10 +867,18 @@ fn parse_args(args: &[String]) -> Result { threads: None, trace: false, max_bytes: 16384, - timeout: 10, + timeout: None, lanes: false, hash: None, dump: None, + time_forms: false, + heap: false, + no_hlsl: false, + warm: false, + all: None, + max_hlsl_mb: 16, + max_dxil_kb: 4096, + out: None, }; let mut p = crate::cli::Parser::new(args); while let Some(arg) = p.next_arg() { @@ -896,10 +913,18 @@ fn parse_args(args: &[String]) -> Result { "--threads" => opts.threads = Some(p.parse_usize("--threads")?), "--trace" => opts.trace = true, "--max-bytes" => opts.max_bytes = p.parse_usize("--max-bytes")?, - "--timeout" => opts.timeout = p.parse_u64("--timeout")?, + "--timeout" => opts.timeout = Some(p.parse_u64("--timeout")?), "--lanes" => opts.lanes = true, "--hash" => opts.hash = Some(p.parse_hex_u64("--hash")?), "--dump" => opts.dump = Some(PathBuf::from(p.value("--dump")?)), + "--time-forms" => opts.time_forms = true, + "--heap" => opts.heap = true, + "--no-hlsl" => opts.no_hlsl = true, + "--warm" => opts.warm = true, + "--all" => opts.all = Some(p.parse_usize("--all")?), + "--max-hlsl" => opts.max_hlsl_mb = p.parse_usize("--max-hlsl")?, + "--max-dxil" => opts.max_dxil_kb = p.parse_usize("--max-dxil")?, + "--out" => opts.out = Some(PathBuf::from(p.value("--out")?)), other => return Err(crate::cli::Parser::unexpected(other)), } } @@ -983,8 +1008,8 @@ pub fn run(path: &Path, args: &[String]) -> i32 { let windows = runtime_windows(); return precompile(&input, opts.limit, windows, opts.split, opts.only.as_deref(), opts.pipelines, used.as_ref(), t0); } - if args.iter().any(|a| a == "--time-forms") { - return time_forms(&input, args, t0); + if opts.time_forms { + return time_forms(&input, &opts, t0); } if opts.direct { return direct_sweep(&input, &opts, t0); @@ -2284,7 +2309,7 @@ fn direct_sweep(input: &Input, opts: &ShadersOptions, t0: std::time::Instant) -> // big programs translate slowly (SSA over every guarded access): skip above the cap, // give up on one after the timeout (its thread is left to finish; the process ends soon) let max_bytes = opts.max_bytes; - let timeout = std::time::Duration::from_secs(opts.timeout); + let timeout = std::time::Duration::from_secs(opts.timeout.unwrap_or(10)); let skipped = AtomicUsize::new(0); // `--lanes`: compute programs through the per-lane form too (`recomp::lower_dxil`); where it // translates, its DXIL size against the per-instruction form's, and the refusals ranked @@ -2439,25 +2464,24 @@ fn direct_sweep(input: &Input, opts: &ShadersOptions, t0: std::time::Instant) -> /// row includes the driver's warm-up. /// `--heap`: the two direct forms with heap windows instead of W. `--no-hlsl`: the HLSL /// columns stay empty. `--dump DIR`: each form's DXIL as `DIR/_.dxil`. -fn time_forms(input: &Input, args: &[String], t0: std::time::Instant) -> i32 { +fn time_forms(input: &Input, opts: &ShadersOptions, t0: std::time::Instant) -> i32 { use std::time::{Duration, Instant}; // driver compilers recurse deeply on big programs (a 2 MB stack overflowed under Wine) const BIG_STACK: usize = 256 << 20; use windows::Win32::Graphics::Direct3D12::*; - let opt = |name: &str| args.iter().position(|a| a == name).and_then(|i| args.get(i + 1)).and_then(|v| v.parse::().ok()); - let windows = opt("--windows").unwrap_or(4) as u32; - let split = opt("--split").map(|v| v != 0).unwrap_or(true); - let timeout = Duration::from_secs(opt("--timeout").unwrap_or(120)); - let limit = opt("--limit").map(|v| v as usize).unwrap_or(usize::MAX); - let out_path = args.iter().position(|a| a == "--out").and_then(|i| args.get(i + 1)).cloned(); - let threads = opt("--threads").map(|v| v.max(1) as usize).unwrap_or(8); + let windows = opts.windows; + let split = opts.split.unwrap_or(true); + let timeout = Duration::from_secs(opts.timeout.unwrap_or(120)); + let limit = opts.limit; + let out_path = opts.out.clone(); + let threads = opts.threads.unwrap_or(8).max(1); // `--all N`: a size-spread sample of N compute programs of every size (the 10 largest // always in), not only the ones the per-lane form takes (its columns are empty where it // refuses one) - let all = opt("--all").map(|v| v as usize); - let heap = args.iter().any(|a| a == "--heap"); - let no_hlsl = args.iter().any(|a| a == "--no-hlsl"); - let dump_dir = args.iter().position(|a| a == "--dump").and_then(|i| args.get(i + 1)).map(std::path::PathBuf::from); + let all = opts.all; + let heap = opts.heap; + let no_hlsl = opts.no_hlsl; + let dump_dir = opts.dump.clone(); if let Some(d) = &dump_dir { let _ = std::fs::create_dir_all(d); } @@ -2468,8 +2492,8 @@ fn time_forms(input: &Input, args: &[String], t0: std::time::Instant) -> i32 { }; // caps for the giants: no DXC above `--max-hlsl` MB of HLSL, no driver build above // `--max-dxil` KB of DXIL (sizes are still recorded) - let max_hlsl = opt("--max-hlsl").unwrap_or(16) as usize * (1 << 20); - let max_dxil = opt("--max-dxil").unwrap_or(4096) as usize * 1024; + let max_hlsl = opts.max_hlsl_mb * (1 << 20); + let max_dxil = opts.max_dxil_kb * 1024; std::panic::set_hook(Box::new(|_| {})); // phase 1 (parallel): the compute programs and whether the per-lane form takes them @@ -2550,7 +2574,7 @@ fn time_forms(input: &Input, args: &[String], t0: std::time::Instant) -> i32 { } }; // cold driver builds: the driver's own shader cache off for this process (developer mode) - if args.iter().all(|a| a != "--warm") { + if !opts.warm { use windows::core::Interface; let r = pipelines.dev.cast::().and_then(|d9| unsafe { d9.ShaderCacheControl(D3D12_SHADER_CACHE_KIND_FLAG_IMPLICIT_DRIVER_MANAGED | D3D12_SHADER_CACHE_KIND_FLAG_IMPLICIT_D3D_CACHE_FOR_DRIVER | D3D12_SHADER_CACHE_KIND_FLAG_IMPLICIT_D3D_CONVERSIONS, D3D12_SHADER_CACHE_CONTROL_FLAG_DISABLE) diff --git a/crates/xcl/tests/shaders_e2e.rs b/crates/xcl/tests/shaders_e2e.rs index 8296f0765e..cb8d52e5da 100644 --- a/crates/xcl/tests/shaders_e2e.rs +++ b/crates/xcl/tests/shaders_e2e.rs @@ -371,6 +371,10 @@ fn shaders_rejects_unknown_options_missing_values_and_mistyped_values() { (&["--direct", "--hash"], "--hash needs a value"), (&["--direct", "--hash", "0xZZ"], "--hash:"), (&["--direct", "--dump"], "--dump needs a value"), + (&["--time-forms", "--all", "abc"], "invalid value for --all: abc"), + (&["--time-forms", "--max-dxil", "abc"], "invalid value for --max-dxil: abc"), + (&["--time-forms", "--max-hlsl", "-1"], "invalid value for --max-hlsl: -1"), + (&["--time-forms", "--out"], "--out needs a value"), ]; for (args, expected_msg) in cases {