Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/xcl/src/gpu/recomp/emit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3020,15 +3020,15 @@ 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)"),
3 => format!("(({e}) * 0.5)"),
_ => 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"));
Expand Down
18 changes: 18 additions & 0 deletions crates/xcl/src/gpu/recomp/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down