Only changed dwords go back into title memory; cheap safe copies; title's own arguments; more shader forms
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
d9a31188be
commit
7fa012814f
16 files changed
+973
-29
No files matched your search
@@ -3110,6 +3110,12 @@ impl<'a> Lower<'a> {
|
||||
let v = inst.read(Reg::V(reg)).ok_or("an unread operand")?;
|
||||
self.i32_of(v)
|
||||
}
|
||||
// src_scc: SCC as 0 or 1 (VIctory upstream 0b35b7f, as the dot
|
||||
// products and packed multiply-adds below).
|
||||
Operand::Const(253) => {
|
||||
let bit = self.scc_in(inst)?;
|
||||
Ok(self.s.m.cast(self.cur, Cast::ZExt, bit, self.s.t.i32))
|
||||
}
|
||||
Operand::Const(c) => crate::resource::inline(c)
|
||||
.map(|x| self.s.m.i32(x))
|
||||
.ok_or("a special operand (vccz, execz, scc, lds_direct)"),
|
||||
@@ -6955,6 +6961,61 @@ impl<'a> Lower<'a> {
|
||||
.op(c, "unaryBits.i32", Attr::ReadNone, self.s.t.i32, op, &[a]);
|
||||
int(self, r)
|
||||
}
|
||||
"v_dot4c_i32_i8" => {
|
||||
// D += the dot product of four signed bytes, wrapping: DXIL's
|
||||
// Dot4AddI8Packed.
|
||||
let (a, bb) = (s(self, 0)?, s(self, 1)?);
|
||||
let Some(Operand::Vector { reg, .. }) = v.dst else {
|
||||
return Err("an accumulator");
|
||||
};
|
||||
let acc = self.i32_of(inst.read(Reg::V(reg)).ok_or("an accumulator")?)?;
|
||||
let i32_ty = self.s.t.i32;
|
||||
let r = self.s.op(
|
||||
c,
|
||||
"dot4AddPacked.i32",
|
||||
Attr::ReadNone,
|
||||
i32_ty,
|
||||
163,
|
||||
&[acc, a, bb],
|
||||
);
|
||||
int(self, r)
|
||||
}
|
||||
"v_dot4_i32_i8" => {
|
||||
// VOP3P: op_sel picks the half each multiplicand's low half
|
||||
// reads, op_sel_hi its high half's; the accumulator is read
|
||||
// whole (as AMD's compilers fold constants into it).
|
||||
if v.clamp || v.neg_hi != 0 {
|
||||
return Err("a saturating or negated dot product");
|
||||
}
|
||||
let mut xs = Vec::new();
|
||||
for k in 0..2 {
|
||||
let x = s(self, k)?;
|
||||
let (lo, hi) = (v.opsel >> k & 1 != 0, v.opsel_hi >> k & 1 != 0);
|
||||
if (lo, hi) == (false, true) {
|
||||
xs.push(x);
|
||||
continue;
|
||||
}
|
||||
let (k16, low) = (self.s.m.i32(16), self.s.m.i32(0xFFFF));
|
||||
let top = self.s.m.bin(c, Bin::LShr, x, k16);
|
||||
let bottom = self.s.m.bin(c, Bin::And, x, low);
|
||||
let hi = self
|
||||
.s
|
||||
.m
|
||||
.bin(c, Bin::Shl, if hi { top } else { bottom }, k16);
|
||||
xs.push(self.s.m.bin(c, Bin::Or, if lo { top } else { bottom }, hi));
|
||||
}
|
||||
let acc = s(self, 2)?;
|
||||
let i32_ty = self.s.t.i32;
|
||||
let r = self.s.op(
|
||||
c,
|
||||
"dot4AddPacked.i32",
|
||||
Attr::ReadNone,
|
||||
i32_ty,
|
||||
163,
|
||||
&[acc, xs[0], xs[1]],
|
||||
);
|
||||
int(self, r)
|
||||
}
|
||||
"v_mov_b32" => {
|
||||
if v.abs != 0 || v.neg != 0 || v.clamp || v.omod != 0 {
|
||||
let a = f(self, 0)?;
|
||||
@@ -8411,6 +8472,30 @@ impl<'a> Lower<'a> {
|
||||
Ok(self.s.m.bin(c, Bin::And, x, m))
|
||||
}
|
||||
|
||||
/// Half `high` of source `k` of `v_pk_fmac_f16`, in the low 16 bits: a
|
||||
/// VOP2 operation (no op_sel) whose third source is its destination.
|
||||
fn fmac_half(&mut self, inst: &Inst, k: usize, high: bool) -> Result<V, Why> {
|
||||
let Fields::Valu(v) = &inst.fields else {
|
||||
unreachable!()
|
||||
};
|
||||
let op = if k == 2 { v.dst } else { v.src.get(k).copied() };
|
||||
let op = op.ok_or("a missing operand")?;
|
||||
if matches!(op, Operand::Const(_) | Operand::Literal(_)) {
|
||||
// shortcut: no constant operand seen; its high half is not known.
|
||||
return Err("a constant operand of v_pk_fmac_f16");
|
||||
}
|
||||
let x = self.operand(inst, &op)?;
|
||||
let c = self.cur;
|
||||
let x = if high {
|
||||
let k16 = self.s.m.i32(16);
|
||||
self.s.m.bin(c, Bin::LShr, x, k16)
|
||||
} else {
|
||||
x
|
||||
};
|
||||
let m = self.s.m.i32(0xFFFF);
|
||||
Ok(self.s.m.bin(c, Bin::And, x, m))
|
||||
}
|
||||
|
||||
/// Packed 16-bit operations (`v_pk_*`): each half computed as the
|
||||
/// 16-bit operation does, f16 through f32 as in [`Self::valu16`].
|
||||
fn packed16(&mut self, inst: &Inst, op: &str, guard: Option<V>) -> Result<(), Why> {
|
||||
@@ -8419,7 +8504,7 @@ impl<'a> Lower<'a> {
|
||||
};
|
||||
let float = op.ends_with("_f16");
|
||||
let n = match op {
|
||||
"fma_f16" | "mad_u16" | "mad_i16" => 3,
|
||||
"fma_f16" | "fmac_f16" | "mad_u16" | "mad_i16" => 3,
|
||||
"add_f16" | "mul_f16" | "min_f16" | "max_f16" | "add_u16" | "sub_u16" | "add_i16"
|
||||
| "sub_i16" | "mul_lo_u16" | "lshlrev_b16" | "lshrrev_b16" | "ashrrev_i16"
|
||||
| "max_u16" | "min_u16" | "max_i16" | "min_i16" => 2,
|
||||
@@ -8434,7 +8519,11 @@ impl<'a> Lower<'a> {
|
||||
for high in [false, true] {
|
||||
let mut xs = Vec::new();
|
||||
for k in 0..n {
|
||||
let h = self.packed_src(inst, k, high, float)?;
|
||||
let h = if op == "fmac_f16" {
|
||||
self.fmac_half(inst, k, high)?
|
||||
} else {
|
||||
self.packed_src(inst, k, high, float)?
|
||||
};
|
||||
if float {
|
||||
let mut f = self
|
||||
.s
|
||||
@@ -9480,7 +9569,8 @@ impl<'a> Lower<'a> {
|
||||
let Fields::Image { cache, .. } = &inst.fields else {
|
||||
unreachable!()
|
||||
};
|
||||
if *d16 || *a16 {
|
||||
// 16-bit coordinates (a16) are read as `addr_val` reads them.
|
||||
if *d16 {
|
||||
return Err("a 16-bit image atomic");
|
||||
}
|
||||
// Compare-exchange consumes a replacement followed by a comparand.
|
||||
|
||||
@@ -284,6 +284,7 @@ pub fn translate(container: &[u8]) -> Result<HostShader, ShaderError> {
|
||||
let c = Container::parse(container)?;
|
||||
let dxil = c
|
||||
.part(FourCC::DXIL)
|
||||
.or(c.part(FourCC::ACCC))
|
||||
.ok_or(ShaderError::Malformed("no DXIL part"))?;
|
||||
let native = crate::native_programs(dxil.data)?
|
||||
.into_iter()
|
||||
|
||||
Reference in new issue
Block a user