From 5dd7a76c8be74ef49886a33b069db15304b9dfc9 Mon Sep 17 00:00:00 2001 From: Faith Ekstrand Date: Mon, 23 Oct 2023 10:36:37 -0500 Subject: [PATCH] nak: Implement vote and ballot Part-of: --- src/nouveau/compiler/nak_encode_sm75.rs | 18 +++++++++++ src/nouveau/compiler/nak_from_nir.rs | 37 ++++++++++++++++++++++ src/nouveau/compiler/nak_ir.rs | 41 ++++++++++++++++++++++++- src/nouveau/compiler/nak_legalize.rs | 1 + 4 files changed, 96 insertions(+), 1 deletion(-) diff --git a/src/nouveau/compiler/nak_encode_sm75.rs b/src/nouveau/compiler/nak_encode_sm75.rs index c8552e2f0f3..38b8a29371e 100644 --- a/src/nouveau/compiler/nak_encode_sm75.rs +++ b/src/nouveau/compiler/nak_encode_sm75.rs @@ -1767,6 +1767,23 @@ impl SM75Instr { ); } + fn encode_vote(&mut self, op: &OpVote) { + self.set_opcode(0x806); + self.set_dst(op.ballot); + + self.set_field( + 72..74, + match op.op { + VoteOp::All => 0_u8, + VoteOp::Any => 1_u8, + VoteOp::Eq => 2_u8, + }, + ); + + self.set_pred_dst(81..84, op.vote); + self.set_pred_src(87..90, 90, op.pred); + } + pub fn encode( instr: &Instr, sm: u8, @@ -1845,6 +1862,7 @@ impl SM75Instr { Op::S2R(op) => si.encode_s2r(&op), Op::Out(op) => si.encode_out(&op), Op::OutFinal(op) => si.encode_out_final(&op), + Op::Vote(op) => si.encode_vote(&op), _ => panic!("Unhandled instruction"), } diff --git a/src/nouveau/compiler/nak_from_nir.rs b/src/nouveau/compiler/nak_from_nir.rs index f29eab9bac3..41ad9e4d7ff 100644 --- a/src/nouveau/compiler/nak_from_nir.rs +++ b/src/nouveau/compiler/nak_from_nir.rs @@ -1337,6 +1337,21 @@ impl<'a> ShaderFromNir<'a> { panic!("Invalid VTG I/O intrinsic"); } } + nir_intrinsic_ballot => { + assert!(srcs[0].bit_size() == 1); + let src = self.get_src(&srcs[0]); + + assert!(intrin.def.bit_size() == 32); + let dst = b.alloc_ssa(RegFile::GPR, 1); + + b.push_op(OpVote { + op: VoteOp::Any, + ballot: dst.into(), + vote: Dst::None, + pred: src, + }); + self.set_dst(&intrin.def, dst); + } nir_intrinsic_bar_break_nv => { let idx = &srcs[0].as_def().index; let (bar, _) = self.bar_ref_label.get(idx).unwrap(); @@ -2008,6 +2023,28 @@ impl<'a> ShaderFromNir<'a> { b.push_op(OpOutFinal { handle: handle }); } } + nir_intrinsic_vote_all + | nir_intrinsic_vote_any + | nir_intrinsic_vote_ieq => { + assert!(srcs[0].bit_size() == 1); + let src = self.get_src(&srcs[0]); + + assert!(intrin.def.bit_size() == 1); + let dst = b.alloc_ssa(RegFile::Pred, 1); + + b.push_op(OpVote { + op: match intrin.intrinsic { + nir_intrinsic_vote_all => VoteOp::All, + nir_intrinsic_vote_any => VoteOp::Any, + nir_intrinsic_vote_ieq => VoteOp::Eq, + _ => panic!("Unknown vote intrinsic"), + }, + ballot: Dst::None, + vote: dst.into(), + pred: src, + }); + self.set_dst(&intrin.def, dst); + } _ => panic!( "Unsupported intrinsic instruction: {}", intrin.info().name() diff --git a/src/nouveau/compiler/nak_ir.rs b/src/nouveau/compiler/nak_ir.rs index 17500f95a93..e7f6051dc98 100644 --- a/src/nouveau/compiler/nak_ir.rs +++ b/src/nouveau/compiler/nak_ir.rs @@ -3703,6 +3703,44 @@ impl fmt::Display for OpS2R { } } +pub enum VoteOp { + Any, + All, + Eq, +} + +impl fmt::Display for VoteOp { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + VoteOp::Any => write!(f, "ANY"), + VoteOp::All => write!(f, "ALL"), + VoteOp::Eq => write!(f, "EQ"), + } + } +} + +#[repr(C)] +#[derive(SrcsAsSlice, DstsAsSlice)] +pub struct OpVote { + pub op: VoteOp, + + pub ballot: Dst, + pub vote: Dst, + + #[src_type(Pred)] + pub pred: Src, +} + +impl fmt::Display for OpVote { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!( + f, + "VOTE.{} {{ {} {} }} {}", + self.op, self.ballot, self.vote, self.pred + ) + } +} + #[repr(C)] #[derive(SrcsAsSlice, DstsAsSlice)] pub struct OpUndef { @@ -4136,6 +4174,7 @@ pub enum Op { Nop(OpNop), PixLd(OpPixLd), S2R(OpS2R), + Vote(OpVote), Undef(OpUndef), PhiSrcs(OpPhiSrcs), PhiDsts(OpPhiDsts), @@ -4572,7 +4611,7 @@ impl Instr { | Op::Kill(_) | Op::PixLd(_) | Op::S2R(_) => false, - Op::Nop(_) => true, + Op::Nop(_) | Op::Vote(_) => true, // Virtual ops Op::Undef(_) diff --git a/src/nouveau/compiler/nak_legalize.rs b/src/nouveau/compiler/nak_legalize.rs index 952a0bd6f23..924959a2b13 100644 --- a/src/nouveau/compiler/nak_legalize.rs +++ b/src/nouveau/compiler/nak_legalize.rs @@ -261,6 +261,7 @@ fn legalize_instr(b: &mut impl SSABuilder, instr: &mut Instr) { } Op::Ldc(_) => (), // Nothing to do Op::BMov(_) | Op::Break(_) | Op::BSSy(_) | Op::BSync(_) => (), + Op::Vote(_) => (), // Nothing to do Op::Copy(_) => (), // Nothing to do _ => { let src_types = instr.src_types();