objc2_metal/generated/MTLIOCommandQueue.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/// [Apple's documentation](https://developer.apple.com/documentation/metal/mtliopriority?language=objc)
11// NS_ENUM
12#[repr(transparent)]
13#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
14pub struct MTLIOPriority(pub NSInteger);
15impl MTLIOPriority {
16 #[doc(alias = "MTLIOPriorityHigh")]
17 pub const High: Self = Self(0);
18 #[doc(alias = "MTLIOPriorityNormal")]
19 pub const Normal: Self = Self(1);
20 #[doc(alias = "MTLIOPriorityLow")]
21 pub const Low: Self = Self(2);
22}
23
24unsafe impl Encode for MTLIOPriority {
25 const ENCODING: Encoding = NSInteger::ENCODING;
26}
27
28unsafe impl RefEncode for MTLIOPriority {
29 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
30}
31
32/// [Apple's documentation](https://developer.apple.com/documentation/metal/mtliocommandqueuetype?language=objc)
33// NS_ENUM
34#[repr(transparent)]
35#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
36pub struct MTLIOCommandQueueType(pub NSInteger);
37impl MTLIOCommandQueueType {
38 #[doc(alias = "MTLIOCommandQueueTypeConcurrent")]
39 pub const Concurrent: Self = Self(0);
40 #[doc(alias = "MTLIOCommandQueueTypeSerial")]
41 pub const Serial: Self = Self(1);
42}
43
44unsafe impl Encode for MTLIOCommandQueueType {
45 const ENCODING: Encoding = NSInteger::ENCODING;
46}
47
48unsafe impl RefEncode for MTLIOCommandQueueType {
49 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
50}
51
52extern "C" {
53 /// [Apple's documentation](https://developer.apple.com/documentation/metal/mtlioerrordomain?language=objc)
54 pub static MTLIOErrorDomain: &'static NSErrorDomain;
55}
56
57/// [Apple's documentation](https://developer.apple.com/documentation/metal/mtlioerror?language=objc)
58// NS_ERROR_ENUM
59#[repr(transparent)]
60#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
61pub struct MTLIOError(pub NSInteger);
62impl MTLIOError {
63 #[doc(alias = "MTLIOErrorURLInvalid")]
64 pub const URLInvalid: Self = Self(1);
65 #[doc(alias = "MTLIOErrorInternal")]
66 pub const Internal: Self = Self(2);
67}
68
69unsafe impl Encode for MTLIOError {
70 const ENCODING: Encoding = NSInteger::ENCODING;
71}
72
73unsafe impl RefEncode for MTLIOError {
74 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
75}
76
77extern_protocol!(
78 /// Represents a queue that schedules command buffers containing command that
79 /// read from handle objects and write to MTLResource objects.
80 ///
81 /// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtliocommandqueue?language=objc)
82 pub unsafe trait MTLIOCommandQueue: NSObjectProtocol + Send + Sync {
83 /// Inserts a barrier that ensures that all commandBuffers commited
84 /// prior are completed before any commandBuffers after start execution.
85 ///
86 /// A serial commandQueue has implicit barriers between
87 /// each commandBuffer.
88 #[unsafe(method(enqueueBarrier))]
89 #[unsafe(method_family = none)]
90 fn enqueueBarrier(&self);
91
92 #[cfg(feature = "MTLIOCommandBuffer")]
93 /// Vends an autoreleased commandBuffer that can be used to
94 /// encode commands that read from handle objects and write to MTLResource objects.
95 #[unsafe(method(commandBuffer))]
96 #[unsafe(method_family = none)]
97 fn commandBuffer(&self) -> Retained<ProtocolObject<dyn MTLIOCommandBuffer>>;
98
99 #[cfg(feature = "MTLIOCommandBuffer")]
100 /// Vends an autoreleased commandBuffer that can be used to
101 /// encode commands that read from handle objects and write to MTLResource objects.
102 /// This commandBuffer does not retain objects referenced by the commandBuffer
103 /// as an optimization.
104 ///
105 /// For correct execution its the application's responsibility to retain
106 /// objects referenced by commands within the commandBuffer.
107 #[unsafe(method(commandBufferWithUnretainedReferences))]
108 #[unsafe(method_family = none)]
109 fn commandBufferWithUnretainedReferences(
110 &self,
111 ) -> Retained<ProtocolObject<dyn MTLIOCommandBuffer>>;
112
113 /// An optional label for this handle.
114 #[unsafe(method(label))]
115 #[unsafe(method_family = none)]
116 fn label(&self) -> Option<Retained<NSString>>;
117
118 /// Setter for [`label`][Self::label].
119 ///
120 /// This is [copied][objc2_foundation::NSCopying::copy] when set.
121 #[unsafe(method(setLabel:))]
122 #[unsafe(method_family = none)]
123 fn setLabel(&self, label: Option<&NSString>);
124 }
125);
126
127extern_protocol!(
128 /// An extendible protocol that can be used to wrap the buffers vended by
129 /// a custom allocator. The underlying buffer is used as scratch space for IO commands
130 /// that need it.
131 ///
132 /// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtlioscratchbuffer?language=objc)
133 pub unsafe trait MTLIOScratchBuffer: NSObjectProtocol {
134 #[cfg(all(
135 feature = "MTLAllocation",
136 feature = "MTLBuffer",
137 feature = "MTLResource"
138 ))]
139 #[unsafe(method(buffer))]
140 #[unsafe(method_family = none)]
141 fn buffer(&self) -> Retained<ProtocolObject<dyn MTLBuffer>>;
142 }
143);
144
145extern_protocol!(
146 /// An extendible protocol that can implement a custom allocator passed
147 /// to the queue descriptor.
148 ///
149 /// If provided, the queue will call newScratchBufferWithMinimumSize
150 /// when it needs scratch storage for IO commands. When the commands that use the memory
151 /// complete they return the storage by dealloc'ing the MTLIOScratchBuffer objects (where
152 /// the application can optionally pool the memory for use by future commands.
153 ///
154 /// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtlioscratchbufferallocator?language=objc)
155 pub unsafe trait MTLIOScratchBufferAllocator: NSObjectProtocol {
156 /// This method is called when additional scratch memory is required by a load command.
157 /// The scratch buffer returned should NOT be an autoreleased object.
158 ///
159 /// Scratch memory is needed for cases where a texture is being copied to. minimumSize
160 /// is the smallest buffer that will allow the command to execute, however a larger buffer can be provided and
161 /// susequent commands will be able to use it, thus avoiding the need for an additional callback. Returning nil
162 /// from the function will result in the load command being skipped and the commandBuffer getting cancelled.
163 ///
164 /// # Safety
165 ///
166 /// `minimumSize` might not be bounds-checked.
167 #[unsafe(method(newScratchBufferWithMinimumSize:))]
168 #[unsafe(method_family = new)]
169 unsafe fn newScratchBufferWithMinimumSize(
170 &self,
171 minimum_size: NSUInteger,
172 ) -> Option<Retained<ProtocolObject<dyn MTLIOScratchBuffer>>>;
173 }
174);
175
176extern_class!(
177 /// Represents a descriptor to create a MTLIOCommandQueue.
178 ///
179 /// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtliocommandqueuedescriptor?language=objc)
180 #[unsafe(super(NSObject))]
181 #[derive(Debug, PartialEq, Eq, Hash)]
182 pub struct MTLIOCommandQueueDescriptor;
183);
184
185extern_conformance!(
186 unsafe impl NSCopying for MTLIOCommandQueueDescriptor {}
187);
188
189unsafe impl CopyingHelper for MTLIOCommandQueueDescriptor {
190 type Result = Self;
191}
192
193extern_conformance!(
194 unsafe impl NSObjectProtocol for MTLIOCommandQueueDescriptor {}
195);
196
197impl MTLIOCommandQueueDescriptor {
198 extern_methods!(
199 /// The maximum number of commandBuffers that can be in flight at a given time for the queue.
200 #[unsafe(method(maxCommandBufferCount))]
201 #[unsafe(method_family = none)]
202 pub fn maxCommandBufferCount(&self) -> NSUInteger;
203
204 /// Setter for [`maxCommandBufferCount`][Self::maxCommandBufferCount].
205 ///
206 /// # Safety
207 ///
208 /// This might not be bounds-checked.
209 #[unsafe(method(setMaxCommandBufferCount:))]
210 #[unsafe(method_family = none)]
211 pub unsafe fn setMaxCommandBufferCount(&self, max_command_buffer_count: NSUInteger);
212
213 /// The priority of the commands executed by this queue.
214 #[unsafe(method(priority))]
215 #[unsafe(method_family = none)]
216 pub fn priority(&self) -> MTLIOPriority;
217
218 /// Setter for [`priority`][Self::priority].
219 #[unsafe(method(setPriority:))]
220 #[unsafe(method_family = none)]
221 pub fn setPriority(&self, priority: MTLIOPriority);
222
223 /// The type (serial or concurrent) of the queue.
224 #[unsafe(method(type))]
225 #[unsafe(method_family = none)]
226 pub fn r#type(&self) -> MTLIOCommandQueueType;
227
228 /// Setter for [`type`][Self::type].
229 #[unsafe(method(setType:))]
230 #[unsafe(method_family = none)]
231 pub fn setType(&self, r#type: MTLIOCommandQueueType);
232
233 /// The maximum number of IO commands that can be in flight at a given time for the queue.
234 ///
235 /// A zero value defaults to the system dependent maximum value, a smaller number can be
236 /// provided to bound the utilization of the storage device.
237 #[unsafe(method(maxCommandsInFlight))]
238 #[unsafe(method_family = none)]
239 pub fn maxCommandsInFlight(&self) -> NSUInteger;
240
241 /// Setter for [`maxCommandsInFlight`][Self::maxCommandsInFlight].
242 #[unsafe(method(setMaxCommandsInFlight:))]
243 #[unsafe(method_family = none)]
244 pub fn setMaxCommandsInFlight(&self, max_commands_in_flight: NSUInteger);
245
246 /// An optional property that allows setting a custom allocator for scratch buffers by the queue.
247 ///
248 /// An application can manage scratch buffers manually by implemeting a class conforming
249 /// to the MTLIOScratchBufferAllocator protocol and creating an instance that is passed in here.
250 #[unsafe(method(scratchBufferAllocator))]
251 #[unsafe(method_family = none)]
252 pub fn scratchBufferAllocator(
253 &self,
254 ) -> Option<Retained<ProtocolObject<dyn MTLIOScratchBufferAllocator>>>;
255
256 /// Setter for [`scratchBufferAllocator`][Self::scratchBufferAllocator].
257 #[unsafe(method(setScratchBufferAllocator:))]
258 #[unsafe(method_family = none)]
259 pub fn setScratchBufferAllocator(
260 &self,
261 scratch_buffer_allocator: Option<&ProtocolObject<dyn MTLIOScratchBufferAllocator>>,
262 );
263 );
264}
265
266/// Methods declared on superclass `NSObject`.
267impl MTLIOCommandQueueDescriptor {
268 extern_methods!(
269 #[unsafe(method(init))]
270 #[unsafe(method_family = init)]
271 pub fn init(this: Allocated<Self>) -> Retained<Self>;
272
273 #[unsafe(method(new))]
274 #[unsafe(method_family = new)]
275 pub fn new() -> Retained<Self>;
276 );
277}
278
279impl DefaultRetained for MTLIOCommandQueueDescriptor {
280 #[inline]
281 fn default_retained() -> Retained<Self> {
282 Self::new()
283 }
284}
285
286extern_protocol!(
287 /// Represents a file (raw or compressed) that can be used as a source
288 /// for load commands encoded in a MTLIOCommandBuffer.
289 ///
290 /// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtliofilehandle?language=objc)
291 pub unsafe trait MTLIOFileHandle: NSObjectProtocol + Send + Sync {
292 /// An optional label for this handle.
293 #[unsafe(method(label))]
294 #[unsafe(method_family = none)]
295 fn label(&self) -> Option<Retained<NSString>>;
296
297 /// Setter for [`label`][Self::label].
298 ///
299 /// This is [copied][objc2_foundation::NSCopying::copy] when set.
300 #[unsafe(method(setLabel:))]
301 #[unsafe(method_family = none)]
302 fn setLabel(&self, label: Option<&NSString>);
303 }
304);