Shaders: model v_add_f64 whole-wave sums and s_mov_b32 copies

This commit is contained in:
Noname0202 committed 2026-11-24 20:39:19 +01:00
1 parent a721e87b03
commit 881c2ccb90
5 files changed
+410 -1

No files matched your search

+71
View File
@@ -1781,6 +1781,9 @@ impl<'a> Lower<'a> {
Shape::K(k) => return Ok(self.s.m.i32(k)),
Shape::Value(v) => return self.i32_of(v),
Shape::Active(op, src, mask, ident) => (op, src, mask, ident, None),
Shape::ActiveF64(lo, hi, mask, high) => {
return self.active_f64_sum(lo, hi, mask, high);
}
Shape::Masked(src, mask, ident) => {
let c = self.cur;
let &m = self
@@ -1946,6 +1949,74 @@ impl<'a> Lower<'a> {
Ok(if float { self.as_int(r) } else { r })
}
/// `WaveActiveSum` of 64-bit floats (`f64(lo, hi)` in active lanes, `+0.0` elsewhere),
/// returning the low (`!high`) or high (`high`) 32-bit word.
fn active_f64_sum(
&mut self,
lo: Value,
hi: Value,
mask: Value,
high: bool,
) -> Result<V, Why> {
if self.mask_data == MaskData::None {
return Err("a wave reduction in a mesh shader");
}
let c = self.cur;
let &m = self
.x
.st
.masks
.get(&mask)
.ok_or("a wave reduction's untracked mask")?;
let on = self.boolean(m, c)?;
let lo = self.i32_of(lo)?;
let hi = self.i32_of(hi)?;
let z = self.s.m.i32(0);
let lo = self.s.m.select(c, on, lo, z);
let hi = self.s.m.select(c, on, hi, z);
self.s.flags |= flags::WAVE_OPS | flags::DOUBLES;
let f64t = self.s.m.double();
let i32t = self.s.t.i32;
let split_ty = self
.s
.m
.named_struct("dx.types.splitdouble", vec![i32t, i32t]);
let arg = self
.s
.op(c, "makeDouble", Attr::ReadNone, f64t, 101, &[lo, hi]);
let (k0, k0b) = (self.s.m.i8(0), self.s.m.i8(0));
let sum = self
.s
.op(c, "waveActiveOp.f64", Attr::NoUnwind, f64t, 119, &[arg, k0, k0b]);
let split = self
.s
.op(c, "splitDouble.f64", Attr::ReadNone, split_ty, 102, &[sum]);
let mut r_lo = self.s.m.extract(c, split, 0);
let mut r_hi = self.s.m.extract(c, split, 1);
if self.exchange.is_some() {
if !self.all_lanes(self.cur_ir) {
need(self.cur_ir);
return Err("a wave reduction where not every lane runs");
}
let (lo0, lo1) = self.exchange_halves(self.cur, r_lo);
let (hi0, hi1) = self.exchange_halves(self.cur, r_hi);
let c = self.cur;
let d0 = self
.s
.op(c, "makeDouble", Attr::ReadNone, f64t, 101, &[lo0, hi0]);
let d1 = self
.s
.op(c, "makeDouble", Attr::ReadNone, f64t, 101, &[lo1, hi1]);
let total = self.s.m.bin(c, Bin::Add, d0, d1);
let split = self
.s
.op(c, "splitDouble.f64", Attr::ReadNone, split_ty, 102, &[total]);
r_lo = self.s.m.extract(c, split, 0);
r_hi = self.s.m.extract(c, split, 1);
}
Ok(if high { r_hi } else { r_lo })
}
/// The sum of two 16-bit floats (the low halves of `a` and `b`) as the console's
/// `v_add_f16` gives it: added in f32 and rounded to 16 bits, to nearest
/// ([`Self::f16_nearest`]).