Skip to content
Closed
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
7 changes: 5 additions & 2 deletions crates/xcl/src/gpu/dxil/graphics_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1140,8 +1140,11 @@ fn groupshared_bytes_follow_the_16bit_layout() {
let mut s = Shader::new(Stage::Mesh, (6, 6));
let (i16, f16) = (s.m.int(16), s.m.f16());
let (a, b) = (s.m.array(6, i16), s.m.array(3, f16));
s.m.global("g", a, 3, None, false, 2);
s.m.global("h", b, 3, None, false, 2);
let (g, h) = (s.m.global("g", a, 3, None, false, 2), s.m.global("h", b, 3, None, false, 2));
let unused = s.m.array(100, i16);
s.m.global("unused", unused, 3, None, false, 2);
s.m.load(g, 2);
s.m.load(h, 2);
assert_eq!(s.m.global_bytes_layout(3, true), 18);
assert_eq!(s.m.global_bytes(3), 36);
}
Expand Down
31 changes: 29 additions & 2 deletions crates/xcl/src/gpu/dxil/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,7 @@ impl Module {
Op::Alloca(t, n, align) => {
// [instty, opty, size (absolute value id), align record (log2 + 1 | explicit type)]
let i32t = self.value_ty(*n);
let a = align.trailing_zeros() as u64 + 1;
let a = if *align == 0 { 0 } else { align.trailing_zeros() as u64 + 1 };
w.record(FUNC_CODE_INST_ALLOCA, &[t.0 as u64, i32t.0 as u64, abs(*n), a | 1 << 6])
}
Op::Br(b) => w.record(FUNC_CODE_INST_BR, &[bb(*b)]),
Expand Down Expand Up @@ -1521,6 +1521,33 @@ impl Module {
}
/// [`Module::global_bytes`] under the native 16-bit layout when `native16`.
pub fn global_bytes_layout(&self, addrspace: u32, native16: bool) -> u64 {
self.globals.iter().filter(|g| g.addrspace == addrspace).map(|g| self.alloc_size_layout(g.ty, native16)).sum()
let (order, _) = self.block_layout();
let mut used = vec![false; self.globals.len()];
let mut mark = |v: Value| {
if let Value::Global(g) = v {
used[g as usize] = true;
}
};
for &b in &order {
for &i in &self.blocks[b] {
self.insts[i as usize].op.for_each_operand(&mut mark);
}
}
for c in &self.consts {
if let ConstDef::Aggregate(_, e) = c {
e.iter().copied().for_each(&mut mark);
}
}
for m in &self.md {
if let MdDef::Val(_, v) = m {
mark(*v);
}
}
self.globals
.iter()
.zip(used)
.filter(|(g, used)| *used && g.addrspace == addrspace)
.map(|(g, _)| self.alloc_size_layout(g.ty, native16))
.sum()
}
}
15 changes: 15 additions & 0 deletions crates/xcl/src/gpu/dxil/ops_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,21 @@ fn check(c: &[u8]) {
}
}

#[test]
fn default_aligned_alloca_validates_without_inalloca() {
let mut s = Shader::new(Stage::Compute, (6, 6));
let out = s.raw_uav(1, 0);
let i32 = s.m.i32();
let p = s.m.alloca(i32, 0);
let seven = s.m.i32c(7);
s.m.store(p, seven, 0);
let v = s.m.load(p, 0);
let zero = s.m.i32c(0);
s.raw_store(out, zero, &[v]);
let c = s.finish([1, 1, 1], Some(32));
check(&c);
}

/// Runs a validated kernel; `None` when there is no wave32 GPU.
fn gpu(c: &[u8], mem: &[u32], tex: &[runner::TestTexture], smp: &[runner::TestSampler]) -> Option<runner::KernelResult> {
match runner::wave32_supported() {
Expand Down
Loading