iOS 和 Mac 上的 Metal 内核有什么区别吗?

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

iOS 和 Mac 上的金属着色器语言之间有什么主要区别吗?我正在尝试从 iOS 移植我的 Metal cifilters,它们看起来完全不同

是的,在语言级别上,平台之间应该没有区别。

我能想到的一个区别是 macOS 支持每通道 32 位的图像("full" 浮点数),而在 iOS 中你可以 "only" 使用 16 位半浮点数图片。

刚刚想到的另一个区别是输入采样器的默认坐标 space。在 iOS 中,采样器 space 在相对坐标中 ([0...1]),而在 macOS 中它在绝对坐标中 ([0...width])。您应该能够通过像这样(在 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, ...])