Metalを利用しているアプリで、iOS 9のデバイスでMTLRenderPipelineStateを作成するのに失敗していて、iOS 10のAPIを使っているところは回避してるはずなのに何だろうと思ってエラーメッセージを見てみたら、
Error Domain=AGXMetalG4P Code=1 "Function {関数名} is using language version 1.2 which is incompatible with this OS."
と、Metal Shading Language のバージョンの問題だった。Metal 1.2はiOS 9では使えないよ、と。
利用するMetal Shading Languageのバージョンを指定する
Metal Shading Language Specificationの「6.3 Options Controlling the Language Version」にバージョンの指定方法と、各言語バージョンとiOSバージョンの関係が書いてあった。
-
ios-metal1.0
– support the unified graphics / compute language revision 1.0 programs
for iOS 8.0. -
ios-metal1.1
– support the unified graphics / compute language revision 1.1 programs
for iOS 9.0. -
ios-metal1.2
– support the unified graphics / compute language revision 1.2 programs
for iOS 10.0. -
osx-metal1.1
– support the unified graphics / compute language revision 1.1 programs
for OS X 10.11. -
osx-metal1.2
– support the unified graphics / compute language revision 1.2 programs
for macOS 10.12.
Xcodeでの設定方法
上記のドキュメントでは、コンパイラオプションに -std=
に続いて上のバージョンのどれかを指定するように書かれているが、Xcode だと "Metal Compiler - Features" というセクションに、"Metal language revision" というプルダウンで設定できる項目がある。(8.3で確認)