Protocol

MTLLibrary

A collection of Metal shader functions.

Declaration

protocol MTLLibrary

Overview

A MTLLibrary object contains Metal shading language source code that is compiled during the app build process or at runtime from a text string.

Don’t implement this protocol yourself; instead, use the library creation methods provided by the MTLDevice protocol. To create a MTLLibrary from a pre-compiled Metal library binary, call one of these MTLDevice methods:

To create a MTLLibrary by compiling source code at runtime, call one of these MTLDevice methods:

Topics

Querying Library Contents

var functionNames: [String]

The names of all public functions in the library.

Required.

Finding Shader Functions

func makeFunction(name: String) -> MTLFunction?

Returns an object representing a shader function in the library.

Required.

func makeFunction(name: String, constantValues: MTLFunctionConstantValues) -> MTLFunction

Synchronously generates a specialized shader function.

Required.

Identifying the Library

var device: MTLDevice

The device object that created the library.

Required.

var label: String?

A string that identifies the library.

Required.

Handling Errors

struct MTLLibraryError

Errors returned by Metal for library errors.

enum MTLLibraryError.Code

Error codes returned by Metal for library errors.

let MTLLibraryErrorDomain: String

The error domain for Metal libraries.

Relationships

Inherits From

See Also

Essentials

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.

class MTLCompileOptions

Compilation settings for a Metal shader library.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software