Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions crates/xcl/src/gpu/dxil/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ pub struct Texture {
pub kind: TexKind,
pub uav: bool,
pub comp: CompType,
pub ncomp: u32,
}

/// A sampler handle.
Expand Down Expand Up @@ -620,7 +621,7 @@ impl Shader {
self.bindings.push(super::shader::Binding { comp_type: comp as u32, ..super::shader::Binding::new(ResClass::Srv, space, lower, kind as u32) });
let h = self.handle_from_binding(ResClass::Srv, lower, lower, space, lower);
let handle = self.annotate(h, kind as u32, typed_props(comp, ncomp));
Texture { handle, kind, uav: false, comp }
Texture { handle, kind, uav: false, comp, ncomp }
}
/// Declares a cbuffer of `size` bytes at `b<lower>, space<space>` (a
/// root-constant block is the same: a small cbuffer).
Expand Down Expand Up @@ -664,7 +665,6 @@ impl Shader {
}
/// A structured buffer from the heap.
pub fn heap_structured_buffer(&mut self, index: Value, uav: bool, stride: u32, nonuniform: bool) -> RawUav {
self.require(Feature::RawAndStructuredBuffers);
let h = self.handle_from_heap(index, false, nonuniform);
let handle = self.annotate(h, kind::STRUCTURED_BUFFER | if uav { 0x1000 } else { 0 }, stride);
RawUav { handle, binding: None }
Expand Down Expand Up @@ -768,7 +768,7 @@ impl Shader {
assert!(!(uav && matches!(kind, TexKind::D2MS | TexKind::D2MSArray)), "RWTexture2DMS needs SM 6.7");
let h = self.handle_from_heap(index, false, nonuniform);
let handle = self.annotate(h, kind as u32 | if uav { 0x1000 } else { 0 }, typed_props(comp, ncomp));
Texture { handle, kind, uav, comp }
Texture { handle, kind, uav, comp, ncomp }
}
/// A sampler from `SamplerDescriptorHeap[index]`.
pub fn heap_sampler(&mut self, index: Value, comparison: bool, nonuniform: bool) -> Sampler {
Expand Down Expand Up @@ -813,7 +813,7 @@ impl Shader {
let mip = mip.unwrap_or_else(|| self.m.undef(i32));
let c = self.padded(coords, 3, i32);
let o = if offs.is_empty() { self.padded(&[], 3, i32) } else { self.offsets(tex.kind, offs, 3) };
if tex.uav && tex.comp != CompType::U32 && tex.comp != CompType::I32 && tex.comp != CompType::F32 {
if tex.uav && tex.ncomp > 1 {
self.require(Feature::TypedUavLoadAdditionalFormats);
}
let mut args = vec![tex.handle, mip];
Expand Down Expand Up @@ -1027,7 +1027,7 @@ impl Shader {
self.op(114, "waveAllTrue", None, i1, &[cond], FnAttrs::NoUnwind)
}
pub fn wave_all_equal(&mut self, v: Value) -> Value {
self.require(Feature::WaveOps);
self.wave_int64(v);
let t = self.m.type_of(v);
let i1 = self.m.i1();
self.op(115, "waveActiveAllEqual", Some(t), i1, &[v], FnAttrs::NoUnwind)
Expand Down
59 changes: 59 additions & 0 deletions crates/xcl/src/gpu/dxil/ops_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1282,3 +1282,62 @@ fn direct_image_atomic_64bit_validates() {
assert!(dis32.contains("@dx.op.atomicCompareExchange.i32("), "32-bit cmpswap must emit i32:\n{dis32}");
assert!(!dis32.contains("@dx.op.atomicCompareExchange.i64("), "32-bit cmpswap must not emit i64:\n{dis32}");
}

fn sfi0(c: &[u8]) -> u64 {
let n = u32::from_le_bytes(c[28..32].try_into().unwrap()) as usize;
for i in 0..n {
let off = u32::from_le_bytes(c[32 + 4 * i..36 + 4 * i].try_into().unwrap()) as usize;
if &c[off..off + 4] == b"SFI0" { return u64::from_le_bytes(c[off + 8..off + 16].try_into().unwrap()); }
}
panic!("no SFI0 part");
}

#[test]
fn ops_feature_flags_heap_structured_buffer() {
let mut s = Shader::new(Stage::Compute, (6, 6));
let (x, i0, i1) = (s.thread_id_in_group(0), s.m.i32c(0), s.m.i32c(1));
let srv = s.heap_structured_buffer(i0, false, 16, false);
let uav = s.heap_structured_buffer(i1, true, 16, false);
let v = s.structured_load(srv, x, 0, 1);
s.structured_store(uav, x, 0, &v);
assert_eq!(s.feature_flags(), (1 << 30, 0x200_0000));
let c = s.finish([32, 1, 1], None);
check(&c);
assert_eq!(sfi0(&c), 0x200_0000);
}

#[test]
fn ops_feature_flags_typed_uav_texture_load() {
for (comp, ncomp, low_prec, want) in [
(CompType::F32, 4, false, 0x200_0800u64), (CompType::I32, 4, false, 0x200_0800), (CompType::U32, 4, false, 0x200_0800),
(CompType::F32, 1, false, 0x200_0000), (CompType::UNormF32, 1, false, 0x200_0000), (CompType::SNormF32, 1, false, 0x200_0000),
(CompType::F16, 1, true, 0x204_0000), (CompType::F16, 4, true, 0x204_0800),
] {
let mut s = Shader::new(Stage::Compute, (6, 6));
if low_prec { s.require(super::shader::Feature::NativeLowPrecision); }
let (x, i0) = (s.thread_id_in_group(0), s.m.i32c(0));
let u = s.heap_texture(i0, TexKind::D2, true, comp, ncomp, false);
let v = s.texture_load(u, None, &[x, x], &[]);
s.texture_store(u, &[x, x], v);
let c = s.finish([32, 1, 1], None);
check(&c);
assert_eq!(sfi0(&c), want, "typed UAV load {comp:?} x{ncomp}");
}
}

#[test]
fn ops_feature_flags_wave_all_equal_64bit() {
for (is_f64, want_bit) in [(false, 0x8000u64), (true, 0x1u64)] {
let mut s = Shader::new(Stage::Compute, (6, 6));
let (x, i0, i32) = (s.thread_id_in_group(0), s.m.i32c(0), s.m.i32());
let uav = s.heap_structured_buffer(i0, true, 4, false);
let v = if is_f64 { let f64 = s.m.f64(); s.m.const_float(f64, 1.0f64.to_bits()) } else { let i64 = s.m.i64(); s.m.const_int(i64, 7) };
let eq = s.wave_all_equal(v);
assert_eq!(s.feature_flags().1 & (0x4000 | want_bit), 0x4000 | want_bit, "wave_all_equal is_f64={is_f64}");
let out = s.m.cast(CastOp::ZExt, eq, i32);
s.structured_store(uav, x, 0, &[out]);
let c = s.finish([32, 1, 1], Some(32));
check(&c);
assert_eq!(sfi0(&c), 0x200_4000 | want_bit, "wave_all_equal SFI0 is_f64={is_f64}");
}
}
Loading