objc2_metal_performance_shaders/generated/MPSImage/
MPSImageKernel.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/// [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpscopyallocator?language=objc)
12#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "block2"))]
13pub type MPSCopyAllocator = *mut block2::DynBlock<
14    dyn Fn(
15        NonNull<MPSKernel>,
16        NonNull<ProtocolObject<dyn MTLCommandBuffer>>,
17        NonNull<ProtocolObject<dyn MTLTexture>>,
18    ) -> NonNull<ProtocolObject<dyn MTLTexture>>,
19>;
20
21extern_class!(
22    /// Dependencies: This depends on Metal.framework
23    ///
24    /// A MPSUnaryImageKernel consumes one MTLTexture and produces one MTLTexture.
25    ///
26    /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpsunaryimagekernel?language=objc)
27    #[unsafe(super(MPSKernel, NSObject))]
28    #[derive(Debug, PartialEq, Eq, Hash)]
29    #[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
30    pub struct MPSUnaryImageKernel;
31);
32
33#[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
34extern_conformance!(
35    unsafe impl NSCoding for MPSUnaryImageKernel {}
36);
37
38#[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
39extern_conformance!(
40    unsafe impl NSCopying for MPSUnaryImageKernel {}
41);
42
43#[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
44unsafe impl CopyingHelper for MPSUnaryImageKernel {
45    type Result = Self;
46}
47
48#[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
49extern_conformance!(
50    unsafe impl NSObjectProtocol for MPSUnaryImageKernel {}
51);
52
53#[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
54extern_conformance!(
55    unsafe impl NSSecureCoding for MPSUnaryImageKernel {}
56);
57
58#[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
59impl MPSUnaryImageKernel {
60    extern_methods!(
61        #[cfg(feature = "MPSCoreTypes")]
62        /// The position of the destination clip rectangle origin relative to the source buffer.
63        ///
64        /// The offset is defined to be the position of clipRect.origin in source coordinates.
65        /// Default: {0,0,0}, indicating that the top left corners of the clipRect and source image align.
66        ///
67        /// See Also:
68        /// MetalPerformanceShaders.hsubsubsection_mpsoffset
69        #[unsafe(method(offset))]
70        #[unsafe(method_family = none)]
71        pub unsafe fn offset(&self) -> MPSOffset;
72
73        #[cfg(feature = "MPSCoreTypes")]
74        /// Setter for [`offset`][Self::offset].
75        #[unsafe(method(setOffset:))]
76        #[unsafe(method_family = none)]
77        pub unsafe fn setOffset(&self, offset: MPSOffset);
78
79        /// An optional clip rectangle to use when writing data. Only the pixels in the rectangle will be overwritten.
80        ///
81        /// A MTLRegion that indicates which part of the destination to overwrite. If the clipRect does not lie
82        /// completely within the destination image, the intersection between clip rectangle and destination bounds is
83        /// used.   Default: MPSRectNoClip (MPSKernel::MPSRectNoClip) indicating the entire image.
84        ///
85        /// See Also:
86        /// MetalPerformanceShaders.hsubsubsection_clipRect
87        #[unsafe(method(clipRect))]
88        #[unsafe(method_family = none)]
89        pub unsafe fn clipRect(&self) -> MTLRegion;
90
91        /// Setter for [`clipRect`][Self::clipRect].
92        #[unsafe(method(setClipRect:))]
93        #[unsafe(method_family = none)]
94        pub unsafe fn setClipRect(&self, clip_rect: MTLRegion);
95
96        #[cfg(feature = "MPSCoreTypes")]
97        /// The MPSImageEdgeMode to use when texture reads stray off the edge of an image
98        ///
99        /// Most MPSKernel objects can read off the edge of the source image. This can happen because of a
100        /// negative offset property, because the offset + clipRect.size is larger than the
101        /// source image or because the filter looks at neighboring pixels, such as a Convolution
102        /// or morphology filter.   Default: usually MPSImageEdgeModeZero. (Some MPSKernel types default
103        /// to MPSImageEdgeModeClamp, because MPSImageEdgeModeZero is either not supported or
104        /// would produce unexpected results.)
105        ///
106        /// See Also:
107        /// MetalPerformanceShaders.hsubsubsection_edgemode
108        #[unsafe(method(edgeMode))]
109        #[unsafe(method_family = none)]
110        pub unsafe fn edgeMode(&self) -> MPSImageEdgeMode;
111
112        #[cfg(feature = "MPSCoreTypes")]
113        /// Setter for [`edgeMode`][Self::edgeMode].
114        #[unsafe(method(setEdgeMode:))]
115        #[unsafe(method_family = none)]
116        pub unsafe fn setEdgeMode(&self, edge_mode: MPSImageEdgeMode);
117
118        /// Standard init with default properties per filter type
119        ///
120        /// Parameter `device`: The device that the filter will be used on. May not be NULL.
121        ///
122        /// Returns: a pointer to the newly initialized object. This will fail, returning
123        /// nil if the device is not supported. Devices must be
124        /// MTLFeatureSet_iOS_GPUFamily2_v1 or later.
125        #[unsafe(method(initWithDevice:))]
126        #[unsafe(method_family = init)]
127        pub unsafe fn initWithDevice(
128            this: Allocated<Self>,
129            device: &ProtocolObject<dyn MTLDevice>,
130        ) -> Retained<Self>;
131
132        /// NSSecureCoding compatability
133        ///
134        /// While the standard NSSecureCoding/NSCoding method
135        /// -initWithCoder: should work, since the file can't
136        /// know which device your data is allocated on, we
137        /// have to guess and may guess incorrectly.  To avoid
138        /// that problem, use initWithCoder:device instead.
139        ///
140        /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSKernel
141        ///
142        /// Parameter `device`: The MTLDevice on which to make the MPSKernel
143        ///
144        /// Returns: A new MPSKernel object, or nil if failure.
145        ///
146        /// # Safety
147        ///
148        /// `a_decoder` possibly has further requirements.
149        #[unsafe(method(initWithCoder:device:))]
150        #[unsafe(method_family = init)]
151        pub unsafe fn initWithCoder_device(
152            this: Allocated<Self>,
153            a_decoder: &NSCoder,
154            device: &ProtocolObject<dyn MTLDevice>,
155        ) -> Option<Retained<Self>>;
156
157        #[cfg(feature = "block2")]
158        /// This method attempts to apply the MPSKernel in place on a texture.
159        ///
160        /// In-place operation means that the same texture is used both to hold the input
161        /// image and the results. Operating in-place can be an excellent way to reduce
162        /// resource utilization, and save time and energy. While simple Metal kernels can
163        /// not operate in place because textures can not be readable and writable at the
164        /// same time, some MPSKernels can operate in place because they use
165        /// multi-pass algorithms. Whether a MPSKernel can operate in-place can
166        /// depend on current hardware, operating system revision and the parameters
167        /// and properties passed to it. You should never assume that a MPSKernel will
168        /// continue to work in place, even if you have observed it doing so before.
169        ///
170        /// If the operation succeeds in-place, YES is returned.  If the in-place operation
171        /// fails and no copyAllocator is provided, then NO is returned. Without a fallback
172        /// MPSCopyAllocator, in neither case is the pointer held at *texture modified.
173        ///
174        /// Failure during in-place operation is very common and will occur inconsistently across
175        /// different hardware platforms and OS releases. Without a fallback MPSCopyAllocator,
176        /// operating in place may require significant error handling code to accompany each
177        /// call to -encodeToCommandBuffer:..., complicating your code.
178        ///
179        /// You may find it simplifies your code to provide a fallback MPSCopyAllocator so
180        /// that the operation can proceed reliably even when it can not proceed in-place.
181        /// When an in-place filter fails, the MPSCopyAllocator (if any) will be
182        /// invoked to create a new texture in which to write the results, allowing the
183        /// filter to proceed reliably out-of-place. The original texture will be released,
184        /// replaced with a pointer to the new texture and YES will be returned. If the
185        /// allocator returns an invalid texture, it is released, *texture remains unmodified
186        /// and NO is returned.  Please see the MPSCopyAllocator definition for a sample allocator
187        /// implementation.
188        ///
189        /// Sample usage with a copy allocator:
190        ///
191        /// ```text
192        ///   id <MTLTexture> inPlaceTex = ...;
193        ///   MPSImageSobel *sobelFiler = [[MPSImageSobel alloc] initWithDevice: myDevice];
194        ///
195        ///   // With a fallback MPSCopyAllocator, failure should only occur in exceptional
196        ///   // conditions such as MTLTexture allocation failure or programmer error.
197        ///   // That is, the operation is roughly as robust as the MPSCopyAllocator.
198        ///   // Depending on the quality of that, we might decide we are justified here
199        ///   // in not checking the return value.
200        ///   [sobelFilter encodeToCommandBuffer: myCommandBuffer
201        ///                       inPlaceTexture: &inPlaceTex  // may be replaced!
202        ///                fallbackCopyAllocator: myAllocator];
203        ///
204        ///   // If myAllocator was not called:
205        ///   //
206        ///   //      inPlaceTex holds the original texture with the result pixels in it
207        ///   //
208        ///   // else,
209        ///   //
210        ///   //      1) myAllocator creates a new texture.
211        ///   //      2) The new texture pixel data is overwritten by MPSUnaryImageKernel.
212        ///   //      3) The old texture passed in *inPlaceTex is released once.
213        ///   //      4) *inPlaceTex = the new texture
214        ///   //
215        ///   // In either case, the caller should now hold one reference to the texture now held in
216        ///   // inPlaceTex, whether it was replaced or not. Most of the time that means that nothing
217        ///   // further needs to be done here, and you can proceed to the next image encoding operation.
218        ///   // However, if other agents held references to the original texture, they still hold them
219        ///   // and may need to be alerted that the texture has been replaced so that they can retain
220        ///   // the new texture and release the old one.
221        ///
222        ///   [sobelFilter release];  // if not ARC, clean up the MPSImageSobel object
223        /// ```
224        ///
225        /// Note: Image filters that look at neighboring pixel values may actually consume more
226        /// memory when operating in place than out of place. Many such operations are
227        /// tiled internally to save intermediate texture storage, but can not tile when
228        /// operating in place. The memory savings for tiling is however very short term,
229        /// typically the lifetime of the MTLCommandBuffer.
230        ///
231        ///
232        /// Attempt to apply a MPSKernel to a texture in place.
233        ///
234        /// Parameter `commandBuffer`: A valid MTLCommandBuffer to receive the encoded filter
235        ///
236        /// Parameter `texture`: A pointer to a valid MTLTexture containing source image.
237        /// On success, the image contents and possibly texture itself
238        /// will be replaced with the result image.
239        ///
240        /// Parameter `copyAllocator`: An optional block to allocate a new texture to hold the
241        /// results, in case in-place operation is not possible. The
242        /// allocator may use a different MTLPixelFormat or size than
243        /// the original texture. You may enqueue operations on the
244        /// provided MTLCommandBuffer using the provided
245        /// MTLComputeCommandEncoder to initialize the texture contents.
246        ///
247        /// Returns: On success, YES is returned. The texture may have been replaced with a new
248        /// texture if a copyAllocator was provided.  On failure, NO is returned. The
249        /// texture is unmodified.
250        ///
251        /// # Safety
252        ///
253        /// - `texture` must be a valid pointer.
254        /// - `copy_allocator` must be a valid pointer or null.
255        #[unsafe(method(encodeToCommandBuffer:inPlaceTexture:fallbackCopyAllocator:))]
256        #[unsafe(method_family = none)]
257        pub unsafe fn encodeToCommandBuffer_inPlaceTexture_fallbackCopyAllocator(
258            &self,
259            command_buffer: &ProtocolObject<dyn MTLCommandBuffer>,
260            texture: NonNull<NonNull<ProtocolObject<dyn MTLTexture>>>,
261            copy_allocator: MPSCopyAllocator,
262        ) -> bool;
263
264        /// Encode a MPSKernel into a command Buffer.  The operation shall proceed out-of-place.
265        ///
266        /// Parameter `commandBuffer`: A valid MTLCommandBuffer to receive the encoded filter
267        ///
268        /// Parameter `sourceTexture`: A valid MTLTexture containing the source image.
269        ///
270        /// Parameter `destinationTexture`: A valid MTLTexture to be overwritten by result image. DestinationTexture may not alias sourceTexture.
271        ///
272        /// # Safety
273        ///
274        /// - `source_texture` may need to be synchronized.
275        /// - `source_texture` may be unretained, you must ensure it is kept alive while in use.
276        /// - `destination_texture` may need to be synchronized.
277        /// - `destination_texture` may be unretained, you must ensure it is kept alive while in use.
278        #[unsafe(method(encodeToCommandBuffer:sourceTexture:destinationTexture:))]
279        #[unsafe(method_family = none)]
280        pub unsafe fn encodeToCommandBuffer_sourceTexture_destinationTexture(
281            &self,
282            command_buffer: &ProtocolObject<dyn MTLCommandBuffer>,
283            source_texture: &ProtocolObject<dyn MTLTexture>,
284            destination_texture: &ProtocolObject<dyn MTLTexture>,
285        );
286
287        /// Encode a MPSKernel into a command Buffer.  The operation shall proceed out-of-place.
288        ///
289        /// Parameter `commandBuffer`: A valid MTLCommandBuffer to receive the encoded filter
290        ///
291        /// Parameter `sourceImage`: A valid MPSImage containing the source image.
292        ///
293        /// Parameter `destinationImage`: A valid MPSImage to be overwritten by result image. DestinationImage may not alias sourceImage.
294        #[unsafe(method(encodeToCommandBuffer:sourceImage:destinationImage:))]
295        #[unsafe(method_family = none)]
296        pub unsafe fn encodeToCommandBuffer_sourceImage_destinationImage(
297            &self,
298            command_buffer: &ProtocolObject<dyn MTLCommandBuffer>,
299            source_image: &MPSImage,
300            destination_image: &MPSImage,
301        );
302
303        #[cfg(feature = "MPSCoreTypes")]
304        /// sourceRegionForDestinationSize: is used to determine which region of the
305        /// sourceTexture will be read by encodeToCommandBuffer:sourceTexture:destinationTexture
306        /// (and similar) when the filter runs. This information may be needed if the
307        /// source image is broken into multiple textures.  The size of the full
308        /// (untiled) destination image is provided. The region of the full (untiled)
309        /// source image that will be read is returned. You can then piece together an
310        /// appropriate texture containing that information for use in your tiled context.
311        ///
312        /// The function will consult the MPSUnaryImageKernel offset and clipRect parameters,
313        /// to determine the full region read by the function. Other parameters such as
314        /// sourceClipRect, kernelHeight and kernelWidth will be consulted as necessary.
315        /// All properties should be set to intended values prior to calling
316        /// sourceRegionForDestinationSize:.
317        ///
318        /// Caution: This function operates using global image coordinates, but
319        /// -encodeToCommandBuffer:... uses coordinates local to the source and
320        /// destination image textures. Consequently, the offset and clipRect
321        /// attached to this object will need to be updated using a global to
322        /// local coordinate transform before -encodeToCommandBuffer:... is
323        /// called.
324        ///
325        ///
326        /// Determine the region of the source texture that will be read for a encode operation
327        ///
328        /// Parameter `destinationSize`: The size of the full virtual destination image.
329        ///
330        /// Returns: The area in the virtual source image that will be read.
331        #[unsafe(method(sourceRegionForDestinationSize:))]
332        #[unsafe(method_family = none)]
333        pub unsafe fn sourceRegionForDestinationSize(&self, destination_size: MTLSize)
334            -> MPSRegion;
335    );
336}
337
338/// Methods declared on superclass `MPSKernel`.
339#[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
340impl MPSUnaryImageKernel {
341    extern_methods!(
342        /// Called by NSCoder to decode MPSKernels
343        ///
344        /// This isn't the right interface to decode a MPSKernel, but
345        /// it is the one that NSCoder uses. To enable your NSCoder
346        /// (e.g. NSKeyedUnarchiver) to set which device to use
347        /// extend the object to adopt the MPSDeviceProvider
348        /// protocol. Otherwise, the Metal system default device
349        /// will be used.
350        ///
351        /// # Safety
352        ///
353        /// `a_decoder` possibly has further requirements.
354        #[unsafe(method(initWithCoder:))]
355        #[unsafe(method_family = init)]
356        pub unsafe fn initWithCoder(
357            this: Allocated<Self>,
358            a_decoder: &NSCoder,
359        ) -> Option<Retained<Self>>;
360    );
361}
362
363/// Methods declared on superclass `NSObject`.
364#[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
365impl MPSUnaryImageKernel {
366    extern_methods!(
367        #[unsafe(method(init))]
368        #[unsafe(method_family = init)]
369        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
370
371        #[unsafe(method(new))]
372        #[unsafe(method_family = new)]
373        pub unsafe fn new() -> Retained<Self>;
374    );
375}
376
377extern_class!(
378    /// Dependencies: This depends on Metal.framework
379    ///
380    /// A MPSBinaryImageKernel consumes two MTLTextures and produces one MTLTexture.
381    ///
382    /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpsbinaryimagekernel?language=objc)
383    #[unsafe(super(MPSKernel, NSObject))]
384    #[derive(Debug, PartialEq, Eq, Hash)]
385    #[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
386    pub struct MPSBinaryImageKernel;
387);
388
389#[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
390extern_conformance!(
391    unsafe impl NSCoding for MPSBinaryImageKernel {}
392);
393
394#[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
395extern_conformance!(
396    unsafe impl NSCopying for MPSBinaryImageKernel {}
397);
398
399#[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
400unsafe impl CopyingHelper for MPSBinaryImageKernel {
401    type Result = Self;
402}
403
404#[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
405extern_conformance!(
406    unsafe impl NSObjectProtocol for MPSBinaryImageKernel {}
407);
408
409#[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
410extern_conformance!(
411    unsafe impl NSSecureCoding for MPSBinaryImageKernel {}
412);
413
414#[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
415impl MPSBinaryImageKernel {
416    extern_methods!(
417        #[cfg(feature = "MPSCoreTypes")]
418        /// The position of the destination clip rectangle origin relative to the primary source buffer.
419        ///
420        /// The offset is defined to be the position of clipRect.origin in source coordinates.
421        /// Default: {0,0,0}, indicating that the top left corners of the clipRect and primary source image align.
422        ///
423        /// See Also:
424        /// MetalPerformanceShaders.hsubsubsection_mpsoffset
425        #[unsafe(method(primaryOffset))]
426        #[unsafe(method_family = none)]
427        pub unsafe fn primaryOffset(&self) -> MPSOffset;
428
429        #[cfg(feature = "MPSCoreTypes")]
430        /// Setter for [`primaryOffset`][Self::primaryOffset].
431        #[unsafe(method(setPrimaryOffset:))]
432        #[unsafe(method_family = none)]
433        pub unsafe fn setPrimaryOffset(&self, primary_offset: MPSOffset);
434
435        #[cfg(feature = "MPSCoreTypes")]
436        /// The position of the destination clip rectangle origin relative to the secondary source buffer.
437        ///
438        /// The offset is defined to be the position of clipRect.origin in source coordinates.
439        /// Default: {0,0,0}, indicating that the top left corners of the clipRect and secondary source image align.
440        ///
441        /// See Also:
442        /// MetalPerformanceShaders.hsubsubsection_mpsoffset
443        #[unsafe(method(secondaryOffset))]
444        #[unsafe(method_family = none)]
445        pub unsafe fn secondaryOffset(&self) -> MPSOffset;
446
447        #[cfg(feature = "MPSCoreTypes")]
448        /// Setter for [`secondaryOffset`][Self::secondaryOffset].
449        #[unsafe(method(setSecondaryOffset:))]
450        #[unsafe(method_family = none)]
451        pub unsafe fn setSecondaryOffset(&self, secondary_offset: MPSOffset);
452
453        #[cfg(feature = "MPSCoreTypes")]
454        /// The MPSImageEdgeMode to use when texture reads stray off the edge of the primary source image
455        ///
456        /// Most MPSKernel objects can read off the edge of a source image. This can happen because of a
457        /// negative offset property, because the offset + clipRect.size is larger than the
458        /// source image or because the filter looks at neighboring pixels, such as a Convolution
459        /// or morphology filter.   Default: usually MPSImageEdgeModeZero. (Some MPSKernel types default
460        /// to MPSImageEdgeModeClamp, because MPSImageEdgeModeZero is either not supported or
461        /// would produce unexpected results.)
462        ///
463        /// See Also:
464        /// MetalPerformanceShaders.hsubsubsection_edgemode
465        #[unsafe(method(primaryEdgeMode))]
466        #[unsafe(method_family = none)]
467        pub unsafe fn primaryEdgeMode(&self) -> MPSImageEdgeMode;
468
469        #[cfg(feature = "MPSCoreTypes")]
470        /// Setter for [`primaryEdgeMode`][Self::primaryEdgeMode].
471        #[unsafe(method(setPrimaryEdgeMode:))]
472        #[unsafe(method_family = none)]
473        pub unsafe fn setPrimaryEdgeMode(&self, primary_edge_mode: MPSImageEdgeMode);
474
475        #[cfg(feature = "MPSCoreTypes")]
476        /// The MPSImageEdgeMode to use when texture reads stray off the edge of the secondary source image
477        ///
478        /// Most MPSKernel objects can read off the edge of a source image. This can happen because of a
479        /// negative offset property, because the offset + clipRect.size is larger than the
480        /// source image or because the filter looks at neighboring pixels, such as a Convolution
481        /// or morphology filter.   Default: usually MPSImageEdgeModeZero. (Some MPSKernel types default
482        /// to MPSImageEdgeModeClamp, because MPSImageEdgeModeZero is either not supported or
483        /// would produce unexpected results.)
484        ///
485        /// See Also:
486        /// MetalPerformanceShaders.hsubsubsection_edgemode
487        #[unsafe(method(secondaryEdgeMode))]
488        #[unsafe(method_family = none)]
489        pub unsafe fn secondaryEdgeMode(&self) -> MPSImageEdgeMode;
490
491        #[cfg(feature = "MPSCoreTypes")]
492        /// Setter for [`secondaryEdgeMode`][Self::secondaryEdgeMode].
493        #[unsafe(method(setSecondaryEdgeMode:))]
494        #[unsafe(method_family = none)]
495        pub unsafe fn setSecondaryEdgeMode(&self, secondary_edge_mode: MPSImageEdgeMode);
496
497        /// An optional clip rectangle to use when writing data. Only the pixels in the rectangle will be overwritten.
498        ///
499        /// A MTLRegion that indicates which part of the destination to overwrite. If the clipRect does not lie
500        /// completely within the destination image, the intersection between clip rectangle and destination bounds is
501        /// used.   Default: MPSRectNoClip (MPSKernel::MPSRectNoClip) indicating the entire image.
502        ///
503        /// See Also:
504        /// MetalPerformanceShaders.hsubsubsection_clipRect
505        #[unsafe(method(clipRect))]
506        #[unsafe(method_family = none)]
507        pub unsafe fn clipRect(&self) -> MTLRegion;
508
509        /// Setter for [`clipRect`][Self::clipRect].
510        #[unsafe(method(setClipRect:))]
511        #[unsafe(method_family = none)]
512        pub unsafe fn setClipRect(&self, clip_rect: MTLRegion);
513
514        /// Standard init with default properties per filter type
515        ///
516        /// Parameter `device`: The device that the filter will be used on. May not be NULL.
517        ///
518        /// Returns: a pointer to the newly initialized object. This will fail, returning
519        /// nil if the device is not supported. Devices must be
520        /// MTLFeatureSet_iOS_GPUFamily2_v1 or later.
521        #[unsafe(method(initWithDevice:))]
522        #[unsafe(method_family = init)]
523        pub unsafe fn initWithDevice(
524            this: Allocated<Self>,
525            device: &ProtocolObject<dyn MTLDevice>,
526        ) -> Retained<Self>;
527
528        /// NSSecureCoding compatability
529        ///
530        /// While the standard NSSecureCoding/NSCoding method
531        /// -initWithCoder: should work, since the file can't
532        /// know which device your data is allocated on, we
533        /// have to guess and may guess incorrectly.  To avoid
534        /// that problem, use initWithCoder:device instead.
535        ///
536        /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSKernel
537        ///
538        /// Parameter `device`: The MTLDevice on which to make the MPSKernel
539        ///
540        /// Returns: A new MPSKernel object, or nil if failure.
541        ///
542        /// # Safety
543        ///
544        /// `a_decoder` possibly has further requirements.
545        #[unsafe(method(initWithCoder:device:))]
546        #[unsafe(method_family = init)]
547        pub unsafe fn initWithCoder_device(
548            this: Allocated<Self>,
549            a_decoder: &NSCoder,
550            device: &ProtocolObject<dyn MTLDevice>,
551        ) -> Option<Retained<Self>>;
552
553        #[cfg(feature = "block2")]
554        /// This method attempts to apply the MPSKernel in place on a texture.
555        ///
556        /// In-place operation means that the same texture is used both to hold the input
557        /// image and the results. Operating in-place can be an excellent way to reduce
558        /// resource utilization, and save time and energy. While simple Metal kernels can
559        /// not operate in place because textures can not be readable and writable at the
560        /// same time, some MPSKernels can operate in place because they use
561        /// multi-pass algorithms. Whether a MPSKernel can operate in-place can
562        /// depend on current hardware, operating system revision and the parameters
563        /// and properties passed to it. You should never assume that a MPSKernel will
564        /// continue to work in place, even if you have observed it doing so before.
565        ///
566        /// If the operation succeeds in-place, YES is returned.  If the in-place operation
567        /// fails and no copyAllocator is provided, then NO is returned. In neither
568        /// case is the pointer held at *texture modified.
569        ///
570        /// Failure during in-place operation is common. You may find it simplifies your
571        /// code to provide a copyAllocator. When an in-place filter fails, your
572        /// copyAllocator will be invoked to create a new texture in which to write
573        /// the results, allowing the filter to proceed reliably out-of-place. The
574        /// original texture will be released, replaced with a pointer to the new texture
575        /// and YES will be returned. If the allocator returns an invalid texture, it is
576        /// released, *texture remains unmodified and NO is returned.  Please see the
577        /// MPSCopyAllocator definition for a sample allocator implementation.
578        ///
579        /// Note: Image filters that look at neighboring pixel values may actually consume more
580        /// memory when operating in place than out of place. Many such operations are
581        /// tiled internally to save intermediate texture storage, but can not tile when
582        /// operating in place. The memory savings for tiling is however very short term,
583        /// typically the lifetime of the MTLCommandBuffer.
584        ///
585        ///
586        /// Attempt to apply a MPSKernel to a texture in place.
587        ///
588        /// Parameter `commandBuffer`: A valid MTLCommandBuffer to receive the encoded filter
589        ///
590        /// Parameter `primaryTexture`: A pointer to a valid MTLTexture containing the
591        /// primary source image. It will not be overwritten.
592        ///
593        /// Parameter `inPlaceSecondaryTexture`: A pointer to a valid MTLTexture containing secondary image.
594        /// On success, the image contents and possibly texture itself
595        /// will be replaced with the result image.
596        ///
597        /// Parameter `copyAllocator`: An optional block to allocate a new texture to hold the
598        /// results, in case in-place operation is not possible. The
599        /// allocator may use a different MTLPixelFormat or size than
600        /// the original texture. You may enqueue operations on the
601        /// provided MTLCommandBuffer using the provided
602        /// MTLComputeCommandEncoder to initialize the texture contents.
603        ///
604        /// Returns: On success, YES is returned. The texture may have been replaced with a new
605        /// texture if a copyAllocator was provided.  On failure, NO is returned. The
606        /// texture is unmodified.
607        ///
608        /// # Safety
609        ///
610        /// - `primary_texture` may need to be synchronized.
611        /// - `primary_texture` may be unretained, you must ensure it is kept alive while in use.
612        /// - `in_place_secondary_texture` must be a valid pointer.
613        /// - `copy_allocator` must be a valid pointer or null.
614        #[unsafe(method(encodeToCommandBuffer:primaryTexture:inPlaceSecondaryTexture:fallbackCopyAllocator:))]
615        #[unsafe(method_family = none)]
616        pub unsafe fn encodeToCommandBuffer_primaryTexture_inPlaceSecondaryTexture_fallbackCopyAllocator(
617            &self,
618            command_buffer: &ProtocolObject<dyn MTLCommandBuffer>,
619            primary_texture: &ProtocolObject<dyn MTLTexture>,
620            in_place_secondary_texture: NonNull<NonNull<ProtocolObject<dyn MTLTexture>>>,
621            copy_allocator: MPSCopyAllocator,
622        ) -> bool;
623
624        #[cfg(feature = "block2")]
625        /// Attempt to apply a MPSKernel to a texture in place.
626        ///
627        /// This method attempts to apply the MPSKernel in place on a texture.
628        ///
629        /// ```text
630        ///           In-place operation means that the same texture is used both to hold the input
631        ///           image and the results. Operating in-place can be an excellent way to reduce
632        ///           resource utilization, and save time and energy. While simple Metal kernels can
633        ///           not operate in place because textures can not be readable and writable at the
634        ///           same time, some MPSKernels can operate in place because they use
635        ///           multi-pass algorithms. Whether a MPSKernel can operate in-place can
636        ///           depend on current hardware, operating system revision and the parameters
637        ///           and properties passed to it. You should never assume that a MPSKernel will
638        ///           continue to work in place, even if you have observed it doing so before.
639        /// ```
640        ///
641        /// If the operation succeeds in-place, YES is returned.  If the in-place operation
642        /// fails and no copyAllocator is provided, then NO is returned. In neither
643        /// case is the pointer held at *texture modified.
644        ///
645        /// Failure during in-place operation is common. You may find it simplifies your
646        /// code to provide a copyAllocator. When an in-place filter fails, your
647        /// copyAllocator will be invoked to create a new texture in which to write
648        /// the results, allowing the filter to proceed reliably out-of-place. The
649        /// original texture will be released, replaced with a pointer to the new texture
650        /// and YES will be returned. If the allocator returns an invalid texture, it is
651        /// released, *texture remains unmodified and NO is returned.  Please see the
652        /// MPSCopyAllocator definition for a sample allocator implementation.
653        ///
654        /// Note: Image filters that look at neighboring pixel values may actually consume more
655        /// memory when operating in place than out of place. Many such operations are
656        /// tiled internally to save intermediate texture storage, but can not tile when
657        /// operating in place. The memory savings for tiling is however very short term,
658        /// typically the lifetime of the MTLCommandBuffer.
659        ///
660        ///
661        /// Parameter `commandBuffer`: A valid MTLCommandBuffer to receive the encoded filter
662        ///
663        /// Parameter `inPlacePrimaryTexture`: A pointer to a valid MTLTexture containing secondary image.
664        /// On success, the image contents and possibly texture itself
665        /// will be replaced with the result image.
666        ///
667        /// Parameter `secondaryTexture`: A pointer to a valid MTLTexture containing the
668        /// primary source image. It will not be overwritten.
669        ///
670        /// Parameter `copyAllocator`: An optional block to allocate a new texture to hold the
671        /// results, in case in-place operation is not possible. The
672        /// allocator may use a different MTLPixelFormat or size than
673        /// the original texture. You may enqueue operations on the
674        /// provided MTLCommandBuffer using the provided
675        /// MTLComputeCommandEncoder to initialize the texture contents.
676        ///
677        /// Returns: On success, YES is returned. The texture may have been replaced with a new
678        /// texture if a copyAllocator was provided.  On failure, NO is returned. The
679        /// texture is unmodified.
680        ///
681        /// # Safety
682        ///
683        /// - `in_place_primary_texture` must be a valid pointer.
684        /// - `secondary_texture` may need to be synchronized.
685        /// - `secondary_texture` may be unretained, you must ensure it is kept alive while in use.
686        /// - `copy_allocator` must be a valid pointer or null.
687        #[unsafe(method(encodeToCommandBuffer:inPlacePrimaryTexture:secondaryTexture:fallbackCopyAllocator:))]
688        #[unsafe(method_family = none)]
689        pub unsafe fn encodeToCommandBuffer_inPlacePrimaryTexture_secondaryTexture_fallbackCopyAllocator(
690            &self,
691            command_buffer: &ProtocolObject<dyn MTLCommandBuffer>,
692            in_place_primary_texture: NonNull<NonNull<ProtocolObject<dyn MTLTexture>>>,
693            secondary_texture: &ProtocolObject<dyn MTLTexture>,
694            copy_allocator: MPSCopyAllocator,
695        ) -> bool;
696
697        /// Encode a MPSKernel into a command Buffer.  The operation shall proceed out-of-place.
698        ///
699        /// Parameter `commandBuffer`: A valid MTLCommandBuffer to receive the encoded filter
700        ///
701        /// Parameter `primaryTexture`: A valid MTLTexture containing the primary source image.
702        ///
703        /// Parameter `secondaryTexture`: A valid MTLTexture containing the secondary source image.
704        ///
705        /// Parameter `destinationTexture`: A valid MTLTexture to be overwritten by result image. destinationTexture may not alias the source textures.
706        ///
707        /// # Safety
708        ///
709        /// - `primary_texture` may need to be synchronized.
710        /// - `primary_texture` may be unretained, you must ensure it is kept alive while in use.
711        /// - `secondary_texture` may need to be synchronized.
712        /// - `secondary_texture` may be unretained, you must ensure it is kept alive while in use.
713        /// - `destination_texture` may need to be synchronized.
714        /// - `destination_texture` may be unretained, you must ensure it is kept alive while in use.
715        #[unsafe(method(encodeToCommandBuffer:primaryTexture:secondaryTexture:destinationTexture:))]
716        #[unsafe(method_family = none)]
717        pub unsafe fn encodeToCommandBuffer_primaryTexture_secondaryTexture_destinationTexture(
718            &self,
719            command_buffer: &ProtocolObject<dyn MTLCommandBuffer>,
720            primary_texture: &ProtocolObject<dyn MTLTexture>,
721            secondary_texture: &ProtocolObject<dyn MTLTexture>,
722            destination_texture: &ProtocolObject<dyn MTLTexture>,
723        );
724
725        /// Encode a MPSKernel into a command Buffer.  The operation shall proceed out-of-place.
726        ///
727        /// Parameter `commandBuffer`: A valid MTLCommandBuffer to receive the encoded filter
728        ///
729        /// Parameter `primaryImage`: A valid MPSImage containing the primary source image.
730        ///
731        /// Parameter `secondaryImage`: A valid MPSImage containing the secondary source image.
732        ///
733        /// Parameter `destinationImage`: A valid MPSImage to be overwritten by result image. destinationImage may not alias the source images.
734        #[unsafe(method(encodeToCommandBuffer:primaryImage:secondaryImage:destinationImage:))]
735        #[unsafe(method_family = none)]
736        pub unsafe fn encodeToCommandBuffer_primaryImage_secondaryImage_destinationImage(
737            &self,
738            command_buffer: &ProtocolObject<dyn MTLCommandBuffer>,
739            primary_image: &MPSImage,
740            secondary_image: &MPSImage,
741            destination_image: &MPSImage,
742        );
743
744        #[cfg(feature = "MPSCoreTypes")]
745        /// primarySourceRegionForDestinationSize: is used to determine which region of the
746        /// primaryTexture will be read by encodeToCommandBuffer:primaryTexture:secondaryTexture:destinationTexture
747        /// (and in-place variants) when the filter runs. This information may be needed if the
748        /// primary source image is broken into multiple textures.  The size of the full
749        /// (untiled) destination image is provided. The region of the full (untiled)
750        /// source image that will be read is returned. You can then piece together an
751        /// appropriate texture containing that information for use in your tiled context.
752        ///
753        /// The function will consult the MPSBinaryImageKernel primaryOffset and clipRect parameters,
754        /// to determine the full region read by the function. Other parameters such as
755        /// kernelHeight and kernelWidth will be consulted as necessary. All properties
756        /// should be set to intended values prior to calling primarySourceRegionForDestinationSize:.
757        ///
758        /// Caution: This function operates using global image coordinates, but
759        /// -encodeToCommandBuffer:... uses coordinates local to the source and
760        /// destination image textures. Consequently, the primaryOffset and clipRect
761        /// attached to this object will need to be updated using a global to
762        /// local coordinate transform before -encodeToCommandBuffer:... is
763        /// called.
764        ///
765        ///
766        /// Determine the region of the source texture that will be read for a encode operation
767        ///
768        /// Parameter `destinationSize`: The size of the full virtual destination image.
769        ///
770        /// Returns: The area in the virtual source image that will be read.
771        #[unsafe(method(primarySourceRegionForDestinationSize:))]
772        #[unsafe(method_family = none)]
773        pub unsafe fn primarySourceRegionForDestinationSize(
774            &self,
775            destination_size: MTLSize,
776        ) -> MPSRegion;
777
778        #[cfg(feature = "MPSCoreTypes")]
779        /// secondarySourceRegionForDestinationSize: is used to determine which region of the
780        /// sourceTexture will be read by encodeToCommandBuffer:primaryTexture:secondaryTexture:destinationTexture
781        /// (and in-place variants) when the filter runs. This information may be needed if the
782        /// secondary source image is broken into multiple textures.  The size of the full
783        /// (untiled) destination image is provided. The region of the full (untiled)
784        /// secondary source image that will be read is returned. You can then piece together an
785        /// appropriate texture containing that information for use in your tiled context.
786        ///
787        /// The function will consult the MPSBinaryImageKernel secondaryOffset and clipRect
788        /// parameters, to determine the full region read by the function. Other parameters
789        /// such as kernelHeight and kernelWidth will be consulted as necessary.  All properties
790        /// should be set to intended values prior to calling secondarySourceRegionForDestinationSize:.
791        ///
792        /// Caution: This function operates using global image coordinates, but
793        /// -encodeToCommandBuffer:... uses coordinates local to the source and
794        /// destination image textures. Consequently, the secondaryOffset and clipRect
795        /// attached to this object will need to be updated using a global to
796        /// local coordinate transform before -encodeToCommandBuffer:... is
797        /// called.
798        ///
799        ///
800        /// Determine the region of the source texture that will be read for a encode operation
801        ///
802        /// Parameter `destinationSize`: The size of the full virtual destination image.
803        ///
804        /// Returns: The area in the virtual source image that will be read.
805        #[unsafe(method(secondarySourceRegionForDestinationSize:))]
806        #[unsafe(method_family = none)]
807        pub unsafe fn secondarySourceRegionForDestinationSize(
808            &self,
809            destination_size: MTLSize,
810        ) -> MPSRegion;
811    );
812}
813
814/// Methods declared on superclass `MPSKernel`.
815#[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
816impl MPSBinaryImageKernel {
817    extern_methods!(
818        /// Called by NSCoder to decode MPSKernels
819        ///
820        /// This isn't the right interface to decode a MPSKernel, but
821        /// it is the one that NSCoder uses. To enable your NSCoder
822        /// (e.g. NSKeyedUnarchiver) to set which device to use
823        /// extend the object to adopt the MPSDeviceProvider
824        /// protocol. Otherwise, the Metal system default device
825        /// will be used.
826        ///
827        /// # Safety
828        ///
829        /// `a_decoder` possibly has further requirements.
830        #[unsafe(method(initWithCoder:))]
831        #[unsafe(method_family = init)]
832        pub unsafe fn initWithCoder(
833            this: Allocated<Self>,
834            a_decoder: &NSCoder,
835        ) -> Option<Retained<Self>>;
836    );
837}
838
839/// Methods declared on superclass `NSObject`.
840#[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
841impl MPSBinaryImageKernel {
842    extern_methods!(
843        #[unsafe(method(init))]
844        #[unsafe(method_family = init)]
845        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
846
847        #[unsafe(method(new))]
848        #[unsafe(method_family = new)]
849        pub unsafe fn new() -> Retained<Self>;
850    );
851}