An object representing a public shader function in the library.


protocol MTLFunction


A MTLFunction object is considered a specialized function if it contains function constants, otherwise it is considered a non-specialized function. Specialized functions are compiled at runtime because they must evaluate constant values for each of its function constants; non-specialized functions are compiled when their respective library is built.

Do not use standard allocation and initialization techniques to create a MTLFunction object. Instead, use the function creation methods provided by the MTLLibrary protocol. To compile and create a specialized function, call one of these MTLLibrary methods:

To fetch a precompiled, nonspecialized function, call the makeFunction(name:) method.


Identifying Shader Functions

var device: MTLDevice

The device object that created the shader function.


var label: String?

A string that identifies the shader function.


var functionType: MTLFunctionType

The shader function’s type.


var name: String

The function’s name.


enum MTLFunctionType

The type of a top-level Metal function.

Identifying the Tessellation Patch

var patchType: MTLPatchType

The tessellation patch type of a post-tessellation vertex function.


var patchControlPointCount: Int

The number of patch control points in the post-tessellation vertex function.


enum MTLPatchType

Types of tessellation patches that can be inputs of a post-tessellation vertex function.

Retrieving Function Attributes

var vertexAttributes: [MTLVertexAttribute]?

An array that describes the vertex input attributes to a vertex function.


var stageInputAttributes: [MTLAttribute]?

An array that describes the input attributes to the function.


class MTLAttribute

An object that describes an attribute defined in the stage-in argument for a shader.

class MTLVertexAttribute

An object that represents an attribute of a vertex function.

Retrieving Function Constants

var functionConstantsDictionary: [String : MTLFunctionConstant]

A dictionary of function constants for a specialized function.


Creating Argument Encoders

func makeArgumentEncoder(bufferIndex: Int) -> MTLArgumentEncoder

Creates an argument encoder for an argument buffer that is one of this function's arguments.


func makeArgumentEncoder(bufferIndex: Int, reflection: AutoreleasingUnsafeMutablePointer<MTLAutoreleasedArgument?>?) -> MTLArgumentEncoder

Creates an argument encoder and returns reflection information for an argument buffer that is one of this function's arguments



Inherits From

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