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:
1 parent
fa97cdb3fe
commit
68c36284d8
5 files changed
+128
-24
No files matched your search
@@ -718,9 +718,12 @@ fn translated_shaders_draw_as_pc_ones() {
|
||||
eprintln!("no console or PC compiler; skipped");
|
||||
return;
|
||||
};
|
||||
let Ok(host) = Host::new(false) else {
|
||||
eprintln!("no SM 6.6 device; skipped");
|
||||
return;
|
||||
let host = match Host::new(false) {
|
||||
Ok(host) => host,
|
||||
Err(e) => {
|
||||
eprintln!("no SM 6.6 device ({e}); skipped");
|
||||
return;
|
||||
}
|
||||
};
|
||||
let dir = std::env::temp_dir().join(format!("victory-diff-{}", std::process::id()));
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
@@ -874,9 +877,12 @@ fn translated_mesh_shaders_draw_as_pc_ones() {
|
||||
eprintln!("no console or PC compiler; skipped");
|
||||
return;
|
||||
};
|
||||
let Ok(host) = Host::new(false) else {
|
||||
eprintln!("no SM 6.6 device; skipped");
|
||||
return;
|
||||
let host = match Host::new(false) {
|
||||
Ok(host) => host,
|
||||
Err(e) => {
|
||||
eprintln!("no SM 6.6 device ({e}); skipped");
|
||||
return;
|
||||
}
|
||||
};
|
||||
let dir = std::env::temp_dir().join(format!("victory-diff-ms-{}", std::process::id()));
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
@@ -991,9 +997,12 @@ fn float_semantics_are_the_consoles() {
|
||||
eprintln!("no console compiler; skipped");
|
||||
return;
|
||||
};
|
||||
let Ok(host) = Host::new(false) else {
|
||||
eprintln!("no SM 6.6 device; skipped");
|
||||
return;
|
||||
let host = match Host::new(false) {
|
||||
Ok(host) => host,
|
||||
Err(e) => {
|
||||
eprintln!("no SM 6.6 device ({e}); skipped");
|
||||
return;
|
||||
}
|
||||
};
|
||||
let dir = std::env::temp_dir().join(format!("victory-float-{}", std::process::id()));
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
@@ -1080,9 +1089,12 @@ fn translated_compute_matches_pc() {
|
||||
eprintln!("no console or PC compiler; skipped");
|
||||
return;
|
||||
};
|
||||
let Ok(host) = Host::new(false) else {
|
||||
eprintln!("no SM 6.6 device; skipped");
|
||||
return;
|
||||
let host = match Host::new(false) {
|
||||
Ok(host) => host,
|
||||
Err(e) => {
|
||||
eprintln!("no SM 6.6 device ({e}); skipped");
|
||||
return;
|
||||
}
|
||||
};
|
||||
let dir = std::env::temp_dir().join(format!("victory-diff-cs-{}", std::process::id()));
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
|
||||
@@ -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(());
|
||||
|
||||
@@ -1252,9 +1252,12 @@ mod tests {
|
||||
#[test]
|
||||
#[cfg(windows)]
|
||||
fn stub_pipeline_is_created() {
|
||||
let Ok(host) = super::host::Host::new(false) else {
|
||||
eprintln!("no SM 6.6 device; skipped");
|
||||
return;
|
||||
let host = match super::host::Host::new(false) {
|
||||
Ok(host) => host,
|
||||
Err(e) => {
|
||||
eprintln!("no SM 6.6 device ({e}); skipped");
|
||||
return;
|
||||
}
|
||||
};
|
||||
let ps = super::HostShader {
|
||||
stage: crate::HwStage::Ps,
|
||||
|
||||
@@ -219,9 +219,12 @@ fn run_cases_on(
|
||||
let _one = ONE_AT_A_TIME.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let mut ran = 0;
|
||||
for &(label, warp) in devices {
|
||||
let Ok(host) = Host::new(warp) else {
|
||||
eprintln!("no SM 6.6 {label} device; skipped");
|
||||
continue;
|
||||
let host = match Host::new(warp) {
|
||||
Ok(host) => host,
|
||||
Err(e) => {
|
||||
eprintln!("no SM 6.6 {label} device ({e}); skipped");
|
||||
continue;
|
||||
}
|
||||
};
|
||||
let (root, pso) = host
|
||||
.compute_pipeline(shader)
|
||||
@@ -320,6 +323,51 @@ fn f16_to_f32(bits: u16) -> f32 {
|
||||
f32::from_bits(f32_bits)
|
||||
}
|
||||
|
||||
/// MTBUF `op vdata, off, s[srsrc:srsrc+3], 0 format:format` (at byte 0).
|
||||
const fn mtbuf(op: u8, vdata: u8, srsrc: u8, format: u8) -> [u32; 2] {
|
||||
[
|
||||
0x3A << 26 | (format as u32 & 0x7F) << 19 | (op as u32 & 7) << 16,
|
||||
0x80 << 24
|
||||
| (op as u32 >> 3 & 1) << 21
|
||||
| (srsrc as u32 >> 2 & 0x1F) << 16
|
||||
| (vdata as u32) << 8,
|
||||
]
|
||||
}
|
||||
|
||||
/// Stores `v1` to the buffer, then reads it back into `v0` with the tbuffer
|
||||
/// load `op` in buffer format `format`.
|
||||
fn tbuffer_load_of_v1(op: u8, format: u8) -> HostShader {
|
||||
let mut body = buffer_store_dword(1, 8, 0).to_vec();
|
||||
body.extend(mtbuf(op, 0, 8, format));
|
||||
build_valu_cs(&body)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tbuffer_d16_loads_pack_two_channels_per_dword() {
|
||||
// tbuffer_load_format_d16_x and tbuffer_load_format_d16_xy.
|
||||
let (x, xy) = (8, 9);
|
||||
// (opcode, format, dword stored, dword loaded)
|
||||
let cases: &[(u8, u8, u32, u32)] = &[
|
||||
// 16_16_FLOAT: the f16 pair (1.0, 2.0) as it was stored.
|
||||
(xy, 29, 0x4000_3C00, 0x4000_3C00),
|
||||
// 16_16_UINT: the 16-bit integers as they were stored.
|
||||
(xy, 27, 0xBEEF_1234, 0xBEEF_1234),
|
||||
// 16_16_UNORM: 0.0 and 1.0, as f16.
|
||||
(xy, 23, 0xFFFF_0000, 0x3C00_0000),
|
||||
// 16_FLOAT, one channel: the high half is 0.
|
||||
(x, 13, 0x4000_3C00, 0x0000_3C00),
|
||||
];
|
||||
for &(op, format, stored, want) in cases {
|
||||
let shader = tbuffer_load_of_v1(op, format);
|
||||
run_cases(&shader, &[[stored, 0, 0, 0]], |backend, _, _, got| {
|
||||
assert_eq!(
|
||||
got, want,
|
||||
"{backend}: d16 opcode {op} format {format} of {stored:#010x} = {got:#010x}, want {want:#010x}",
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn normalized_buffer_formats_load_their_ends_exactly() {
|
||||
// tbuffer_load_format_x.
|
||||
|
||||
@@ -115,9 +115,12 @@ pub(super) fn run(shader: &HostShader, views: &[View]) -> Vec<(&'static str, Vec
|
||||
.lock()
|
||||
.unwrap_or_else(|e| e.into_inner());
|
||||
for (label, warp) in [("hardware", false), ("warp", true)] {
|
||||
let Ok(host) = Host::new(warp) else {
|
||||
eprintln!("no SM 6.6 {label} device; skipped");
|
||||
continue;
|
||||
let host = match Host::new(warp) {
|
||||
Ok(host) => host,
|
||||
Err(e) => {
|
||||
eprintln!("no SM 6.6 {label} device ({e}); skipped");
|
||||
continue;
|
||||
}
|
||||
};
|
||||
let (root, pso) = match host.compute_pipeline(shader) {
|
||||
Ok(p) => p,
|
||||
|
||||
Reference in new issue
Block a user