---
title: "encode(commandBuffer:sourceTexture:destinationTexture:)"
framework: metalperformanceshaders
role: symbol
role_heading: Instance Method
path: "metalperformanceshaders/mpsunaryimagekernel/encode(commandbuffer:sourcetexture:destinationtexture:)"
---

# encode(commandBuffer:sourceTexture:destinationTexture:)

Encodes a kernel into a command buffer, out of place.

## Declaration

```swift
func encode(commandBuffer: any MTLCommandBuffer, sourceTexture: any MTLTexture, destinationTexture: any MTLTexture)
```

## Parameters

- `commandBuffer`: A valid command buffer to receive the encoded kernel.
- `sourceTexture`: A valid texture containing the source image.
- `destinationTexture`: A valid texture to be overwritten by the result image. destinationTexture may not alias sourceTexture.

## See Also

### Methods

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