<!--
{
  "documentType" : "article",
  "framework" : "Metal",
  "identifier" : "/documentation/Metal/setting-load-and-store-actions",
  "metadataVersion" : "0.1.0",
  "role" : "article",
  "title" : "Setting load and store actions"
}
-->

# Setting load and store actions

Set actions that define how a render pass loads and stores a render target.

## Discussion

[`MTLLoadAction`](/documentation/Metal/MTLLoadAction) and [`MTLStoreAction`](/documentation/Metal/MTLStoreAction) values allow you to define how a render pass loads and stores your [`MTLRenderPassAttachmentDescriptor`](/documentation/Metal/MTLRenderPassAttachmentDescriptor) objects. By choosing appropriate actions for your render targets, you can avoid costly and unnecessary work at the start (load) or end (store) of a render pass.

Set a render targetʼs texture on its [`texture`](/documentation/Metal/MTLRenderPassAttachmentDescriptor/texture) property. Then, set its actions on its [`loadAction`](/documentation/Metal/MTLRenderPassAttachmentDescriptor/loadAction) and [`storeAction`](/documentation/Metal/MTLRenderPassAttachmentDescriptor/storeAction) properties:

```objective-c
MTLRenderPassDescriptor *renderPassDescriptor = [MTLRenderPassDescriptor renderPassDescriptor];

// Color render target
renderPassDescriptor.colorAttachments[0].texture = colorTexture;
renderPassDescriptor.colorAttachments[0].loadAction = MTLLoadActionClear;
renderPassDescriptor.colorAttachments[0].storeAction = MTLStoreActionStore;

// Depth render target
renderPassDescriptor.depthAttachment.texture = depthTexture;
renderPassDescriptor.depthAttachment.loadAction = MTLLoadActionDontCare;
renderPassDescriptor.depthAttachment.storeAction = MTLStoreActionDontCare;

// Stencil render target
renderPassDescriptor.stencilAttachment.texture = stencilTexture;
renderPassDescriptor.stencilAttachment.loadAction = MTLLoadActionDontCare;
renderPassDescriptor.stencilAttachment.storeAction = MTLStoreActionDontCare;
```

### Choose a load action

Several options are available, depending on which of the following scenarios describes your render targetʼs loading needs.

**You donʼt need the previous contents of the render target and you render to all of its pixels.** Choose [`MTLLoadAction.dontCare`](/documentation/Metal/MTLLoadAction/dontCare). This action incurs no cost, and pixel values are always undefined at the start of the render pass.

![A block diagram that shows the previous contents of a render target and its loaded contents after a Don’t Care load action.](images/com.apple.metal/setting-load-and-store-actions-6@2x.png)

**You donʼt need the previous contents of the render target and you render to only some of its pixels.** Choose [`MTLLoadAction.clear`](/documentation/Metal/MTLLoadAction/clear). This action incurs the cost of writing the render targetʼs clear value to each pixel.

![A block diagram that shows the previous contents of a render target and its loaded contents after a Clear load action.](images/com.apple.metal/setting-load-and-store-actions-5@2x.png)

**You do need the previous contents of the render target and you render to only some of its pixels.** Choose [`MTLLoadAction.load`](/documentation/Metal/MTLLoadAction/load). This action incurs the cost of loading the previous values of each pixel from memory. This action is significantly slower than [`MTLLoadAction.dontCare`](/documentation/Metal/MTLLoadAction/dontCare) or [`MTLLoadAction.clear`](/documentation/Metal/MTLLoadAction/clear).

![A block diagram that shows the previous contents of a render target and its loaded contents after a Load load action.](images/com.apple.metal/setting-load-and-store-actions-1@2x.png)

> Note:
> You canʼt choose ``doc://com.apple.metal/documentation/Metal/MTLLoadAction/load`` for a memoryless render target because it isnʼt backed by system memory. For more information about memoryless render targets, see <doc://com.apple.metal/documentation/Metal/choosing-a-resource-storage-mode-for-apple-gpus>.

### Choose a store action

Several options are available, depending on which of the following scenarios describes your render targetʼs storage needs.

**You donʼt need to preserve the contents of the render target.** Choose [`MTLStoreAction.dontCare`](/documentation/Metal/MTLStoreAction/dontCare). This action incurs no cost, and pixel values are always undefined at the end of the render pass. Choose this action for intermediary render targets that you use within the render pass, but you donʼt need afterward. This is typically the correct action for depth and stencil render targets.

![A block diagram that shows the previous contents of a render target and its stored contents after a Don’t Care store action.](images/com.apple.metal/setting-load-and-store-actions-8@2x.png)

**You do need to preserve the contents of the render target.** Choose [`MTLStoreAction.store`](/documentation/Metal/MTLStoreAction/store). This action incurs the cost of storing the values of each pixel to memory. This is always the correct action for drawables.

![A block diagram that shows the previous contents of a render target and its stored contents after a Store store action.](images/com.apple.metal/setting-load-and-store-actions-7@2x.png)

**Your render target is a multisample texture.** When you perform multisampling, you decide whether to store the render targetʼs multisampled or resolved data. Multisampled data is stored in the render targetʼs [`texture`](/documentation/Metal/MTLRenderPassAttachmentDescriptor/texture) property. Resolved data is stored in the render targetʼs [`resolveTexture`](/documentation/Metal/MTLRenderPassAttachmentDescriptor/resolveTexture) property. Refer to this table to choose a store action when multisampling:

|Multisampled data stored|Resolved data stored|Resolve texture required|Required store action                                                                  |
|------------------------|--------------------|------------------------|---------------------------------------------------------------------------------------|
|Yes                     |Yes                 |Yes                     |``doc://com.apple.metal/documentation/Metal/MTLStoreAction/storeAndMultisampleResolve``|
|Yes                     |No                  |No                      |``doc://com.apple.metal/documentation/Metal/MTLStoreAction/store``                     |
|No                      |Yes                 |Yes                     |``doc://com.apple.metal/documentation/Metal/MTLStoreAction/multisampleResolve``        |
|No                      |No                  |No                      |``doc://com.apple.metal/documentation/Metal/MTLStoreAction/dontCare``                  |

To store and resolve a multisample texture in a single render pass, always choose the [`MTLStoreAction.storeAndMultisampleResolve`](/documentation/Metal/MTLStoreAction/storeAndMultisampleResolve) action and use a single render command encoder.

**You need to defer your storage choice.** In some cases, you might not know which store action to use for a particular render target until you gather more render pass information. To defer your store action choice, set the temporary [`MTLStoreAction.unknown`](/documentation/Metal/MTLStoreAction/unknown) value when you create your [`MTLRenderPassAttachmentDescriptor`](/documentation/Metal/MTLRenderPassAttachmentDescriptor) object. Setting an unknown store action may avoid potential costs incurred by setting another store action prematurely. However, you need to specify a valid store action before you finish encoding your render pass; otherwise, an error occurs.

> Note:
> You canʼt choose ``doc://com.apple.metal/documentation/Metal/MTLStoreAction/store`` or ``doc://com.apple.metal/documentation/Metal/MTLStoreAction/storeAndMultisampleResolve`` for a memoryless render target because it isnʼt backed by system memory. For more information about memoryless render targets, see <doc://com.apple.metal/documentation/Metal/choosing-a-resource-storage-mode-for-apple-gpus>.

### Evaluate actions between render passes

You can use the same render targets across multiple render passes. Several load and store combinations are possible for the same render target between any two render passes, depending on which of the following scenarios describes your render targetʼs needs from one render pass to another.

**You donʼt need the previous contents of a render target in the next render pass.** In the first render pass, choose [`MTLStoreAction.dontCare`](/documentation/Metal/MTLStoreAction/dontCare) to avoid storing the contents of the render target. In the second render pass, choose [`MTLLoadAction.dontCare`](/documentation/Metal/MTLLoadAction/dontCare) or [`MTLLoadAction.clear`](/documentation/Metal/MTLLoadAction/clear) to avoid loading the contents of the render target.

![A block diagram that shows a store and load sequence for a single render target. The render target uses a Don’t Care store action and a Don’t Care load action.](images/com.apple.metal/setting-load-and-store-actions-2@2x.png)

![A block diagram that shows a store and load sequence for a single render target. The render target uses a Don’t Care store action and a Clear load action.](images/com.apple.metal/setting-load-and-store-actions-3@2x.png)

**You do need the previous contents of a render target in the next render pass.** In the first render pass, choose [`MTLStoreAction.store`](/documentation/Metal/MTLStoreAction/store), [`MTLStoreAction.multisampleResolve`](/documentation/Metal/MTLStoreAction/multisampleResolve), or [`MTLStoreAction.storeAndMultisampleResolve`](/documentation/Metal/MTLStoreAction/storeAndMultisampleResolve) to store the contents of the render target. In the second render pass, choose [`MTLLoadAction.load`](/documentation/Metal/MTLLoadAction/load) to load the contents of the render target.

![A block diagram that shows a store and load sequence for a single render target. The render target uses a Store, Multisample Resolve, or Store And Multisample Resolve store action, and then uses a Load load action.](images/com.apple.metal/setting-load-and-store-actions-4@2x.png)

---

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)