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
305
306
307
308
309
use core::{ffi::c_void, ptr::NonNull};
use objc2::{extern_protocol, rc::Retained, runtime::ProtocolObject};
use objc2_foundation::{NSObjectProtocol, NSRange, NSString};
use crate::{
MTLAccelerationStructure, MTLBuffer, MTLComputePipelineState, MTLDepthStencilState, MTLDevice,
MTLIndirectCommandBuffer, MTLRenderPipelineState, MTLSamplerState, MTLTexture,
};
/// When calling functions with an `attributeStrides:` parameter on a render
/// or compute command encoder, this value must be provided for the binding
/// points that are either not part of the set of MTLBufferLayoutDescriptor,
/// or whose stride values in the descriptor is not set to
/// `MTLBufferLayoutStrideDynamic`
pub const MTL_ATTRIBUTE_STRIDE_STATIC: usize = usize::MAX;
extern_protocol!(
/// Encodes buffer, texture, sampler, pipeline, indirect command buffer,
/// acceleration structure, and constant data into a buffer.
///
/// Availability: macOS 10.13+, iOS 11.0+
pub unsafe trait MTLArgumentEncoder: NSObjectProtocol {
/// The device this argument encoder was created against.
#[unsafe(method(device))]
#[unsafe(method_family = none)]
fn device(&self) -> Retained<ProtocolObject<dyn MTLDevice>>;
/// A string to help identify this object.
#[unsafe(method(label))]
#[unsafe(method_family = none)]
fn label(&self) -> Option<Retained<NSString>>;
/// Setter for `label`.
#[unsafe(method(setLabel:))]
#[unsafe(method_family = none)]
fn set_label(
&self,
label: Option<&NSString>,
);
/// The number of bytes required to store the encoded resource bindings.
#[unsafe(method(encodedLength))]
#[unsafe(method_family = none)]
fn encoded_length(&self) -> usize;
/// The alignment in bytes required to store the encoded resource bindings.
#[unsafe(method(alignment))]
#[unsafe(method_family = none)]
fn alignment(&self) -> usize;
/// Sets the destination buffer and offset at which the arguments will be encoded.
#[unsafe(method(setArgumentBuffer:offset:))]
#[unsafe(method_family = none)]
fn set_argument_buffer(
&self,
argument_buffer: Option<&ProtocolObject<dyn MTLBuffer>>,
offset: usize,
);
/// Sets the destination buffer, starting offset and specific array element
/// that arguments will be encoded into.
#[unsafe(method(setArgumentBuffer:startOffset:arrayElement:))]
#[unsafe(method_family = none)]
fn set_argument_buffer_with_array_element(
&self,
argument_buffer: Option<&ProtocolObject<dyn MTLBuffer>>,
start_offset: usize,
array_element: usize,
);
/// Set a buffer at the given bind point index.
#[unsafe(method(setBuffer:offset:atIndex:))]
#[unsafe(method_family = none)]
fn set_buffer(
&self,
buffer: Option<&ProtocolObject<dyn MTLBuffer>>,
offset: usize,
index: usize,
);
/// Set an array of buffers at the given bind point index range.
///
/// Safety: `buffers` and `offsets` must be valid pointers.
#[unsafe(method(setBuffers:offsets:withRange:))]
#[unsafe(method_family = none)]
fn set_buffers(
&self,
buffers: NonNull<*const ProtocolObject<dyn MTLBuffer>>,
offsets: NonNull<usize>,
range: NSRange,
);
/// Set a texture at the given bind point index.
#[unsafe(method(setTexture:atIndex:))]
#[unsafe(method_family = none)]
fn set_texture(
&self,
texture: Option<&ProtocolObject<dyn MTLTexture>>,
index: usize,
);
/// Set an array of textures at the given bind point index range.
///
/// Safety: `textures` must be a valid pointer.
#[unsafe(method(setTextures:withRange:))]
#[unsafe(method_family = none)]
fn set_textures(
&self,
textures: NonNull<*const ProtocolObject<dyn MTLTexture>>,
range: NSRange,
);
/// Set a sampler at the given bind point index.
#[unsafe(method(setSamplerState:atIndex:))]
#[unsafe(method_family = none)]
fn set_sampler_state(
&self,
sampler: Option<&ProtocolObject<dyn MTLSamplerState>>,
index: usize,
);
/// Set an array of samplers at the given bind point index range.
///
/// Safety: `samplers` must be a valid pointer.
#[unsafe(method(setSamplerStates:withRange:))]
#[unsafe(method_family = none)]
fn set_sampler_states(
&self,
samplers: NonNull<*const ProtocolObject<dyn MTLSamplerState>>,
range: NSRange,
);
/// Returns a pointer to the constant data at the given bind point index.
///
/// Safety: The returned pointer is only valid as long as the encoder and
/// backing storage are alive.
#[unsafe(method(constantDataAtIndex:))]
#[unsafe(method_family = none)]
fn constant_data_at_index(
&self,
index: usize,
) -> NonNull<c_void>;
/// Sets a render pipeline state at a given bind point index.
///
/// Availability: macOS 10.14+, iOS 13.0+
#[unsafe(method(setRenderPipelineState:atIndex:))]
#[unsafe(method_family = none)]
fn set_render_pipeline_state(
&self,
pipeline: Option<&ProtocolObject<dyn MTLRenderPipelineState>>,
index: usize,
);
/// Set an array of render pipeline states at a given bind point index range.
///
/// Safety: `pipelines` must be a valid pointer.
///
/// Availability: macOS 10.14+, iOS 13.0+
#[unsafe(method(setRenderPipelineStates:withRange:))]
#[unsafe(method_family = none)]
fn set_render_pipeline_states(
&self,
pipelines: NonNull<*const ProtocolObject<dyn MTLRenderPipelineState>>,
range: NSRange,
);
/// Sets a compute pipeline state at a given bind point index.
///
/// Availability: macOS 11.0+, iOS 13.0+
#[unsafe(method(setComputePipelineState:atIndex:))]
#[unsafe(method_family = none)]
fn set_compute_pipeline_state(
&self,
pipeline: Option<&ProtocolObject<dyn MTLComputePipelineState>>,
index: usize,
);
/// Set an array of compute pipeline states at a given bind point index range.
///
/// Safety: `pipelines` must be a valid pointer.
///
/// Availability: macOS 11.0+, iOS 13.0+
#[unsafe(method(setComputePipelineStates:withRange:))]
#[unsafe(method_family = none)]
fn set_compute_pipeline_states(
&self,
pipelines: NonNull<*const ProtocolObject<dyn MTLComputePipelineState>>,
range: NSRange,
);
/// Sets an indirect command buffer at a given bind point index.
///
/// Availability: macOS 10.14+, iOS 12.0+
#[unsafe(method(setIndirectCommandBuffer:atIndex:))]
#[unsafe(method_family = none)]
fn set_indirect_command_buffer(
&self,
indirect_command_buffer: Option<&ProtocolObject<dyn MTLIndirectCommandBuffer>>,
index: usize,
);
/// Set an array of indirect command buffers at the given bind point index range.
///
/// Safety: `buffers` must be a valid pointer.
///
/// Availability: macOS 10.14+, iOS 12.0+
#[unsafe(method(setIndirectCommandBuffers:withRange:))]
#[unsafe(method_family = none)]
fn set_indirect_command_buffers(
&self,
buffers: NonNull<*const ProtocolObject<dyn MTLIndirectCommandBuffer>>,
range: NSRange,
);
/// Sets an acceleration structure at a given bind point index.
///
/// Availability: macOS 11.0+, iOS 14.0+, tvOS 16.0+
#[unsafe(method(setAccelerationStructure:atIndex:))]
#[unsafe(method_family = none)]
fn set_acceleration_structure(
&self,
acceleration_structure: Option<&ProtocolObject<dyn MTLAccelerationStructure>>,
index: usize,
);
/// Returns a new argument encoder for an argument buffer bound at `index`.
/// Returns `None` if the resource at `index` is not an argument buffer.
#[unsafe(method(newArgumentEncoderForBufferAtIndex:))]
#[unsafe(method_family = new)]
fn new_argument_encoder_for_buffer_at_index(
&self,
index: usize,
) -> Option<Retained<ProtocolObject<dyn super::MTLArgumentEncoder>>>;
/// Set a visible function table at the given buffer index.
///
/// Availability: macOS 11.0+, iOS 14.0+, tvOS 16.0+
#[unsafe(method(setVisibleFunctionTable:atIndex:))]
#[unsafe(method_family = none)]
fn set_visible_function_table(
&self,
visible_function_table: Option<&ProtocolObject<dyn crate::MTLVisibleFunctionTable>>,
index: usize,
);
/// Set visible function tables at the given buffer index range.
///
/// Safety: `visible_function_tables` must be a valid pointer.
///
/// Availability: macOS 11.0+, iOS 14.0+, tvOS 16.0+
#[unsafe(method(setVisibleFunctionTables:withRange:))]
#[unsafe(method_family = none)]
fn set_visible_function_tables(
&self,
visible_function_tables: NonNull<*const ProtocolObject<dyn crate::MTLVisibleFunctionTable>>,
range: NSRange,
);
/// Set an intersection function table at the given buffer index.
///
/// Availability: macOS 11.0+, iOS 14.0+, tvOS 16.0+
#[unsafe(method(setIntersectionFunctionTable:atIndex:))]
#[unsafe(method_family = none)]
fn set_intersection_function_table(
&self,
intersection_function_table: Option<&ProtocolObject<dyn crate::MTLIntersectionFunctionTable>>,
index: usize,
);
/// Set intersection function tables at the given buffer index range.
///
/// Safety: `intersection_function_tables` must be a valid pointer.
///
/// Availability: macOS 11.0+, iOS 14.0+, tvOS 16.0+
#[unsafe(method(setIntersectionFunctionTables:withRange:))]
#[unsafe(method_family = none)]
fn set_intersection_function_tables(
&self,
intersection_function_tables: NonNull<*const ProtocolObject<dyn crate::MTLIntersectionFunctionTable>>,
range: NSRange,
);
/// Sets a depth stencil state at a given bind point index.
///
/// Availability: macOS 26.0+, iOS 26.0+
#[unsafe(method(setDepthStencilState:atIndex:))]
#[unsafe(method_family = none)]
fn set_depth_stencil_state(
&self,
depth_stencil_state: Option<&ProtocolObject<dyn MTLDepthStencilState>>,
index: usize,
);
/// Sets an array of depth stencil states at a given buffer index range.
///
/// Safety: `depth_stencil_states` must be a valid pointer.
///
/// Availability: macOS 26.0+, iOS 26.0+
#[unsafe(method(setDepthStencilStates:withRange:))]
#[unsafe(method_family = none)]
fn set_depth_stencil_states(
&self,
depth_stencil_states: NonNull<*const ProtocolObject<dyn MTLDepthStencilState>>,
range: NSRange,
);
}
);