---
title: "encode(commandBuffer:primaryTexture:secondaryTexture:destinationTexture:)"
framework: metalperformanceshaders
role: symbol
role_heading: Instance Method
path: "metalperformanceshaders/mpsbinaryimagekernel/encode(commandbuffer:primarytexture:secondarytexture:destinationtexture:)"
---

# encode(commandBuffer:primaryTexture:secondaryTexture:destinationTexture:)

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

## Declaration

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

## Parameters

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

## See Also

### Methods

- [encode(commandBuffer:primaryTexture:inPlaceSecondaryTexture:fallbackCopyAllocator:)](metalperformanceshaders/mpsbinaryimagekernel/encode(commandbuffer:primarytexture:inplacesecondarytexture:fallbackcopyallocator:).md)
- [encode(commandBuffer:inPlacePrimaryTexture:secondaryTexture:fallbackCopyAllocator:)](metalperformanceshaders/mpsbinaryimagekernel/encode(commandbuffer:inplaceprimarytexture:secondarytexture:fallbackcopyallocator:).md)
- [encode(commandBuffer:primaryImage:secondaryImage:destinationImage:)](metalperformanceshaders/mpsbinaryimagekernel/encode(commandbuffer:primaryimage:secondaryimage:destinationimage:).md)
- [primarySourceRegion(forDestinationSize:)](metalperformanceshaders/mpsbinaryimagekernel/primarysourceregion(fordestinationsize:).md)
- [secondarySourceRegion(forDestinationSize:)](metalperformanceshaders/mpsbinaryimagekernel/secondarysourceregion(fordestinationsize:).md)
