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.

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

[commandBuffer commit];

Note

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 kernel object at the same time and achieve coherent output. In common usage, the kernel 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 kernel objects per thread (they are cheap). You can use multiple kernel objects on multiple threads, as long as only one thread is operating on any particular kernel object at a time.

Relationships

Inherits From

Conforms To

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.