CIKernel & Metal Shading Language

Updated
Mar 23, 2021 1:09 PM
Created
Mar 23, 2021 5:42 AM
Tags
CoreImage
Keywords

image

Metal Shading Language Extensions

☝️

Core Image provides a set of language extensions to MSL in CIKernelMetalLib.h. These extensions include three new data types for working with images: sampler (for accessing the input image), sample_t (represents a single color sample from the input image), and destination (for accessing the output image). The extensions also include convenience functions such as color conversion and premultiply / unpremultiply. Whereas in CIKL, you typically called global functions when working with, for example, coordinates and samples, these functions are implemented as member functions on the new types. The following table shows a summary of CIKL global functions and their equivalent MSL functions.

Keyword Mapping

TitleTypeCore Image Kernel LanguageMetal Shading Language
Get destination coordinate
destCoord()
dest.coord()
Transform coordinate to sampler space
samplerTransform(src, p)
src.transform(p)
Get destination coordinate in sampler space
samplerCoord(src)
src.coord()
Sample from source image
sample(src, p)
src.sample(p)
Get extent of source image
samplerExtent(src)
src.extent()

Notes

  • CIColorKernel is specialized kernels for processing single samples (i.e. pixels), not whole samplers (i.e. textures).

Examples