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
2 changes: 1 addition & 1 deletion crates/xcl/src/gpu/dxil/lower_geom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ impl Lw {
let a = lw.addc(src, 16 * r + 4 * c);
let i = lw.lshrc(a, 2);
let i = lw.andc(i, 8191);
let i = if lw.split { let top = lw.c(lw.lds_top); lw.umin(i, top) } else { i };
let i = if lw.split || lw.lds_top < 8191 { let top = lw.c(lw.lds_top); lw.umin(i, top) } else { i };
vals[c as usize] = lw.s.gs_load(lds, i);
}
let o = lw.addc(dst, 4 * slot as u32);
Expand Down
4 changes: 2 additions & 2 deletions crates/xcl/src/gpu/dxil/lower_mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2228,11 +2228,11 @@ impl Lw {
// ------------------------------------------------------------ LDS / DS

/// LDS dword index of byte address `at` (`(at >> 2) & 8191`, below the exchange words
/// in the split form).
/// in the split form and below the safe barrier's words, as HLSL's `XCL_LDS_TOP`).
fn lds_index(&mut self, at: Value) -> Value {
let i = self.lshrc(at, 2);
let i = self.andc(i, 8191);
if self.split {
if self.split || self.lds_top < 8191 {
let k = self.c(self.lds_top);
self.umin(i, k)
} else {
Expand Down
24 changes: 24 additions & 0 deletions crates/xcl/src/gpu/dxil/robustness_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,30 @@ fn a_group_barrier_of_several_hardware_waves_uses_safe_barrier_directly() {
}
}

/// A program's own LDS accesses stop below the safe barrier's words in `xcl_lds[8189..8190]`
/// in every form (HLSL: `XCL_LDS_TOP` 8188), not only in the split one, so a write to the top
/// of LDS cannot change the barrier's counts.
#[test]
fn lds_accesses_stop_below_the_safe_barrier_words() {
if !crate::gpu::recomp::emit::safe_barrier_wanted() {
return;
}
// the address is v0, the thread ID, so the clamp is not folded away
let code = prog(&[
("DS_WRITE_B32", "ENC_DS", &[("ADDR", 0), ("DATA0", 0)], None),
("S_BARRIER", "ENC_SOPP", &[], None),
("DS_READ_B32", "ENC_DS", &[("VDST", 2), ("ADDR", 0)], None),
]);
let cs = CsInterface { threads: [16, 16, 1], user_sgprs: 4, tgid: [true, false, false], tg_size: false, tid_components: 1 };
for wave64 in [true, false] {
let o = KernelOptions { wave64, split: false, mem_windows: 1, sampler_base: 0 };
let k = kernel::translate_compute(&code, o, &cs).unwrap_or_else(|e| panic!("wave64 {wave64}: {e}"));
let dis = super::validate::disassemble(&k.dxil).expect("disassemble");
let clamps = dis.lines().filter(|l| l.contains("@dx.op.binary.i32(i32 40,") && l.contains(", i32 8188)")).count();
assert!(clamps > 0, "wave64 {wave64}: no LDS index clamped to 8188:\n{dis}");
}
}

/// The translator's own variables after the loop budget each have a slot of their own (the
/// multi-wave barrier's once shared `VAR_F32_MODE`'s), below the image-store slots.
#[test]
Expand Down
Loading