Bill Hollings
Bill Hollings

Reputation: 2374

Format of Metal compiled metallib shader file?

For runtime-generated shader code, I'm interested in exploring whether it's possible to auto-generate compiled Metal Shader Language (MSL) code directly (as found in a .metallib file, and as used with the newLibraryWithData:error: method), instead of auto-generating human-readable MSL source code (as used with the newLibraryWithSource:options:error: method).

Rationale for this are two-fold:

  1. Depending on the compiled-code format, it may be simpler and cleaner for a program to auto-generate compiled shader code, rather than messing around with the human-readable format.
  2. Removing the shader compile stage would speed-up the creation of runtime-generated shaders.

Is documentation available for the format of compiled MSL code, as found in a .metallib file? And is the compiled format GPU-specific, or does it exist as an intermediate-language format that is taken to the GPU-level during a final compilation stage within the newLibraryWithData:error: method?

Upvotes: 3

Views: 2243

Answers (1)

warrenm
warrenm

Reputation: 31782

The format of metallib files is not publicly documented. Library files essentially contain metadata and compiled shader code in an LLVM-derived intermediate language, which is device-agnostic. There is a second, back-end compilation step that transforms this intermediate language into the final machine code. It is not possible to generate intermediate code directly, but if this is a feature you want, you should file an enhancement request bug with Apple.

Upvotes: 5

Related Questions