|
@@ -816,6 +816,127 @@ mod tests {
|
|
|
use super::lower::LOOP_LIMIT;
|
|
use super::lower::LOOP_LIMIT;
|
|
|
use super::parse_loop_limit;
|
|
use super::parse_loop_limit;
|
|
|
|
|
|
|
|
|
|
+ /// The LLVM text `dxc -dumpbin` prints for a DXIL container, when dxc
|
|
|
|
|
+ /// is installed.
|
|
|
|
|
+ #[cfg(windows)]
|
|
|
|
|
+ fn dump_dxil(container: &[u8]) -> Option<String> {
|
|
|
|
|
+ let dxc = match std::env::var_os("VICTORY_PC_DXC") {
|
|
|
|
|
+ Some(p) => std::path::PathBuf::from(p),
|
|
|
|
|
+ None => super::validator::Validator::default_path()?.with_file_name("dxc.exe"),
|
|
|
|
|
+ };
|
|
|
|
|
+ if !dxc.exists() {
|
|
|
|
|
+ return None;
|
|
|
|
|
+ }
|
|
|
|
|
+ let file = std::env::temp_dir().join(format!("victory-interp-{}.dxil", std::process::id()));
|
|
|
|
|
+ std::fs::write(&file, container).ok()?;
|
|
|
|
|
+ let out = std::process::Command::new(dxc)
|
|
|
|
|
+ .arg("-dumpbin")
|
|
|
|
|
+ .arg(&file)
|
|
|
|
|
+ .output()
|
|
|
|
|
+ .ok()?;
|
|
|
|
|
+ let _ = std::fs::remove_file(&file);
|
|
|
|
|
+ assert!(
|
|
|
|
|
+ out.status.success(),
|
|
|
|
|
+ "dxc -dumpbin failed: {}",
|
|
|
|
|
+ String::from_utf8_lossy(&out.stderr)
|
|
|
|
|
+ );
|
|
|
|
|
+ Some(String::from_utf8_lossy(&out.stdout).into_owned())
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ #[cfg(windows)]
|
|
|
|
|
+ #[test]
|
|
|
|
|
+ fn interpolated_f16_writes_the_op_sel_half_with_modifiers() {
|
|
|
|
|
+ // p1_f32 v2, v0, attr0.x; then a p2_f16 completing it into v3, which holds a value
|
|
|
|
|
+ // (v2's own is no number here: a first half is evaluated with its second).
|
|
|
|
|
+ let p2 = |dst_high: bool, omod: u32, clamp: bool| {
|
|
|
|
|
+ let vgpr = |n: u32| 256 + n;
|
|
|
|
|
+ let mut w0 = 0x35u32 << 26 | 0x35au32 << 16 | 3;
|
|
|
|
|
+ if dst_high {
|
|
|
|
|
+ w0 |= 1 << 14; // op_sel[3]: the high destination half.
|
|
|
|
|
+ }
|
|
|
|
|
+ if clamp {
|
|
|
|
|
+ w0 |= 1 << 15;
|
|
|
|
|
+ }
|
|
|
|
|
+ let w1 = vgpr(1) << 9 | vgpr(2) << 18;
|
|
|
|
|
+ [w0, w1 | omod << 27]
|
|
|
|
|
+ };
|
|
|
|
|
+ let dump = |dst_high: bool, omod: u32, clamp: bool| {
|
|
|
|
|
+ let [w0, w1] = p2(dst_high, omod, clamp);
|
|
|
|
|
+ let words = [
|
|
|
|
|
+ 0x7E06_0301u32, // v_mov_b32 v3, v1
|
|
|
|
|
+ 0xC808_0000, // v_interp_p1_f32 v2, v0, attr0.x
|
|
|
|
|
+ w0,
|
|
|
|
|
+ w1, // v_interp_p2_f16 v3, attr0, v1, v2
|
|
|
|
|
+ 0xF800_180F,
|
|
|
|
|
+ 0x0303_0303, // exp mrt0, v3, v3, v3, v3 done vm
|
|
|
|
|
+ 0xBF81_0000,
|
|
|
|
|
+ ];
|
|
|
|
|
+ let native = super::NativeProgram {
|
|
|
|
|
+ stage: super::HwStage::Ps,
|
|
|
|
|
+ wave64: false,
|
|
|
|
|
+ vgprs: 4,
|
|
|
|
|
+ layout: vec![],
|
|
|
|
|
+ used: vec![],
|
|
|
|
|
+ io: crate::native::StageIo::Ps {
|
|
|
|
|
+ inputs: vec![crate::native::PsInput {
|
|
|
|
|
+ usage: crate::native::Usage::Generic,
|
|
|
|
|
+ row: 0,
|
|
|
|
|
+ mask: 0b1111,
|
|
|
|
|
+ attr: 0,
|
|
|
|
|
+ flat: false,
|
|
|
|
|
+ fp16: true,
|
|
|
|
|
+ pack2: false,
|
|
|
|
|
+ row2: 0,
|
|
|
|
|
+ }],
|
|
|
|
|
+ input_addr: 2,
|
|
|
|
|
+ db_shader_control: 0,
|
|
|
|
|
+ patches: vec![],
|
|
|
|
|
+ },
|
|
|
|
|
+ code: words.iter().flat_map(|w| w.to_le_bytes()).collect(),
|
|
|
|
|
+ };
|
|
|
|
|
+ let el = |name: &str, kind, usage, half| SigElement {
|
|
|
|
|
+ name: name.into(),
|
|
|
|
|
+ index: 0,
|
|
|
|
|
+ kind,
|
|
|
|
|
+ comp: 9,
|
|
|
|
|
+ interp: 0,
|
|
|
|
|
+ row: Some(0),
|
|
|
|
|
+ col: 0,
|
|
|
|
|
+ cols: 4,
|
|
|
|
|
+ usage,
|
|
|
|
|
+ half,
|
|
|
|
|
+ };
|
|
|
|
|
+ let isg1 = super::container::signature(&[el("TEXCOORD", 0, 0, true)], true);
|
|
|
|
|
+ let osg1 = super::container::signature(&[el("SV_Target", 16, 15, false)], false);
|
|
|
|
|
+ let bytes =
|
|
|
|
|
+ crate::dxbc::build(&[(super::FourCC::ISG1, &isg1), (super::FourCC::OSG1, &osg1)]);
|
|
|
|
|
+ let c = super::Container::parse(&bytes).unwrap();
|
|
|
|
|
+ let p = crate::ir::build(&native.patched_code(), native.wave64, native.vgprs).unwrap();
|
|
|
|
|
+ let st = crate::structure::structure(&p).unwrap();
|
|
|
|
|
+ let res = crate::resource::track(&p, &native.layout, native.stage, Some(&st)).unwrap();
|
|
|
|
|
+ let io = crate::io::raise(&p, &native).unwrap();
|
|
|
|
|
+ super::emit(&c, &native, &p, &st, &io, &res).unwrap().dxil
|
|
|
|
|
+ };
|
|
|
|
|
+ let (Some(low), Some(high)) = (
|
|
|
|
|
+ dump_dxil(&dump(false, 0, false)),
|
|
|
|
|
+ dump_dxil(&dump(true, 1, true)),
|
|
|
|
|
+ ) else {
|
|
|
|
|
+ eprintln!("no dxc.exe; DXIL check skipped");
|
|
|
|
|
+ return;
|
|
|
|
|
+ };
|
|
|
|
|
+ // The low-half write keeps the destination's high half.
|
|
|
|
|
+ assert!(low.contains("-65536"), "low write keeps the high half");
|
|
|
|
|
+ // The high-half write shifts the result up by 16.
|
|
|
|
|
+ assert!(high.contains("shl i32"), "op_sel[3] writes the high half");
|
|
|
|
|
+ // omod mul:2 and clamp (dx.op.unary.f32, opcode 7) are applied.
|
|
|
|
|
+ assert!(high.contains("2.000000e+00"), "omod multiplies by two");
|
|
|
|
|
+ assert!(
|
|
|
|
|
+ high.contains("dx.op.unary.f32(i32 7"),
|
|
|
|
|
+ "clamp saturates the result"
|
|
|
|
|
+ );
|
|
|
|
|
+ assert!(!low.contains("dx.op.unary.f32(i32 7"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
#[test]
|
|
#[test]
|
|
|
fn the_clean_up_switch_parses_or_runs_every_pass() {
|
|
fn the_clean_up_switch_parses_or_runs_every_pass() {
|
|
|
let all = super::bitcode::opt::ALL;
|
|
let all = super::bitcode::opt::ALL;
|