objc2_metal/generated/MTLResource.rs
1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6use objc2_foundation::*;
7
8use crate::*;
9
10/// Options for setPurgeable call.
11///
12///
13/// The contents of this resource may not be discarded.
14///
15///
16/// The contents of this resource may be discarded.
17///
18///
19/// The contents of this are discarded.
20///
21///
22/// The purgeabelity state is not changed.
23///
24/// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtlpurgeablestate?language=objc)
25// NS_ENUM
26#[repr(transparent)]
27#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
28pub struct MTLPurgeableState(pub NSUInteger);
29impl MTLPurgeableState {
30 #[doc(alias = "MTLPurgeableStateKeepCurrent")]
31 pub const KeepCurrent: Self = Self(1);
32 #[doc(alias = "MTLPurgeableStateNonVolatile")]
33 pub const NonVolatile: Self = Self(2);
34 #[doc(alias = "MTLPurgeableStateVolatile")]
35 pub const Volatile: Self = Self(3);
36 #[doc(alias = "MTLPurgeableStateEmpty")]
37 pub const Empty: Self = Self(4);
38}
39
40unsafe impl Encode for MTLPurgeableState {
41 const ENCODING: Encoding = NSUInteger::ENCODING;
42}
43
44unsafe impl RefEncode for MTLPurgeableState {
45 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
46}
47
48/// Describes what CPU cache mode is used for the CPU's mapping of a texture resource.
49///
50/// The default cache mode for the system.
51///
52///
53/// Write combined memory is optimized for resources that the CPU will write into, but never read. On some implementations, writes may bypass caches avoiding cache pollution, and reads perform very poorly.
54///
55///
56/// Applications should only investigate changing the cache mode if writing to normally cached buffers is known to cause performance issues due to cache pollution, as write combined memory can have surprising performance pitfalls. Another approach is to use non-temporal stores to normally cached memory (STNP on ARMv8, _mm_stream_* on x86_64).
57///
58/// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtlcpucachemode?language=objc)
59// NS_ENUM
60#[repr(transparent)]
61#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
62pub struct MTLCPUCacheMode(pub NSUInteger);
63impl MTLCPUCacheMode {
64 #[doc(alias = "MTLCPUCacheModeDefaultCache")]
65 pub const DefaultCache: Self = Self(0);
66 #[doc(alias = "MTLCPUCacheModeWriteCombined")]
67 pub const WriteCombined: Self = Self(1);
68}
69
70unsafe impl Encode for MTLCPUCacheMode {
71 const ENCODING: Encoding = NSUInteger::ENCODING;
72}
73
74unsafe impl RefEncode for MTLCPUCacheMode {
75 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
76}
77
78/// Describes location and CPU mapping of MTLTexture.
79///
80/// In this mode, CPU and device will nominally both use the same underlying memory when accessing the contents of the texture resource.
81/// However, coherency is only guaranteed at command buffer boundaries to minimize the required flushing of CPU and GPU caches.
82/// This is the default storage mode for iOS Textures.
83///
84///
85/// This mode relaxes the coherency requirements and requires that the developer make explicit requests to maintain
86/// coherency between a CPU and GPU version of the texture resource. In order for CPU to access up to date GPU results,
87/// first, a blit synchronizations must be completed (see synchronize methods of MTLBlitCommandEncoder).
88/// Blit overhead is only incurred if GPU has modified the resource.
89/// This is the default storage mode for OS X Textures.
90///
91///
92/// This mode allows the texture resource data to be kept entirely to GPU (or driver) private memory that will never be accessed by the CPU directly, so no
93/// conherency of any kind must be maintained.
94///
95///
96/// This mode allows creation of resources that do not have a GPU or CPU memory backing, but do have on-chip storage for TBDR
97/// devices. The contents of the on-chip storage is undefined and does not persist, but its configuration is controlled by the
98/// MTLTexture descriptor. Textures created with MTLStorageModeMemoryless dont have an IOAccelResource at any point in their
99/// lifetime. The only way to populate such resource is to perform rendering operations on it. Blit operations are disallowed.
100///
101/// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtlstoragemode?language=objc)
102// NS_ENUM
103#[repr(transparent)]
104#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
105pub struct MTLStorageMode(pub NSUInteger);
106impl MTLStorageMode {
107 #[doc(alias = "MTLStorageModeShared")]
108 pub const Shared: Self = Self(0);
109 #[doc(alias = "MTLStorageModeManaged")]
110 pub const Managed: Self = Self(1);
111 #[doc(alias = "MTLStorageModePrivate")]
112 pub const Private: Self = Self(2);
113 #[doc(alias = "MTLStorageModeMemoryless")]
114 pub const Memoryless: Self = Self(3);
115}
116
117unsafe impl Encode for MTLStorageMode {
118 const ENCODING: Encoding = NSUInteger::ENCODING;
119}
120
121unsafe impl RefEncode for MTLStorageMode {
122 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
123}
124
125/// Describes how hazard tracking is performed.
126///
127/// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtlhazardtrackingmode?language=objc)
128// NS_ENUM
129#[repr(transparent)]
130#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
131pub struct MTLHazardTrackingMode(pub NSUInteger);
132impl MTLHazardTrackingMode {
133 #[doc(alias = "MTLHazardTrackingModeDefault")]
134 pub const Default: Self = Self(0);
135 #[doc(alias = "MTLHazardTrackingModeUntracked")]
136 pub const Untracked: Self = Self(1);
137 #[doc(alias = "MTLHazardTrackingModeTracked")]
138 pub const Tracked: Self = Self(2);
139}
140
141unsafe impl Encode for MTLHazardTrackingMode {
142 const ENCODING: Encoding = NSUInteger::ENCODING;
143}
144
145unsafe impl RefEncode for MTLHazardTrackingMode {
146 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
147}
148
149/// [Apple's documentation](https://developer.apple.com/documentation/metal/mtlresourceoptions?language=objc)
150// NS_OPTIONS
151#[repr(transparent)]
152#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
153pub struct MTLResourceOptions(pub NSUInteger);
154bitflags::bitflags! {
155 impl MTLResourceOptions: NSUInteger {
156 #[doc(alias = "MTLResourceCPUCacheModeDefaultCache")]
157 const CPUCacheModeDefaultCache = MTLCPUCacheMode::DefaultCache.0<<MTLResourceCPUCacheModeShift;
158 #[doc(alias = "MTLResourceCPUCacheModeWriteCombined")]
159 const CPUCacheModeWriteCombined = MTLCPUCacheMode::WriteCombined.0<<MTLResourceCPUCacheModeShift;
160 #[doc(alias = "MTLResourceStorageModeShared")]
161 const StorageModeShared = MTLStorageMode::Shared.0<<MTLResourceStorageModeShift;
162 #[doc(alias = "MTLResourceStorageModeManaged")]
163 const StorageModeManaged = MTLStorageMode::Managed.0<<MTLResourceStorageModeShift;
164 #[doc(alias = "MTLResourceStorageModePrivate")]
165 const StorageModePrivate = MTLStorageMode::Private.0<<MTLResourceStorageModeShift;
166 #[doc(alias = "MTLResourceStorageModeMemoryless")]
167 const StorageModeMemoryless = MTLStorageMode::Memoryless.0<<MTLResourceStorageModeShift;
168 #[doc(alias = "MTLResourceHazardTrackingModeDefault")]
169 const HazardTrackingModeDefault = MTLHazardTrackingMode::Default.0<<MTLResourceHazardTrackingModeShift;
170 #[doc(alias = "MTLResourceHazardTrackingModeUntracked")]
171 const HazardTrackingModeUntracked = MTLHazardTrackingMode::Untracked.0<<MTLResourceHazardTrackingModeShift;
172 #[doc(alias = "MTLResourceHazardTrackingModeTracked")]
173 const HazardTrackingModeTracked = MTLHazardTrackingMode::Tracked.0<<MTLResourceHazardTrackingModeShift;
174 #[doc(alias = "MTLResourceOptionCPUCacheModeDefault")]
175#[deprecated]
176 const OptionCPUCacheModeDefault = MTLResourceOptions::CPUCacheModeDefaultCache.0;
177 #[doc(alias = "MTLResourceOptionCPUCacheModeWriteCombined")]
178#[deprecated]
179 const OptionCPUCacheModeWriteCombined = MTLResourceOptions::CPUCacheModeWriteCombined.0;
180 }
181}
182
183unsafe impl Encode for MTLResourceOptions {
184 const ENCODING: Encoding = NSUInteger::ENCODING;
185}
186
187unsafe impl RefEncode for MTLResourceOptions {
188 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
189}
190
191/// Physical size of sparse resource page in KBs.
192///
193/// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtlsparsepagesize?language=objc)
194// NS_ENUM
195#[repr(transparent)]
196#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
197pub struct MTLSparsePageSize(pub NSInteger);
198impl MTLSparsePageSize {
199 #[doc(alias = "MTLSparsePageSize16")]
200 pub const Size16: Self = Self(101);
201 #[doc(alias = "MTLSparsePageSize64")]
202 pub const Size64: Self = Self(102);
203 #[doc(alias = "MTLSparsePageSize256")]
204 pub const Size256: Self = Self(103);
205}
206
207unsafe impl Encode for MTLSparsePageSize {
208 const ENCODING: Encoding = NSInteger::ENCODING;
209}
210
211unsafe impl RefEncode for MTLSparsePageSize {
212 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
213}
214
215/// Enumerates the different support levels for sparse buffers.
216///
217/// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtlbuffersparsetier?language=objc)
218// NS_ENUM
219#[repr(transparent)]
220#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
221pub struct MTLBufferSparseTier(pub NSInteger);
222impl MTLBufferSparseTier {
223 /// Indicates that the buffer is not sparse.
224 #[doc(alias = "MTLBufferSparseTierNone")]
225 pub const TierNone: Self = Self(0);
226 /// Indicates support for sparse buffers tier 1.
227 ///
228 /// Tier 1 sparse buffers allow the following:
229 /// * Partial memory backing at sparse page granularity.
230 /// * Defined behavior for accessing an *unbacked* buffer range.
231 ///
232 /// An unbacked buffer range indicates a range within the buffer that doesn't
233 /// have memory backing at a given point in time. Accessing an unbacked buffer
234 /// range of a sparse buffer produces the following results:
235 /// * Reading return zero.
236 /// * Writing produces no result.
237 #[doc(alias = "MTLBufferSparseTier1")]
238 pub const Tier1: Self = Self(1);
239}
240
241unsafe impl Encode for MTLBufferSparseTier {
242 const ENCODING: Encoding = NSInteger::ENCODING;
243}
244
245unsafe impl RefEncode for MTLBufferSparseTier {
246 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
247}
248
249/// Enumerates the different support levels for sparse textures.
250///
251/// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtltexturesparsetier?language=objc)
252// NS_ENUM
253#[repr(transparent)]
254#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
255pub struct MTLTextureSparseTier(pub NSInteger);
256impl MTLTextureSparseTier {
257 /// Indicates that the texture is not sparse.
258 #[doc(alias = "MTLTextureSparseTierNone")]
259 pub const TierNone: Self = Self(0);
260 /// Indicates support for sparse textures tier 1.
261 ///
262 /// Tier 1 sparse textures allow the following:
263 /// * Partial memory backing at sparse tile granularity.
264 /// * Defined behavior for accessing an unbacked texture region.
265 /// * Shader feedback on texture access to determine memory backing.
266 ///
267 /// An unbacked texture region indicates a region within the texture that doesn't
268 /// have memory backing at a given point in time. Accessing an unbacked texture
269 /// region produces the following results:
270 /// * Reading returns zero (transparent black) for pixel formats with an alpha (A) channel.
271 /// * Reading return zero in RGB and one in alpha (A) channels (opaque black) otherwise.
272 /// * Writing produces no result.
273 #[doc(alias = "MTLTextureSparseTier1")]
274 pub const Tier1: Self = Self(1);
275 /// Indicates support for sparse textures tier 2.
276 ///
277 /// In addition to the guarantees tier 1 sparse textures provide,
278 /// tier 2 sparse textures allow the following:
279 /// * Obtain per-tile activity counters.
280 #[doc(alias = "MTLTextureSparseTier2")]
281 pub const Tier2: Self = Self(2);
282}
283
284unsafe impl Encode for MTLTextureSparseTier {
285 const ENCODING: Encoding = NSInteger::ENCODING;
286}
287
288unsafe impl RefEncode for MTLTextureSparseTier {
289 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
290}
291
292extern_protocol!(
293 /// Common APIs available for MTLBuffer and MTLTexture instances
294 ///
295 /// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtlresource?language=objc)
296 #[cfg(feature = "MTLAllocation")]
297 pub unsafe trait MTLResource: MTLAllocation {
298 /// A string to help identify this object.
299 #[unsafe(method(label))]
300 #[unsafe(method_family = none)]
301 fn label(&self) -> Option<Retained<NSString>>;
302
303 /// Setter for [`label`][Self::label].
304 ///
305 /// This is [copied][objc2_foundation::NSCopying::copy] when set.
306 #[unsafe(method(setLabel:))]
307 #[unsafe(method_family = none)]
308 fn setLabel(&self, label: Option<&NSString>);
309
310 #[cfg(feature = "MTLDevice")]
311 /// The device this resource was created against. This resource can only be used with this device.
312 #[unsafe(method(device))]
313 #[unsafe(method_family = none)]
314 fn device(&self) -> Retained<ProtocolObject<dyn MTLDevice>>;
315
316 /// The cache mode used for the CPU mapping for this resource
317 #[unsafe(method(cpuCacheMode))]
318 #[unsafe(method_family = none)]
319 fn cpuCacheMode(&self) -> MTLCPUCacheMode;
320
321 /// The resource storage mode used for the CPU mapping for this resource
322 #[unsafe(method(storageMode))]
323 #[unsafe(method_family = none)]
324 fn storageMode(&self) -> MTLStorageMode;
325
326 /// Whether or not the resource is hazard tracked.
327 ///
328 /// This value can be either MTLHazardTrackingModeUntracked or MTLHazardTrackingModeTracked.
329 /// Resources created from heaps are by default untracked, whereas resources created from the device are by default tracked.
330 #[unsafe(method(hazardTrackingMode))]
331 #[unsafe(method_family = none)]
332 fn hazardTrackingMode(&self) -> MTLHazardTrackingMode;
333
334 /// A packed tuple of the storageMode, cpuCacheMode and hazardTrackingMode properties.
335 #[unsafe(method(resourceOptions))]
336 #[unsafe(method_family = none)]
337 fn resourceOptions(&self) -> MTLResourceOptions;
338
339 /// Set (or query) the purgeability state of a resource
340 ///
341 /// Synchronously set the purgeability state of a resource and return what the prior (or current) state is.
342 /// FIXME: If the device is keeping a cached copy of the resource, both the shared copy and cached copy are made purgeable. Any access to the resource by either the CPU or device will be undefined.
343 #[unsafe(method(setPurgeableState:))]
344 #[unsafe(method_family = none)]
345 fn setPurgeableState(&self, state: MTLPurgeableState) -> MTLPurgeableState;
346
347 #[cfg(feature = "MTLHeap")]
348 /// The heap from which this resouce was created.
349 ///
350 /// Nil when this resource is not backed by a heap.
351 #[unsafe(method(heap))]
352 #[unsafe(method_family = none)]
353 fn heap(&self) -> Option<Retained<ProtocolObject<dyn MTLHeap>>>;
354
355 /// The offset inside the heap at which this resource was created.
356 ///
357 /// Zero when this resource was not created on a heap with MTLHeapTypePlacement.
358 #[unsafe(method(heapOffset))]
359 #[unsafe(method_family = none)]
360 fn heapOffset(&self) -> NSUInteger;
361
362 /// The size in bytes occupied by this resource
363 #[unsafe(method(allocatedSize))]
364 #[unsafe(method_family = none)]
365 fn allocatedSize(&self) -> NSUInteger;
366
367 /// Allow future heap sub-allocations to alias against this resource's memory.
368 ///
369 /// It is illegal to call this method on a non heap-based resource.
370 /// It is also illegal to call this method on texture views created from heap-based textures.
371 /// The debug layer will raise an exception. Calling this method on textures sub-allocated
372 /// from Buffers backed by heap memory has no effect.
373 /// Once a resource is made aliasable, the decision cannot be reverted.
374 #[unsafe(method(makeAliasable))]
375 #[unsafe(method_family = none)]
376 unsafe fn makeAliasable(&self);
377
378 /// Returns whether future heap sub-allocations may alias against this resource's memory.
379 ///
380 /// Returns: YES if
381 /// <st
382 /// >makeAliasable
383 /// </st
384 /// > was previously successfully called on this resource. NO otherwise.
385 /// If resource is sub-allocated from other resource created on the heap, isAliasable returns
386 /// aliasing state of that base resource. Also returns NO when storage mode is memoryless.
387 #[unsafe(method(isAliasable))]
388 #[unsafe(method_family = none)]
389 fn isAliasable(&self) -> bool;
390 }
391);