Recommended optimization level for Metal shaders

Hi,


When compiling the shader from the command line via "xcrun metal" there is an option toi specify compiler optimization levels "-Od", "-O0", "-O1", "-O2", "-O3" and a few more exotic ones.

What it the recommended level?


Bonus questions:

Are these levels respected by the Metal compiler frontent and backend?

How do they map to optimizations clang can perform in comparison to C++?

Accepted Reply

There probably isn't much difference between these optimization levels (at this point anyways). When you run xcrun metal, you're only compiling to an internal representation which will ship with your app. When you create a pipeline at runtime with a shader from that internal represntation, the GPU Specific Compiler will covert the representation to the GPU Specific ISA and do a lot of optimization work regardless of the optimization level you used with -O flag.


These flags mostly exist in the metal compiler becasue it's based upon the Clang compiler which uses these flags (and actually makes some difference).

Replies

There probably isn't much difference between these optimization levels (at this point anyways). When you run xcrun metal, you're only compiling to an internal representation which will ship with your app. When you create a pipeline at runtime with a shader from that internal represntation, the GPU Specific Compiler will covert the representation to the GPU Specific ISA and do a lot of optimization work regardless of the optimization level you used with -O flag.


These flags mostly exist in the metal compiler becasue it's based upon the Clang compiler which uses these flags (and actually makes some difference).