<!--
{
  "documentType" : "article",
  "framework" : "Metal",
  "identifier" : "/documentation/Metal/fragment-shader-resource-preparation-commands",
  "metadataVersion" : "0.1.0",
  "role" : "collectionGroup",
  "title" : "Fragment shader resource preparation commands"
}
-->

# Fragment shader resource preparation commands

Assign resources to fragment shaders, including buffers, textures, acceleration structures, sampler states, and function tables.

## Discussion

Fragment shaders share argument tables for each resource type, such as buffers, textures, and sampler states.
Each shader type has its own argument tables, separate from fragment shaders and other shader types.

## Topics

### Assigning buffers

[`func setFragmentBuffer((any MTLBuffer)?, offset: Int, index: Int)`](/documentation/Metal/MTLRenderCommandEncoder/setFragmentBuffer(_:offset:index:))

Assigns a buffer to an entry in the fragment shader argument table.

[`func setFragmentBuffers([(any MTLBuffer)?], offsets: [Int], range: Range<Int>)`](/documentation/Metal/MTLRenderCommandEncoder/setFragmentBuffers(_:offsets:range:))

Assigns multiple buffers to a range of entries in the fragment shader argument table.

[`- (void) setFragmentBuffers:(id<MTLBuffer> const[]) buffers offsets:(const NSUInteger[]) offsets withRange:(NSRange) range;`](/documentation/Metal/MTLRenderCommandEncoder/setFragmentBuffers:offsets:withRange:)

Assigns multiple buffers to a range of entries in the fragment shader argument table.

[`func setFragmentBytes(UnsafeRawPointer, length: Int, index: Int)`](/documentation/Metal/MTLRenderCommandEncoder/setFragmentBytes(_:length:index:))

Creates a buffer from bytes and assigns it to an entry in the fragment shader argument table.

[`func setFragmentBufferOffset(Int, index: Int)`](/documentation/Metal/MTLRenderCommandEncoder/setFragmentBufferOffset(_:index:))

Updates an entry in the fragment shader argument table with a new location within the entry’s current buffer.

### Assigning textures

[`func setFragmentTexture((any MTLTexture)?, index: Int)`](/documentation/Metal/MTLRenderCommandEncoder/setFragmentTexture(_:index:))

Assigns a texture to an entry in the fragment shader argument table.

[`func setFragmentTextures([(any MTLTexture)?], range: Range<Int>)`](/documentation/Metal/MTLRenderCommandEncoder/setFragmentTextures(_:range:))

Assigns multiple textures to a range of entries in the fragment shader argument table.

[`- (void) setFragmentTextures:(id<MTLTexture> const[]) textures withRange:(NSRange) range;`](/documentation/Metal/MTLRenderCommandEncoder/setFragmentTextures:withRange:)

Assigns multiple textures to a range of entries in the fragment shader argument table.

### Assigning sampler states

[`func setFragmentSamplerState((any MTLSamplerState)?, index: Int)`](/documentation/Metal/MTLRenderCommandEncoder/setFragmentSamplerState(_:index:))

Assigns a sampler state to an entry in the fragment shader argument table.

[`func setFragmentSamplerState((any MTLSamplerState)?, lodMinClamp: Float, lodMaxClamp: Float, index: Int)`](/documentation/Metal/MTLRenderCommandEncoder/setFragmentSamplerState(_:lodMinClamp:lodMaxClamp:index:))

Assigns a sampler state and clamp values to an entry in the fragment shader argument table.

[`func setFragmentSamplerStates([(any MTLSamplerState)?], range: Range<Int>)`](/documentation/Metal/MTLRenderCommandEncoder/setFragmentSamplerStates(_:range:))

Assigns multiple sampler states to a range of entries in the fragment shader argument table.

[`func setFragmentSamplerStates([(any MTLSamplerState)?], lodMinClamps: [Float], lodMaxClamps: [Float], range: Range<Int>)`](/documentation/Metal/MTLRenderCommandEncoder/setFragmentSamplerStates(_:lodMinClamps:lodMaxClamps:range:))

Assigns multiple sampler states and clamp values to a range of entries in the fragment shader argument table.

[`- (void) setFragmentSamplerStates:(id<MTLSamplerState> const[]) samplers withRange:(NSRange) range;`](/documentation/Metal/MTLRenderCommandEncoder/setFragmentSamplerStates:withRange:)

Assigns multiple sampler states to a range of entries in the fragment shader argument table.

[`- (void) setFragmentSamplerStates:(id<MTLSamplerState> const[]) samplers lodMinClamps:(const float[]) lodMinClamps lodMaxClamps:(const float[]) lodMaxClamps withRange:(NSRange) range;`](/documentation/Metal/MTLRenderCommandEncoder/setFragmentSamplerStates:lodMinClamps:lodMaxClamps:withRange:)

Assigns multiple sampler states and clamp values to a range of entries in the fragment shader argument table.

### Assigning acceleration structures

[`func setFragmentAccelerationStructure((any MTLAccelerationStructure)?, bufferIndex: Int)`](/documentation/Metal/MTLRenderCommandEncoder/setFragmentAccelerationStructure(_:bufferIndex:))

Assigns an acceleration structure to an entry in the fragment shader argument table.

### Assigning visible function tables

[`func setFragmentVisibleFunctionTable((any MTLVisibleFunctionTable)?, bufferIndex: Int)`](/documentation/Metal/MTLRenderCommandEncoder/setFragmentVisibleFunctionTable(_:bufferIndex:))

Assigns a visible function table to an entry in the fragment shader argument table.

[`func setFragmentVisibleFunctionTables([(any MTLVisibleFunctionTable)?], bufferRange: Range<Int>)`](/documentation/Metal/MTLRenderCommandEncoder/setFragmentVisibleFunctionTables(_:bufferRange:))

Assigns multiple visible function tables to a range of entries in the fragment shader argument table.

[`- (void) setFragmentVisibleFunctionTables:(id<MTLVisibleFunctionTable> const[]) functionTables withBufferRange:(NSRange) range;`](/documentation/Metal/MTLRenderCommandEncoder/setFragmentVisibleFunctionTables:withBufferRange:)

Assigns multiple visible function tables to a range of entries in the fragment shader argument table.

### Assigning intersection function tables

[`func setFragmentIntersectionFunctionTable((any MTLIntersectionFunctionTable)?, bufferIndex: Int)`](/documentation/Metal/MTLRenderCommandEncoder/setFragmentIntersectionFunctionTable(_:bufferIndex:))

Assigns an intersection function table to an entry in the fragment shader argument table.

[`func setFragmentIntersectionFunctionTables([(any MTLIntersectionFunctionTable)?], bufferRange: Range<Int>)`](/documentation/Metal/MTLRenderCommandEncoder/setFragmentIntersectionFunctionTables(_:bufferRange:))

Assigns multiple intersection function tables to a range of entries in the fragment shader argument table.

[`- (void) setFragmentIntersectionFunctionTables:(id<MTLIntersectionFunctionTable> const[]) intersectionFunctionTables withBufferRange:(NSRange) range;`](/documentation/Metal/MTLRenderCommandEncoder/setFragmentIntersectionFunctionTables:withBufferRange:)

Assigns multiple intersection function tables to a range of entries in the fragment shader argument table.



---

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)