<!--
{
  "availability" : [
    "Reality Composer Pro: 3.0.0 -",
    "iOS: 27.0.0 -",
    "iPadOS: 27.0.0 -",
    "macOS: 27.0.0 -",
    "tvOS: 27.0.0 -",
    "visionOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "ComputeGraph",
  "identifier" : "/documentation/ComputeGraph",
  "metadataVersion" : "0.1.0",
  "role" : "Framework",
  "symbol" : {
    "kind" : "Framework",
    "modules" : [
      "Compute Graph"
    ],
    "preciseIdentifier" : "ComputeGraph"
  },
  "title" : "Compute Graph"
}
-->

# Compute Graph

Build and run custom particle effects and compute simulations for RealityKit using a programmable node graph.

## Overview

Compute Graph is a node-based framework for building particle simulations and general-purpose GPU compute graphs in <doc://com.apple.documentation/documentation/RealityKit>.
Where <doc://com.apple.documentation/documentation/ShaderGraph> lets you build material appearance through a node-based visual editor, Compute Graph provides the same graph-driven, connection-based authoring for simulation behavior.
Use Compute Graph when you build tools or editors that need fine-grained, per-stage control over how simulations execute on the GPU. Reality Composer Pro uses this framework to author and preview particle systems for RealityKit scenes.

The Swift API centers on a three-step compilation pipeline.
Describe a simulation as a [`ComputeNodeGraph`](/documentation/ComputeGraph/ComputeNodeGraph), a directed graph of typed nodes and edges.
Then produce a [`ComputeNodeGraph.Assembly`](/documentation/ComputeGraph/ComputeNodeGraph/Assembly) from the graph, which resolves the buffer, uniform, and texture layout the simulation requires.
Compile that assembly into [`ComputeNodeGraph.Pipelines`](/documentation/ComputeGraph/ComputeNodeGraph/Pipelines) to produce GPU shader code; a single set of pipelines can back multiple [`ComputeGraphSimulation`](/documentation/ComputeGraph/ComputeGraphSimulation) instances running concurrently.
Supply custom Metal Shading Language functions through a [`ComputeNodeGraph.Library`](/documentation/ComputeGraph/ComputeNodeGraph/Library) alongside the framework’s built-in node namespaces.

At runtime, [`ComputeGraphSimulation`](/documentation/ComputeGraph/ComputeGraphSimulation) drives GPU execution.
Call [`advance(_:)`](/documentation/ComputeGraph/ComputeGraphSimulation/advance(_:)) each frame, passing a [`ComputeGraphSimulation.AdvanceParams`](/documentation/ComputeGraph/ComputeGraphSimulation/AdvanceParams) that carries the time delta, a Metal command buffer, a compute encoder, and optional world-space transforms.
To inject elements programmatically, call [`spawn(elements:in:using:)`](/documentation/ComputeGraph/ComputeGraphSimulation/spawn(elements:in:using:)) with [`ElementSpawnParameters`](/documentation/ComputeGraph/ElementSpawnParameters) values that set each element’s initial position, velocity, size, color, and lifetime.

## Topics

### Graph definition and assembly

[`struct ComputeNodeGraph`](/documentation/ComputeGraph/ComputeNodeGraph)

[`struct Assembly`](/documentation/ComputeGraph/ComputeNodeGraph/Assembly)

Fully assembled configuration of compute graph nodes.

[`struct Pipelines`](/documentation/ComputeGraph/ComputeNodeGraph/Pipelines)

Fully-compiled shaders for a compute graph.

[`struct PipelinesDescriptor`](/documentation/ComputeGraph/ComputeNodeGraph/PipelinesDescriptor)

Specifies the configuration used to compile a set of compute pipelines for a
compute graph effect.

[`struct NodeDefinition`](/documentation/ComputeGraph/ComputeNodeGraph/NodeDefinition)

[`class Library`](/documentation/ComputeGraph/ComputeNodeGraph/Library)

A class defining a library of node definitions that can be added to a ComputeNodeGraph

[`struct LibraryReference`](/documentation/ComputeGraph/ComputeNodeGraph/LibraryReference)

A Metal library and an optional bundle identifier that locates shader functions.

### Node parameters and connections

[`struct PortReference`](/documentation/ComputeGraph/PortReference)

A reference to another group’s values.

[`enum BinaryOperation`](/documentation/ComputeGraph/BinaryOperation)

An enumeration of binary operations.

[`enum UnaryOperation`](/documentation/ComputeGraph/UnaryOperation)

An enumeration of single-operand operations.

[`enum StandardLibraryFunction`](/documentation/ComputeGraph/StandardLibraryFunction)

### Simulation-stage nodes

[`element`](/documentation/ComputeGraph/element)

A set of nodes for reading and writing the current element within a particle simulation.

[`emitter`](/documentation/ComputeGraph/emitter)

A set of nodes for the emission stage that control how often and how many elements a simulation spawns.

[`initialize`](/documentation/ComputeGraph/initialize)

A set of nodes for the initialization stage that set an element’s starting state.

[`module`](/documentation/ComputeGraph/module)

A set of nodes that mutate per-particle state, including position, velocity, color, size, and lifetime.

[`output`](/documentation/ComputeGraph/output)

A set of nodes for the output stage that adjust an element’s appearance without modifying its underlying state.

[`force`](/documentation/ComputeGraph/force)

A set of nodes that apply physics forces to particles, including gravity, drag, noise, and twist.

### Utility nodes

[`graph`](/documentation/ComputeGraph/graph)

A set of nodes that provide graph-wide information, such as time and coordinate-space transforms, usable in any stage.

[`group`](/documentation/ComputeGraph/group)

A set of nodes for querying the group of the current particle. Available only when the simulation uses a grouped or strips element grouping.

[`texture`](/documentation/ComputeGraph/texture)

A set of nodes for the texture stage that sample and generate texture data.

[`random`](/documentation/ComputeGraph/random)

A set of nodes that generate pseudo-random scalars and vectors.

[`matrix4x4f`](/documentation/ComputeGraph/matrix4x4f)

A set of nodes that transform positions and directions with single-precision 4×4 matrices.

[`matrix4x4h`](/documentation/ComputeGraph/matrix4x4h)

A set of nodes that transform positions and directions with half-precision 4×4 matrices.

[`Viewpoint viewpoint()`](/documentation/ComputeGraph/viewpoint-swift.func)

Returns the current viewpoint, if one is provided.

[`void element_integrate()`](/documentation/ComputeGraph/element_integrate)

[`float4 texture_sample(texture, uv)`](/documentation/ComputeGraph/texture_sample)

[`float4 texture_sample1d(texture, u)`](/documentation/ComputeGraph/texture_sample1d)

[`void orient_to_velocity()`](/documentation/ComputeGraph/orient_to_velocity)

Orient the particle by setting its `axisY` to the velocity’s current direction.

[`void gridDebugCells(grid)`](/documentation/ComputeGraph/gridDebugCells)

[`void gridFromPoints(gridStorage, inputPositions, inputFlags)`](/documentation/ComputeGraph/gridFromPoints)

[`void spawn_demo()`](/documentation/ComputeGraph/spawn_demo)

### Running a simulation

[`class ComputeGraphSimulation`](/documentation/ComputeGraph/ComputeGraphSimulation)

A simulation of particles, which use a single pipeline.

[`struct ElementSpawnParameters`](/documentation/ComputeGraph/ElementSpawnParameters)

Parameters used to configure the initial state of a particle when it’s spawned in the simulation.

[`enum ElementGrouping`](/documentation/ComputeGraph/ElementGrouping)

An enumeration of how elements are grouped.

[`struct SimulationRate`](/documentation/ComputeGraph/ComputeGraphSimulation/SimulationRate-swift.struct)

Specifies the rate and mode for simulation.

[`enum Sorting`](/documentation/ComputeGraph/Sorting)

An enumeration of sorting modes.

### Graph resources

[`struct SamplerSettings`](/documentation/ComputeGraph/ComputeNodeGraph/SamplerSettings)

[`struct SwizzleChannels`](/documentation/ComputeGraph/ComputeNodeGraph/SwizzleChannels)

[`enum AddressSpace`](/documentation/ComputeGraph/AddressSpace)

A GPU memory address space.

### Geometry and simulation inputs

[`enum Topology`](/documentation/ComputeGraph/ComputeNodeGraph/Topology)

The primitive topology used to assemble output geometry for an output stage.

[`enum CoordinateSpace`](/documentation/ComputeGraph/CoordinateSpace)

Simulation coordinate space, controlling how positions and orientations are stored.

[`struct StructureLayout`](/documentation/ComputeGraph/ComputeNodeGraph/StructureLayout)

[`enum StripOrientation`](/documentation/ComputeGraph/StripOrientation)

An enumeration that specifies how a strip should be oriented.

[`struct Viewpoint`](/documentation/ComputeGraph/Viewpoint-swift.struct)

Camera viewpoint parameters in 3D space.

[`struct MouseParams`](/documentation/ComputeGraph/MouseParams)

Parameters describing mouse interaction in 3D space.

### Functions

[`void filteredLinesFromNeighbors(grid, positions, groupings, outputSegments, maxDistance)`](/documentation/ComputeGraph/filteredLinesFromNeighbors)

[`void linesFromNeighbors(grid, positions, outputSegments, maxDistance)`](/documentation/ComputeGraph/linesFromNeighbors)

---

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)