1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ffi::*;
use core::ptr::NonNull;
use objc2::__framework_prelude::*;
use objc2_foundation::*;
use objc2_metal::*;
use crate::*;
extern_class!(
/// Dependencies: This depends on Metal.framework
///
/// The MPSKernel class is the base class for all MPS objects. It defines a standard interface for
/// MPS kernels. You should not use the MPSKernel class directly. Instead, a number of MPSKernel
/// subclasses are available in MetalPerformanceShaders.framework that define specific high-performance
/// image processing operations.
///
/// The basic sequence for applying a MPSKernel to an image is as follows:
///
/// 1. Create a MPSKernel corresponding to the operation you wish to perform:
///
/// ```text
/// MPSImageSobel *sobel = [[MPSImageSobel alloc] initWithDevice: mtlDevice];
/// ```
///
/// 2. Encode the filter into a command buffer:
///
/// ```text
/// sobel.offset = ...;
/// sobel.clipRect = ...;
/// sobel.options = ...;
/// [sobel encodeToCommandBuffer: commandBuffer
/// sourceTexture: inputImage
/// destinationTexture: resultImage ];
/// ```
///
/// Encoding the kernel merely encodes the operation into a MTLCommandBuffer. It does not modify any pixels, yet.
/// All MPSKernel state has been copied to the command buffer. MPSKernels may be reused. If the texture was previously
/// operated on by another command encoder (e.g. MTLRenderCommandEncoder), you should call -endEncoding on the other
/// encoder before encoding the filter.
///
/// Some MPS filters work in place (inputImage = resultImage) even in situations where Metal might not
/// normally allow in place operation on textures. If in-place operation is desired, you may attempt to call
/// [MPSKernel encodeKernelInPlace...]. If the operation can not be completed in place, then
/// NO will be returned and you will have to create a new result texture and try again. To make an in-place
/// image filter reliable, pass a fallback MPSCopyAllocator to the method to create a new texture to write
/// to in the event that a filter can not operate in place.
///
/// (Repeat steps 2 for more filters, as desired.)
///
/// It should be self evident that step 2 may not be thread safe. That is, you can not have
/// multiple threads manipulating the same properties on the same MPSKernel object at the
/// same time and achieve coherent output. In common usage, the MPSKernel properties don't
/// often need to be changed from their default values, but if you need to apply the same
/// filter to multiple images on multiple threads with cropping / tiling, make additional
/// MPSKernel objects per thread. They are cheap. You can use multiple MPSKernel objects on
/// multiple threads, as long as only one thread is operating on any particular MPSKernel
/// object at a time.
///
/// 3. After encoding any additional work to the command buffer using other encoders, submit the MTLCommandBuffer
/// to your MTLCommandQueue, using:
///
/// ```text
/// [mtlCommandBuffer commit];
/// ```
///
/// A MPSKernel can be saved to disk / network using NSCoders such as NSKeyedArchiver.
/// When decoding, the system default MTLDevice will be chosen unless the NSCoder adopts
/// the
/// <MPSDeviceProvider
/// > protocol. To accomplish this, subclass or extend your unarchiver
/// to add this method.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpskernel?language=objc)
#[unsafe(super(NSObject))]
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct MPSKernel;
);
extern_conformance!(
unsafe impl NSCoding for MPSKernel {}
);
extern_conformance!(
unsafe impl NSCopying for MPSKernel {}
);
unsafe impl CopyingHelper for MPSKernel {
type Result = Self;
}
extern_conformance!(
unsafe impl NSObjectProtocol for MPSKernel {}
);
extern_conformance!(
unsafe impl NSSecureCoding for MPSKernel {}
);
impl MPSKernel {
extern_methods!(
#[cfg(feature = "MPSCoreTypes")]
/// The set of options used to run the kernel.
/// subsubsection_options
#[unsafe(method(options))]
#[unsafe(method_family = none)]
pub unsafe fn options(&self) -> MPSKernelOptions;
#[cfg(feature = "MPSCoreTypes")]
/// Setter for [`options`][Self::options].
#[unsafe(method(setOptions:))]
#[unsafe(method_family = none)]
pub unsafe fn setOptions(&self, options: MPSKernelOptions);
/// The device on which the kernel will be used
#[unsafe(method(device))]
#[unsafe(method_family = none)]
pub unsafe fn device(&self) -> Retained<ProtocolObject<dyn MTLDevice>>;
/// A string to help identify this object.
#[unsafe(method(label))]
#[unsafe(method_family = none)]
pub unsafe fn label(&self) -> Option<Retained<NSString>>;
/// Setter for [`label`][Self::label].
///
/// This is [copied][objc2_foundation::NSCopying::copy] when set.
#[unsafe(method(setLabel:))]
#[unsafe(method_family = none)]
pub unsafe fn setLabel(&self, label: Option<&NSString>);
/// Standard init with default properties per filter type
///
/// Parameter `device`: The device that the filter will be used on. May not be NULL.
///
/// Returns: a pointer to the newly initialized object. This will fail, returning
/// nil if the device is not supported. Devices must be
/// MTLFeatureSet_iOS_GPUFamily2_v1 or later.
#[unsafe(method(initWithDevice:))]
#[unsafe(method_family = init)]
pub unsafe fn initWithDevice(
this: Allocated<Self>,
device: &ProtocolObject<dyn MTLDevice>,
) -> Retained<Self>;
/// Make a copy of this MPSKernel for a new device
///
/// -copyWithZone: will call this API to make a copy of the
/// MPSKernel on the same device. This interface may also be
/// called directly to make a copy of the MPSKernel on a new
/// device. Typically, the same MPSKernels should not be used
/// to encode kernels on multiple command buffers from multiple
/// threads. Many MPSKernels have mutable properties that might
/// be changed by the other thread while this one is trying to
/// encode. If you need to use a MPSKernel from multiple threads
/// make a copy of it for each additional thread using -copyWithZone:
/// or -copyWithZone:device:
///
/// Parameter `zone`: The NSZone in which to allocate the object
///
/// Parameter `device`: The device for the new MPSKernel. If nil, then use
/// self.device.
///
/// Returns: a pointer to a copy of this MPSKernel. This will fail, returning
/// nil if the device is not supported. Devices must be
/// MTLFeatureSet_iOS_GPUFamily2_v1 or later.
///
/// # Safety
///
/// `zone` must be a valid pointer or null.
#[unsafe(method(copyWithZone:device:))]
#[unsafe(method_family = copy)]
pub unsafe fn copyWithZone_device(
&self,
zone: *mut NSZone,
device: Option<&ProtocolObject<dyn MTLDevice>>,
) -> Retained<Self>;
/// Called by NSCoder to decode MPSKernels
///
/// This isn't the right interface to decode a MPSKernel, but
/// it is the one that NSCoder uses. To enable your NSCoder
/// (e.g. NSKeyedUnarchiver) to set which device to use
/// extend the object to adopt the MPSDeviceProvider
/// protocol. Otherwise, the Metal system default device
/// will be used.
///
/// # Safety
///
/// `a_decoder` possibly has further requirements.
#[unsafe(method(initWithCoder:))]
#[unsafe(method_family = init)]
pub unsafe fn initWithCoder(
this: Allocated<Self>,
a_decoder: &NSCoder,
) -> Option<Retained<Self>>;
/// NSSecureCoding compatability
///
/// While the standard NSSecureCoding/NSCoding method
/// -initWithCoder: should work, since the file can't
/// know which device your data is allocated on, we
/// have to guess and may guess incorrectly. To avoid
/// that problem, use initWithCoder:device instead.
///
/// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSKernel
///
/// Parameter `device`: The MTLDevice on which to make the MPSKernel
///
/// Returns: A new MPSKernel object, or nil if failure.
///
/// # Safety
///
/// `a_decoder` possibly has further requirements.
#[unsafe(method(initWithCoder:device:))]
#[unsafe(method_family = init)]
pub unsafe fn initWithCoder_device(
this: Allocated<Self>,
a_decoder: &NSCoder,
device: &ProtocolObject<dyn MTLDevice>,
) -> Option<Retained<Self>>;
);
}
/// Methods declared on superclass `NSObject`.
impl MPSKernel {
extern_methods!(
#[unsafe(method(init))]
#[unsafe(method_family = init)]
pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
#[unsafe(method(new))]
#[unsafe(method_family = new)]
pub unsafe fn new() -> Retained<Self>;
);
}