mtl_gpu/enums/
indirect_command.rs1use mtl_foundation::UInteger;
6
7#[repr(transparent)]
11#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
12pub struct IndirectCommandType(pub UInteger);
13
14impl IndirectCommandType {
15 pub const NONE: Self = Self(0);
16 pub const DRAW: Self = Self(1);
17 pub const DRAW_INDEXED: Self = Self(1 << 1);
18 pub const DRAW_PATCHES: Self = Self(1 << 2);
19 pub const DRAW_INDEXED_PATCHES: Self = Self(1 << 3);
20 pub const CONCURRENT_DISPATCH: Self = Self(1 << 5);
21 pub const CONCURRENT_DISPATCH_THREADS: Self = Self(1 << 6);
22 pub const DRAW_MESH_THREADGROUPS: Self = Self(1 << 7);
23 pub const DRAW_MESH_THREADS: Self = Self(1 << 8);
24
25 #[inline]
27 pub const fn bits(&self) -> UInteger {
28 self.0
29 }
30
31 #[inline]
33 pub const fn from_bits(bits: UInteger) -> Self {
34 Self(bits)
35 }
36
37 #[inline]
39 pub const fn is_empty(&self) -> bool {
40 self.0 == 0
41 }
42
43 #[inline]
45 pub const fn contains(&self, other: Self) -> bool {
46 (self.0 & other.0) == other.0
47 }
48}
49
50impl std::ops::BitOr for IndirectCommandType {
51 type Output = Self;
52 #[inline]
53 fn bitor(self, rhs: Self) -> Self {
54 Self(self.0 | rhs.0)
55 }
56}
57
58impl std::ops::BitAnd for IndirectCommandType {
59 type Output = Self;
60 #[inline]
61 fn bitand(self, rhs: Self) -> Self {
62 Self(self.0 & rhs.0)
63 }
64}
65
66impl std::ops::BitOrAssign for IndirectCommandType {
67 #[inline]
68 fn bitor_assign(&mut self, rhs: Self) {
69 self.0 |= rhs.0;
70 }
71}
72
73#[cfg(test)]
74mod tests {
75 use super::*;
76
77 #[test]
78 fn test_indirect_command_type_values() {
79 assert_eq!(IndirectCommandType::DRAW.0, 1);
80 assert_eq!(IndirectCommandType::DRAW_INDEXED.0, 2);
81 assert_eq!(IndirectCommandType::DRAW_MESH_THREADS.0, 256);
82 }
83
84 #[test]
85 fn test_indirect_command_type_bitor() {
86 let cmd = IndirectCommandType::DRAW | IndirectCommandType::DRAW_INDEXED;
87 assert!(cmd.contains(IndirectCommandType::DRAW));
88 assert!(cmd.contains(IndirectCommandType::DRAW_INDEXED));
89 }
90}