---
title: MTLBuffer
framework: metal
role: symbol
role_heading: Protocol
path: metal/mtlbuffer
---

# MTLBuffer

A resource that stores data in a format defined by your app.

## Declaration

```swift
protocol MTLBuffer : MTLResource
```

## Mentioned in

Improving CPU performance by using argument buffers Estimating how often a texture region is accessed Setting resource storage modes Converting a GPU’s counter data into a readable format Synchronizing a managed resource in macOS Improving ray-tracing data access using per-primitive data Indexing argument buffers Optimizing texture data Simplifying GPU resource management with residency sets Specifying drawing and dispatch arguments indirectly

## Overview

Overview An MTLBuffer instance can be used only with the MTLDevice that created it. Don’t implement this protocol yourself; instead, use the following MTLDevice methods to create MTLBuffer instances: makeBuffer(length:options:) creates a MTLBuffer instance with a new storage allocation. makeBuffer(bytes:length:options:) creates a MTLBuffer instance by copying data from an existing storage allocation into a new allocation. makeBuffer(bytesNoCopy:length:options:deallocator:) creates a MTLBuffer instance that reuses an existing storage allocation and does not allocate any new storage. The Metal framework doesn’t know anything about the contents of an MTLBuffer, just its size. You define the format of the data in the buffer and ensure that your app and your shaders know how to read and write the data. For example, you might create a struct in your shader that defines the data you want to store in the buffer and its memory layout. If you create a buffer with a managed resource storage mode (MTLStorageMode.managed), you need to call didModifyRange: to tell Metal to copy any changes to the GPU.

## Topics

### Creating a texture that shares buffer data

- [makeTexture(descriptor:offset:bytesPerRow:)](metal/mtlbuffer/maketexture(descriptor:offset:bytesperrow:).md)

### Reading the buffer’s data on the CPU

- [contents()](metal/mtlbuffer/contents().md)

### Synchronizing data to the GPU for managed buffers

- [didModifyRange(_:)](metal/mtlbuffer/didmodifyrange(_:).md)

### Debugging buffers

- [addDebugMarker(_:range:)](metal/mtlbuffer/adddebugmarker(_:range:).md)
- [removeAllDebugMarkers()](metal/mtlbuffer/removealldebugmarkers().md)

### Reading buffer length

- [length](metal/mtlbuffer/length.md)

### Creating views of buffers on other GPUs

- [makeRemoteBufferView(_:)](metal/mtlbuffer/makeremotebufferview(_:).md)
- [remoteStorageBuffer](metal/mtlbuffer/remotestoragebuffer.md)

### Instance Properties

- [gpuAddress](metal/mtlbuffer/gpuaddress.md)
- [sparseBufferTier](metal/mtlbuffer/sparsebuffertier.md)

### Instance Methods

- [makeTensor(descriptor:offset:)](metal/mtlbuffer/maketensor(descriptor:offset:).md)

## Relationships

### Inherits From

- [MTLAllocation](metal/mtlallocation.md)
- [MTLResource](metal/mtlresource.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
