---
title: MTLFunction
framework: metal
role: symbol
role_heading: Protocol
path: metal/mtlfunction
---

# MTLFunction

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

## Declaration

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

## Overview

Overview Use 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 and MTLComputePipelineDescriptor. An 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 instance. 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: makeFunction(name:constantValues:completionHandler:) makeFunction(name:constantValues:) 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](metal/mtlfunction/device.md)
- [label](metal/mtlfunction/label.md)
- [functionType](metal/mtlfunction/functiontype.md)
- [name](metal/mtlfunction/name.md)
- [MTLFunctionType](metal/mtlfunctiontype.md)
- [options](metal/mtlfunction/options.md)
- [MTLFunctionOptions](metal/mtlfunctionoptions.md)

### Identifying the tessellation patch

- [patchType](metal/mtlfunction/patchtype.md)
- [patchControlPointCount](metal/mtlfunction/patchcontrolpointcount.md)
- [MTLPatchType](metal/mtlpatchtype.md)

### Retrieving function attributes

- [vertexAttributes](metal/mtlfunction/vertexattributes.md)
- [stageInputAttributes](metal/mtlfunction/stageinputattributes.md)

### Retrieving function constants

- [functionConstantsDictionary](metal/mtlfunction/functionconstantsdictionary.md)

### Creating argument encoders

- [makeArgumentEncoder(bufferIndex:)](metal/mtlfunction/makeargumentencoder(bufferindex:).md)
- [makeArgumentEncoder(bufferIndex:reflection:)](metal/mtlfunction/makeargumentencoder(bufferindex:reflection:).md)

## Relationships

### Inherits From

- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### Shader functions

- [MTLFunctionDescriptor](metal/mtlfunctiondescriptor.md)
- [MTLFunctionHandle](metal/mtlfunctionhandle.md)
- [MTLVisibleFunctionTableDescriptor](metal/mtlvisiblefunctiontabledescriptor.md)
- [MTLVisibleFunctionTable](metal/mtlvisiblefunctiontable.md)
- [MTLIntersectionFunctionDescriptor](metal/mtlintersectionfunctiondescriptor.md)
- [MTLIntersectionFunctionTableDescriptor](metal/mtlintersectionfunctiontabledescriptor.md)
- [MTLIntersectionFunctionTable](metal/mtlintersectionfunctiontable.md)
