1use crate::spirv;
2
3use super::storage::Token;
4
5#[derive(Clone, Debug, PartialEq)]
7pub enum Constant {
8 Bool(bool),
9 Int(i32),
11 UInt(u32),
12 Float(f32),
13 Composite(Vec<Token<Constant>>),
14 Null,
15 Sampler {
16 addressing_mode: spirv::SamplerAddressingMode,
17 normalized: bool,
18 filter_mode: spirv::SamplerFilterMode,
19 },
20 SpecBool(bool),
21 SpecInt(i32),
22 SpecUInt(u32),
23 SpecFloat(f32),
24 SpecComposite(Vec<Token<Constant>>),
25 SpecOp(spirv::Op, Vec<Token<Constant>>),
26}
27
28impl Constant {
29 pub fn is_bool_constant(&self) -> bool {
30 matches!(self, Constant::Bool { .. } | Constant::SpecBool { .. })
31 }
32
33 pub fn is_int_constant(&self) -> bool {
34 matches!(self, Constant::Int { .. } | Constant::SpecInt { .. })
35 }
36
37 pub fn is_uint_constant(&self) -> bool {
38 matches!(self, Constant::UInt { .. } | Constant::SpecUInt { .. })
39 }
40
41 pub fn is_float_constant(&self) -> bool {
42 matches!(self, Constant::Float { .. } | Constant::SpecFloat { .. })
43 }
44
45 pub fn is_composite_constant(&self) -> bool {
46 matches!(
47 self,
48 Constant::Composite { .. } | Constant::SpecComposite { .. }
49 )
50 }
51
52 pub fn is_null_constant(&self) -> bool {
53 matches!(self, Constant::Null { .. })
54 }
55
56 pub fn is_sampler_constant(&self) -> bool {
57 matches!(self, Constant::Sampler { .. })
58 }
59
60 pub fn is_spec_constant(&self) -> bool {
61 matches!(
62 self,
63 Constant::SpecBool { .. }
64 | Constant::SpecInt { .. }
65 | Constant::SpecUInt { .. }
66 | Constant::SpecFloat { .. }
67 | Constant::SpecComposite { .. }
68 | Constant::SpecOp { .. }
69 )
70 }
71
72 pub fn is_spec_op_constant(&self) -> bool {
73 matches!(self, Constant::SpecOp { .. })
74 }
75}