Protocol

MTLFunction

An object representing a public shader function in the library.

Declaration

protocol MTLFunction

Overview

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.

Topics

Identifying Shader Functions

var device: MTLDevice

The device object that created the shader function.

Required.

var label: String?

A string that identifies the shader function.

Required.

var functionType: MTLFunctionType

The shader function’s type.

Required.

var name: String

The function’s name.

Required.

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.

Required.

var patchControlPointCount: Int

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

Required.

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.

Required.

var stageInputAttributes: [MTLAttribute]?

An array that describes the input attributes to the function.

Required.

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.

Required.

Creating Argument Encoders

func makeArgumentEncoder(bufferIndex: Int) -> MTLArgumentEncoder

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

Required.

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

Required.

Relationships

Inherits From