Skip to content
Open
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
3 changes: 3 additions & 0 deletions crates/xcl/src/gpu/dxil/core_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1458,6 +1458,9 @@ fn raw_loads_in_root_windows_are_branchless() {
if let (Ok(heap), Ok(flat)) = (super::validate::disassemble(&heap_dxil), super::validate::disassemble(&flat_dxil)) {
let branches = |s: &str| s.lines().filter(|line| line.trim_start().starts_with("br i1 ")).count();
assert!(branches(&flat) < branches(&heap), "flat heap reads must remove guarded-read branches: guarded {}, flat {}", branches(&heap), branches(&flat));
// a flat read outside the windows or under a false guard takes the null view, not window 0
let null = format!(", i32 {}", crate::gpu::recomp::MEM_NULL_LOAD);
assert!(flat.lines().any(|l| l.contains("select i1") && l.contains(&null)), "flat heap reads must select the null-load view (descriptor {}):\n{flat}", crate::gpu::recomp::MEM_NULL_LOAD);
}

let writes = prog(&[
Expand Down
8 changes: 6 additions & 2 deletions crates/xcl/src/gpu/dxil/lower_mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,11 +416,15 @@ impl Lw {
let carry_case = high.filter(|&(_, hi)| matches!(hi, Value::Inst(_))).map(|(_, hi)| (hi, self.high_one_slot()));
let inside = self.cmpc(Pred::ULt, w, self.mems.len() as u32);
let ok = if let Some(g) = guard { self.and(g, inside) } else { inside };
let safe = self.sel(ok, w, z);
let i = self.addc(safe, crate::gpu::recomp::MEM_HEAP_BASE);
// (an access outside the windows or under a false guard still runs here, without a
// branch: it reads the null view, as the HLSL accessors do, never a window's memory.
// The optimizer's carry rewrite of `inside` and of this add keeps that: `FlatRead`)
let i = self.addc(w, crate::gpu::recomp::MEM_HEAP_BASE);
if let (Some((hi, (valid1, slot1))), Value::Inst(test), Value::Inst(slot)) = (carry_case, inside, i) {
self.s.m.flat_reads.push(super::module::FlatRead { hi, test, slot, valid1, slot1 });
}
let null = self.c(crate::gpu::recomp::MEM_NULL_LOAD);
let i = self.sel(ok, i, null);
let m = self.s.heap_raw_buffer_uav(i, coherent);
let vals = f(self, m);
debug_assert_eq!(vals.len(), n);
Expand Down
Loading