Skip to main content

mtl_gpu/enums/
library.rs

1//! Library enumerations.
2//!
3//! Corresponds to `Metal/MTLLibrary.hpp`.
4
5use mtl_foundation::{Integer, UInteger};
6
7/// Patch type for tessellation.
8///
9/// C++ equivalent: `MTL::PatchType`
10#[repr(transparent)]
11#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
12pub struct PatchType(pub UInteger);
13
14impl PatchType {
15    pub const NONE: Self = Self(0);
16    pub const TRIANGLE: Self = Self(1);
17    pub const QUAD: Self = Self(2);
18}
19
20/// Function type.
21///
22/// C++ equivalent: `MTL::FunctionType`
23#[repr(transparent)]
24#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
25pub struct FunctionType(pub UInteger);
26
27impl FunctionType {
28    pub const VERTEX: Self = Self(1);
29    pub const FRAGMENT: Self = Self(2);
30    pub const KERNEL: Self = Self(3);
31    pub const VISIBLE: Self = Self(5);
32    pub const INTERSECTION: Self = Self(6);
33    pub const MESH: Self = Self(7);
34    pub const OBJECT: Self = Self(8);
35}
36
37/// Metal shading language version.
38///
39/// C++ equivalent: `MTL::LanguageVersion`
40#[repr(transparent)]
41#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
42pub struct LanguageVersion(pub UInteger);
43
44impl LanguageVersion {
45    pub const VERSION_1_0: Self = Self(65536); // (1 << 16)
46    pub const VERSION_1_1: Self = Self(65537); // (1 << 16) + 1
47    pub const VERSION_1_2: Self = Self(65538); // (1 << 16) + 2
48    pub const VERSION_2_0: Self = Self(131072); // (2 << 16)
49    pub const VERSION_2_1: Self = Self(131073); // (2 << 16) + 1
50    pub const VERSION_2_2: Self = Self(131074); // (2 << 16) + 2
51    pub const VERSION_2_3: Self = Self(131075); // (2 << 16) + 3
52    pub const VERSION_2_4: Self = Self(131076); // (2 << 16) + 4
53    pub const VERSION_3_0: Self = Self(196608); // (3 << 16)
54    pub const VERSION_3_1: Self = Self(196609); // (3 << 16) + 1
55    pub const VERSION_3_2: Self = Self(196610); // (3 << 16) + 2
56    pub const VERSION_4_0: Self = Self(262144); // (4 << 16)
57}
58
59/// Library type.
60///
61/// C++ equivalent: `MTL::LibraryType`
62#[repr(transparent)]
63#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
64pub struct LibraryType(pub Integer);
65
66impl LibraryType {
67    pub const EXECUTABLE: Self = Self(0);
68    pub const DYNAMIC: Self = Self(1);
69}
70
71/// Library optimization level.
72///
73/// C++ equivalent: `MTL::LibraryOptimizationLevel`
74#[repr(transparent)]
75#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
76pub struct LibraryOptimizationLevel(pub Integer);
77
78impl LibraryOptimizationLevel {
79    pub const DEFAULT: Self = Self(0);
80    pub const SIZE: Self = Self(1);
81}
82
83/// Compile symbol visibility.
84///
85/// C++ equivalent: `MTL::CompileSymbolVisibility`
86#[repr(transparent)]
87#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
88pub struct CompileSymbolVisibility(pub Integer);
89
90impl CompileSymbolVisibility {
91    pub const DEFAULT: Self = Self(0);
92    pub const HIDDEN: Self = Self(1);
93}
94
95/// Math mode for shader compilation.
96///
97/// C++ equivalent: `MTL::MathMode`
98#[repr(transparent)]
99#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
100pub struct MathMode(pub Integer);
101
102impl MathMode {
103    pub const SAFE: Self = Self(0);
104    pub const RELAXED: Self = Self(1);
105    pub const FAST: Self = Self(2);
106}
107
108/// Math floating point functions precision.
109///
110/// C++ equivalent: `MTL::MathFloatingPointFunctions`
111#[repr(transparent)]
112#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
113pub struct MathFloatingPointFunctions(pub Integer);
114
115impl MathFloatingPointFunctions {
116    pub const FAST: Self = Self(0);
117    pub const PRECISE: Self = Self(1);
118}
119
120/// Library error codes.
121///
122/// C++ equivalent: `MTL::LibraryError`
123#[repr(transparent)]
124#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
125pub struct LibraryError(pub UInteger);
126
127impl LibraryError {
128    pub const UNSUPPORTED: Self = Self(1);
129    pub const INTERNAL: Self = Self(2);
130    pub const COMPILE_FAILURE: Self = Self(3);
131    pub const COMPILE_WARNING: Self = Self(4);
132    pub const FUNCTION_NOT_FOUND: Self = Self(5);
133    pub const FILE_NOT_FOUND: Self = Self(6);
134}
135
136/// Dynamic library error codes.
137///
138/// C++ equivalent: `MTL::DynamicLibraryError`
139#[repr(transparent)]
140#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
141pub struct DynamicLibraryError(pub UInteger);
142
143impl DynamicLibraryError {
144    pub const NONE: Self = Self(0);
145    pub const INVALID_FILE: Self = Self(1);
146    pub const COMPILATION_FAILURE: Self = Self(2);
147    pub const UNRESOLVED_INSTALL_NAME: Self = Self(3);
148    pub const DEPENDENCY_LOAD_FAILURE: Self = Self(4);
149    pub const UNSUPPORTED: Self = Self(5);
150}
151
152#[cfg(test)]
153mod tests {
154    use super::*;
155
156    #[test]
157    fn test_function_type_values() {
158        assert_eq!(FunctionType::VERTEX.0, 1);
159        assert_eq!(FunctionType::FRAGMENT.0, 2);
160        assert_eq!(FunctionType::KERNEL.0, 3);
161        assert_eq!(FunctionType::MESH.0, 7);
162    }
163
164    #[test]
165    fn test_language_version_values() {
166        assert_eq!(LanguageVersion::VERSION_1_0.0, 65536);
167        assert_eq!(LanguageVersion::VERSION_2_0.0, 131072);
168        assert_eq!(LanguageVersion::VERSION_3_0.0, 196608);
169        assert_eq!(LanguageVersion::VERSION_4_0.0, 262144);
170    }
171
172    #[test]
173    fn test_library_error_values() {
174        assert_eq!(LibraryError::UNSUPPORTED.0, 1);
175        assert_eq!(LibraryError::COMPILE_FAILURE.0, 3);
176    }
177
178    #[test]
179    fn test_patch_type_values() {
180        assert_eq!(PatchType::NONE.0, 0);
181        assert_eq!(PatchType::TRIANGLE.0, 1);
182        assert_eq!(PatchType::QUAD.0, 2);
183    }
184
185    #[test]
186    fn test_dynamic_library_error_values() {
187        assert_eq!(DynamicLibraryError::NONE.0, 0);
188        assert_eq!(DynamicLibraryError::INVALID_FILE.0, 1);
189        assert_eq!(DynamicLibraryError::COMPILATION_FAILURE.0, 2);
190        assert_eq!(DynamicLibraryError::UNRESOLVED_INSTALL_NAME.0, 3);
191        assert_eq!(DynamicLibraryError::DEPENDENCY_LOAD_FAILURE.0, 4);
192        assert_eq!(DynamicLibraryError::UNSUPPORTED.0, 5);
193    }
194}