Skip to main content

mtl_gpu/mtl4/
enums.rs

1//! Metal 4 enumerations.
2//!
3//! Corresponds to enums in MTL4 headers.
4
5use mtl_foundation::{Integer, UInteger};
6
7/// Error codes for MTL4 command queue operations.
8///
9/// C++ equivalent: `MTL4::CommandQueueError`
10#[repr(transparent)]
11#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
12pub struct CommandQueueError(pub Integer);
13
14impl CommandQueueError {
15    /// No error.
16    pub const NONE: Self = Self(0);
17
18    /// Operation timed out.
19    pub const TIMEOUT: Self = Self(1);
20
21    /// Operation not permitted.
22    pub const NOT_PERMITTED: Self = Self(2);
23
24    /// Out of memory.
25    pub const OUT_OF_MEMORY: Self = Self(3);
26
27    /// Device was removed.
28    pub const DEVICE_REMOVED: Self = Self(4);
29
30    /// Access was revoked.
31    pub const ACCESS_REVOKED: Self = Self(5);
32
33    /// Internal error.
34    pub const INTERNAL: Self = Self(6);
35}
36
37// ============================================================
38// Pipeline State Enums
39// ============================================================
40
41/// Alpha to one state for pipeline.
42///
43/// C++ equivalent: `MTL4::AlphaToOneState`
44#[repr(transparent)]
45#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
46pub struct AlphaToOneState(pub Integer);
47
48impl AlphaToOneState {
49    /// Alpha to one is disabled.
50    pub const DISABLED: Self = Self(0);
51
52    /// Alpha to one is enabled.
53    pub const ENABLED: Self = Self(1);
54}
55
56/// Alpha to coverage state for pipeline.
57///
58/// C++ equivalent: `MTL4::AlphaToCoverageState`
59#[repr(transparent)]
60#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
61pub struct AlphaToCoverageState(pub Integer);
62
63impl AlphaToCoverageState {
64    /// Alpha to coverage is disabled.
65    pub const DISABLED: Self = Self(0);
66
67    /// Alpha to coverage is enabled.
68    pub const ENABLED: Self = Self(1);
69}
70
71/// Blend state for pipeline color attachments.
72///
73/// C++ equivalent: `MTL4::BlendState`
74#[repr(transparent)]
75#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
76pub struct BlendState(pub Integer);
77
78impl BlendState {
79    /// Blending is disabled.
80    pub const DISABLED: Self = Self(0);
81
82    /// Blending is enabled.
83    pub const ENABLED: Self = Self(1);
84
85    /// Blending state is unspecialized (runtime configurable).
86    pub const UNSPECIALIZED: Self = Self(2);
87}
88
89/// Indirect command buffer support state.
90///
91/// C++ equivalent: `MTL4::IndirectCommandBufferSupportState`
92#[repr(transparent)]
93#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
94pub struct IndirectCommandBufferSupportState(pub Integer);
95
96impl IndirectCommandBufferSupportState {
97    /// Indirect command buffers are not supported.
98    pub const DISABLED: Self = Self(0);
99
100    /// Indirect command buffers are supported.
101    pub const ENABLED: Self = Self(1);
102}
103
104/// Shader reflection options.
105///
106/// C++ equivalent: `MTL4::ShaderReflection`
107#[repr(transparent)]
108#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
109pub struct ShaderReflection(pub UInteger);
110
111impl ShaderReflection {
112    /// No reflection.
113    pub const NONE: Self = Self(0);
114
115    /// Include binding info.
116    pub const BINDING_INFO: Self = Self(1);
117
118    /// Include buffer type info.
119    pub const BUFFER_TYPE_INFO: Self = Self(1 << 1);
120
121    /// Combine flags.
122    #[inline]
123    pub const fn union(self, other: Self) -> Self {
124        Self(self.0 | other.0)
125    }
126
127    /// Check if contains flag.
128    #[inline]
129    pub const fn contains(self, other: Self) -> bool {
130        (self.0 & other.0) == other.0
131    }
132}
133
134impl std::ops::BitOr for ShaderReflection {
135    type Output = Self;
136    fn bitor(self, rhs: Self) -> Self {
137        Self(self.0 | rhs.0)
138    }
139}
140
141impl std::ops::BitAnd for ShaderReflection {
142    type Output = Self;
143    fn bitand(self, rhs: Self) -> Self {
144        Self(self.0 & rhs.0)
145    }
146}
147
148/// Logical to physical color attachment mapping state.
149///
150/// C++ equivalent: `MTL4::LogicalToPhysicalColorAttachmentMappingState`
151#[repr(transparent)]
152#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
153pub struct LogicalToPhysicalColorAttachmentMappingState(pub Integer);
154
155impl LogicalToPhysicalColorAttachmentMappingState {
156    /// Identity mapping (logical index equals physical index).
157    pub const IDENTITY: Self = Self(0);
158
159    /// Mapping is inherited from render pass.
160    pub const INHERITED: Self = Self(1);
161}
162
163// ============================================================
164// Compiler Enums
165// ============================================================
166
167/// Compiler task status.
168///
169/// C++ equivalent: `MTL4::CompilerTaskStatus`
170#[repr(transparent)]
171#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
172pub struct CompilerTaskStatus(pub Integer);
173
174impl CompilerTaskStatus {
175    /// No status.
176    pub const NONE: Self = Self(0);
177
178    /// Task is scheduled.
179    pub const SCHEDULED: Self = Self(1);
180
181    /// Task is compiling.
182    pub const COMPILING: Self = Self(2);
183
184    /// Task is finished.
185    pub const FINISHED: Self = Self(3);
186}
187
188/// Binary function options.
189///
190/// C++ equivalent: `MTL4::BinaryFunctionOptions`
191#[repr(transparent)]
192#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
193pub struct BinaryFunctionOptions(pub UInteger);
194
195impl BinaryFunctionOptions {
196    /// No options.
197    pub const NONE: Self = Self(0);
198
199    /// Function is pipeline independent.
200    pub const PIPELINE_INDEPENDENT: Self = Self(1 << 1);
201
202    /// Combine flags.
203    #[inline]
204    pub const fn union(self, other: Self) -> Self {
205        Self(self.0 | other.0)
206    }
207
208    /// Check if contains flag.
209    #[inline]
210    pub const fn contains(self, other: Self) -> bool {
211        (self.0 & other.0) == other.0
212    }
213}
214
215impl std::ops::BitOr for BinaryFunctionOptions {
216    type Output = Self;
217    fn bitor(self, rhs: Self) -> Self {
218        Self(self.0 | rhs.0)
219    }
220}
221
222impl std::ops::BitAnd for BinaryFunctionOptions {
223    type Output = Self;
224    fn bitand(self, rhs: Self) -> Self {
225        Self(self.0 & rhs.0)
226    }
227}
228
229/// Pipeline data set serializer configuration.
230///
231/// C++ equivalent: `MTL4::PipelineDataSetSerializerConfiguration`
232#[repr(transparent)]
233#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
234pub struct PipelineDataSetSerializerConfiguration(pub UInteger);
235
236impl PipelineDataSetSerializerConfiguration {
237    /// Capture pipeline descriptors.
238    pub const CAPTURE_DESCRIPTORS: Self = Self(1);
239
240    /// Capture pipeline binaries.
241    pub const CAPTURE_BINARIES: Self = Self(1 << 1);
242
243    /// Combine flags.
244    #[inline]
245    pub const fn union(self, other: Self) -> Self {
246        Self(self.0 | other.0)
247    }
248
249    /// Check if contains flag.
250    #[inline]
251    pub const fn contains(self, other: Self) -> bool {
252        (self.0 & other.0) == other.0
253    }
254}
255
256impl std::ops::BitOr for PipelineDataSetSerializerConfiguration {
257    type Output = Self;
258    fn bitor(self, rhs: Self) -> Self {
259        Self(self.0 | rhs.0)
260    }
261}
262
263impl std::ops::BitAnd for PipelineDataSetSerializerConfiguration {
264    type Output = Self;
265    fn bitand(self, rhs: Self) -> Self {
266        Self(self.0 & rhs.0)
267    }
268}
269
270// ============================================================
271// Command Encoder Enums
272// ============================================================
273
274/// Visibility options for command encoder operations.
275///
276/// C++ equivalent: `MTL4::VisibilityOptions`
277#[repr(transparent)]
278#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
279pub struct VisibilityOptions(pub UInteger);
280
281impl VisibilityOptions {
282    /// No visibility options.
283    pub const NONE: Self = Self(0);
284
285    /// Make visible to device.
286    pub const DEVICE: Self = Self(1);
287
288    /// Make visible for resource aliasing.
289    pub const RESOURCE_ALIAS: Self = Self(1 << 1);
290
291    /// Combine flags.
292    #[inline]
293    pub const fn union(self, other: Self) -> Self {
294        Self(self.0 | other.0)
295    }
296
297    /// Check if contains flag.
298    #[inline]
299    pub const fn contains(self, other: Self) -> bool {
300        (self.0 & other.0) == other.0
301    }
302}
303
304impl std::ops::BitOr for VisibilityOptions {
305    type Output = Self;
306    fn bitor(self, rhs: Self) -> Self {
307        Self(self.0 | rhs.0)
308    }
309}
310
311impl std::ops::BitAnd for VisibilityOptions {
312    type Output = Self;
313    fn bitand(self, rhs: Self) -> Self {
314        Self(self.0 & rhs.0)
315    }
316}
317
318/// Render encoder options.
319///
320/// C++ equivalent: `MTL4::RenderEncoderOptions`
321#[repr(transparent)]
322#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
323pub struct RenderEncoderOptions(pub UInteger);
324
325impl RenderEncoderOptions {
326    /// No options.
327    pub const NONE: Self = Self(0);
328
329    /// Suspending render pass (can be resumed later).
330    pub const SUSPENDING: Self = Self(1);
331
332    /// Resuming a previously suspended render pass.
333    pub const RESUMING: Self = Self(1 << 1);
334
335    /// Combine flags.
336    #[inline]
337    pub const fn union(self, other: Self) -> Self {
338        Self(self.0 | other.0)
339    }
340
341    /// Check if contains flag.
342    #[inline]
343    pub const fn contains(self, other: Self) -> bool {
344        (self.0 & other.0) == other.0
345    }
346}
347
348impl std::ops::BitOr for RenderEncoderOptions {
349    type Output = Self;
350    fn bitor(self, rhs: Self) -> Self {
351        Self(self.0 | rhs.0)
352    }
353}
354
355impl std::ops::BitAnd for RenderEncoderOptions {
356    type Output = Self;
357    fn bitand(self, rhs: Self) -> Self {
358        Self(self.0 & rhs.0)
359    }
360}
361
362#[cfg(test)]
363mod tests {
364    use super::*;
365
366    #[test]
367    fn test_command_queue_error_values() {
368        assert_eq!(CommandQueueError::NONE.0, 0);
369        assert_eq!(CommandQueueError::TIMEOUT.0, 1);
370        assert_eq!(CommandQueueError::NOT_PERMITTED.0, 2);
371        assert_eq!(CommandQueueError::OUT_OF_MEMORY.0, 3);
372        assert_eq!(CommandQueueError::DEVICE_REMOVED.0, 4);
373        assert_eq!(CommandQueueError::ACCESS_REVOKED.0, 5);
374        assert_eq!(CommandQueueError::INTERNAL.0, 6);
375    }
376
377    #[test]
378    fn test_alpha_to_one_state_values() {
379        assert_eq!(AlphaToOneState::DISABLED.0, 0);
380        assert_eq!(AlphaToOneState::ENABLED.0, 1);
381    }
382
383    #[test]
384    fn test_alpha_to_coverage_state_values() {
385        assert_eq!(AlphaToCoverageState::DISABLED.0, 0);
386        assert_eq!(AlphaToCoverageState::ENABLED.0, 1);
387    }
388
389    #[test]
390    fn test_blend_state_values() {
391        assert_eq!(BlendState::DISABLED.0, 0);
392        assert_eq!(BlendState::ENABLED.0, 1);
393        assert_eq!(BlendState::UNSPECIALIZED.0, 2);
394    }
395
396    #[test]
397    fn test_indirect_command_buffer_support_state_values() {
398        assert_eq!(IndirectCommandBufferSupportState::DISABLED.0, 0);
399        assert_eq!(IndirectCommandBufferSupportState::ENABLED.0, 1);
400    }
401
402    #[test]
403    fn test_shader_reflection_values() {
404        assert_eq!(ShaderReflection::NONE.0, 0);
405        assert_eq!(ShaderReflection::BINDING_INFO.0, 1);
406        assert_eq!(ShaderReflection::BUFFER_TYPE_INFO.0, 2);
407
408        let combined = ShaderReflection::BINDING_INFO | ShaderReflection::BUFFER_TYPE_INFO;
409        assert_eq!(combined.0, 3);
410        assert!(combined.contains(ShaderReflection::BINDING_INFO));
411        assert!(combined.contains(ShaderReflection::BUFFER_TYPE_INFO));
412    }
413
414    #[test]
415    fn test_color_attachment_mapping_state_values() {
416        assert_eq!(LogicalToPhysicalColorAttachmentMappingState::IDENTITY.0, 0);
417        assert_eq!(LogicalToPhysicalColorAttachmentMappingState::INHERITED.0, 1);
418    }
419
420    #[test]
421    fn test_compiler_task_status_values() {
422        assert_eq!(CompilerTaskStatus::NONE.0, 0);
423        assert_eq!(CompilerTaskStatus::SCHEDULED.0, 1);
424        assert_eq!(CompilerTaskStatus::COMPILING.0, 2);
425        assert_eq!(CompilerTaskStatus::FINISHED.0, 3);
426    }
427
428    #[test]
429    fn test_binary_function_options_values() {
430        assert_eq!(BinaryFunctionOptions::NONE.0, 0);
431        assert_eq!(BinaryFunctionOptions::PIPELINE_INDEPENDENT.0, 2);
432    }
433
434    #[test]
435    fn test_pipeline_data_set_serializer_configuration_values() {
436        assert_eq!(
437            PipelineDataSetSerializerConfiguration::CAPTURE_DESCRIPTORS.0,
438            1
439        );
440        assert_eq!(
441            PipelineDataSetSerializerConfiguration::CAPTURE_BINARIES.0,
442            2
443        );
444
445        let combined = PipelineDataSetSerializerConfiguration::CAPTURE_DESCRIPTORS
446            | PipelineDataSetSerializerConfiguration::CAPTURE_BINARIES;
447        assert_eq!(combined.0, 3);
448    }
449
450    #[test]
451    fn test_visibility_options_values() {
452        assert_eq!(VisibilityOptions::NONE.0, 0);
453        assert_eq!(VisibilityOptions::DEVICE.0, 1);
454        assert_eq!(VisibilityOptions::RESOURCE_ALIAS.0, 2);
455
456        let combined = VisibilityOptions::DEVICE | VisibilityOptions::RESOURCE_ALIAS;
457        assert_eq!(combined.0, 3);
458        assert!(combined.contains(VisibilityOptions::DEVICE));
459        assert!(combined.contains(VisibilityOptions::RESOURCE_ALIAS));
460    }
461
462    #[test]
463    fn test_render_encoder_options_values() {
464        assert_eq!(RenderEncoderOptions::NONE.0, 0);
465        assert_eq!(RenderEncoderOptions::SUSPENDING.0, 1);
466        assert_eq!(RenderEncoderOptions::RESUMING.0, 2);
467
468        let combined = RenderEncoderOptions::SUSPENDING | RenderEncoderOptions::RESUMING;
469        assert_eq!(combined.0, 3);
470        assert!(combined.contains(RenderEncoderOptions::SUSPENDING));
471        assert!(combined.contains(RenderEncoderOptions::RESUMING));
472    }
473}