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
//! 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/mtliostatus?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct MTLIOStatus(pub NSInteger);
impl MTLIOStatus {
#[doc(alias = "MTLIOStatusPending")]
pub const Pending: Self = Self(0);
#[doc(alias = "MTLIOStatusCancelled")]
pub const Cancelled: Self = Self(1);
#[doc(alias = "MTLIOStatusError")]
pub const Error: Self = Self(2);
#[doc(alias = "MTLIOStatusComplete")]
pub const Complete: Self = Self(3);
}
unsafe impl Encode for MTLIOStatus {
const ENCODING: Encoding = NSInteger::ENCODING;
}
unsafe impl RefEncode for MTLIOStatus {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
/// [Apple's documentation](https://developer.apple.com/documentation/metal/mtliocommandbufferhandler?language=objc)
#[cfg(feature = "block2")]
pub type MTLIOCommandBufferHandler =
*mut block2::DynBlock<dyn Fn(NonNull<ProtocolObject<dyn MTLIOCommandBuffer>>)>;
extern_protocol!(
/// represents a list of IO commands for a queue to execute
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtliocommandbuffer?language=objc)
pub unsafe trait MTLIOCommandBuffer: NSObjectProtocol {
#[cfg(feature = "block2")]
/// Add a block to be called when this command buffer has completed execution.
///
/// # Safety
///
/// `block` must be a valid pointer.
#[unsafe(method(addCompletedHandler:))]
#[unsafe(method_family = none)]
unsafe fn addCompletedHandler(&self, block: MTLIOCommandBufferHandler);
#[cfg(feature = "MTLIOCommandQueue")]
/// Encodes a command that loads from a handle
/// and offset into a memory location.
///
/// # Safety
///
/// - `pointer` must be a valid pointer.
/// - `size` might not be bounds-checked.
/// - `sourceHandleOffset` might not be bounds-checked.
#[unsafe(method(loadBytes:size:sourceHandle:sourceHandleOffset:))]
#[unsafe(method_family = none)]
unsafe fn loadBytes_size_sourceHandle_sourceHandleOffset(
&self,
pointer: NonNull<c_void>,
size: NSUInteger,
source_handle: &ProtocolObject<dyn MTLIOFileHandle>,
source_handle_offset: NSUInteger,
);
#[cfg(all(
feature = "MTLAllocation",
feature = "MTLBuffer",
feature = "MTLIOCommandQueue",
feature = "MTLResource"
))]
/// Encodes a command that loads from a handle
/// and offset into a buffer and an offset.
///
/// # Safety
///
/// - `buffer` may need to be synchronized.
/// - `buffer` may be unretained, you must ensure it is kept alive while in use.
/// - `buffer` contents should be of the correct type.
/// - `offset` might not be bounds-checked.
/// - `size` might not be bounds-checked.
/// - `sourceHandleOffset` might not be bounds-checked.
#[unsafe(method(loadBuffer:offset:size:sourceHandle:sourceHandleOffset:))]
#[unsafe(method_family = none)]
unsafe fn loadBuffer_offset_size_sourceHandle_sourceHandleOffset(
&self,
buffer: &ProtocolObject<dyn MTLBuffer>,
offset: NSUInteger,
size: NSUInteger,
source_handle: &ProtocolObject<dyn MTLIOFileHandle>,
source_handle_offset: NSUInteger,
);
#[cfg(all(
feature = "MTLAllocation",
feature = "MTLIOCommandQueue",
feature = "MTLResource",
feature = "MTLTexture",
feature = "MTLTypes"
))]
/// Encodes a command that loads a region from a handle
/// and offset into a texture at a given slice, level and origin.
///
/// # Safety
///
/// - `texture` may need to be synchronized.
/// - `texture` may be unretained, you must ensure it is kept alive while in use.
/// - `size` might not be bounds-checked.
/// - `sourceHandleOffset` might not be bounds-checked.
#[unsafe(method(loadTexture:slice:level:size:sourceBytesPerRow:sourceBytesPerImage:destinationOrigin:sourceHandle:sourceHandleOffset:))]
#[unsafe(method_family = none)]
unsafe fn loadTexture_slice_level_size_sourceBytesPerRow_sourceBytesPerImage_destinationOrigin_sourceHandle_sourceHandleOffset(
&self,
texture: &ProtocolObject<dyn MTLTexture>,
slice: NSUInteger,
level: NSUInteger,
size: MTLSize,
source_bytes_per_row: NSUInteger,
source_bytes_per_image: NSUInteger,
destination_origin: MTLOrigin,
source_handle: &ProtocolObject<dyn MTLIOFileHandle>,
source_handle_offset: NSUInteger,
);
#[cfg(all(
feature = "MTLAllocation",
feature = "MTLBuffer",
feature = "MTLResource"
))]
/// Encodes a command that writes the status of this commandBuffer upon completion
/// to a buffer at a given offset
///
/// # Safety
///
/// - `buffer` may need to be synchronized.
/// - `buffer` may be unretained, you must ensure it is kept alive while in use.
/// - `buffer` contents should be of the correct type.
/// - `offset` might not be bounds-checked.
#[unsafe(method(copyStatusToBuffer:offset:))]
#[unsafe(method_family = none)]
unsafe fn copyStatusToBuffer_offset(
&self,
buffer: &ProtocolObject<dyn MTLBuffer>,
offset: NSUInteger,
);
/// Commit a command buffer so it can be executed as soon as possible.
#[unsafe(method(commit))]
#[unsafe(method_family = none)]
fn commit(&self);
/// Synchronously wait for this command buffer to complete.
#[unsafe(method(waitUntilCompleted))]
#[unsafe(method_family = none)]
fn waitUntilCompleted(&self);
/// request a cancellation of an in-flight command buffer.
#[unsafe(method(tryCancel))]
#[unsafe(method_family = none)]
fn tryCancel(&self);
/// add a barrier that starts subsequent commands after all
/// the previously encoded commands have completed.
#[unsafe(method(addBarrier))]
#[unsafe(method_family = none)]
fn addBarrier(&self);
/// Push a new named string onto a stack of string labels.
#[unsafe(method(pushDebugGroup:))]
#[unsafe(method_family = none)]
fn pushDebugGroup(&self, string: &NSString);
/// Pop the latest named string off of the stack.
#[unsafe(method(popDebugGroup))]
#[unsafe(method_family = none)]
fn popDebugGroup(&self);
/// Append this command buffer to the end of its MTLCommandQueue.
#[unsafe(method(enqueue))]
#[unsafe(method_family = none)]
fn enqueue(&self);
#[cfg(feature = "MTLEvent")]
/// Encodes a command that pauses execution of this command buffer until the specified event reaches a given value.
#[unsafe(method(waitForEvent:value:))]
#[unsafe(method_family = none)]
fn waitForEvent_value(&self, event: &ProtocolObject<dyn MTLSharedEvent>, value: u64);
#[cfg(feature = "MTLEvent")]
/// Encodes a command that signals an event with a given value.
#[unsafe(method(signalEvent:value:))]
#[unsafe(method_family = none)]
fn signalEvent_value(&self, event: &ProtocolObject<dyn MTLSharedEvent>, value: u64);
/// 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>);
/// status reports the completion status of the MTLIOCommandBuffer, pending, cancelled, error or complete.
#[unsafe(method(status))]
#[unsafe(method_family = none)]
fn status(&self) -> MTLIOStatus;
/// If an error occurred during execution, the NSError may contain more details about the problem.
#[unsafe(method(error))]
#[unsafe(method_family = none)]
fn error(&self) -> Option<Retained<NSError>>;
}
);