swift - 设置 fastMathEnabled 以便在 swift 中进行精确计算

标签 swift metal metalkit

由于我不需要在计算中优化浮点运算,我该如何在 swift 中将 fastMathEnabled 设置为 false?

最佳答案

如果您希望它应用于由 Xcode 编译并包含在默认库中的所有着色器,您可以将选项 -fno-fast-math 添加到 MTL_COMPILER_FLAGS(其他 Metal 编译器标志) 在 Xcode build设置中设置。来源:Apple Metal Shading Language Specification .

如果您在运行时编译着色器,则将选项传递给 MTLDevice makeLibrary function :

let device = MTLCreateSystemDefaultDevice()!
let options = MTLCompileOptions()
options.fastMathEnabled = false
try device.makeLibrary(source: source, options: options)

其中 source 是包含您要编译的着色器源代码的字符串。

关于swift - 设置 fastMathEnabled 以便在 swift 中进行精确计算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51375608/

相关文章:

swift - 如何使用swift获取字典中的索引值

arrays - 如何从数组中删除特定对象?

swift - 使用 SCNGeometryPrimitiveType 多边形崩溃/错误创建自定义 SCNGeometry 多边形平面

cocoa - 如何使 NSScrollView 内的 MTKView 显示滚动条

image-processing - 使用 Swift 4 在 Metal Compute Kernel 中传递参数

ios - Metal 计算着色器线程组和线程执行宽度

ios - 如何使用图像纹理数据创建 OffScreen 缓冲区

ios - Swift:如何更新可变形对象

swift - MTLCreateSystemDefaultDevice() 在装有 iOS 10.3 的 iPad 上返回 nil

swift - 带有协议(protocol)对象的纯 swift 集