"xcrun metal" vs. "MTLDevice::newLibraryWithSource()" compile options

Hi,

when compiling shaders, metal command line tool has more options than MTLDevice::newLibraryWithSource().

For instance, "man metal" mentions 10 levels of optimization (-O0, -O1, -O2, -O3, -Ofast, -Os ...) while MTLCompileOptions doc only shows 2 levels (Default, Size).

Is there a way to pass -O2 as optimization level to MTLDevice::newLibraryWithSource()?

Thanks

Accepted Reply

You do not need to explicitly set any MTLCompileOption to get -O2 optimization level as that is the default. The explicit level in the API is MTLLibraryOptimizationLevelDefault.

While man metal mentions all those options, please note that in the Metal Shading Language Specification 3.1 §1.5.5 (Optimization Compiler Options) lists -O2 and -Os (just like the documentation for MTLLibraryOptimizationLevel) as the only supported options.

Replies

You do not need to explicitly set any MTLCompileOption to get -O2 optimization level as that is the default. The explicit level in the API is MTLLibraryOptimizationLevelDefault.

While man metal mentions all those options, please note that in the Metal Shading Language Specification 3.1 §1.5.5 (Optimization Compiler Options) lists -O2 and -Os (just like the documentation for MTLLibraryOptimizationLevel) as the only supported options.