diff --git a/crates/xcl/src/gpu/recomp/emit.rs b/crates/xcl/src/gpu/recomp/emit.rs index b72eda37e..1e3ae1cd7 100644 --- a/crates/xcl/src/gpu/recomp/emit.rs +++ b/crates/xcl/src/gpu/recomp/emit.rs @@ -3020,7 +3020,7 @@ impl Em { } _ => return Err("VALU 64-bit"), }; - // omod, then clamp (DXIL has a double saturate) + // omod, then clamp (clamp to [0.0, 1.0] since HLSL SM 6.6 has no double saturate overload) let mut e = match m.omod { 1 => format!("(({e}) * 2.0)"), 2 => format!("(({e}) * 4.0)"), @@ -3028,7 +3028,7 @@ impl Em { _ => e, }; if m.clamp { - e = format!("saturate({e})"); + e = format!("clamp({e}, 0.0, 1.0)"); } self.line(&format!("double {t}_d = {e}; uint {t}_l, {t}_h; asuint({t}_d, {t}_l, {t}_h);")); self.write64(&dst, &format!("{t}_l"), &format!("{t}_h")); diff --git a/crates/xcl/src/gpu/recomp/tests.rs b/crates/xcl/src/gpu/recomp/tests.rs index e609a34cd..11a6af68e 100644 --- a/crates/xcl/src/gpu/recomp/tests.rs +++ b/crates/xcl/src/gpu/recomp/tests.rs @@ -6750,6 +6750,24 @@ fn sdwa_f16_inline_constants_hlsl() { assert!(!t_int.hlsl.contains("0x00003C00u"), "{}", t_int.hlsl); } +#[test] +fn valu64_clamp_and_omod_hlsl() { + let code = prog(&[ + ("V_ADD_F64", "ENC_VOP3", &[("VDST", 2), ("SRC0", V), ("SRC1", V + 2), ("CLAMP", 1)], None), + ("V_MUL_F64", "ENC_VOP3", &[("VDST", 4), ("SRC0", V), ("SRC1", V + 2), ("OMOD", 1)], None), + ("V_FMA_F64", "ENC_VOP3", &[("VDST", 6), ("SRC0", V), ("SRC1", V + 2), ("SRC2", V + 4), ("OMOD", 2), ("CLAMP", 1)], None), + ]); + let t = translate(&code, &Options { wave64: false, ..Default::default() }).unwrap(); + assert!(t.complete(), "{:?}", t.unsupported_why); + assert!(t.hlsl.contains("double t1_d = clamp(asdouble(v0, v1) + asdouble(v2, v3), 0.0, 1.0);"), "{}", t.hlsl); + assert!(t.hlsl.contains("double t2_d = ((asdouble(v0, v1) * asdouble(v2, v3)) * 2.0);"), "{}", t.hlsl); + assert!(t.hlsl.contains("double t3_d = clamp(((fma(asdouble(v0, v1), asdouble(v2, v3), asdouble(v4, v5))) * 4.0), 0.0, 1.0);"), "{}", t.hlsl); + assert!(!t.hlsl.contains("saturate(asdouble"), "{}", t.hlsl); + if super::dxc::location().is_ok() { + super::dxc::compile(&t.hlsl, "main", "cs_6_6", &[]).unwrap_or_else(|e| panic!("{e}\n{}", t.hlsl)); + } +} + #[test] fn gpu_wave32_and_wave64_src_vccz_execz() { if !gpu_ready() {