From 25656f87fcf2da20d7a36d420b2fd588b029cd0d Mon Sep 17 00:00:00 2001 From: voiceovarian1-max <360456911+voiceovarian1-max@users.noreply.github.com> Date: Fri, 27 Nov 2026 16:36:24 +0400 Subject: [PATCH] D3D12.X: DXC compiles XCL's own HLSL when D3DCompile refuses it `real::compile` builds XCL's own small programs with D3DCompile: the indirect count check's (`indirect_guard`), the scatter program and the stand-ins. Under Wine, D3DCompile is Wine's own HLSL compiler, which refuses the count check's program (`E5005: Method 'Load3' is not defined on type 'RWByteAddressBuffer'`). The check was then off, and in a retail title an indirect dispatch with group counts read from GPU-written floats (0x3f800000 x ...) never ended and the device was removed. The compiler's error is now read and logged, and DXC compiles the program for the matching 6.0 profile. Where D3DCompile takes the program, as on Windows, nothing changes. Test `a_program_d3dcompile_refuses_still_compiles`. Co-Authored-By: Claude Opus 5.5 --- crates/xcl/src/hle/d3d12x/real.rs | 34 +++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/crates/xcl/src/hle/d3d12x/real.rs b/crates/xcl/src/hle/d3d12x/real.rs index 9c618fa178..8e463a1692 100644 --- a/crates/xcl/src/hle/d3d12x/real.rs +++ b/crates/xcl/src/hle/d3d12x/real.rs @@ -4187,6 +4187,7 @@ fn dummy_mesh() -> Option<&'static (Vec, Vec)> { pub(super) fn compile(src: &str, target: &str) -> Vec { unsafe { let mut blob = None; + let mut errors: Option = None; let t = format!("{target}\0"); let r = D3DCompile( src.as_ptr() as *const c_void, @@ -4199,12 +4200,41 @@ pub(super) fn compile(src: &str, target: &str) -> Vec { 0, 0, &mut blob, - None, + Some(&mut errors), ); match (r, blob) { (Ok(()), Some(b)) => std::slice::from_raw_parts(b.GetBufferPointer() as *const u8, b.GetBufferSize()).to_vec(), - _ => Vec::new(), + _ => { + // The system's HLSL compiler refused the program (Wine's own d3dcompiler does not + // take all of HLSL): DXC compiles it for the matching 6.0 profile. + let why = errors.map(|e| String::from_utf8_lossy(std::slice::from_raw_parts(e.GetBufferPointer() as *const u8, e.GetBufferSize())).trim_end_matches('\0').trim().to_string()).unwrap_or_default(); + let profile = target.replace("_5_0", "_6_0"); + match crate::gpu::recomp::dxc::compile(src, "main", &profile, &[]) { + Ok(code) => { + crate::xlog_info!("D3D12.X: D3DCompile refused a {target} program of XCL's own ({}); DXC compiled it as {profile}", why.lines().next().unwrap_or("no message")); + code + } + Err(e) => { + crate::xlog_warn!("D3D12.X: a {target} program of XCL's own does not compile: D3DCompile: {}; DXC ({profile}): {}", why.lines().next().unwrap_or("no message"), e.lines().next().unwrap_or("")); + Vec::new() + } + } + } + } + } +} + +#[cfg(test)] +mod compile_tests { + /// A cs_5_0 program that Wine's d3dcompiler refuses (`Load3` on a RWByteAddressBuffer, as + /// in the indirect count check's program) still compiles: DXC takes it then. + #[test] + fn a_program_d3dcompile_refuses_still_compiles() { + const SRC: &str = "RWByteAddressBuffer b : register(u0);\n[numthreads(1, 1, 1)]\nvoid main() { uint3 v = b.Load3(0); b.Store(12, v.x + v.y + v.z); }\n"; + if crate::gpu::recomp::dxc::compile(SRC, "main", "cs_6_0", &[]).is_err() { + return crate::gpu::recomp::runner::skip_test("no DXC"); } + assert!(!super::compile(SRC, "cs_5_0").is_empty()); } }