pebble/graphics/types/
flags.rs1macro_rules! bitflags_mirror {
2 (
3 pub struct $Name:ident => $Wgpu:ty {
4 $(const $Flag:ident = $val:expr;)*
5 }
6 ) => {
7 #[derive(Copy, Clone, PartialEq, Eq, Hash)]
8 pub struct $Name(u32);
9
10 impl $Name {
11 $(pub const $Flag: Self = Self($val);)*
12
13 pub const fn empty() -> Self {
14 Self(0)
15 }
16
17 pub const fn bits(self) -> u32 {
18 self.0
19 }
20
21 pub const fn contains(self, other: Self) -> bool {
22 (self.0 & other.0) == other.0
23 }
24
25 pub const fn intersects(self, other: Self) -> bool {
26 (self.0 & other.0) != 0
27 }
28 }
29
30 impl core::ops::BitOr for $Name {
31 type Output = Self;
32 fn bitor(self, rhs: Self) -> Self {
33 Self(self.0 | rhs.0)
34 }
35 }
36
37 impl core::ops::BitOrAssign for $Name {
38 fn bitor_assign(&mut self, rhs: Self) {
39 self.0 |= rhs.0;
40 }
41 }
42
43 impl From<$Name> for $Wgpu {
44 fn from(value: $Name) -> Self {
45 <$Wgpu>::from_bits_truncate(value.0)
46 }
47 }
48 };
49}
50
51bitflags_mirror! {
52 pub struct ShaderStages => wgpu::ShaderStages {
53 const NONE = 0;
54 const VERTEX = 1 << 0;
55 const FRAGMENT = 1 << 1;
56 const COMPUTE = 1 << 2;
57 const VERTEX_FRAGMENT = (1 << 0) | (1 << 1);
58 const TASK = 1 << 3;
59 const MESH = 1 << 4;
60 const RAY_GENERATION = 1 << 5;
61 const ANY_HIT = 1 << 6;
62 const CLOSEST_HIT = 1 << 7;
63 const MISS = 1 << 8;
64 }
65}
66
67bitflags_mirror! {
68 pub struct BufferUsages => wgpu::BufferUsages {
69 const MAP_READ = 1 << 0;
70 const MAP_WRITE = 1 << 1;
71 const COPY_SRC = 1 << 2;
72 const COPY_DST = 1 << 3;
73 const INDEX = 1 << 4;
74 const VERTEX = 1 << 5;
75 const UNIFORM = 1 << 6;
76 const STORAGE = 1 << 7;
77 const INDIRECT = 1 << 8;
78 const QUERY_RESOLVE = 1 << 9;
79 const BLAS_INPUT = 1 << 10;
80 const TLAS_INPUT = 1 << 11;
81 }
82}
83
84bitflags_mirror! {
85 pub struct TextureUsages => wgpu::TextureUsages {
86 const COPY_SRC = 1 << 0;
87 const COPY_DST = 1 << 1;
88 const TEXTURE_BINDING = 1 << 2;
89 const STORAGE_BINDING = 1 << 3;
90 const RENDER_ATTACHMENT = 1 << 4;
91 const STORAGE_ATOMIC = 1 << 16;
92 const TRANSIENT = 1 << 17;
93 }
94}
95
96bitflags_mirror! {
97 pub struct ColorWrites => wgpu::ColorWrites {
98 const RED = 1 << 0;
99 const GREEN = 1 << 1;
100 const BLUE = 1 << 2;
101 const ALPHA = 1 << 3;
102 const COLOR = (1 << 0) | (1 << 1) | (1 << 2);
103 const ALL = (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3);
104 }
105}
106
107impl Default for ColorWrites {
108 fn default() -> Self {
109 Self::ALL
110 }
111}