<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.11.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Metal",
  "identifier" : "/documentation/Metal/MTLFunction",
  "metadataVersion" : "0.1.0",
  "role" : "Protocol",
  "symbol" : {
    "kind" : "Protocol",
    "modules" : [
      "Metal"
    ],
    "preciseIdentifier" : "c:objc(pl)MTLFunction"
  },
  "title" : "MTLFunction"
}
-->

# MTLFunction

A interface that represents a public shader function in a Metal library.

```
protocol MTLFunction : NSObjectProtocol, Sendable
```

## Overview

Use [`MTLFunction`](/documentation/Metal/MTLFunction) instances to specify which shaders a Metal pipeline calls when the GPU executes commands that specify that pipeline. For more information on creating pipeline states, see [`MTLRenderPipelineDescriptor`](/documentation/Metal/MTLRenderPipelineDescriptor) and [`MTLComputePipelineDescriptor`](/documentation/Metal/MTLComputePipelineDescriptor).

An [`MTLFunction`](/documentation/Metal/MTLFunction) instance is a *specialized* function if the shader contains function constants, otherwise it is a *nonspecialized* function.

Don’t use standard allocation and initialization techniques to create an [`MTLFunction`](/documentation/Metal/MTLFunction) instance. Instead, use the function creation methods provided by the [`MTLLibrary`](/documentation/Metal/MTLLibrary) protocol. To create a nonspecialized function, call the [`makeFunction(name:)`](/documentation/Metal/MTLLibrary/makeFunction(name:)) method.

To create a specialized function, call one of these [`MTLLibrary`](/documentation/Metal/MTLLibrary) methods:

- [`makeFunction(name:constantValues:completionHandler:)`](/documentation/Metal/MTLLibrary/makeFunction(name:constantValues:completionHandler:))
- [`makeFunction(name:constantValues:)`](/documentation/Metal/MTLLibrary/makeFunction(name:constantValues:))

[`MTLFunction`](/documentation/Metal/MTLFunction) instances can use a significant amount of memory; release any strong references to them after you finish creating pipeline instances.

## Topics

### Identifying shader functions

[`device`](/documentation/Metal/MTLFunction/device)

The device object that created the shader function.

[`label`](/documentation/Metal/MTLFunction/label)

A string that identifies the shader function.

[`functionType`](/documentation/Metal/MTLFunction/functionType)

The shader function’s type.

[`name`](/documentation/Metal/MTLFunction/name)

The function’s name.

[`MTLFunctionType`](/documentation/Metal/MTLFunctionType)

The type of a top-level Metal Shading Language (MSL) function.

[`options`](/documentation/Metal/MTLFunction/options)

The options that Metal used to compile this function.

[`MTLFunctionOptions`](/documentation/Metal/MTLFunctionOptions)

Options that define how Metal compiles a GPU function.

### Identifying the tessellation patch

[`patchType`](/documentation/Metal/MTLFunction/patchType)

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

[`patchControlPointCount`](/documentation/Metal/MTLFunction/patchControlPointCount)

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

[`MTLPatchType`](/documentation/Metal/MTLPatchType)

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

### Retrieving function attributes

[`vertexAttributes`](/documentation/Metal/MTLFunction/vertexAttributes)

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

[`stageInputAttributes`](/documentation/Metal/MTLFunction/stageInputAttributes)

An array that describes the input attributes to the function.

### Retrieving function constants

[`functionConstantsDictionary`](/documentation/Metal/MTLFunction/functionConstantsDictionary)

A dictionary of function constants for a specialized function.

### Creating argument encoders

[`makeArgumentEncoder(bufferIndex:)`](/documentation/Metal/MTLFunction/makeArgumentEncoder(bufferIndex:))

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

[`makeArgumentEncoder(bufferIndex:reflection:)`](/documentation/Metal/MTLFunction/makeArgumentEncoder(bufferIndex:reflection:))

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



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)