Passing MTLTexture to Metal Core Image Kernel

Is it possible to pass MTLTexture to Metal Core Image Kernel? How can Metal resources be shared with Core Image?

Accepted Reply

You can simply initialize a CIImage with the texture and pass that to the kernel:

let ciImage = CIImage(mtlTexture: texture)

The documentation also mentions what you need to do to let Core Image render into a Metal texture.

If you want to incorporate a Metal processing step into a Core Image pipeline instead, I recommend you check out CIImageProcessorKernel.

  • I think in this case, CIContext may also need to be initialised with metalDevice, correct?

  • Correct. But it also creates a Metal context by default if you just use CIContext(). You would need to have a Metal-based context anyways if you want to use Metal Core Image kernels.

Add a Comment

Replies

You can simply initialize a CIImage with the texture and pass that to the kernel:

let ciImage = CIImage(mtlTexture: texture)

The documentation also mentions what you need to do to let Core Image render into a Metal texture.

If you want to incorporate a Metal processing step into a Core Image pipeline instead, I recommend you check out CIImageProcessorKernel.

  • I think in this case, CIContext may also need to be initialised with metalDevice, correct?

  • Correct. But it also creates a Metal context by default if you just use CIContext(). You would need to have a Metal-based context anyways if you want to use Metal Core Image kernels.

Add a Comment