A standard interface for Metal Performance Shaders kernels.
- iOS 9.0+
- macOS 10.13+
- tvOS 9.0+
- Metal Performance Shaders
You should not use the
MPSKernel class directly. Instead, a number of subclasses are available that define specific high-performance data-parallel operations.
The basic sequence for applying a kernel to an image is as follows:
Initialize a kernel corresponding to the operation you wish to perform:
Encode the kernel into a command buffer.
Encoding the kernel merely encodes the operation into a command buffer. It does not modify any pixels, yet. All kernel state has been copied to the command buffer. Kernels may be reused. If the texture was previously operated on by another command encoder (e.g. a render command encoder), you should call the
endmethod on the other encoder before encoding the filter.
Some kernels work in place, 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 the
encode(commandmethod. If the operation cannot be completed in place, then
Buffer: in Place Texture: fallback Copy Allocator:)
falsewill 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
MPSCopyblock to the method to create a new texture to write to in the event that a filter cannot operate in place.
You may repeat step 2 to encode more kernels, as desired.
After encoding any additional work to the command buffer using other encoders, submit the command buffer to your command queue, using: