rspirv/sr/
types.rs

1use crate::spirv;
2
3use super::{storage::Token, Constant, Decoration};
4
5#[derive(Clone, Debug)]
6pub struct StructMember {
7    pub token: Token<Type>,
8    pub decorations: Vec<Decoration>,
9}
10
11impl StructMember {
12    pub fn new(ty: Token<Type>) -> Self {
13        StructMember {
14            token: ty,
15            decorations: Vec::new(),
16        }
17    }
18}
19
20include!("autogen_types.rs");
21
22impl PartialEq for Type {
23    fn eq(&self, other: &Self) -> bool {
24        use Type::*;
25        match (self, other) {
26            (Bool, Bool) => true,
27            (
28                Int {
29                    width: sw,
30                    signedness: ss,
31                },
32                Int {
33                    width: ow,
34                    signedness: os,
35                },
36            ) => sw == ow && ss == os,
37            (Float { width: s }, Float { width: o }) => s == o,
38            (
39                Vector {
40                    component_type: st,
41                    component_count: sc,
42                },
43                Vector {
44                    component_type: ot,
45                    component_count: oc,
46                },
47            ) => st == ot && sc == oc,
48            (
49                Matrix {
50                    column_type: st,
51                    column_count: sc,
52                },
53                Matrix {
54                    column_type: ot,
55                    column_count: oc,
56                },
57            ) => st == ot && sc == oc,
58            _ => false,
59        }
60    }
61}
62
63impl Type {
64    pub fn is_numerical_type(&self) -> bool {
65        matches!(self, Type::Int { .. } | Type::Float { .. })
66    }
67
68    pub fn is_scalar_type(&self) -> bool {
69        match self {
70            Type::Bool => true,
71            _ => self.is_numerical_type(),
72        }
73    }
74
75    pub fn is_aggregate_type(&self) -> bool {
76        matches!(
77            self,
78            Type::Struct { .. } | Type::Array { .. } | Type::RuntimeArray { .. }
79        )
80    }
81
82    pub fn is_composite_type(&self) -> bool {
83        match self {
84            Type::Vector { .. } | Type::Matrix { .. } => true,
85            _ => self.is_aggregate_type(),
86        }
87    }
88}