using xcrun to compile .metal shader

XCRUN

Two questions

  1. What version does xcrun use when not specified with 'std=ios-metal2.4'?
  2. How can I find out, if I want to use 'std=ios-metal...', what version to use?

Also is there somewhere documentation about all the xcrun command flags and what ios-metal version(s) run on what chipset (eg. A11 can run ios-metal...)? Can't seem to find them.

Test setup

I am building for a iPhone 8 running iOS version 13.5.1. The terminal commands I run (see below):

$ xcrun -sdk iphoneos metal -c -mios-version-min=13.5 MyLibrary.metal -o MyLibrary.air
$ xcrun -sdk iphoneos metallib MyLibrary.air -o MyLibrary.metallib

This builds and run on the device. But when I run it with the 'std=ios-metal2.4' flag (see below):

$ xcrun -sdk iphoneos metal -c -std=ios-metal2.4 -mios-version-min=13.5 MyLibrary.metal -o MyLibrary.air
$ xcrun -sdk iphoneos metallib MyLibrary.air -o MyLibrary.metallib

It does not build and run on the device. The error I get is this: Error Domain=AGXMetalA11 Code=3 "Function myFunction is using language version 2.4 which is incompatible with this OS."

I refer to this 4 year old forum post, there a similar question is asked, but I still miss some information: https://developer.apple.com/forums/thread/105719

I did found this on the forum, which helped me to lower the compiler iOS build version using '-mios-version-min', but no information on '-std=ios-metal' is given: https://developer.apple.com/forums/thread/105719

I found this post on the forum which gave me information on 'mios-version-min', but nothing was give on '-std': https://developer.apple.com/forums/thread/105719. However, the question about the documentation, I found on the forum that you can run xcrun metal -help and get an extensive list of flags: https://developer.apple.com/forums/thread/720556. Sadly the information on 'std=...' is limited.

I think you're trying to over-specify it. When building Metal shaders from Xcode 14.2 there is no "-std" or "-mios-version-min". Instead there is just "-target air64-apple-ios16.2" where 16.2 should be replaced by your iOS deployment target. And this will automatically enable the corresponding available Metal language version.

You can add this to one of your shaders and see which warnings get generated:

#if __METAL_VERSION__ >= 200
#warning Metal 2.0
#endif

#if __METAL_VERSION__ >= 240
#warning Metal 2.4
#endif

#if __METAL_VERSION__ >= 300
#warning Metal 3.0
#endif

In my tries iOS 15 gives up to Metal 2.4 while setting iOS 16 target will also give Metal 3.0. And iOS 13.5 just gives Metal 2.0 (you can maybe get some intermediate versions between 2.0 and 2.4).

using xcrun to compile .metal shader
 
 
Q