A standard interface for Metal Performance Shaders kernels.


@interface MPSKernel : NSObject


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:

  1. Initialize a kernel corresponding to the operation you wish to perform:

    MPSImageSobel *sobel = [[MPSImageSobel alloc] initWithDevice: mtlDevice];
  2. Encode the kernel into a command buffer.

    sobel.offset = ...;
    sobel.clipRect = ...;
    sobel.options = ...;
    [sobel encodeToCommandBuffer: commandBuffer sourceTexture: inputImage destinationTexture: resultImage;
    if(returnVal < 0)

    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 endEncoding method 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 encodeToCommandBuffer:inPlaceTexture:fallbackCopyAllocator: method. If the operation cannot 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 block 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.

  3. After encoding any additional work to the command buffer using other encoders, submit the command buffer to your command queue, using:

    [commandBuffer commit];



- initWithDevice:

Initializes a new kernel object.

- copyWithZone:device:

Makes a copy of this kernel object for a new device.



The set of options used to run the kernel.


The options used when creating a kernel.


The device on which the kernel will be used.


The string that identifies the kernel.


Inherits From