---
title: MPSCopyAllocator
framework: metalperformanceshaders
role: symbol
role_heading: Type Alias
path: metalperformanceshaders/mpscopyallocator
---

# MPSCopyAllocator

A block to make a copy of a source texture for filters that can only execute out of place.

## Declaration

```swift
typealias MPSCopyAllocator = (MPSKernel, any MTLCommandBuffer, any MTLTexture) -> any MTLTexture
```

## Discussion

Discussion The block takes the following parameters: The copy allocator returns a new valid texture to use as the destination for the kernel operation. If the calling function succeeds, its texture parameter will be overwritten with a pointer to this texture. If the calling function fails, then the texture will be released before the calling function returns. Allocating a new texture each time is slow (they take up to 1 ms each). You can recycle old textures (or buffers and make texture from them) and reuse the memory inside the copy allocator block. If there is any metadata associated with the source texture, such as colorspace information, resource label, CPU cache mode, purgeable state, etc., it may need to be similarly associated with the new texture to avoid losing your metadata. If the kernel’s clipRect property doesn’t cover the entire image, you may need to copy pixels from the source texture to the new texture, or regions of the next texture will be uninitialized. You can make a command encoder to encode work on the command buffer here, if necessary. It will be scheduled to run immediately before the kernel work. You may call any of the enqueue(), commit(), waitUntilCompleted(), or waitUntilScheduled() methods inside the copy allocator block. Make sure to call endEncoding() on the command encoder so that the command buffer has no active encoder before returning. note: The next command placed on the command buffer after the copy allocator returns is almost assuredly going to be encoded with a compute command encoder. Creating any other type of encoder in the copy allocator will probably cost an additional 0.5 ms of both CPU and GPU time (or more!) due to a double mode switch penalty. The following listing shows a minimal copy allocator implementation. Listing 1. Minimal MPSCopyAllocator Implementation

## See Also

### Methods

- [encode(commandBuffer:inPlaceTexture:fallbackCopyAllocator:)](metalperformanceshaders/mpsunaryimagekernel/encode(commandbuffer:inplacetexture:fallbackcopyallocator:).md)
- [encode(commandBuffer:sourceImage:destinationImage:)](metalperformanceshaders/mpsunaryimagekernel/encode(commandbuffer:sourceimage:destinationimage:).md)
- [encode(commandBuffer:sourceTexture:destinationTexture:)](metalperformanceshaders/mpsunaryimagekernel/encode(commandbuffer:sourcetexture:destinationtexture:).md)
- [sourceRegion(destinationSize:)](metalperformanceshaders/mpsunaryimagekernel/sourceregion(destinationsize:).md)
