<!--
{
  "availability" : [
    "iOS: 9.0.0 -",
    "iPadOS: 9.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.13.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "MetalPerformanceShaders",
  "identifier" : "/documentation/MetalPerformanceShaders/MPSBinaryImageKernel/encode(commandBuffer:primaryTexture:secondaryTexture:destinationTexture:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Metal Performance Shaders"
    ],
    "preciseIdentifier" : "c:objc(cs)MPSBinaryImageKernel(im)encodeToCommandBuffer:primaryTexture:secondaryTexture:destinationTexture:"
  },
  "title" : "encode(commandBuffer:primaryTexture:secondaryTexture:destinationTexture:)"
}
-->

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

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

```
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`.

---

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)