---
title: "encode(commandBuffer:sourceImage:destinationImage:)"
framework: metalperformanceshaders
role: symbol
role_heading: Instance Method
path: "metalperformanceshaders/mpscnnkernel/encode(commandbuffer:sourceimage:destinationimage:)"
---

# encode(commandBuffer:sourceImage:destinationImage:)

Encodes a kernel into a command buffer.  The ensuing operation proceeds out-of-place.

## Declaration

```swift
func encode(commandBuffer: any MTLCommandBuffer, sourceImage: MPSImage, destinationImage: MPSImage)
```

## Parameters

- `commandBuffer`: A valid command buffer to receive the encoded filter.
- `sourceImage`: A valid source image.
- `destinationImage`: A valid destination image to be overwritten by the results.

## Discussion

Discussion The destinationImage object may not alias the sourceImage object.

## See Also

### Instance Methods

- [encode(commandBuffer:sourceImage:)](metalperformanceshaders/mpscnnkernel/encode(commandbuffer:sourceimage:).md)
- [appendBatchBarrier()](metalperformanceshaders/mpscnnkernel/appendbatchbarrier().md)
- [batchEncodingStorageSize(sourceImage:sourceStates:destinationImage:)](metalperformanceshaders/mpscnnkernel/batchencodingstoragesize(sourceimage:sourcestates:destinationimage:).md)
- [destinationImageDescriptor(sourceImages:sourceStates:)](metalperformanceshaders/mpscnnkernel/destinationimagedescriptor(sourceimages:sourcestates:).md)
- [encode(commandBuffer:sourceImage:destinationState:destinationImage:)](metalperformanceshaders/mpscnnkernel/encode(commandbuffer:sourceimage:destinationstate:destinationimage:).md)
- [encode(commandBuffer:sourceImage:destinationState:destinationStateIsTemporary:)](metalperformanceshaders/mpscnnkernel/encode(commandbuffer:sourceimage:destinationstate:destinationstateistemporary:).md)
- [encodeBatch(commandBuffer:sourceImages:)](metalperformanceshaders/mpscnnkernel/encodebatch(commandbuffer:sourceimages:).md)
- [encodeBatch(commandBuffer:sourceImages:destinationImages:)](metalperformanceshaders/mpscnnkernel/encodebatch(commandbuffer:sourceimages:destinationimages:).md)
- [encodeBatch(commandBuffer:sourceImages:destinationStates:destinationImages:)](metalperformanceshaders/mpscnnkernel/encodebatch(commandbuffer:sourceimages:destinationstates:destinationimages:).md)
- [encodeBatch(commandBuffer:sourceImages:destinationStates:destinationStateIsTemporary:)](metalperformanceshaders/mpscnnkernel/encodebatch(commandbuffer:sourceimages:destinationstates:destinationstateistemporary:).md)
- [encodingStorageSize(sourceImage:sourceStates:destinationImage:)](metalperformanceshaders/mpscnnkernel/encodingstoragesize(sourceimage:sourcestates:destinationimage:).md)
- [isResultStateReusedAcrossBatch()](metalperformanceshaders/mpscnnkernel/isresultstatereusedacrossbatch().md)
- [resultState(sourceImage:sourceStates:destinationImage:)](metalperformanceshaders/mpscnnkernel/resultstate(sourceimage:sourcestates:destinationimage:).md)
- [resultStateBatch(sourceImage:sourceStates:destinationImage:)](metalperformanceshaders/mpscnnkernel/resultstatebatch(sourceimage:sourcestates:destinationimage:).md)
- [temporaryResultState(commandBuffer:sourceImage:sourceStates:destinationImage:)](metalperformanceshaders/mpscnnkernel/temporaryresultstate(commandbuffer:sourceimage:sourcestates:destinationimage:).md)
