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
37 changes: 37 additions & 0 deletions crates/xcl/src/gpu/dxil/kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1036,3 +1036,40 @@ fn geom_init(lw: &mut Lw, g: &GsInterface, _tid: Value, io: super::shader::RawUa
lw.wr(base, none);
lw.geom = Some(super::lower_geom::GeomCtx { g: g.clone(), emitted, strip, ntri, base, tri, maxt, rec });
}

#[cfg(test)]
#[test]
fn gpu_compact_slots_use_the_dispatch_prologues_exec_mask() {
use crate::gpu::rdna2::encode;
use crate::gpu::recomp::{runner, IO_THREAD_LIMIT};

if runner::wave32_supported() != Ok(true) {
return runner::skip_test("no wave32");
}
// Each active lane stores its id in mem[id]. The execution mask itself
// is the ALU/store predicate, so a stale full mask overwrites sentinels.
let mut code = Vec::new();
for (name, enc, fields) in [
("V_MOV_B32", "ENC_VOP1", &[("VDST", 2), ("SRC0", 256)][..]),
("V_LSHLREV_B32", "ENC_VOP2", &[("VDST", 0), ("SRC0", 130), ("VSRC1", 0)]),
("V_MOV_B32", "ENC_VOP1", &[("VDST", 1), ("SRC0", 128)]),
("GLOBAL_STORE_DWORD", "ENC_FLAT_GLBL", &[("ADDR", 0), ("DATA", 2), ("SADDR", 0x7D)]),
("S_ENDPGM", "ENC_SOPP", &[]),
] {
code.extend(encode(name, enc, fields, None).unwrap());
}
let cs = CsInterface { threads: [32, 1, 1], user_sgprs: 0, tgid: [false; 3], tg_size: false, tid_components: 1 };
let options = KernelOptions { wave64: false, split: false, mem_windows: 1, sampler_base: 0 };
let kernel = translate_entry(&code, options, Entry::Compute(cs), Some(true), None).unwrap();
let initial = [0xa5a5_5a5a; 32];
for (limit, active) in [(0, 32), (17, 17)] {
let mut io = [0; 128];
io[IO_THREAD_LIMIT[0]] = limit;
let got = runner::dispatch(&kernel.dxil, [1, 1, 1], &io, &initial).unwrap();
let mut expected = initial;
for (lane, word) in expected[..active].iter_mut().enumerate() {
*word = lane as u32;
}
assert_eq!(&got[..initial.len()], &expected, "DispatchX thread limit {limit}");
}
}
3 changes: 3 additions & 0 deletions crates/xcl/src/gpu/dxil/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ impl Init {
s.m.set_block(self.entry);
let i32 = s.m.i32();
let p = s.m.alloca(i32, 4);
// The slot lives in entry, but a DispatchX EXEC mask is defined at the
// prologue join. Initialize there so the store sees the selected mask.
s.m.set_block(s.m.def_block(v).unwrap_or(self.entry));
s.m.store(p, v, 4);
s.m.set_block(cur);
s.m.set_insert_before_term(before);
Expand Down
3 changes: 3 additions & 0 deletions crates/xcl/src/gpu/dxil/lower_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ impl Lw {
None => {
let k = self.static_used.len() as u32;
let cur = self.cur();
// DispatchX can terminate the physical entry before this sampler's first use.
let before = self.s.m.set_insert_before_term(true);
self.s.m.set_block(self.init.entry);
let h = self.s.sampler(self.sampler_base + k, 1, has_c);
self.s.m.set_block(cur);
self.s.m.set_insert_before_term(before);
self.static_used.push((w, has_c, h));
h
}
Expand Down
32 changes: 32 additions & 0 deletions crates/xcl/src/gpu/recomp/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3212,6 +3212,38 @@ fn gpu_static_samplers_from_constants_in_code() {
assert_eq!([fl(10), fl(11), fl(12), fl(13)], [2.0, 0.0, 2.0, 1.0], "lane {l}: static point sampler");
assert_eq!([fl(20), fl(21), fl(22), fl(23)], [1.5, 0.0, 1.5, 1.0], "lane {l}: static linear sampler");
}
if runner::wave32_supported() != Ok(true) {
return runner::skip_test("no wave32");
}
// The compute prologue branches on DispatchX thread limits. Both sampler handles
// must dominate their uses on either path, including lanes masked off at entry.
let mut compute = vec![
("V_LSHLREV_B32", "ENC_VOP2", vec![("VDST", 8), ("SRC0", 131), ("VSRC1", 0)], None), // lane * 8 bytes
("V_MOV_B32", "ENC_VOP1", vec![("VDST", 9), ("SRC0", 128)], None),
("V_MOV_B32", "ENC_VOP1", vec![("VDST", 0), ("SRC0", 255)], Some(f(0.5))),
("V_MOV_B32", "ENC_VOP1", vec![("VDST", 1), ("SRC0", 255)], Some(f(0.125))),
];
compute.extend(list);
compute.extend([
("V_MOV_B32", "ENC_VOP1", vec![("VDST", 11), ("SRC0", V + 20)], None),
("GLOBAL_STORE_DWORDX2", "ENC_FLAT_GLBL", vec![("ADDR", 8), ("DATA", 10), ("SADDR", 0x7D)], None),
]);
let refs: Vec<_> = compute.iter().map(|(n, e, fields, literal)| (*n, *e, fields.as_slice(), *literal)).collect();
let cs = super::CsInterface { threads: [32, 1, 1], user_sgprs: 24, tgid: [false; 3], tg_size: false, tid_components: 1 };
let options = crate::gpu::dxil::kernel::KernelOptions { wave64: false, split: false, mem_windows: 1, sampler_base: 0 };
let translated = crate::gpu::dxil::kernel::translate_compute(&prog(&refs), options, &cs).unwrap();
assert_eq!(translated.static_samplers, [(point, false), (linear, false)]);
let sentinel = 0xa5a5_5a5a;
let initial = [sentinel; 64];
for (limit, active) in [(0, 32), (17, 17)] {
st.sgpr[super::IO_THREAD_LIMIT[0]] = limit;
let result = runner::run_with_statics(&translated.dxil, &st, &initial, &tex, &[], &translated.static_samplers).unwrap();
let mut expected = initial;
for lane in expected[..active * 2].chunks_exact_mut(2) {
lane.copy_from_slice(&[f(2.0), f(1.5)]);
}
assert_eq!(result.mem, expected, "DispatchX thread limit {limit}");
}
}

/// A static sampler's S# word that the compiler writes bit-reversed (`s_brev_b32 s26, 40` is
Expand Down
Loading