Set Metal language version

Hi,

I'm trying to compile my .metal file into .metallib with:

xcrun -sdk iphoneos metal -std=ios-metal1.1 Shaders.metal -o CameraShader.air
xcrun -sdk iphoneos metallib CameraShader.air -o CameraShader.metallib


But when I call device.makeRenderPipelineState it throws with error:

Error Domain=AGXMetalA9 Code=1 "Function displayTexture has a deployment target which is incompatible with this OS." UserInfo={NSLocalizedDescription=Function displayTexture has a deployment target which is incompatible with this OS.}

If I use .metal file everything works fine.

What I'm doing wrong?

Answered by Graphics and Games Engineer in 321138022

Since you're compiling your Metal code on the command-line (not using the Xcode project), the complier doesn't know the deployment target. So, by default, it uses the version of the SDK as the deployment target (I'm guessing you have an iOS 11 SDK since it works on a device with iOS11 but not iOS10).


You need to use the -mios-version-min option with the Metal compiler like the following:


xcrun -sdk iphoneos metal -std=ios-metal1.1 -mios-version-min=8.0 Shaders.metal -o CameraShader.air

What version of the OS are you trying to run your app on? What is your app's depolyment target?

iPhone 6s running on iOS 10.3.3, app deployment target iOS 8.

On iPhone X with iOS 11.4 everything works fine.

Accepted Answer

Since you're compiling your Metal code on the command-line (not using the Xcode project), the complier doesn't know the deployment target. So, by default, it uses the version of the SDK as the deployment target (I'm guessing you have an iOS 11 SDK since it works on a device with iOS11 but not iOS10).


You need to use the -mios-version-min option with the Metal compiler like the following:


xcrun -sdk iphoneos metal -std=ios-metal1.1 -mios-version-min=8.0 Shaders.metal -o CameraShader.air

Thank you!

Set Metal language version
 
 
Q