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

# encode(commandBuffer:sourceImage:destinationImage:)

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

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

The `destinationImage` object may not alias the `sourceImage` object.

---

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)