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()); } }