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
2 changes: 1 addition & 1 deletion crates/xcl/src/gpu/recomp/emit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub(super) struct Em {
pub static_ss: BTreeMap<u64, [u32; 4]>,
/// the static samplers sampled with: (S#, comparison), in register order
pub static_used: Vec<([u32; 4], bool)>,
/// highest VGPR the program references (v_movrel* ranges)
/// highest VGPR for M0-indexed vector moves and swaps
pub max_vgpr: u64,
/// program contains an f16 VALU/interp instruction whose rounding obeys `MODE[3:2]`
has_f16_round_op: bool,
Expand Down
19 changes: 11 additions & 8 deletions crates/xcl/src/gpu/recomp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1497,6 +1497,16 @@ pub(crate) fn needs_coherent_mem(insts: &[Decoded]) -> bool {
})
}

fn relative_vgpr_limit(insts: &[Decoded]) -> u64 {
if !insts.iter().any(|d| d.inst.name.starts_with("V_MOVREL") || d.inst.name == "V_SWAPREL_B32") {
return 0;
}
insts.iter().flat_map(|d| {
let (reads, writes) = rdna2::vgpr_uses(d);
reads.into_iter().chain(writes)
}).max().unwrap_or(0)
}

pub fn translate(code: &[u8], opt: &Options) -> Result<Translation, String> {
let program = code;
let normalized;
Expand Down Expand Up @@ -1570,14 +1580,7 @@ pub fn translate(code: &[u8], opt: &Options) -> Result<Translation, String> {
if !opt.wave64 && matches!(opt.mode, Mode::Vertex(_) | Mode::Pixel(_)) {
em.reductions = wave32_reductions(&insts, &leaders);
}
em.max_vgpr = insts
.iter()
.flat_map(|d| {
let (r, w) = rdna2::vgpr_uses(d);
r.into_iter().chain(w)
})
.max()
.unwrap_or(0);
em.max_vgpr = relative_vgpr_limit(&insts);
if let Mode::Pixel(ps) = &opt.mode {
em.ps_modes = emit::ps_attr_modes(&insts, ps.input_ena);
}
Expand Down
13 changes: 13 additions & 0 deletions crates/xcl/src/gpu/recomp/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,19 @@ fn gpu_scalar_relative_moves() {
assert_eq!(r.sgpr[33], 101, "split source/destination offsets");
}

#[test]
fn relative_vgpr_limit_is_only_needed_for_indexed_vector_registers() {
let inst = |op, dst, src| {
let bytes = encode(op, "ENC_VOP1", &[("VDST", dst), ("SRC0", V + src)], None).unwrap();
crate::gpu::rdna2::decode(&bytes, 0).unwrap()
};
let high = || inst("V_MOV_B32", 61, 47);
assert_eq!(super::relative_vgpr_limit(&[high()]), 0);
for op in ["V_MOVRELS_B32", "V_MOVRELD_B32", "V_MOVRELSD_B32", "V_MOVRELSD_2_B32", "V_SWAPREL_B32"] {
assert_eq!(super::relative_vgpr_limit(&[inst(op, 2, 3), high()]), 61, "{op}");
}
}

/// v_swaprel_b32: both sides are read-write (fixed VDST + the VGPR at SRC0 + M0); emitted
/// as the same bounded switch over M0 as v_movrel, both old values captured before writes.
#[test]
Expand Down
Loading