diff --git a/crates/xcl/src/gpu/recomp/emit.rs b/crates/xcl/src/gpu/recomp/emit.rs index 2f817a809f..fcd36e54d5 100644 --- a/crates/xcl/src/gpu/recomp/emit.rs +++ b/crates/xcl/src/gpu/recomp/emit.rs @@ -59,7 +59,7 @@ pub(super) struct Em { pub static_ss: BTreeMap, /// 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, diff --git a/crates/xcl/src/gpu/recomp/mod.rs b/crates/xcl/src/gpu/recomp/mod.rs index 528493d6e5..6317024420 100644 --- a/crates/xcl/src/gpu/recomp/mod.rs +++ b/crates/xcl/src/gpu/recomp/mod.rs @@ -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 { let program = code; let normalized; @@ -1570,14 +1580,7 @@ pub fn translate(code: &[u8], opt: &Options) -> Result { 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); } diff --git a/crates/xcl/src/gpu/recomp/tests.rs b/crates/xcl/src/gpu/recomp/tests.rs index 0b018edc36..052f0744da 100644 --- a/crates/xcl/src/gpu/recomp/tests.rs +++ b/crates/xcl/src/gpu/recomp/tests.rs @@ -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]