swift 3.0 load metallib file to create MTLlibrary failed

I met a problem about using xcrun command line tool building a metallib file from metal source , but I use swift codes as follows:


let mstr : String? = Bundle.main.path(forResource: "PS", ofType: "metallib")//it is ok

styleLib = try! device!.makeLibrary(filepath: mstr!)//it crashed here with error


It gives a error like this:

fatal error: 'try!' expression unexpectedly raised an error: Error Domain=MTLLibraryErrorDomain Code=1 "This library format is not supported on this platform (or was built with an old version of the tools)" UserInfo={NSLocalizedDescription=This library format is not supported on this platform (or was built with an old version of the tools)}: file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-800.0.63/src/swift/stdlib/public/core/ErrorType.swift, line 178

It seems that my command line tool is old ,but I update it , errors like that also occured.


Anyone meet this?

Replies

I try add metal source to my project ,and using newDefaultLibrary for create globel MTLlibrary ,it successed.

But I use ".metallib" file to create library is crash, so Why?

How are you creating your metallib on the command line, and what kind of device are you running on? It's important to specify which SDK should be used when running the metal and metallib tools, as shown here.

Hi @wcm,

I used Metal Tools command line as follows to produce a metallib file :

xcrun -sdk macosx metal MyLibrary.metal -o MyLibrary.air

xcrun -sdk macosx metallib MyLibrary.air -o MyLibrary.metallib

My device is iphone6 plus and on ios 10

Have you tried specifying --sdk iphoneos instead?