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
1 change: 1 addition & 0 deletions crates/xcl/src/gpu/dxil/compact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,7 @@ pub fn plan(cfg: &Cfg, lw: &Lw) -> Option<Plan> {
let to = crate::gpu::rdna2::sgpr_uses(d).1.into_iter().chain([106]).chain(sdwa);
key.extend(to.filter(|&r| r < 126).map(|r| (l >> r) as u64 & 3));
}
key.push(lw.ps_masks.get(&d.pc).map_or(0, |&f| f as u64 + 1));
if d.inst.name == "S_GETPC_B64" {
key.push(if param_pc { d.pc.wrapping_sub(blk.pc) } else { d.pc });
}
Expand Down
4 changes: 4 additions & 0 deletions crates/xcl/src/gpu/dxil/kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,7 @@ impl Lw {
gfx: None,
gfx_half: None,
whole_live: Default::default(),
ps_masks: Default::default(),
guard_override: None,
mask_override: None,
local_masks: false,
Expand Down Expand Up @@ -784,6 +785,9 @@ impl Lw {
if split && std::env::var_os("XCL_X64_ALL_MASKS").is_none() {
lw.whole_live = crate::gpu::recomp::x64_masks::by_pc(insts, kernel);
}
if matches!(entry, Entry::Pixel(_)) && !split {
lw.ps_masks = crate::gpu::recomp::ps_masks::forms(insts);
}
// (before the storage: the spin exchange has its own slots and counters)
if let (Some(t), true) = (group_threads, split) {
lw.partner = match t {
Expand Down
34 changes: 31 additions & 3 deletions crates/xcl/src/gpu/dxil/lanes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,34 @@ impl Lw {
(lo, hi)
}

/// Pixel-shader mask with only the live lanes' bits right besides this lane's own
/// (`recomp::ps_masks`; parity with HLSL `ballot_px_local`): `WaveActiveBallot`, which
/// leaves helper lanes out, OR this lane's bit; `own_only` leaves out the ballot too.
pub fn ballot_ps_local(&mut self, cond: Value, own_only: bool) -> (Value, Value) {
let z = self.c(0);
let b = self.u(cond);
let l31 = self.lane31;
let b = self.bin(BinOp::Shl, b, l31);
let (mut lo, mut hi) = if self.wave64 {
let u = self.upper;
(self.sel(u, z, b), self.sel(u, b, z))
} else {
(b, z)
};
if !own_only {
let w = self.s.wave_ballot(cond);
let (wl, wh) = match (self.wave64, self.gfx_half) {
(true, _) => (w[0], w[1]),
(false, Some(h)) => (self.sel(h, w[1], w[0]), z),
(false, None) => (w[0], z),
};
lo = self.or(lo, wl);
hi = self.or(hi, wh);
}
self.note_own_bit(lo, hi, cond);
(lo, hi)
}

/// Each live lane contributes four predicate bits for its quad, including helper
/// lanes. OR contributions into that quad's nibble of the hardware ballot word.
pub fn ballot_ps_quad(&mut self, q: Value) -> (Value, Value) {
Expand Down Expand Up @@ -1096,8 +1124,8 @@ mod ps_ballot_tests {
assert!(dis.contains("dx.op.quadReadLaneAt.i32"), "wave64 {wave64}: PS VOPC must quad-read VGPR operands via quadReadLaneAt:\n{dis}");
assert!(!dis.contains("dx.op.quadOp"), "wave64 {wave64}: PS VOPC must not emit quadOp on compare results (#134):\n{dis}");

// Standalone VOPC with no DPP / readfirstlane (so `rla` is never called):
// proves VOPC itself emits the 4 VGPR operand `quadReadLaneAt` reads and zero `quadOp`.
// Standalone VOPC with no DPP / readfirstlane (so `rla` is never called), whose
// mask only `v_cndmask` reads: the lane's own bit (`recomp::ps_masks`), no quad ops.
let mut vopc_only = Vec::new();
vopc_only.extend(encode(if wave64 { "S_WQM_B64" } else { "S_WQM_B32" }, "ENC_SOP1", &[("SDST", 126), ("SSRC0", 126)], None).unwrap());
vopc_only.extend(encode("V_CMP_LT_F32", "ENC_VOPC", &[("SRC0", 128), ("VSRC1", 2)], None).unwrap());
Expand All @@ -1107,7 +1135,7 @@ mod ps_ballot_tests {
let kv = kernel::translate_pixel(&vopc_only, opt, &psi).expect("translate VOPC-only PS");
validate::validate(&kv.dxil).expect("validate VOPC-only PS");
let vdis = validate::disassemble(&kv.dxil).expect("disassemble VOPC-only PS");
assert_eq!(vdis.matches("call i32 @dx.op.quadReadLaneAt.i32(").count(), 4, "wave64 {wave64}: expected 4 operand quad reads for V_CMP_LT_F32(0, v2):\n{vdis}");
assert_eq!(vdis.matches("call i32 @dx.op.quadReadLaneAt.i32(").count(), 0, "wave64 {wave64}: V_CMP_LT_F32(0, v2) read only by v_cndmask needs no quad reads:\n{vdis}");
assert!(!vdis.contains("dx.op.quadOp"), "wave64 {wave64}: VOPC-only PS must not emit quadOp:\n{vdis}");

// Entry EXEC alone (no post-entry ballot) must stay live-lanes-only (no quad reads).
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 @@ -338,6 +338,8 @@ pub struct Lw {
pub gfx_half: Option<Value>,
/// split form: SGPRs whole-live after each instruction (`recomp::x64_masks::by_pc`)
pub whole_live: std::collections::BTreeMap<u64, u128>,
/// pixel shaders: compares whose mask needs less than the per-quad form (`recomp::ps_masks`)
pub ps_masks: std::collections::BTreeMap<u64, crate::gpu::recomp::ps_masks::Form>,
/// set when an exchange was needed where it is not supported
pub exchange_error: Option<String>,
pub pc: u64,
Expand Down
30 changes: 29 additions & 1 deletion crates/xcl/src/gpu/dxil/lower_valu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use super::lower::{err, ext_encoding, Dst, LResult, Lw, Mods, VAR_VGPR};
use super::module::{BinOp, Pred, Value};
use super::ops_core::op;
use crate::gpu::rdna2::{self, Decoded, Encoding, Operand, Variant};
use crate::gpu::recomp::ps_masks::Form as PsForm;

/// A source operand: one dword, or a mask pair (SGPR pair / VCC).
#[derive(Clone, Copy)]
Expand Down Expand Up @@ -1306,6 +1307,26 @@ impl Lw {
if matches!(dst, Dst::Null) && matches!(ty, "f32" | "i32" | "u32") {
return Ok(());
}
// the forms `recomp::ps_masks` found enough for this mask
let form = if self.split { None } else { self.ps_masks.get(&d.pc).copied() };
if let Some(form) = form {
let c = self.vopc_cond(d, opn, ty, ua, ub, m)?;
let (lo, hi) = if form == PsForm::Uniform {
let (el, eh) = self.exec_mask();
let z = self.c(0);
(self.sel(c, el, z), self.sel(c, eh, z))
} else {
let a = self.act();
let c = self.land(a, c);
self.ballot_ps_local(c, form == PsForm::Own)
};
if self.wave64 {
self.write64(&dst, lo, hi);
} else {
self.write32(&dst, lo);
}
return Ok(());
}
let is_vgpr = |o: &Operand| match o.field {
Some("LITERAL") | None => false,
Some(f) => {
Expand Down Expand Up @@ -1341,10 +1362,17 @@ impl Lw {
let sh = self.shlc(up, p);
q = self.or(q, sh);
}
let (lo, hi) = self.ballot_ps_quad(q);
let (mut lo, mut hi) = self.ballot_ps_quad(q);
let own_cond = self.vopc_cond(d, opn, ty, ua, ub, m)?;
let own_active = self.act();
let own_bit = self.land(own_active, own_cond);
// the quad's live lanes read this lane's EXEC bit from their own copy of EXEC,
// which a compare in the local form may have left without it (`recomp::ps_masks`)
if !self.ps_masks.is_empty() && !self.split {
let (ol, oh) = self.ballot_ps_local(own_bit, true);
lo = self.or(lo, ol);
hi = self.or(hi, oh);
}
self.note_own_bit(lo, hi, own_bit);
if self.wave64 {
self.write64(&dst, lo, hi);
Expand Down
1 change: 1 addition & 0 deletions crates/xcl/src/gpu/recomp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ pub(crate) mod emit;
pub mod mesh_dispatch;
pub mod mesh_wave;
pub mod partition;
pub mod ps_masks;
pub mod x64_masks;
pub mod pso;
pub use emit::mesh_passthrough;
Expand Down
Loading
Loading