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