From 688bcea2ba3d787168acd244b086b8645db9df0c Mon Sep 17 00:00:00 2001 From: Faith Ekstrand Date: Fri, 15 May 2026 17:13:56 -0400 Subject: [PATCH] kraid: Add a FlowCtrl struct Part-of: --- src/panfrost/compiler/kraid/flow.rs | 122 ++++++++++++++++++++++++++++ src/panfrost/compiler/kraid/ir.rs | 7 +- src/panfrost/compiler/kraid/lib.rs | 1 + 3 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 src/panfrost/compiler/kraid/flow.rs diff --git a/src/panfrost/compiler/kraid/flow.rs b/src/panfrost/compiler/kraid/flow.rs new file mode 100644 index 00000000000..09851d6a585 --- /dev/null +++ b/src/panfrost/compiler/kraid/flow.rs @@ -0,0 +1,122 @@ +// Copyright © 2026 Collabora, Ltd. +// SPDX-License-Identifier: MIT + +use crate::bitview::*; + +#[repr(u8)] +#[derive(Clone, Copy, Eq, Hash, PartialEq)] +pub enum FlowWaitBit { + Slot0 = 0, + Slot1 = 1, + Slot2 = 2, + Resource = 5, + ZS = 6, + Barrier = 7, +} + +#[repr(u8)] +#[derive(Clone, Copy, Eq, Hash, PartialEq)] +enum FlowCtrlBit { + MsgSlotBit0 = 0, + MsgSlotBit1 = 1, + Reconverge, + Discard, + EndShader, +} + +#[derive(Clone, Copy, Default, Eq, Hash, PartialEq)] +pub struct FlowCtrl { + pub wait: u8, + ctrl: u8, +} + +impl FlowCtrl { + pub const NONE: FlowCtrl = FlowCtrl { wait: 0, ctrl: 0 }; + + fn get_ctrl_bit(&self, bit: FlowCtrlBit) -> bool { + BitView::new(&self.ctrl).get_bit(bit as usize) + } + + fn set_ctrl_bit(&mut self, bit: FlowCtrlBit) { + BitMutView::new(&mut self.ctrl).set_bit(bit as usize, true); + } + + fn take_ctrl_bit(&mut self, bit: FlowCtrlBit) -> bool { + let mut bv = BitMutView::new(&mut self.ctrl); + let val = bv.get_bit(bit as usize); + bv.set_bit(bit as usize, false); + val + } + + pub fn get_msg_slot_idx(&self) -> Option { + let slot = BitView::new(&self.ctrl).get_bit_range_u64(0..2) as u8; + if slot > 0 { + Some((slot - 1) as u8) + } else { + None + } + } + + pub fn set_msg_slot_idx(&mut self, slot_idx: u8) { + assert!(slot_idx < 3); + let slot = slot_idx + 1; + BitMutView::new(&mut self.ctrl).set_field(0..2, slot); + } + + pub fn take_msg_slot_idx(&mut self) -> Option { + let val = self.get_msg_slot_idx(); + BitMutView::new(&mut self.ctrl).set_field(0..2, 0_u8); + val + } + + pub fn get_reconverge(&self) -> bool { + self.get_ctrl_bit(FlowCtrlBit::Reconverge) + } + + pub fn set_reconverge(&mut self) { + self.set_ctrl_bit(FlowCtrlBit::Reconverge) + } + + pub fn take_reconverge(&mut self) -> bool { + self.take_ctrl_bit(FlowCtrlBit::Reconverge) + } + + pub fn get_discard(&self) -> bool { + self.get_ctrl_bit(FlowCtrlBit::Discard) + } + + pub fn set_discard(&mut self) { + self.set_ctrl_bit(FlowCtrlBit::Discard) + } + + pub fn take_discard(&mut self) -> bool { + self.take_ctrl_bit(FlowCtrlBit::Discard) + } + + pub fn get_end_shader(&self) -> bool { + self.get_ctrl_bit(FlowCtrlBit::EndShader) + } + + pub fn set_end_shader(&mut self) { + self.set_ctrl_bit(FlowCtrlBit::EndShader) + } + + pub fn take_end_shader(&mut self) -> bool { + self.take_ctrl_bit(FlowCtrlBit::EndShader) + } + + pub fn get_wait_bit(&self, bit: FlowWaitBit) -> bool { + BitView::new(&self.wait).get_bit(bit as usize) + } + + pub fn set_wait_bit(&mut self, bit: FlowWaitBit) { + BitMutView::new(&mut self.wait).set_bit(bit as usize, true); + } + + pub fn take_wait_bit(&mut self, bit: FlowWaitBit) -> bool { + let mut bv = BitMutView::new(&mut self.wait); + let val = bv.get_bit(bit as usize); + bv.set_bit(bit as usize, false); + val + } +} diff --git a/src/panfrost/compiler/kraid/ir.rs b/src/panfrost/compiler/kraid/ir.rs index 6bbdc7caea7..43714a5c43d 100644 --- a/src/panfrost/compiler/kraid/ir.rs +++ b/src/panfrost/compiler/kraid/ir.rs @@ -2,6 +2,7 @@ // SPDX-License-Identifier: MIT pub use crate::data_type::DataType; +pub use crate::flow::FlowCtrl; pub use crate::model::Model; pub use crate::ops::Op; use crate::ssa_value::SSAValueAllocator; @@ -507,6 +508,7 @@ pub trait Opcode: #[derive(Clone)] pub struct Instr { pub op: Op, + pub flow: FlowCtrl, } impl Deref for Instr { @@ -527,7 +529,10 @@ impl> From for Instr { fn from(op: T) -> Instr { let op = op.into(); assert!(op.is_valid_variant()); - Instr { op } + Instr { + op, + flow: Default::default(), + } } } diff --git a/src/panfrost/compiler/kraid/lib.rs b/src/panfrost/compiler/kraid/lib.rs index 777df1ca70c..a18f3eb036c 100644 --- a/src/panfrost/compiler/kraid/lib.rs +++ b/src/panfrost/compiler/kraid/lib.rs @@ -5,6 +5,7 @@ mod bitview; mod builder; mod compile; mod data_type; +mod flow; mod ir; mod model; mod nir;