From cbb05f0e6b4c541633ab85d0525d530db1810b9d Mon Sep 17 00:00:00 2001 From: Faith Ekstrand Date: Tue, 12 Sep 2023 09:53:01 -0500 Subject: [PATCH] nak: Implement discard and demote Part-of: --- src/nouveau/compiler/nak_encode_sm75.rs | 6 ++++++ src/nouveau/compiler/nak_from_nir.rs | 7 +++++++ src/nouveau/compiler/nak_ir.rs | 18 +++++++++++++++++- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/nouveau/compiler/nak_encode_sm75.rs b/src/nouveau/compiler/nak_encode_sm75.rs index f3e8e6b39fd..b4364785781 100644 --- a/src/nouveau/compiler/nak_encode_sm75.rs +++ b/src/nouveau/compiler/nak_encode_sm75.rs @@ -1536,6 +1536,11 @@ impl SM75Instr { self.set_field(72..80, op.idx); } + fn encode_kill(&mut self, op: &OpKill) { + self.set_opcode(0x95b); + self.set_pred_src(87..90, 90, SrcRef::True.into()); + } + fn encode_pixld(&mut self, op: &OpPixLd) { self.set_opcode(0x925); self.set_dst(op.dst); @@ -1621,6 +1626,7 @@ impl SM75Instr { Op::Exit(op) => si.encode_exit(&op), Op::Bar(op) => si.encode_bar(&op), Op::CS2R(op) => si.encode_cs2r(&op), + Op::Kill(op) => si.encode_kill(&op), Op::PixLd(op) => si.encode_pixld(&op), Op::S2R(op) => si.encode_s2r(&op), _ => panic!("Unhandled instruction"), diff --git a/src/nouveau/compiler/nak_from_nir.rs b/src/nouveau/compiler/nak_from_nir.rs index e153e2cdcfd..3614bd067e9 100644 --- a/src/nouveau/compiler/nak_from_nir.rs +++ b/src/nouveau/compiler/nak_from_nir.rs @@ -1110,6 +1110,13 @@ impl<'a> ShaderFromNir<'a> { data: data, }); } + nir_intrinsic_demote | nir_intrinsic_discard => { + b.push_op(OpKill {}); + } + nir_intrinsic_demote_if | nir_intrinsic_discard_if => { + let cond = self.get_ssa(&srcs[0].as_def())[0]; + b.predicate(cond.into()).push_op(OpKill {}); + } nir_intrinsic_global_atomic => { let bit_size = intrin.def.bit_size(); let (addr, offset) = self.get_io_addr_offset(&srcs[0], 24); diff --git a/src/nouveau/compiler/nak_ir.rs b/src/nouveau/compiler/nak_ir.rs index b072e8a7eca..daca93632ed 100644 --- a/src/nouveau/compiler/nak_ir.rs +++ b/src/nouveau/compiler/nak_ir.rs @@ -3277,6 +3277,16 @@ impl fmt::Display for OpCS2R { } } +#[repr(C)] +#[derive(SrcsAsSlice, DstsAsSlice)] +pub struct OpKill {} + +impl fmt::Display for OpKill { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "KILL") + } +} + pub enum PixVal { MsCount, CovMask, @@ -3685,6 +3695,7 @@ pub enum Op { Exit(OpExit), Bar(OpBar), CS2R(OpCS2R), + Kill(OpKill), PixLd(OpPixLd), S2R(OpS2R), Undef(OpUndef), @@ -4002,6 +4013,7 @@ impl Instr { | Op::Atom(_) | Op::AtomCas(_) | Op::MemBar(_) + | Op::Kill(_) | Op::Bra(_) | Op::Exit(_) | Op::Bar(_) @@ -4074,7 +4086,11 @@ impl Instr { Op::Bra(_) | Op::Exit(_) => true, // Miscellaneous ops - Op::Bar(_) | Op::CS2R(_) | Op::PixLd(_) | Op::S2R(_) => false, + Op::Bar(_) + | Op::CS2R(_) + | Op::Kill(_) + | Op::PixLd(_) + | Op::S2R(_) => false, // Virtual ops Op::Undef(_)