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!

Replies

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.

  • @Iolo,

    When you say When you're able to get metal-source to work, ..., does that mean metal-source doesn't work on the currrent betas (1,2)?

    Thanks.

Add a Comment

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!

  • I tried your project, I was able to get it to work by using air-lipo to thin the harvested archive to not include the AIR slice. This is a bug and won't be necessary in a future release.

  • @Iolo,

    I've tried air-lipo. Even though metal-source doesn't fail with this thin file, it produces a directory, not a JSON file. I've tried feeding this directory and JSON files in the directory, nothing gets me a GPU native binary using the metal command, as per the session video).

    So it still doesn't seem possible to harvest a Pipeline JSON file that can ultimately be used to generate a GPU binary.

  • @Iolo, one of the files in the directory produced by metal-source, look sort of like mtlp-json in the session video. I've uploaded the file and file listing of the directory in this gist. Again, trying to use this file or the directory with metal to produce a GPU native binary did not work.

Add a Comment

@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