How it works
CompositorContent is the protocol you adopt to describe the work that gets drawn into a CompositorLayer's drawable for fully custom, immersive rendering on visionOS. Where ordinary SwiftUI builds a view hierarchy, CompositorContent builds the per-frame Metal rendering you submit to the compositor — so you reach for it when you need to take over the drawable yourself rather than letting RealityKit or the SwiftUI scene system render the scene for you. It sits at the boundary between SwiftUI's declarative layer and a hand-authored render loop, giving immersive apps a typed entry point for low-level frame drawing. Because it produces compositor frames rather than views, a conforming type has no on-screen SwiftUI preview of its own.
Adopt CompositorContent to own the render loop
Conforming a type to CompositorContent declares that it is responsible for producing the immersive content drawn into a CompositorLayer's drawable, frame after frame. This is the seam where you move from declaring views to driving rendering; the placeholder
CompositorContentDemoshown alongside is only a descriptive card, since a real conformer has no SwiftUI body to display.Attach content to a CompositorLayer
CompositorContent is meaningful only in the context of a CompositorLayer, which vends the drawable surface the compositor presents. Your conforming type reads the layer's configuration and renderer to obtain each frame's drawable, so the protocol is the typed handoff between the layer you create and the drawing code you supply.
Render into the drawable each frame
Inside a CompositorContent implementation you query the layer for the next drawable, encode your Metal commands against its color and depth textures, and present it on the compositor's schedule. This per-frame drawing — not a view tree — is the actual product of the protocol, which is why no preview surface like the
Image,Text, andVStackin the sample applies to it.Drive frames with the immersive scene's timing
Because the compositor presents to a head-mounted display, a CompositorContent type uses the drawable's pose and timing information to draw with correct prediction and pacing. You synchronize your encoding to the frame cadence the CompositorLayer provides rather than to SwiftUI's update cycle, keeping the immersive scene stable and low-latency.
Place it in an immersive scene
A CompositorContent-backed layer lives inside an immersive space scene, so the protocol is how your custom rendering plugs into the surrounding app structure. The SwiftUI you do write — scenes and immersion style — frames where the compositor content appears, while the protocol itself stays focused on what gets drawn into the drawable.
Text line in CompositorContentDemo that begins "A visionOS protocol describing content..." with the name of your CompositorLayer configuration to remind yourself that the real work happens in the drawable, not in this card's VStack.Example & preview
Press Run live & edit to compile it in your browser — then edit the Swift on the left and the preview re-renders live.
struct CompositorContentDemo: View {
var body: some View {
VStack(spacing: 12) {
Image(systemName: "visionpro")
.font(.largeTitle)
.foregroundStyle(.tint)
Text("CompositorContent")
.font(.headline)
Text("A visionOS protocol describing content drawn into a CompositorLayer's drawable for immersive rendering. It has no SwiftUI preview surface.")
.font(.caption)
.foregroundStyle(.secondary)
.multilineTextAlignment(.center)
}
.padding()
}
}