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
46 changes: 46 additions & 0 deletions crates/xcl/src/gpu/dxil/core_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,3 +581,49 @@ fn gpu_direct_unaligned_multi_dword_format_store() {
let got: Vec<u8> = r.mem.iter().flat_map(|v| v.to_le_bytes()).collect();
assert_eq!(&got[0xFC..0x118], &want[0xFC..0x118], "bytes 0xFC..0x118 after the store at 0x102");
}

/// `v_movreld_b32` and `v_movrels_b32` with `m0 > 0` where target or source VGPRs are not
/// statically referenced earlier in the block: `top_vgpr` must be bounded by the program's
/// `max_vgpr` rather than `init.touched` (which starts empty outside `Entry::Kernel`).
#[test]
fn v_movrel_with_non_static_target_vgpr() {
use crate::gpu::recomp::runner;
let code = prog(&[
("V_MOV_B32", "ENC_VOP1", &[("VDST", 1), ("SRC0", 160)], None), // v1 = 32
("S_MOV_B32", "ENC_SOP1", &[("SDST", 124), ("SSRC0", 130)], None), // m0 = 2
("V_MOVRELD_B32", "ENC_VOP1", &[("VDST", 0), ("SRC0", 257)], None), // v[0 + m0] = v[2] = v1 = 32
("V_MOVRELS_B32", "ENC_VOP1", &[("VDST", 3), ("SRC0", 256)], None), // v3 = v[0 + m0] = v2 = 32
("V_MOV_B32", "ENC_VOP1", &[("VDST", 10), ("SRC0", 259)], None), // v10 = v3 = 32 (names max_vgpr = 10)
]);
let ko = KernelOptions { wave64: false, split: false, mem_windows: 1, sampler_base: 0 };
let dxil = translate(&code, ko).unwrap_or_else(|e| panic!("direct DXIL failed: {e}"));
if runner::wave32_supported() != Ok(true) {
return runner::skip_test("no wave32");
}
let st = runner::KernelState::default();
let direct = runner::run(&dxil, &st, &[]).unwrap();
assert_eq!(direct.vgpr[0][10], 32, "v10 must be 32 (transferred through dynamically-indexed v2)");
}

/// `v_swaprel_b32` with `m0 > 0` where intermediate indexed VGPRs are not
/// statically referenced earlier in the block: `top_vgpr` must be bounded by the program's
/// `max_vgpr` rather than `init.touched`.
#[test]
fn v_swaprel_with_non_static_target_vgpr() {
use crate::gpu::recomp::runner;
let code = prog(&[
("V_MOV_B32", "ENC_VOP1", &[("VDST", 1), ("SRC0", 160)], None), // v1 = 32
("V_MOV_B32", "ENC_VOP1", &[("VDST", 2), ("SRC0", 161)], None), // v2 = 33
("S_MOV_B32", "ENC_SOP1", &[("SDST", 124), ("SSRC0", 130)], None), // m0 = 2
("V_SWAPREL_B32", "ENC_VOP1", &[("VDST", 1), ("SRC0", 256)], None), // swap(v1, v[0 + m0] = v2) -> v1=33, v2=32
("V_MOV_B32", "ENC_VOP1", &[("VDST", 10), ("SRC0", 257)], None), // v10 = v1 = 33 (names max_vgpr = 10)
]);
let ko = KernelOptions { wave64: false, split: false, mem_windows: 1, sampler_base: 0 };
let dxil = translate(&code, ko).unwrap_or_else(|e| panic!("direct DXIL failed: {e}"));
if runner::wave32_supported() != Ok(true) {
return runner::skip_test("no wave32");
}
let st = runner::KernelState::default();
let direct = runner::run(&dxil, &st, &[]).unwrap();
assert_eq!(direct.vgpr[0][10], 33, "v10 must be 33 after swaprel");
}
10 changes: 10 additions & 0 deletions crates/xcl/src/gpu/dxil/kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,10 +450,20 @@ impl Lw {
let (mems, heap_mem) = mem_windows(&mut s, o.mem_windows, cs.is_some());
let i32 = s.m.i32();
let z = s.m.i32c(0);
let max_vgpr = insts
.iter()
.flat_map(|d| {
let (r, w) = crate::gpu::rdna2::vgpr_uses(d);
r.into_iter().chain(w)
})
.filter(|&r| r < 256)
.max()
.unwrap_or(0);
let mut lw = Lw {
s,
ssa: Ssa::new(i32),
init: Init { io: Some(io), compute: None, vgpr_base: None, entry: Block(0), touched: BTreeSet::new(), slots: HashMap::new(), mem: None },
max_vgpr,
wave64: o.wave64,
split,
lane: z,
Expand Down
2 changes: 2 additions & 0 deletions crates/xcl/src/gpu/dxil/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ pub struct Lw {
pub s: Shader,
pub ssa: Ssa,
pub init: Init,
/// the highest VGPR the program references (v_movrel* and v_swaprel ranges)
pub max_vgpr: u64,
pub wave64: bool,
/// wave64 program in two hardware wave32 halves
pub split: bool,
Expand Down
2 changes: 1 addition & 1 deletion crates/xcl/src/gpu/dxil/lower_wide.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ impl Lw {

/// The highest VGPR the program names (relative moves index up to it).
fn top_vgpr(&self) -> u64 {
self.init.touched.iter().filter(|&&v| (VAR_VGPR..VAR_VGPR + 256).contains(&v)).map(|&v| (v - VAR_VGPR) as u64).max().unwrap_or(0)
self.max_vgpr
}

pub fn movrel(&mut self, d: &Decoded, name: &str) -> LResult<()> {
Expand Down
14 changes: 14 additions & 0 deletions crates/xcl/src/gpu/recomp/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1619,6 +1619,9 @@ impl<I: Ir> Lower<'_, I> {
if self.track_frexp_denorm && self.partial[b] && super::emit::writes_frexp_f32_denorm(d) {
return Err("a FREXP denormal mode write where some lanes are elsewhere".into());
}
if name.starts_with("V_MOVREL") || name == "V_SWAPREL_B32" {
return Err("movrel/swaprel dynamically indexes VGPRs".into());
}
// instructions whose #1426 semantics are known to differ from the HLSL path and the
// console (each reported on #1426): left to the fallback until fixed there
const DIFFERS_ON_1426: &[&str] = &[
Expand Down Expand Up @@ -3334,6 +3337,17 @@ pub(crate) mod tests {
assert_eq!(err, "unsupported S_BCNT1_I32_B32");
}

#[test]
fn dynamically_indexed_vgpr_moves_are_refused_in_per_lane() {
let lines: &[I] = &[
("S_MOV_B32", "ENC_SOP1", &[("SDST", 124), ("SSRC0", 130)]), // m0 = 2
("V_MOVRELD_B32", "ENC_VOP1", &[("VDST", 0), ("SRC0", 257)]),
ENDPGM,
];
let err = lower_kernel(&decode(lines), false, Interp::default()).err().expect("refused");
assert_eq!(err, "unsupported V_MOVRELD_B32 (movrel/swaprel dynamically indexes VGPRs)");
}

/// `s_wqm` of a mask sets every lane of a quad with a bit; `s_cselect` picks a mask or a
/// number by SCC.
#[test]
Expand Down
Loading