Offline compilation: are the new metal tools already available in Xcode 14 beta?

Hi All, I tried using the new metal tools for compiling Metal shaders at build time (as explained in this session https://developer.apple.com/videos/play/wwdc2022/10102/), but I got some errors. In particular:

  • the command "metal shadersfilename.metal -N descriptors.mtlp-json -o archive.metallib" complains about the -N argument.
  • the command "metal-tt shaders.metallib descriptors.mtlp-json -o archive.metallib" doesn't seem to recognise the JSON format.

Also the command to extract the JSON pipeline from a binary archive (metal-source) fails. I'm using Xcode 14.0 beta (14A5228q) on macOS Ventura beta.

Are the new Metal tools for offline compilation already available (and I'm simply doing something wrong) or do I need to wait for next betas?

Thanks!

I would check the mtlp-json extension, since it uses new formatting. The screenshot at 4:53 in that video is actually a different format then the one mtlp-json uses. That one will use pipelines-json, so maybe try again with that extension.

When you're able to get metal-source to work, it should produce mtlp-json, which will look a bit different than the format from that time-code I mentioned.

I also have had no luck with metal-source, even with the new beta 2 (MacOS and XCode).

Here's my single swift, command line reproduction project:

I'm excited to plug this into my project once it works!

@lolo, thanks for your reply.

Unfortunately using the pipelines-json extension doesn't seem to help.

I get the same error:

warning build: argument unused during compilation: '-N descriptors.pipelines-json' [-Wunused-command-line-argument]

I'm also stuck on trying to generate a proper mtlp-json file using metal-source. I have exactly the same error as reported by @peterwong7:

metal-source: error: unsupported binary format

FYI - Still seems to be an issue with Beta 4.

Updated my reproduction repo (peterwmwong/x-metal-source-on-harvested-gpu-archive) with Beta 4 results and using trying air-lipo before metal-source (doesn't create a JSON file, but a directory of .metallib files).

I have an open ticket for this FB10274656.

Does anyone know what the status with this is?

I'm really excited about generating GPU binaries entirely at project build time but still can't this feature to work.

FYI I just updated to the latest Xcode version Version 14.1 (14B47b) released 1st November 2022.

I'm trying to run the same command in the WWDC 2022 video (6:32)

xcrun -sdk macosx metal -c shader.metal -N descriptors.mtlp-json -o shader.air

but get this warning

...
metal: warning: argument unused during compilation: '-N descriptors.mtlp-json' [-Wunused-command-line-argument]
...

Xcode Version 14.1 (14B47) + iPhone12ProMax 16.2beta still do not get mtlp-json by metal-source (with or without air-lipo), below is the command:

xcrun metal-source -flatbuffers=json binaryArchive_1007_iOS16_.metallib -o ./descriptors3.mtlp-json

xcrun air-lipo binaryArchive_1007_iOS16_.metallib -thin applegpu_g13p -output applegpu_g13p.metallib

xcrun metal-source -flatbuffers=json applegpu_g13p.metallib -o ./descriptors3.mtlp-json

both of them got the same result(three binary, no json files):

descriptors3.mtlp-json ~metallib ~~98C2A0BE-8A64-3CD2-B587-B427709ACDA7.metallib ~object ~~0-0.metallib ~~1-0.metallib

Offline compilation: are the new metal tools already available in Xcode 14 beta?
 
 
Q