0

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

4

1 回答 1

1

如果您希望它适用于所有由 Xcode 编译并包含在默认库中的着色器,您可以在 Xcode 构建设置中的 MTL_COMPILER_FLAGS(其他金属编译器标志)设置中添加选项-fno-fast-math 。资料来源:Apple 金属着色语言规范

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

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

source包含要编译的着色器源代码的字符串在哪里。

于 2018-07-17T08:03:09.440 回答