Search code examples
kernelmetalcifiltercikernel

Are there any differences between Metal kernels on iOS and Mac?


Are there any major differences between the Metal Shader Language on iOS and Mac? I'm trying to port my Metal cifilters from iOS, and they seem to look completely different


Solution

  • Yes, there shouldn't be a difference between the platforms on the language level.

    One difference I can think of is that macOS supports images with 32 bits per channel ("full" float), whereas in iOS you can "only" use 16-bit half float images.

    Another difference that just came to mind is the default coordinate space of input samplers. In iOS, the sampler space is in relative coordinates ([0...1]), whereas in macOS it's in absolute coordinates ([0...width]). You should be able to unify that behavior by explicitly setting the sampler matrix like that (in macOS):

    // see documentation for `kCISamplerAffineMatrix`
    let scaleMatrix = [1.0/inputImage.extent.width, 0, 0, 1.0/inputImage.extent.height, 0, 0]
    let inputSampler = CISampler(image: inputImage, options: [kCISamplerAffineMatrix: scaleMatrix])
    kernel.apply(extent: domainOfDefinition, roiCallback: roiCallback, arguments: [inputSampler, ...])