<!--
{
  "availability" : [
    "macOS: 26.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CompositorServices",
  "identifier" : "/documentation/CompositorServices/CompositorLayer",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Compositor Services",
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:27_CompositorServices_SwiftUI0A5LayerV"
  },
  "title" : "CompositorLayer"
}
-->

# CompositorLayer

A type that you use with an immersive space to display fully immersive content using Metal.

macOS:

```
struct CompositorLayer
```

visionOS:

```
@MainActor @preconcurrency struct CompositorLayer
```

## Overview

Use a [`CompositorLayer`](/documentation/CompositorServices/CompositorLayer) to specify the content of an
<doc://com.apple.documentation/documentation/SwiftUI/ImmersiveSpace>
when you want to render that content yourself using Metal.
When you present a space with this content, Compositor Services creates a
[`LayerRenderer`](/documentation/CompositorServices/LayerRenderer) type for you to use with your rendering code.
The layer renderer provides configuration details, timing information,
and the Metal types and information you need to configure your rendering loop
and manage the rendering process.

The following example shows a
<doc://com.apple.documentation/documentation/SwiftUI/ImmersiveSpace>
that uses a [`CompositorLayer`](/documentation/CompositorServices/CompositorLayer) to specify its content.
Use the closure for the [`CompositorLayer`](/documentation/CompositorServices/CompositorLayer) to set up and start your
Metal rendering code.
In this example, Compositor Services creates the layer using a default set of
Metal configuration options.
To customize the configuration of your Metal rendering environment,
pass a custom [`CompositorLayerConfiguration`](/documentation/CompositorServices/CompositorLayerConfiguration) type to your [`CompositorLayer`](/documentation/CompositorServices/CompositorLayer)
at initialization time.

```swift
ImmersiveSpace(id: "MyContent") {
    CompositorLayer { layerRenderer in
        // Set up and run the Metal render loop.
        let renderThread = Thread {
            let engine = my_engine_create(layerRenderer)
            my_engine_render_loop(engine)
        }
        renderThread.name = "Render Thread"
        renderThread.start()
    }
}
```

For more information about how to set up and start your Metal rendering engine,
see [Drawing fully immersive content using Metal](/documentation/CompositorServices/drawing-fully-immersive-content-using-metal).

## Topics

### Creating the scene content

### Initializers

[`init(configuration: any CompositorLayerConfiguration, renderer: (LayerRenderer) -> Void)`](/documentation/CompositorServices/CompositorLayer/init(configuration:renderer:)-2uxn7)

Creates a [`CompositorLayer`](/documentation/CompositorServices/CompositorLayer) instance.

[`init(configuration: any CompositorLayerConfiguration, renderer: (LayerRenderer, NWEndpoint?) -> Void)`](/documentation/CompositorServices/CompositorLayer/init(configuration:renderer:)-81vbz)

[`init(configuration: any CompositorLayerConfiguration, renderer: (LayerRenderer) -> Void, Void)`](/documentation/CompositorServices/CompositorLayer/init(configuration:renderer:_:))

## Relationships

### Conforms To

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

[`CompositorContent`](/documentation/SwiftUI/CompositorContent)

[`Escapable`](/documentation/Swift/Escapable)

[`Sendable`](/documentation/Swift/Sendable)

[`ImmersiveSpaceContent`](/documentation/SwiftUI/ImmersiveSpaceContent)

[`Copyable`](/documentation/Swift/Copyable)

---

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)