Skip to content
Merged
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
40 changes: 40 additions & 0 deletions crates/xcl/src/gpu/dxil/core_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,46 @@ fn ps_32bit_rt_export_declines_patch_when_aliased_pkrtz_dst_is_live_after_exp()
assert!(!dis.contains("storeOutput.i32(i32 105, i32 1, i32 0, i8 0, i32 2015180568)"), "direct DXIL must not store raw literal 0x781d3718 to RT1 when patch is declined:\n{dis}");
}

#[test]
fn ps_32bit_rt_export_declines_patch_for_clamped_vop3_pkrtz() {
use crate::gpu::dxbc::SigElement as S;
use crate::gpu::recomp::{translate, Mode, Options, PsInterface};
let el = |name: &str, index: u32, sv: u32, ct: u32, reg: u32, mask: u8| S {
name: name.into(), index, system_value: sv, component_type: ct, register: reg, mask, rw_mask: mask, stream: 0,
};
const V: u64 = 256;
// MRT1 exports a VOP3 v_cvt_pkrtz_f16_f32 of v6 (a large float) and v7; with CLAMP set, the
// raw 32-bit v6 is not what the title exports, so the patch must leave the conversion alone.
let code = |clamp: u64| {
prog(&[
("V_MOV_B32", "ENC_VOP1", &[("VDST", 6), ("SRC0", 255)], Some(0x781d_3718)),
("V_MOV_B32", "ENC_VOP1", &[("VDST", 7), ("SRC0", 128)], None),
("V_CVT_PKRTZ_F16_F32", "ENC_VOP3", &[("VDST", 8), ("SRC0", V + 6), ("SRC1", V + 7), ("CLAMP", clamp)], None),
("EXP", "ENC_EXP", &[("TGT", 1), ("EN", 0x3), ("COMPR", 1), ("DONE", 1), ("VM", 1), ("VSRC0", 8), ("VSRC1", 0), ("VSRC2", 0), ("VSRC3", 0)], None),
])
};
let psi = PsInterface {
inputs: vec![el("SV_Position", 0, 1, 3, 0, 0xF)],
outputs: vec![el("SV_Target", 1, 64, 1, 1, 0x1)],
input_ena: 0x2,
attrs: None,
};
let hlsl = |clamp: u64| translate(&code(clamp), &Options { mode: Mode::Pixel(psi.clone()), wave64: false, ps_rt32_mask: 1 << 1, ..Default::default() }).unwrap().hlsl;

let unclamped = hlsl(0);
assert!(unclamped.contains("xo.t1[0] = v6;"), "an unclamped VOP3 pkrtz is patched to export raw v6:\n{unclamped}");
let clamped = hlsl(1);
assert!(!clamped.contains("xo.t1[0] = v6;"), "a clamped VOP3 pkrtz must not be patched away:\n{clamped}");
assert!(clamped.contains("xo.t1[0] = (v8 & 0xFFFFu);"), "RT1 must keep exporting the clamped conversion:\n{clamped}");

let ko = KernelOptions { wave64: false, split: false, mem_windows: 1, sampler_base: 0 };
let k = super::kernel::translate_pixel_rt32(&code(1), ko, &psi, 1 << 1)
.unwrap_or_else(|e| panic!("direct DXIL PS rt32 clamped pkrtz failed: {}", &e[..e.len().min(800)]));
super::validate::validate(&k.dxil).expect("valid direct DXIL when patch is declined");
let dis = super::validate::disassemble(&k.dxil).expect("disassemble direct DXIL");
assert!(!dis.contains("i32 2015180568)"), "direct DXIL must not store raw literal 0x781d3718 to RT1 for a clamped pkrtz:\n{dis}");
}

#[test]
fn straight_line_and_loop_kernels_validate() {
let code = prog(&[
Expand Down
2 changes: 1 addition & 1 deletion crates/xcl/src/gpu/recomp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ pub(crate) fn patch_ps_32bit_exports(insts: &mut [Decoded], rt32_mask: u8) {
((256..512).contains(&s0) && s1 < 256).then(|| (s0 - 256, s1))
}
"ENC_VOP3" => {
if f("ABS") != 0 || f("NEG") != 0 || f("CLMP") != 0 || f("OMOD") != 0 {
if f("ABS") != 0 || f("NEG") != 0 || f("CLAMP") != 0 || f("OMOD") != 0 {
return None;
}
let s0 = f("SRC0");
Expand Down
Loading