mtl_gpu/enums/
resource.rs1use mtl_foundation::{Integer, UInteger};
6
7#[repr(transparent)]
11#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
12pub struct PurgeableState(pub UInteger);
13
14impl PurgeableState {
15 pub const KEEP_CURRENT: Self = Self(1);
16 pub const NON_VOLATILE: Self = Self(2);
17 pub const VOLATILE: Self = Self(3);
18 pub const EMPTY: Self = Self(4);
19}
20
21#[repr(transparent)]
25#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
26pub struct CPUCacheMode(pub UInteger);
27
28impl CPUCacheMode {
29 pub const DEFAULT_CACHE: Self = Self(0);
30 pub const WRITE_COMBINED: Self = Self(1);
31}
32
33#[repr(transparent)]
37#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
38pub struct StorageMode(pub UInteger);
39
40impl StorageMode {
41 pub const SHARED: Self = Self(0);
42 pub const MANAGED: Self = Self(1);
43 pub const PRIVATE: Self = Self(2);
44 pub const MEMORYLESS: Self = Self(3);
45}
46
47#[repr(transparent)]
51#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
52pub struct HazardTrackingMode(pub UInteger);
53
54impl HazardTrackingMode {
55 pub const DEFAULT: Self = Self(0);
56 pub const UNTRACKED: Self = Self(1);
57 pub const TRACKED: Self = Self(2);
58}
59
60#[repr(transparent)]
64#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
65pub struct SparsePageSize(pub Integer);
66
67impl SparsePageSize {
68 pub const SIZE_16: Self = Self(101);
69 pub const SIZE_64: Self = Self(102);
70 pub const SIZE_256: Self = Self(103);
71}
72
73#[repr(transparent)]
77#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
78pub struct BufferSparseTier(pub Integer);
79
80impl BufferSparseTier {
81 pub const NONE: Self = Self(0);
82 pub const TIER1: Self = Self(1);
83}
84
85#[repr(transparent)]
89#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
90pub struct TextureSparseTier(pub Integer);
91
92impl TextureSparseTier {
93 pub const NONE: Self = Self(0);
94 pub const TIER1: Self = Self(1);
95 pub const TIER2: Self = Self(2);
96}
97
98#[repr(transparent)]
102#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
103pub struct ResourceOptions(pub UInteger);
104
105impl ResourceOptions {
106 pub const CPU_CACHE_MODE_DEFAULT_CACHE: Self = Self(0);
107 pub const CPU_CACHE_MODE_WRITE_COMBINED: Self = Self(1);
108 pub const STORAGE_MODE_SHARED: Self = Self(0);
109 pub const STORAGE_MODE_MANAGED: Self = Self(1 << 4);
110 pub const STORAGE_MODE_PRIVATE: Self = Self(1 << 5);
111 pub const STORAGE_MODE_MEMORYLESS: Self = Self(1 << 5);
112 pub const HAZARD_TRACKING_MODE_DEFAULT: Self = Self(0);
113 pub const HAZARD_TRACKING_MODE_UNTRACKED: Self = Self(1 << 8);
114 pub const HAZARD_TRACKING_MODE_TRACKED: Self = Self(1 << 9);
115 pub const OPTION_CPU_CACHE_MODE_DEFAULT: Self = Self(0);
116 pub const OPTION_CPU_CACHE_MODE_WRITE_COMBINED: Self = Self(1);
117
118 #[inline]
120 pub const fn bits(&self) -> UInteger {
121 self.0
122 }
123
124 #[inline]
126 pub const fn from_bits(bits: UInteger) -> Self {
127 Self(bits)
128 }
129
130 #[inline]
132 pub const fn is_empty(&self) -> bool {
133 self.0 == 0
134 }
135
136 #[inline]
138 pub const fn contains(&self, other: Self) -> bool {
139 (self.0 & other.0) == other.0
140 }
141}
142
143impl std::ops::BitOr for ResourceOptions {
144 type Output = Self;
145 #[inline]
146 fn bitor(self, rhs: Self) -> Self {
147 Self(self.0 | rhs.0)
148 }
149}
150
151impl std::ops::BitAnd for ResourceOptions {
152 type Output = Self;
153 #[inline]
154 fn bitand(self, rhs: Self) -> Self {
155 Self(self.0 & rhs.0)
156 }
157}
158
159impl std::ops::BitOrAssign for ResourceOptions {
160 #[inline]
161 fn bitor_assign(&mut self, rhs: Self) {
162 self.0 |= rhs.0;
163 }
164}
165
166impl std::ops::BitAndAssign for ResourceOptions {
167 #[inline]
168 fn bitand_assign(&mut self, rhs: Self) {
169 self.0 &= rhs.0;
170 }
171}
172
173#[repr(transparent)]
177#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
178pub struct SparseTextureMappingMode(pub UInteger);
179
180impl SparseTextureMappingMode {
181 pub const MAP: Self = Self(0);
183 pub const UNMAP: Self = Self(1);
185}
186
187#[cfg(test)]
188mod tests {
189 use super::*;
190
191 #[test]
192 fn test_purgeable_state_values() {
193 assert_eq!(PurgeableState::KEEP_CURRENT.0, 1);
194 assert_eq!(PurgeableState::NON_VOLATILE.0, 2);
195 assert_eq!(PurgeableState::VOLATILE.0, 3);
196 assert_eq!(PurgeableState::EMPTY.0, 4);
197 }
198
199 #[test]
200 fn test_storage_mode_values() {
201 assert_eq!(StorageMode::SHARED.0, 0);
202 assert_eq!(StorageMode::MANAGED.0, 1);
203 assert_eq!(StorageMode::PRIVATE.0, 2);
204 assert_eq!(StorageMode::MEMORYLESS.0, 3);
205 }
206
207 #[test]
208 fn test_resource_options_bitor() {
209 let opts =
210 ResourceOptions::CPU_CACHE_MODE_WRITE_COMBINED | ResourceOptions::STORAGE_MODE_PRIVATE;
211 assert!(opts.contains(ResourceOptions::CPU_CACHE_MODE_WRITE_COMBINED));
212 }
213}