Typed buffer loads of 16-bit channels pack two per register; skipped devices say why (upstream c430b1d, 100de0e)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
localandClaude Opus 5.5 committed 2026-11-24 23:25:32 -06:00
1 parent fa97cdb3fe
commit 68c36284d8
5 files changed
+128 -24

No files matched your search

+41 -3
View File
@@ -6414,6 +6414,39 @@ impl<'a> Lower<'a> {
Ok(out)
}
/// Channels of buffer format `format`, as [`Self::format_load`] gives
/// them, as d16 data: 16 bits each, two per dword, low half first (an
/// odd last high half 0). Integer formats keep their low 16 bits; the
/// others become f16.
fn d16_channels(&mut self, format: u8, channels: Vec<V>) -> Result<Vec<V>, Why> {
let (_, numeric) = buffer_format(format).ok_or("a buffer format")?;
let c = self.cur;
let mut halves = Vec::new();
for x in channels {
halves.push(if matches!(numeric, Numeric::Uint | Numeric::Sint) {
let m = self.s.m.i32(0xFFFF);
self.s.m.bin(c, Bin::And, x, m)
} else {
let (f, i32t) = (self.as_float(x), self.s.t.i32);
self.s
.op(c, "legacyF32ToF16", Attr::ReadNone, i32t, 130, &[f])
});
}
let mut out = Vec::new();
for pair in halves.chunks(2) {
out.push(match *pair {
[lo, hi] => {
let k16 = self.s.m.i32(16);
let hi = self.s.m.bin(c, Bin::Shl, hi, k16);
self.s.m.bin(c, Bin::Or, lo, hi)
}
[lo] => lo,
_ => unreachable!("chunks of one or two"),
});
}
Ok(out)
}
/// The byte offset a buffer descriptor built around a root descriptor adds
/// (constant and computed parts); none for other descriptors.
fn built_offset(&mut self, src: &Source) -> Result<(u32, Option<V>), Why> {
@@ -10808,8 +10841,9 @@ impl<'a> Lower<'a> {
"buffer_load_sshort" => Some((16, true)),
_ => None,
};
// d16: two 16-bit channels per VGPR, low half first.
let d16 = name.starts_with("buffer_") && name.contains("_format_d16_");
// d16: two 16-bit channels per VGPR, low half first (buffer and
// tbuffer formats alike).
let d16 = name.contains("_format_d16_");
let plain = name.replace("_format_d16_", "_format_");
let (typed, count) = match plain
.strip_prefix("buffer_load_")
@@ -11143,7 +11177,11 @@ impl<'a> Lower<'a> {
let Some(Operand::Vector { reg, .. }) = *data else {
return Err("a buffer result");
};
for (k, x) in self.format_load(h, off, f, count)?.into_iter().enumerate() {
let mut xs = self.format_load(h, off, f, count)?;
if d16 {
xs = self.d16_channels(f, xs)?;
}
for (k, x) in xs.into_iter().enumerate() {
self.write(inst, Reg::V(reg + k as u8), x, guard);
}
return Ok(());