euv_engine/renderer/status/impl.rs
1use super::*;
2
3/// Implements CSS composite operation string conversion for `BlendMode`.
4impl BlendMode {
5 /// Returns the CSS `globalCompositeOperation` string for this blend mode.
6 ///
7 /// # Returns
8 ///
9 /// - `&str` - The CSS composite operation string.
10 pub fn to_css(&self) -> &str {
11 match self {
12 BlendMode::Normal => BLEND_MODE_NORMAL,
13 BlendMode::Multiply => BLEND_MODE_MULTIPLY,
14 BlendMode::Screen => BLEND_MODE_SCREEN,
15 BlendMode::Lighter => BLEND_MODE_LIGHTER,
16 BlendMode::Overlay => BLEND_MODE_OVERLAY,
17 BlendMode::Darken => BLEND_MODE_DARKEN,
18 BlendMode::Lighten => BLEND_MODE_LIGHTEN,
19 BlendMode::ColorDodge => BLEND_MODE_COLOR_DODGE,
20 BlendMode::ColorBurn => BLEND_MODE_COLOR_BURN,
21 BlendMode::HardLight => BLEND_MODE_HARD_LIGHT,
22 BlendMode::SoftLight => BLEND_MODE_SOFT_LIGHT,
23 BlendMode::Difference => BLEND_MODE_DIFFERENCE,
24 BlendMode::Exclusion => BLEND_MODE_EXCLUSION,
25 BlendMode::Hue => BLEND_MODE_HUE,
26 BlendMode::Saturation => BLEND_MODE_SATURATION,
27 BlendMode::Color => BLEND_MODE_COLOR,
28 BlendMode::Luminosity => BLEND_MODE_LUMINOSITY,
29 }
30 }
31}
32
33/// Inherent implementation of [`VertexStepMode`].
34impl VertexStepMode {
35 /// Returns the WGSL / WebGPU string representation.
36 ///
37 /// # Returns
38 ///
39 /// - `&'static str` - A static `&str` representation.
40 pub fn as_str(&self) -> &'static str {
41 match self {
42 Self::Vertex => WEBGPU_VERTEX_STEP_MODE_VERTEX,
43 Self::Instance => WEBGPU_VERTEX_STEP_MODE_INSTANCE,
44 }
45 }
46}
47
48/// Combines two buffer uses into the bitmask a `GpuBufferDescriptor`
49/// expects.
50///
51/// A buffer may be used for several purposes at once, and the WebGPU
52/// `usage` field is a bitmask rather than an enum, so combining uses is
53/// the normal case rather than the exception. The `|` operator is the
54/// only way the engine combines them, which keeps every bit value in
55/// exactly one place.
56impl std::ops::BitOr for BufferUsage {
57 /// The combined `usage` bitmask.
58 type Output = u32;
59
60 /// Combines two buffer uses into their `usage` bitmask.
61 ///
62 /// # Arguments
63 ///
64 /// - `Self` - The right-hand use.
65 ///
66 /// # Returns
67 ///
68 /// - `Self::Output` - The bitmask carrying both uses.
69 fn bitor(self, rhs: Self) -> Self::Output {
70 buffer_usage_bit(self) | buffer_usage_bit(rhs)
71 }
72}
73
74/// Combines two texture uses into the bitmask a `GpuTextureDescriptor`
75/// expects.
76///
77/// The texture counterpart of the `|` operator on [`BufferUsage`], with
78/// the same single-source-of-truth rationale.
79impl std::ops::BitOr for TextureUsage {
80 /// The combined `usage` bitmask.
81 type Output = u32;
82
83 /// Combines two texture uses into their `usage` bitmask.
84 ///
85 /// # Arguments
86 ///
87 /// - `Self` - The right-hand use.
88 ///
89 /// # Returns
90 ///
91 /// - `Self::Output` - The bitmask carrying both uses.
92 fn bitor(self, rhs: Self) -> Self::Output {
93 texture_usage_bit(self) | texture_usage_bit(rhs)
94 }
95}
96
97/// Combines two shader stages into the visibility bitmask a bind group
98/// layout entry expects.
99///
100/// The third of the three bitmask-carrying WebGPU enums; see
101/// [`BufferUsage`] for why combining is expressed as an operator rather
102/// than a helper call.
103impl std::ops::BitOr for ShaderStage {
104 /// The combined visibility bitmask.
105 type Output = u32;
106
107 /// Combines two shader stages into their visibility bitmask.
108 ///
109 /// # Arguments
110 ///
111 /// - `Self` - The right-hand stage.
112 ///
113 /// # Returns
114 ///
115 /// - `Self::Output` - The bitmask naming both stages.
116 fn bitor(self, rhs: Self) -> Self::Output {
117 shader_stage_bit(self) | shader_stage_bit(rhs)
118 }
119}
120
121/// The `GPUBufferUsage` bit one use occupies.
122///
123/// The canonical WebGPU values, in one place: a buffer's legal uses
124/// are a `GPUTextureUsage`-style bitmask, and getting a bit wrong
125/// produces a buffer that validates in some draws and silently loses
126/// the access in others. Keeping the table on the enum itself means a
127/// call site cannot reference a stale duplicate constant.
128impl BufferUsage {
129 /// The `GPUBufferUsage` bit this use occupies.
130 ///
131 /// # Returns
132 ///
133 /// - `u32` - The bit this use occupies in a `GpuBufferDescriptor`
134 /// `usage`; combine several with `|`.
135 pub fn usage_bit(self) -> u32 {
136 buffer_usage_bit(self)
137 }
138}
139
140/// The `GPUTextureUsage` bit one use occupies.
141///
142/// The texture-side counterpart of [`BufferUsage::usage_bit`]. Note
143/// that the buffer and texture families share their variant *names*
144/// but not their *values* - `CopySource` is `4` for a buffer and `1`
145/// for a texture - which is why the two tables are separate.
146impl TextureUsage {
147 /// The `GPUTextureUsage` bit this use occupies.
148 ///
149 /// # Returns
150 ///
151 /// - `u32` - The bit this use occupies in a `GpuTextureDescriptor`
152 /// `usage`; combine several with `|`.
153 pub fn usage_bit(self) -> u32 {
154 texture_usage_bit(self)
155 }
156}
157
158/// The `GPUShaderStage` bit one pipeline stage occupies.
159impl ShaderStage {
160 /// The `GPUShaderStage` bit this pipeline stage occupies.
161 ///
162 /// # Returns
163 ///
164 /// - `u32` - The bit this stage occupies in a
165 /// `BindGroupLayoutEntry` `visibility`; combine several with
166 /// `|`.
167 pub fn stage_bit(self) -> u32 {
168 shader_stage_bit(self)
169 }
170}