VIctory e29391f, 13185f5 and 4fc9d70, by hand

16-bit interpolations write the half op_sel picks, with omod and clamp; the
device says whether it was removed; detiling ends with its staging buffer.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
localandClaude Opus 5.5 committed 2026-11-25 01:12:28 -06:00
1 parent adb608af1f
commit 38410b88ab
4 files changed
+157 -2

No files matched your search

+17 -1
View File
@@ -9927,7 +9927,23 @@ impl<'a> Lower<'a> {
let f = half(self, h)?.ok_or("a packed input half no element holds")?;
self.as_int(f)
} else if f16 {
let f = half(self, h)?.ok_or("a packed input half no element holds")?;
let mut f = half(self, h)?.ok_or("a packed input half no element holds")?;
if let Fields::Valu(v) = &inst.fields {
// omod, then clamp, before the one rounding to 16 bits; op_sel[3]
// picks the destination half (VIctory e29391f: the low half was
// always written, the high one's value never arrived).
let (omod, clamp) = (v.omod, v.clamp);
if omod != 0 {
let factor = [1.0f32, 2.0, 4.0, 0.5][usize::from(omod)];
let k = self.s.m.f32(factor.to_bits());
f = self.s.m.bin(c, Bin::Mul, f, k);
}
if clamp {
f = self.unary(7, f);
}
let lo = to_f16(self, f);
return self.write_half(inst, lo, None);
}
let lo = to_f16(self, f);
self.low_half(inst, reg, lo)
} else if matches!(eval, Eval::Mode(1)) {
+121
View File
@@ -816,6 +816,127 @@ mod tests {
use super::lower::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]
fn the_clean_up_switch_parses_or_runs_every_pass() {
let all = super::bitcode::opt::ALL;