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

# drawMaskOnStencilAttachment(commandEncoder:value:)

Store the value parameter in the stencil texture in the pixels that the compositor will display onscreen.

```
func drawMaskOnStencilAttachment(commandEncoder command_encoder: any MTLRenderCommandEncoder, value: UInt8)
```

## Parameters

`value`

The value to use when updating the stencil texture in the <doc://com.apple.documentation/documentation/Metal/MTLRenderCommandEncoder>.

## Discussion

In full and mixed immersion styles, [`drawMaskOnStencilAttachment(commandEncoder:value:)`](/documentation/CompositorServices/LayerRenderer/Drawable/RenderContext/drawMaskOnStencilAttachment(commandEncoder:value:)-65i67) stores the full texture.
The command encoder used in the render context has the following constraints:

- The stencil texture has the same pixel format as [`cp_layer_renderer_configuration_get_drawable_render_context_stencil_format`](/documentation/CompositorServices/cp_layer_renderer_configuration_get_drawable_render_context_stencil_format).
- 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 or 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.

This function modifies the depth stencil state, viewports, vertex amplification count, and some of the texture bindings in the render command encoder passed to the function.
Make sure to set those values again to those expected in your app.

---

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)