objc2_metal_performance_shaders/generated/MPSMatrix/MPSMatrixCombination.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::*;
7use objc2_metal::*;
8
9use crate::*;
10
11/// A description of each copy operation
12///
13/// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpsmatrixcopyoffsets?language=objc)
14#[repr(C)]
15#[derive(Clone, Copy, Debug, PartialEq)]
16pub struct MPSMatrixCopyOffsets {
17 /// offset to start of source region to read in rows
18 pub sourceRowOffset: u32,
19 /// offset to start of source region to read in columns
20 pub sourceColumnOffset: u32,
21 /// offset to start of destination region to read in rows
22 pub destinationRowOffset: u32,
23 /// offset to start of destination region to read in columns
24 pub destinationColumnOffset: u32,
25}
26
27unsafe impl Encode for MPSMatrixCopyOffsets {
28 const ENCODING: Encoding = Encoding::Struct(
29 "?",
30 &[
31 <u32>::ENCODING,
32 <u32>::ENCODING,
33 <u32>::ENCODING,
34 <u32>::ENCODING,
35 ],
36 );
37}
38
39unsafe impl RefEncode for MPSMatrixCopyOffsets {
40 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
41}
42
43extern_class!(
44 /// A list of copy operations
45 ///
46 /// The MPSMatrixCopy filter can do multiple copy operations. For RNN filters, these
47 /// copies are often small, and are more efficient when grouped together.
48 /// The MPSMatriceCopyDescriptor provides a container to list the operations.
49 /// The operations occur in any order, and may not alias.
50 ///
51 /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpsmatrixcopydescriptor?language=objc)
52 #[unsafe(super(NSObject))]
53 #[derive(Debug, PartialEq, Eq, Hash)]
54 pub struct MPSMatrixCopyDescriptor;
55);
56
57extern_conformance!(
58 unsafe impl NSObjectProtocol for MPSMatrixCopyDescriptor {}
59);
60
61impl MPSMatrixCopyDescriptor {
62 extern_methods!(
63 #[cfg(feature = "MPSCore")]
64 /// convenience allocator for single copies
65 #[unsafe(method(descriptorWithSourceMatrix:destinationMatrix:offsets:))]
66 #[unsafe(method_family = none)]
67 pub unsafe fn descriptorWithSourceMatrix_destinationMatrix_offsets(
68 source_matrix: &MPSMatrix,
69 destination_matrix: &MPSMatrix,
70 offsets: MPSMatrixCopyOffsets,
71 ) -> Retained<Self>;
72
73 /// initialize a MPSMatrixCopyDescriptor with default values.
74 ///
75 /// Use -setCopyOperationAtIndex:sourceMatrix:destinationMatrix:copyOffsets
76 /// to initialize. All indices must be initialized before use.
77 ///
78 /// Parameter `device`: The device on which the copy will be performed
79 ///
80 /// Parameter `count`: The number of copy operations the object will encode
81 ///
82 /// Returns: A MPSMatrixCopyDescriptor. It still needs to be initialized with
83 /// -setCopyOperationAtIndex:sourceMatrix:destinationMatrix:copyOffsets
84 #[unsafe(method(initWithDevice:count:))]
85 #[unsafe(method_family = init)]
86 pub unsafe fn initWithDevice_count(
87 this: Allocated<Self>,
88 device: &ProtocolObject<dyn MTLDevice>,
89 count: NSUInteger,
90 ) -> Retained<Self>;
91
92 #[cfg(feature = "MPSCore")]
93 /// Initialize a MPSMatrixCopyDescriptor using offsets generated on the CPU
94 ///
95 /// This is for one at a time intialization of the copy operations
96 ///
97 /// Parameter `index`: The index of the copy operation
98 ///
99 /// Parameter `sourceMatrix`: The source matrix for this copy operation
100 ///
101 /// Parameter `destinationMatrix`: The destination matrix for this copy operation
102 ///
103 /// Parameter `offsets`: The offsets to use for the copy operation
104 #[unsafe(method(setCopyOperationAtIndex:sourceMatrix:destinationMatrix:offsets:))]
105 #[unsafe(method_family = none)]
106 pub unsafe fn setCopyOperationAtIndex_sourceMatrix_destinationMatrix_offsets(
107 &self,
108 index: NSUInteger,
109 source_matrix: &MPSMatrix,
110 destination_matrix: &MPSMatrix,
111 offsets: MPSMatrixCopyOffsets,
112 );
113
114 #[cfg(feature = "MPSCore")]
115 /// Initialize a MPSMatrixCopyDescriptor using offsets generated on the GPU
116 ///
117 /// Use this method when the offsets needed are coming from GPU based computation.
118 ///
119 /// Parameter `sourceMatrices`: A list of matrices from which the matrix data is read
120 ///
121 /// Parameter `destinationMatrices`: A list of matrices to which to write the data. The count
122 /// must match the number of source matrices.
123 ///
124 /// Parameter `offsets`: A MPSVector of type MPSDataTypeUInt32 containing the list of
125 /// offsets, stored as a packed array of MPSMatrixCopyOffsets.
126 ///
127 /// Parameter `byteOffset`: A byte offset into the offsets vector where the data starts in 'offsets'.
128 /// This value must be a multiple of 16.
129 ///
130 /// Returns: A valid MPSMatrixCopyDescriptor to represent the list of copy operations
131 #[unsafe(method(initWithSourceMatrices:destinationMatrices:offsetVector:offset:))]
132 #[unsafe(method_family = init)]
133 pub unsafe fn initWithSourceMatrices_destinationMatrices_offsetVector_offset(
134 this: Allocated<Self>,
135 source_matrices: &NSArray<MPSMatrix>,
136 destination_matrices: &NSArray<MPSMatrix>,
137 offsets: Option<&MPSVector>,
138 byte_offset: NSUInteger,
139 ) -> Retained<Self>;
140
141 #[unsafe(method(init))]
142 #[unsafe(method_family = init)]
143 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
144 );
145}
146
147/// Methods declared on superclass `NSObject`.
148impl MPSMatrixCopyDescriptor {
149 extern_methods!(
150 #[unsafe(method(new))]
151 #[unsafe(method_family = new)]
152 pub unsafe fn new() -> Retained<Self>;
153 );
154}
155
156extern_class!(
157 /// [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpsmatrixcopy?language=objc)
158 #[unsafe(super(MPSKernel, NSObject))]
159 #[derive(Debug, PartialEq, Eq, Hash)]
160 #[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
161 pub struct MPSMatrixCopy;
162);
163
164#[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
165extern_conformance!(
166 unsafe impl NSCoding for MPSMatrixCopy {}
167);
168
169#[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
170extern_conformance!(
171 unsafe impl NSCopying for MPSMatrixCopy {}
172);
173
174#[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
175unsafe impl CopyingHelper for MPSMatrixCopy {
176 type Result = Self;
177}
178
179#[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
180extern_conformance!(
181 unsafe impl NSObjectProtocol for MPSMatrixCopy {}
182);
183
184#[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
185extern_conformance!(
186 unsafe impl NSSecureCoding for MPSMatrixCopy {}
187);
188
189#[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
190impl MPSMatrixCopy {
191 extern_methods!(
192 #[unsafe(method(initWithDevice:))]
193 #[unsafe(method_family = init)]
194 pub unsafe fn initWithDevice(
195 this: Allocated<Self>,
196 device: &ProtocolObject<dyn MTLDevice>,
197 ) -> Retained<Self>;
198
199 /// Initialize a copy operator
200 ///
201 /// Parameter `copyRows`: The number of rows to copy for each copy operation
202 ///
203 /// Parameter `copyColumns`: The number of matrix columns to copy in each copy operation
204 ///
205 /// Parameter `sourcesAreTransposed`: If YES, the sources are in column major storage order
206 ///
207 /// Parameter `destinationsAreTransposed`: If YES, the destinations are in column major storage order
208 #[unsafe(method(initWithDevice:copyRows:copyColumns:sourcesAreTransposed:destinationsAreTransposed:))]
209 #[unsafe(method_family = init)]
210 pub unsafe fn initWithDevice_copyRows_copyColumns_sourcesAreTransposed_destinationsAreTransposed(
211 this: Allocated<Self>,
212 device: &ProtocolObject<dyn MTLDevice>,
213 copy_rows: NSUInteger,
214 copy_columns: NSUInteger,
215 sources_are_transposed: bool,
216 destinations_are_transposed: bool,
217 ) -> Retained<Self>;
218
219 /// The number of rows to copy for each copy operation
220 #[unsafe(method(copyRows))]
221 #[unsafe(method_family = none)]
222 pub unsafe fn copyRows(&self) -> NSUInteger;
223
224 /// The number of columns to copy for each copy operation
225 #[unsafe(method(copyColumns))]
226 #[unsafe(method_family = none)]
227 pub unsafe fn copyColumns(&self) -> NSUInteger;
228
229 /// If YES, the sources are in row major storage order
230 #[unsafe(method(sourcesAreTransposed))]
231 #[unsafe(method_family = none)]
232 pub unsafe fn sourcesAreTransposed(&self) -> bool;
233
234 /// If YES, the destinations are in row major storage order
235 #[unsafe(method(destinationsAreTransposed))]
236 #[unsafe(method_family = none)]
237 pub unsafe fn destinationsAreTransposed(&self) -> bool;
238
239 /// Encode the copy operations to the command buffer
240 ///
241 ///
242 /// Parameter `commandBuffer`: A valid MTLCommandBuffer to receive the encoded kernel.
243 ///
244 ///
245 /// Parameter `copyDescriptor`: The descriptor that defines the copy operator
246 #[unsafe(method(encodeToCommandBuffer:copyDescriptor:))]
247 #[unsafe(method_family = none)]
248 pub unsafe fn encodeToCommandBuffer_copyDescriptor(
249 &self,
250 command_buffer: &ProtocolObject<dyn MTLCommandBuffer>,
251 copy_descriptor: &MPSMatrixCopyDescriptor,
252 );
253
254 /// Encode the copy operations to the command buffer.
255 /// This of the encode version support permuting the outputs with custom vectors of indices.
256 /// The permutations are defined on the destination indices and are the same for each copy
257 /// operation.
258 ///
259 ///
260 /// Parameter `commandBuffer`: A valid MTLCommandBuffer to receive the encoded kernel.
261 ///
262 ///
263 /// Parameter `copyDescriptor`: The descriptor that defines the copy operator
264 ///
265 ///
266 /// Parameter `rowPermuteIndices`: If not nil then the output row index is
267 /// 'rowPermuteIndices[i] + rowOffset' instead of 'i + rowOffset',
268 /// where 'i' is the local row index of the copy operation.
269 /// Note: if destinationsAreTransposed is set to YES then the destination
270 /// transpose is performed before permutations.
271 ///
272 ///
273 /// Parameter `rowPermuteOffset`: Offset in numbers to apply to the 'rowPermuteIndices' vector.
274 ///
275 ///
276 /// Parameter `columnPermuteIndices`: If not nil then the output column index is
277 /// 'columnPermuteIndices[i] + columnOffset' instead of 'i + columnOffset',
278 /// where 'i' is the local column index of the copy operation.
279 /// Note: if destinationsAreTransposed is set to YES then the destination
280 /// transpose is performed before permutations.
281 ///
282 ///
283 /// Parameter `columnPermuteOffset`: Offset in numbers to apply to the 'columnPermuteIndices' vector.
284 #[unsafe(method(encodeToCommandBuffer:copyDescriptor:rowPermuteIndices:rowPermuteOffset:columnPermuteIndices:columnPermuteOffset:))]
285 #[unsafe(method_family = none)]
286 pub unsafe fn encodeToCommandBuffer_copyDescriptor_rowPermuteIndices_rowPermuteOffset_columnPermuteIndices_columnPermuteOffset(
287 &self,
288 command_buffer: &ProtocolObject<dyn MTLCommandBuffer>,
289 copy_descriptor: &MPSMatrixCopyDescriptor,
290 row_permute_indices: Option<&MPSVector>,
291 row_permute_offset: NSUInteger,
292 column_permute_indices: Option<&MPSVector>,
293 column_permute_offset: NSUInteger,
294 );
295
296 /// NSSecureCoding compatability
297 ///
298 /// See
299 /// MPSKernel#initWithCoder.
300 /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSMatrixLookUpAndCopy
301 ///
302 /// Parameter `device`: The MTLDevice on which to make the MPSMatrixLookUpAndCopy
303 ///
304 /// Returns: A new MPSMatrixLookUpAndCopy object, or nil if failure.
305 ///
306 /// # Safety
307 ///
308 /// `a_decoder` possibly has further requirements.
309 #[unsafe(method(initWithCoder:device:))]
310 #[unsafe(method_family = init)]
311 pub unsafe fn initWithCoder_device(
312 this: Allocated<Self>,
313 a_decoder: &NSCoder,
314 device: &ProtocolObject<dyn MTLDevice>,
315 ) -> Option<Retained<Self>>;
316 );
317}
318
319/// Methods declared on superclass `MPSKernel`.
320#[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
321impl MPSMatrixCopy {
322 extern_methods!(
323 /// Called by NSCoder to decode MPSKernels
324 ///
325 /// This isn't the right interface to decode a MPSKernel, but
326 /// it is the one that NSCoder uses. To enable your NSCoder
327 /// (e.g. NSKeyedUnarchiver) to set which device to use
328 /// extend the object to adopt the MPSDeviceProvider
329 /// protocol. Otherwise, the Metal system default device
330 /// will be used.
331 ///
332 /// # Safety
333 ///
334 /// `a_decoder` possibly has further requirements.
335 #[unsafe(method(initWithCoder:))]
336 #[unsafe(method_family = init)]
337 pub unsafe fn initWithCoder(
338 this: Allocated<Self>,
339 a_decoder: &NSCoder,
340 ) -> Option<Retained<Self>>;
341 );
342}
343
344/// Methods declared on superclass `NSObject`.
345#[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
346impl MPSMatrixCopy {
347 extern_methods!(
348 #[unsafe(method(init))]
349 #[unsafe(method_family = init)]
350 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
351
352 #[unsafe(method(new))]
353 #[unsafe(method_family = new)]
354 pub unsafe fn new() -> Retained<Self>;
355 );
356}