Compilation settings for a Metal shader library.


class MTLCompileOptions : NSObject


Use a MTLCompileOptions object to specify how a new Metal shader library should be compiled. If you want to set the following options, use standard allocation and initialization techniques to create a MTLCompileOptions object and then set any or all of these properties:

  • To allow the compiler to perform optimizations for floating-point arithmetic that may violate the IEEE 754 standard, set fastMathEnabled to true.

  • To target previous OS releases, set languageVersion to a supported Metal shading language version.

  • Set preprocessorMacros to a list of preprocessor macros to be considered when compiling this code.

The MTLCompileOptions object is used with either the makeLibrary(source:options:) or makeLibrary(source:options:completionHandler:) method of MTLDevice to compile shading language functions into a new library.


Specifying Compiler Options

var fastMathEnabled: Bool

A Boolean value that indicates whether the compiler can perform optimizations for floating-point arithmetic that may violate the IEEE 754 standard.

var languageVersion: MTLLanguageVersion

The language version used to interpret the library source code.

enum MTLLanguageVersion

Metal shading language versions.

var preprocessorMacros: [String : NSObject]?

A list of preprocessor macros to apply when compiling the library source.


Inherits From

See Also


Understanding the Metal Shading Language Filename Extension

Use the .metal filename extension to gain access to Metal's build, profile, and debug tools.

Building a Library with Metal's Command-Line Tools

Use command-line tools to run the Metal compiler toolchain.

protocol MTLLibrary

A collection of Metal shader functions.