compiler/rust: Add a nir_alu_type wrapper

Reviewed-by: Mel Henning <mhenning@darkrefraction.com>
Reviewed-by: Benjamin Lee <benjamin.lee@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/34126>
This commit is contained in:
Faith Ekstrand
2025-03-12 16:50:49 -05:00
committed by Marge Bot
parent 47cfc77085
commit 1355c71943
2 changed files with 32 additions and 0 deletions
+1
View File
@@ -39,6 +39,7 @@ _compiler_bindgen_args = [
'--raw-line', '#![allow(non_camel_case_types)]',
'--raw-line', '#![allow(non_snake_case)]',
'--raw-line', '#![allow(non_upper_case_globals)]',
'--allowlist-var', 'NIR_.*',
'--allowlist-var', 'nir_.*_infos',
'--allowlist-var', 'rust_.*',
'--allowlist-function', 'glsl_.*',
+31
View File
@@ -70,6 +70,37 @@ impl<'a, T: 'a> Iterator for ExecListIter<'a, T> {
}
}
#[derive(Clone, Copy, Eq, Hash, PartialEq)]
pub struct ALUType(nir_alu_type);
impl ALUType {
pub const INT: Self = Self(nir_type_int);
pub const UINT: Self = Self(nir_type_uint);
pub const BOOL: Self = Self(nir_type_bool);
pub const FLOAT: Self = Self(nir_type_float);
pub fn new(base: Self, bit_size: u8) -> Self {
assert!(bit_size.is_power_of_two());
assert!(bit_size & (NIR_ALU_TYPE_BASE_TYPE_MASK as u8) == 0);
assert!(
base.is_base_type() || bit_size == 0 || bit_size == base.bit_size()
);
Self(base.0 | bit_size)
}
pub fn is_base_type(&self) -> bool {
self.bit_size() == 0
}
pub fn bit_size(&self) -> u8 {
self.0 & (NIR_ALU_TYPE_SIZE_MASK as u8)
}
pub fn base_type(&self) -> Self {
Self(self.0 & (NIR_ALU_TYPE_BASE_TYPE_MASK as u8))
}
}
impl nir_def {
pub fn parent_instr<'a>(&'a self) -> &'a nir_instr {
unsafe { NonNull::new(self.parent_instr).unwrap().as_ref() }