<!--
{
  "availability" : [
    "macOS: 26.0.0 -",
    "visionOS: 26.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CompositorServices",
  "identifier" : "/documentation/CompositorServices/LayerRenderer/Drawable/RenderContext/endEncoding(commandEncoder:)-2l6lk",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Compositor Services",
      "CompositorServices"
    ],
    "preciseIdentifier" : "c:@F@cp_drawable_render_context_mtl4_end_encoding"
  },
  "title" : "endEncoding(commandEncoder:)"
}
-->

# endEncoding(commandEncoder:)

Finish encoding the render context.

```
func endEncoding(commandEncoder command_encoder: any MTL4RenderCommandEncoder)
```

## Discussion

`endEncoding(commandEncoder:)` passes the ownership of the command encoder to the drawable render context and calls <doc://com.apple.documentation/documentation/Metal/MTLCommandEncoder/endEncoding()> on the command encoder.
The command encoder used in the render context has the following constraints:

- The `colorAttachment[0]` contains the color texture provided by the layer renderer drawable.
- The <doc://com.apple.documentation/documentation/Metal/MTLRenderPassDescriptor/depthAttachment> contains the depth texture provided by the layer renderer drawable.
- The <doc://com.apple.documentation/documentation/Metal/MTLRenderPassDescriptor/renderTargetArrayLength> is the same as the number of views in the layer renderer drawable.
- The <doc://com.apple.documentation/documentation/Metal/MTLRenderPassDescriptor/rasterizationRateMap> matches the one provided by the layer renderer drawable.
- The API doesn’t support dedicated and shared layouts.

If the render encoder has multiple color attachments, set <doc://com.apple.documentation/documentation/Metal/MTL4RenderPassDescriptor/supportColorAttachmentMapping> to `true` to avoid Metal API validation errors.

For testing performance of this method, always test your app on-device rather than in Simulator.
However, if you need to iterate on your code in development, you can disable API validation in Xcode, or separate the rendering into multiple render encoders for other color attachments.

---

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)