From 0f8ad632837fcbb5bfbfc7ec6945773e91cddb95 Mon Sep 17 00:00:00 2001 From: Faith Ekstrand Date: Mon, 8 Jun 2026 21:52:45 -0400 Subject: [PATCH] kraid: Add a Model::op_is_supported() query Most of the other queries assert or return a default value if the op itself is unsupported. This gives a clear answer to whether that op is supported at all, which is useful to know as a sanity check, if nothing else. Part-of: --- src/panfrost/compiler/kraid/encode_v9.rs | 16 +++++++++++++--- src/panfrost/compiler/kraid/model.rs | 6 ++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/panfrost/compiler/kraid/encode_v9.rs b/src/panfrost/compiler/kraid/encode_v9.rs index 6a94978e506..c53608be456 100644 --- a/src/panfrost/compiler/kraid/encode_v9.rs +++ b/src/panfrost/compiler/kraid/encode_v9.rs @@ -805,8 +805,8 @@ impl V9Instr for OpStore { } } -macro_rules! v9_op_match { - ($op: expr, |$x: ident| $y: expr) => { +macro_rules! v9_op_match_else { + ($op: expr, |$x: ident| $y: expr, $z: expr) => { match $op { Op::Branch($x) => $y, Op::CSel($x) => $y, @@ -823,15 +823,25 @@ macro_rules! v9_op_match { Op::Nop($x) => $y, Op::ShiftLop($x) => $y, Op::Store($x) => $y, - _ => panic!("Unsupported op: {}", $op), + _ => $z, } }; } +macro_rules! v9_op_match { + ($op: expr, |$x: ident| $y: expr) => { + v9_op_match_else!($op, |$x| $y, panic!("Unsupported op: {}", $op)) + }; +} + fn v9_op_info(op: &Op, arch: u8) -> Option<&InstructionInfo> { v9_op_match!(op, |op| op.get_info(arch)) } +pub fn v9_op_is_supported(op: &Op, arch: u8) -> bool { + v9_op_match_else!(op, |op| op.get_info(arch).is_some(), false) +} + pub fn v9_op_is_message(op: &Op, arch: u8) -> bool { v9_op_info(op, arch).is_some_and(|info| info.is_message) } diff --git a/src/panfrost/compiler/kraid/model.rs b/src/panfrost/compiler/kraid/model.rs index 88efd7ec6ea..d0dfdaffdba 100644 --- a/src/panfrost/compiler/kraid/model.rs +++ b/src/panfrost/compiler/kraid/model.rs @@ -10,6 +10,8 @@ pub trait Model { fn encode_shader(&self, s: &Shader<'_>) -> Vec; + fn op_is_supported(&self, op: &Op) -> bool; + fn op_is_message(&self, op: &Op) -> bool; fn op_src_supports_imm32(&self, op: &Op, src: &Src) -> bool; @@ -39,6 +41,10 @@ impl Model for ValhallModel { encode_v9(s, self.arch) } + fn op_is_supported(&self, op: &Op) -> bool { + op.as_virtual().is_some() || v9_op_is_supported(op, self.arch) + } + fn op_is_message(&self, op: &Op) -> bool { if let Some(vop) = op.as_virtual() { vop.is_message()