objc2_metal_performance_shaders/generated/MPSNeuralNetwork/
MPSNNReshape.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
11extern_class!(
12    /// [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpsnnreshape?language=objc)
13    #[unsafe(super(MPSCNNKernel, MPSKernel, NSObject))]
14    #[derive(Debug, PartialEq, Eq, Hash)]
15    #[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
16    pub struct MPSNNReshape;
17);
18
19#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
20extern_conformance!(
21    unsafe impl NSCoding for MPSNNReshape {}
22);
23
24#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
25extern_conformance!(
26    unsafe impl NSCopying for MPSNNReshape {}
27);
28
29#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
30unsafe impl CopyingHelper for MPSNNReshape {
31    type Result = Self;
32}
33
34#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
35extern_conformance!(
36    unsafe impl NSObjectProtocol for MPSNNReshape {}
37);
38
39#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
40extern_conformance!(
41    unsafe impl NSSecureCoding for MPSNNReshape {}
42);
43
44#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
45impl MPSNNReshape {
46    extern_methods!(
47        /// Initialize a MPSNNReshape kernel
48        ///
49        /// Parameter `device`: The device the filter will run on
50        ///
51        /// Returns: A valid MPSNNReshape object or nil, if failure.
52        #[unsafe(method(initWithDevice:))]
53        #[unsafe(method_family = init)]
54        pub unsafe fn initWithDevice(
55            this: Allocated<Self>,
56            device: &ProtocolObject<dyn MTLDevice>,
57        ) -> Retained<Self>;
58
59        /// # Safety
60        ///
61        /// `a_decoder` possibly has further requirements.
62        #[unsafe(method(initWithCoder:device:))]
63        #[unsafe(method_family = init)]
64        pub unsafe fn initWithCoder_device(
65            this: Allocated<Self>,
66            a_decoder: &NSCoder,
67            device: &ProtocolObject<dyn MTLDevice>,
68        ) -> Option<Retained<Self>>;
69
70        #[cfg(feature = "MPSImage")]
71        /// Encode a reshape to a command buffer for a given shape.
72        ///
73        /// Parameter `commandBuffer`: The command buffer on which to encode the reshape operation.
74        ///
75        /// Parameter `sourceImage`: The input image to be reshaped.
76        ///
77        /// Parameter `reshapedWidth`: The width of the resulting reshaped image.
78        ///
79        /// Parameter `reshapedHeight`: The height of the resulting reshaped image.
80        ///
81        /// Parameter `reshapedFeatureChannels`: The number of feature channels in the resulting reshaped image.
82        #[unsafe(method(encodeToCommandBuffer:sourceImage:reshapedWidth:reshapedHeight:reshapedFeatureChannels:))]
83        #[unsafe(method_family = none)]
84        pub unsafe fn encodeToCommandBuffer_sourceImage_reshapedWidth_reshapedHeight_reshapedFeatureChannels(
85            &self,
86            command_buffer: &ProtocolObject<dyn MTLCommandBuffer>,
87            source_image: &MPSImage,
88            reshaped_width: NSUInteger,
89            reshaped_height: NSUInteger,
90            reshaped_feature_channels: NSUInteger,
91        ) -> Retained<MPSImage>;
92
93        #[cfg(all(feature = "MPSImage", feature = "MPSState"))]
94        /// Encode a reshape to a command buffer for a given shape.
95        ///
96        /// Parameter `commandBuffer`: The command buffer on which to encode the reshape operation.
97        ///
98        /// Parameter `outState`: A state to be created and autoreleased which will hold information about this execution
99        /// to be provided to a subsequent gradient pass.
100        ///
101        /// Parameter `isTemporary`: YES if the state is to be created as a temporary state, NO otherwise.
102        ///
103        /// Parameter `sourceImage`: The input image to be reshaped.
104        ///
105        /// Parameter `reshapedWidth`: The width of the resulting reshaped image.
106        ///
107        /// Parameter `reshapedHeight`: The height of the resulting reshaped image.
108        ///
109        /// Parameter `reshapedFeatureChannels`: The number of feature channels in the resulting reshaped image.
110        #[unsafe(method(encodeToCommandBuffer:sourceImage:destinationState:destinationStateIsTemporary:reshapedWidth:reshapedHeight:reshapedFeatureChannels:))]
111        #[unsafe(method_family = none)]
112        pub unsafe fn encodeToCommandBuffer_sourceImage_destinationState_destinationStateIsTemporary_reshapedWidth_reshapedHeight_reshapedFeatureChannels(
113            &self,
114            command_buffer: &ProtocolObject<dyn MTLCommandBuffer>,
115            source_image: &MPSImage,
116            out_state: &mut Option<Retained<MPSState>>,
117            is_temporary: bool,
118            reshaped_width: NSUInteger,
119            reshaped_height: NSUInteger,
120            reshaped_feature_channels: NSUInteger,
121        ) -> Retained<MPSImage>;
122
123        #[cfg(all(feature = "MPSImage", feature = "MPSNDArray"))]
124        /// Encode a reshape to a command buffer for a given shape.
125        ///
126        /// Parameter `commandBuffer`: The command buffer on which to encode the reshape operation.
127        ///
128        /// Parameter `sourceImages`: The image batch containing images to be reshaped.
129        ///
130        /// Parameter `reshapedWidth`: The width of the resulting reshaped images.
131        ///
132        /// Parameter `reshapedHeight`: The height of the resulting reshaped images.
133        ///
134        /// Parameter `reshapedFeatureChannels`: The number of feature channels in each of the resulting reshaped images.
135        #[unsafe(method(encodeBatchToCommandBuffer:sourceImages:reshapedWidth:reshapedHeight:reshapedFeatureChannels:))]
136        #[unsafe(method_family = none)]
137        pub unsafe fn encodeBatchToCommandBuffer_sourceImages_reshapedWidth_reshapedHeight_reshapedFeatureChannels(
138            &self,
139            command_buffer: &ProtocolObject<dyn MTLCommandBuffer>,
140            source_images: &MPSImageBatch,
141            reshaped_width: NSUInteger,
142            reshaped_height: NSUInteger,
143            reshaped_feature_channels: NSUInteger,
144        ) -> Retained<MPSImageBatch>;
145
146        #[cfg(all(feature = "MPSImage", feature = "MPSNDArray", feature = "MPSState"))]
147        /// Encode a reshape to a command buffer for a given shape.
148        ///
149        /// Parameter `commandBuffer`: The command buffer on which to encode the reshape operation.
150        ///
151        /// Parameter `outStates`: A batch of states to be created and autoreleased which will hold information about this execution
152        /// to be provided to a subsequent gradient pass.
153        ///
154        /// Parameter `isTemporary`: YES if the states are to be created as temporary states, NO otherwise.
155        ///
156        /// Parameter `sourceImages`: The batch of input images to be reshaped.
157        ///
158        /// Parameter `reshapedWidth`: The width of the resulting reshaped images.
159        ///
160        /// Parameter `reshapedHeight`: The height of the resulting reshaped images.
161        ///
162        /// Parameter `reshapedFeatureChannels`: The number of feature channels in each of the resulting reshaped images.
163        #[unsafe(method(encodeBatchToCommandBuffer:sourceImages:destinationStates:destinationStateIsTemporary:reshapedWidth:reshapedHeight:reshapedFeatureChannels:))]
164        #[unsafe(method_family = none)]
165        pub unsafe fn encodeBatchToCommandBuffer_sourceImages_destinationStates_destinationStateIsTemporary_reshapedWidth_reshapedHeight_reshapedFeatureChannels(
166            &self,
167            command_buffer: &ProtocolObject<dyn MTLCommandBuffer>,
168            source_images: &MPSImageBatch,
169            out_states: &mut Option<Retained<MPSStateBatch>>,
170            is_temporary: bool,
171            reshaped_width: NSUInteger,
172            reshaped_height: NSUInteger,
173            reshaped_feature_channels: NSUInteger,
174        ) -> Retained<MPSImageBatch>;
175    );
176}
177
178/// Methods declared on superclass `MPSKernel`.
179#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
180impl MPSNNReshape {
181    extern_methods!(
182        /// Called by NSCoder to decode MPSKernels
183        ///
184        /// This isn't the right interface to decode a MPSKernel, but
185        /// it is the one that NSCoder uses. To enable your NSCoder
186        /// (e.g. NSKeyedUnarchiver) to set which device to use
187        /// extend the object to adopt the MPSDeviceProvider
188        /// protocol. Otherwise, the Metal system default device
189        /// will be used.
190        ///
191        /// # Safety
192        ///
193        /// `a_decoder` possibly has further requirements.
194        #[unsafe(method(initWithCoder:))]
195        #[unsafe(method_family = init)]
196        pub unsafe fn initWithCoder(
197            this: Allocated<Self>,
198            a_decoder: &NSCoder,
199        ) -> Option<Retained<Self>>;
200    );
201}
202
203/// Methods declared on superclass `NSObject`.
204#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
205impl MPSNNReshape {
206    extern_methods!(
207        #[unsafe(method(init))]
208        #[unsafe(method_family = init)]
209        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
210
211        #[unsafe(method(new))]
212        #[unsafe(method_family = new)]
213        pub unsafe fn new() -> Retained<Self>;
214    );
215}
216
217extern_class!(
218    /// Dependencies: This depends on Metal.framework
219    ///
220    /// The reshape gradient filter reshapes the incoming gradient into the dimensions
221    /// of the forward reshape kernel's source image.
222    ///
223    /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpsnnreshapegradient?language=objc)
224    #[unsafe(super(MPSCNNGradientKernel, MPSCNNBinaryKernel, MPSKernel, NSObject))]
225    #[derive(Debug, PartialEq, Eq, Hash)]
226    #[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
227    pub struct MPSNNReshapeGradient;
228);
229
230#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
231extern_conformance!(
232    unsafe impl NSCoding for MPSNNReshapeGradient {}
233);
234
235#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
236extern_conformance!(
237    unsafe impl NSCopying for MPSNNReshapeGradient {}
238);
239
240#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
241unsafe impl CopyingHelper for MPSNNReshapeGradient {
242    type Result = Self;
243}
244
245#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
246extern_conformance!(
247    unsafe impl NSObjectProtocol for MPSNNReshapeGradient {}
248);
249
250#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
251extern_conformance!(
252    unsafe impl NSSecureCoding for MPSNNReshapeGradient {}
253);
254
255#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
256impl MPSNNReshapeGradient {
257    extern_methods!(
258        /// Initializes a MPSNNReshapeGradient function
259        ///
260        /// Parameter `device`: The MTLDevice on which this filter will be used
261        ///
262        ///
263        /// Returns: A valid MPSNNReshapeGradient object or nil, if failure.
264        #[unsafe(method(initWithDevice:))]
265        #[unsafe(method_family = init)]
266        pub unsafe fn initWithDevice(
267            this: Allocated<Self>,
268            device: &ProtocolObject<dyn MTLDevice>,
269        ) -> Retained<Self>;
270
271        /// NSSecureCoding compatability
272        ///
273        /// While the standard NSSecureCoding/NSCoding method
274        /// -initWithCoder: should work, since the file can't
275        /// know which device your data is allocated on, we
276        /// have to guess and may guess incorrectly.  To avoid
277        /// that problem, use initWithCoder:device instead.
278        ///
279        /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSKernel
280        ///
281        /// Parameter `device`: The MTLDevice on which to make the MPSKernel
282        ///
283        /// Returns: A new MPSKernel object, or nil if failure.
284        ///
285        /// # Safety
286        ///
287        /// `a_decoder` possibly has further requirements.
288        #[unsafe(method(initWithCoder:device:))]
289        #[unsafe(method_family = init)]
290        pub unsafe fn initWithCoder_device(
291            this: Allocated<Self>,
292            a_decoder: &NSCoder,
293            device: &ProtocolObject<dyn MTLDevice>,
294        ) -> Option<Retained<Self>>;
295    );
296}
297
298/// Methods declared on superclass `MPSKernel`.
299#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
300impl MPSNNReshapeGradient {
301    extern_methods!(
302        /// Called by NSCoder to decode MPSKernels
303        ///
304        /// This isn't the right interface to decode a MPSKernel, but
305        /// it is the one that NSCoder uses. To enable your NSCoder
306        /// (e.g. NSKeyedUnarchiver) to set which device to use
307        /// extend the object to adopt the MPSDeviceProvider
308        /// protocol. Otherwise, the Metal system default device
309        /// will be used.
310        ///
311        /// # Safety
312        ///
313        /// `a_decoder` possibly has further requirements.
314        #[unsafe(method(initWithCoder:))]
315        #[unsafe(method_family = init)]
316        pub unsafe fn initWithCoder(
317            this: Allocated<Self>,
318            a_decoder: &NSCoder,
319        ) -> Option<Retained<Self>>;
320    );
321}
322
323/// Methods declared on superclass `NSObject`.
324#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
325impl MPSNNReshapeGradient {
326    extern_methods!(
327        #[unsafe(method(init))]
328        #[unsafe(method_family = init)]
329        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
330
331        #[unsafe(method(new))]
332        #[unsafe(method_family = new)]
333        pub unsafe fn new() -> Retained<Self>;
334    );
335}
336
337extern_class!(
338    /// [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpsnnpad?language=objc)
339    #[unsafe(super(MPSCNNKernel, MPSKernel, NSObject))]
340    #[derive(Debug, PartialEq, Eq, Hash)]
341    #[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
342    pub struct MPSNNPad;
343);
344
345#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
346extern_conformance!(
347    unsafe impl NSCoding for MPSNNPad {}
348);
349
350#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
351extern_conformance!(
352    unsafe impl NSCopying for MPSNNPad {}
353);
354
355#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
356unsafe impl CopyingHelper for MPSNNPad {
357    type Result = Self;
358}
359
360#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
361extern_conformance!(
362    unsafe impl NSObjectProtocol for MPSNNPad {}
363);
364
365#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
366extern_conformance!(
367    unsafe impl NSSecureCoding for MPSNNPad {}
368);
369
370#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
371impl MPSNNPad {
372    extern_methods!(
373        #[cfg(feature = "MPSCoreTypes")]
374        /// This property is used for automatically sizing the destination image
375        /// for the function
376        /// destinationImageDescriptorForSourceImages:sourceStates:.Defines
377        /// how much padding to assign on the left, top and smaller feature channel indices
378        /// of the image. NOTE: the x and y coordinates of this property are only
379        /// used through
380        /// destinationImageDescriptorForSourceImages:sourceStates:,since
381        /// the clipRect and offset together define the padding sizes in those directions, but
382        /// the 'channel' size defines the amount of padding to be applied in the feature
383        /// channel dimension, before the feature channels starting from feature channel
384        /// index
385        /// sourceFeatureChannelOffset.Default: { 0, 0, 0 }
386        #[unsafe(method(paddingSizeBefore))]
387        #[unsafe(method_family = none)]
388        pub unsafe fn paddingSizeBefore(&self) -> MPSImageCoordinate;
389
390        #[cfg(feature = "MPSCoreTypes")]
391        /// Setter for [`paddingSizeBefore`][Self::paddingSizeBefore].
392        #[unsafe(method(setPaddingSizeBefore:))]
393        #[unsafe(method_family = none)]
394        pub unsafe fn setPaddingSizeBefore(&self, padding_size_before: MPSImageCoordinate);
395
396        #[cfg(feature = "MPSCoreTypes")]
397        /// This property is used for automatically sizing the destination image
398        /// for the function
399        /// destinationImageDescriptorForSourceImages:sourceStates:.Defines
400        /// how much padding to assign on the right, bottom and higher feature channel indices
401        /// of the image. NOTE: the x and y coordinates of this property are only
402        /// used through
403        /// destinationImageDescriptorForSourceImages:sourceStates:,since
404        /// the clipRect and offset together define the padding sizes in those directions, but
405        /// the 'channel' size defines the amount of padding to be applied in the feature
406        /// channel dimension after source feature channel index determined by the sum of
407        /// sourceFeatureChannelOffsetand
408        /// sourceFeatureChannelMaxCount,naturally
409        /// clipped to fit the feature channels in the provided source image.
410        /// Default: { 0, 0, 0 }
411        #[unsafe(method(paddingSizeAfter))]
412        #[unsafe(method_family = none)]
413        pub unsafe fn paddingSizeAfter(&self) -> MPSImageCoordinate;
414
415        #[cfg(feature = "MPSCoreTypes")]
416        /// Setter for [`paddingSizeAfter`][Self::paddingSizeAfter].
417        #[unsafe(method(setPaddingSizeAfter:))]
418        #[unsafe(method_family = none)]
419        pub unsafe fn setPaddingSizeAfter(&self, padding_size_after: MPSImageCoordinate);
420
421        /// Determines the constant value to apply when using
422        /// MPSImageEdgeModeConstant.Default: 0.0f.
423        /// NOTE: this value is ignored if the filter is initialized with a per-channel fill value
424        /// using
425        /// initWithDevice:paddingSizeBefore:paddingSizeAfter:fillValueArray:.
426        #[unsafe(method(fillValue))]
427        #[unsafe(method_family = none)]
428        pub unsafe fn fillValue(&self) -> c_float;
429
430        /// Setter for [`fillValue`][Self::fillValue].
431        #[unsafe(method(setFillValue:))]
432        #[unsafe(method_family = none)]
433        pub unsafe fn setFillValue(&self, fill_value: c_float);
434
435        /// Initialize a MPSNNPad kernel
436        ///
437        /// Parameter `device`: The device the filter will run on.
438        ///
439        /// Returns: A valid MPSNNPad object or nil, if failure.
440        #[unsafe(method(initWithDevice:))]
441        #[unsafe(method_family = init)]
442        pub unsafe fn initWithDevice(
443            this: Allocated<Self>,
444            device: &ProtocolObject<dyn MTLDevice>,
445        ) -> Retained<Self>;
446
447        #[cfg(feature = "MPSCoreTypes")]
448        /// Initialize a MPSNNPad kernel
449        ///
450        /// Parameter `device`: The device the filter will run on
451        ///
452        /// Parameter `paddingSizeBefore`: The amount of padding to add before the source image - see details above.
453        ///
454        /// Parameter `paddingSizeAfter`: The amount of padding to add after the source image - see details above.
455        ///
456        /// Returns: A valid MPSNNPad object or nil, if failure.
457        #[unsafe(method(initWithDevice:paddingSizeBefore:paddingSizeAfter:))]
458        #[unsafe(method_family = init)]
459        pub unsafe fn initWithDevice_paddingSizeBefore_paddingSizeAfter(
460            this: Allocated<Self>,
461            device: &ProtocolObject<dyn MTLDevice>,
462            padding_size_before: MPSImageCoordinate,
463            padding_size_after: MPSImageCoordinate,
464        ) -> Retained<Self>;
465
466        #[cfg(feature = "MPSCoreTypes")]
467        /// Initialize a MPSNNPad kernel
468        ///
469        /// Parameter `device`: The device the filter will run on
470        ///
471        /// Parameter `paddingSizeBefore`: The amount of padding to add before the source image - see details above.
472        ///
473        /// Parameter `paddingSizeAfter`: The amount of padding to add after the source image - see details above.
474        ///
475        /// Parameter `fillValueArray`: A NSData containing a float array to use with
476        /// MPSImageEdgeModeConstant.The first value of the array will correspond to the first feature channel
477        /// written out to the destination image and the number of float values in the
478        /// data must be at least as large as the number of feature channels written onto
479        /// the destination by the filter. Failing to pass a large enough array will
480        /// result in undefined behavior. Passing in nil is fine.
481        ///
482        /// Returns: A valid MPSNNPad object or nil, if failure.
483        #[unsafe(method(initWithDevice:paddingSizeBefore:paddingSizeAfter:fillValueArray:))]
484        #[unsafe(method_family = init)]
485        pub unsafe fn initWithDevice_paddingSizeBefore_paddingSizeAfter_fillValueArray(
486            this: Allocated<Self>,
487            device: &ProtocolObject<dyn MTLDevice>,
488            padding_size_before: MPSImageCoordinate,
489            padding_size_after: MPSImageCoordinate,
490            fill_value_array: Option<&NSData>,
491        ) -> Retained<Self>;
492
493        /// NSSecureCoding compatability
494        ///
495        /// See
496        /// MPSKernel#initWithCoder.
497        /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSNNPad
498        ///
499        /// Parameter `device`: The MTLDevice on which to make the MPSNNPad
500        ///
501        /// Returns: A new MPSNNPad object, or nil if failure.
502        ///
503        /// # Safety
504        ///
505        /// `a_decoder` possibly has further requirements.
506        #[unsafe(method(initWithCoder:device:))]
507        #[unsafe(method_family = init)]
508        pub unsafe fn initWithCoder_device(
509            this: Allocated<Self>,
510            a_decoder: &NSCoder,
511            device: &ProtocolObject<dyn MTLDevice>,
512        ) -> Option<Retained<Self>>;
513    );
514}
515
516/// Methods declared on superclass `MPSKernel`.
517#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
518impl MPSNNPad {
519    extern_methods!(
520        /// Called by NSCoder to decode MPSKernels
521        ///
522        /// This isn't the right interface to decode a MPSKernel, but
523        /// it is the one that NSCoder uses. To enable your NSCoder
524        /// (e.g. NSKeyedUnarchiver) to set which device to use
525        /// extend the object to adopt the MPSDeviceProvider
526        /// protocol. Otherwise, the Metal system default device
527        /// will be used.
528        ///
529        /// # Safety
530        ///
531        /// `a_decoder` possibly has further requirements.
532        #[unsafe(method(initWithCoder:))]
533        #[unsafe(method_family = init)]
534        pub unsafe fn initWithCoder(
535            this: Allocated<Self>,
536            a_decoder: &NSCoder,
537        ) -> Option<Retained<Self>>;
538    );
539}
540
541/// Methods declared on superclass `NSObject`.
542#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
543impl MPSNNPad {
544    extern_methods!(
545        #[unsafe(method(init))]
546        #[unsafe(method_family = init)]
547        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
548
549        #[unsafe(method(new))]
550        #[unsafe(method_family = new)]
551        pub unsafe fn new() -> Retained<Self>;
552    );
553}
554
555extern_class!(
556    /// Dependencies: This depends on Metal.framework
557    ///
558    /// Computes the gradient for the
559    /// MPSNNPadlayer.
560    /// Since the padding forward operation typically increases the size of the image, the gradient operation
561    /// decreases it. In case of zero or constant padding forward operation the gradient operation slices the
562    /// input gradient and in other edge modes the padded values copied in the forward operation are
563    /// summed together in the gradient operation.
564    /// For Example for the
565    /// MPSImageEdgeModeClampthe forward operation with offset = -2, destSize = 8
566    /// or
567    /// paddingSizeBefore= 2,
568    /// paddingSizeAfter= 3, sourceSize = 3:
569    ///
570    /// ```text
571    ///               Source Image:
572    ///                 |--------------|
573    ///                 | x0 | x1 | x2 |
574    ///                 |--------------|
575    ///               Destination Image:
576    ///                 |---------------------------------------|
577    ///                 | x0 | x0 | x0 | x1 | x2 | x2 | x2 | x2 |
578    ///                 |---------------------------------------|
579    /// ```
580    ///
581    /// Then the gradient operation becomes:
582    ///
583    /// ```text
584    ///               Source Gradient Image:
585    ///                 |---------------------------------------|
586    ///                 | d0 | d1 | d2 | d3 | d4 | d5 | d6 | d7 |
587    ///                 |---------------------------------------|
588    ///               Destination Gradient Image:
589    ///                 |-----------------------------|
590    ///                 | d0+d1+d2 | d3 | d4+d5+d6+d7 |
591    ///                 |-----------------------------|
592    /// ```
593    ///
594    /// Another example with
595    /// MPSImageEdgeModeMirror,the forward operation with offset = -4, destSize = 8
596    /// or
597    /// paddingSizeBefore= 4,
598    /// paddingSizeAfter= 1, sourceSize = 3:
599    ///
600    /// ```text
601    ///               Source Image:
602    ///                 |--------------|
603    ///                 | x0 | x1 | x2 |
604    ///                 |--------------|
605    ///               Destination Image:
606    ///                 |---------------------------------------|
607    ///                 | x0 | x1 | x2 | x1 | x0 | x1 | x2 | x1 |
608    ///                 |---------------------------------------|
609    /// ```
610    ///
611    /// Then the gradient operation becomes:
612    ///
613    /// ```text
614    ///               Source Gradient Image:
615    ///                 |---------------------------------------|
616    ///                 | d0 | d1 | d2 | d3 | d4 | d5 | d6 | d7 |
617    ///                 |---------------------------------------|
618    ///               Destination Gradient Image:
619    ///                 |-----------------------------|
620    ///                 | d0+d4 | d1+d3+d5+d7 | d2+d6 |
621    ///                 |-----------------------------|
622    /// ```
623    ///
624    /// NOTE: There are no channel fill-values to use with
625    /// MPSImageEdgeModeConstantsince the gradient values are independent of the constant of the forward pass.
626    /// NOTE: In case the forward pass defined a slice operation in feature channels then
627    /// the channels not read in the forward pass will be filled with zeros in the gradient pass.
628    ///
629    /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpsnnpadgradient?language=objc)
630    #[unsafe(super(MPSCNNGradientKernel, MPSCNNBinaryKernel, MPSKernel, NSObject))]
631    #[derive(Debug, PartialEq, Eq, Hash)]
632    #[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
633    pub struct MPSNNPadGradient;
634);
635
636#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
637extern_conformance!(
638    unsafe impl NSCoding for MPSNNPadGradient {}
639);
640
641#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
642extern_conformance!(
643    unsafe impl NSCopying for MPSNNPadGradient {}
644);
645
646#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
647unsafe impl CopyingHelper for MPSNNPadGradient {
648    type Result = Self;
649}
650
651#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
652extern_conformance!(
653    unsafe impl NSObjectProtocol for MPSNNPadGradient {}
654);
655
656#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
657extern_conformance!(
658    unsafe impl NSSecureCoding for MPSNNPadGradient {}
659);
660
661#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
662impl MPSNNPadGradient {
663    extern_methods!(
664        /// Initializes a MPSNNPadGradient filter
665        ///
666        /// Parameter `device`: The MTLDevice on which this filter will be used
667        ///
668        ///
669        /// Returns: A valid MPSNNPadGradient object or nil, if failure.
670        #[unsafe(method(initWithDevice:))]
671        #[unsafe(method_family = init)]
672        pub unsafe fn initWithDevice(
673            this: Allocated<Self>,
674            device: &ProtocolObject<dyn MTLDevice>,
675        ) -> Retained<Self>;
676
677        /// NSSecureCoding compatability
678        ///
679        /// See
680        /// MPSKernel#initWithCoder.
681        /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSNNPadGradient.
682        ///
683        /// Parameter `device`: The MTLDevice on which to make the MPSNNPadGradient.
684        ///
685        /// Returns: A new MPSNNPadGradient object, or nil if failure.
686        ///
687        /// # Safety
688        ///
689        /// `a_decoder` possibly has further requirements.
690        #[unsafe(method(initWithCoder:device:))]
691        #[unsafe(method_family = init)]
692        pub unsafe fn initWithCoder_device(
693            this: Allocated<Self>,
694            a_decoder: &NSCoder,
695            device: &ProtocolObject<dyn MTLDevice>,
696        ) -> Option<Retained<Self>>;
697    );
698}
699
700/// Methods declared on superclass `MPSKernel`.
701#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
702impl MPSNNPadGradient {
703    extern_methods!(
704        /// Called by NSCoder to decode MPSKernels
705        ///
706        /// This isn't the right interface to decode a MPSKernel, but
707        /// it is the one that NSCoder uses. To enable your NSCoder
708        /// (e.g. NSKeyedUnarchiver) to set which device to use
709        /// extend the object to adopt the MPSDeviceProvider
710        /// protocol. Otherwise, the Metal system default device
711        /// will be used.
712        ///
713        /// # Safety
714        ///
715        /// `a_decoder` possibly has further requirements.
716        #[unsafe(method(initWithCoder:))]
717        #[unsafe(method_family = init)]
718        pub unsafe fn initWithCoder(
719            this: Allocated<Self>,
720            a_decoder: &NSCoder,
721        ) -> Option<Retained<Self>>;
722    );
723}
724
725/// Methods declared on superclass `NSObject`.
726#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
727impl MPSNNPadGradient {
728    extern_methods!(
729        #[unsafe(method(init))]
730        #[unsafe(method_family = init)]
731        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
732
733        #[unsafe(method(new))]
734        #[unsafe(method_family = new)]
735        pub unsafe fn new() -> Retained<Self>;
736    );
737}