An object that represents a public shader function in a Metal library.


protocol MTLFunction


Use MTLFunction objects to specify which shaders a Metal pipeline calls when the GPU executes commands that specify that pipeline. For more information on creating pipeline state objects, see MTLRenderPipelineDescriptor and MTLComputePipelineDescriptor.

A MTLFunction object is a specialized function if the shader contains function constants, otherwise it is a non-specialized function.

Don’t use standard allocation and initialization techniques to create a MTLFunction object. Instead, use the function creation methods provided by the MTLLibrary protocol. To create a nonspecialized function, call the makeFunction(name:) method.

To create a specialized function, call one of these MTLLibrary methods:

MTLFunction objects can use a significant amount of memory; release any strong references to them after you finish creating pipeline objects.


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 Shading Language (MSL) 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