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

# ComputeGraphSimulation

A simulation of particles, which use a single pipeline.

```
final class ComputeGraphSimulation
```

## Overview

This class is independent of the output, which makes for simpler testing.

## Topics

### Structures

[`struct AdvanceParams`](/documentation/ComputeGraph/ComputeGraphSimulation/AdvanceParams)

Parameters for advancing a compute graph simulation by one time step.

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

Specifies the rate and mode for simulation.

### Initializers

[`convenience init(pipelines: ComputeNodeGraph.Pipelines?)`](/documentation/ComputeGraph/ComputeGraphSimulation/init(pipelines:))

Initialize a ComputeGraphSimulation for the given pipelines, or a
default pipeline if not specified.

[`convenience init(pipelines: ComputeNodeGraph.Pipelines, commandQueue: any MTLCommandQueue)`](/documentation/ComputeGraph/ComputeGraphSimulation/init(pipelines:commandQueue:))

Initialize a ComputeGraphSimulation for the given pipelines

### Instance Properties

[`var commandQueue: any MTLCommandQueue`](/documentation/ComputeGraph/ComputeGraphSimulation/commandQueue)

[`var graphUniforms: any MTLBuffer`](/documentation/ComputeGraph/ComputeGraphSimulation/graphUniforms)

Returns a read-only copy of the uniforms buffer.

[`var pipelines: ComputeNodeGraph.Pipelines`](/documentation/ComputeGraph/ComputeGraphSimulation/pipelines)

[`var simulationRate: ComputeGraphSimulation.SimulationRate`](/documentation/ComputeGraph/ComputeGraphSimulation/simulationRate-swift.property)

Specifies the current simulation rate.

### Instance Methods

[`func addUserResource(any MTLResource)`](/documentation/ComputeGraph/ComputeGraphSimulation/addUserResource(_:))

Registers a resource for residency on all command encoders used by this simulation.

[`func advance(ComputeGraphSimulation.AdvanceParams)`](/documentation/ComputeGraph/ComputeGraphSimulation/advance(_:))

Advances the simulation by one time step, encoding all simulation
stage dispatches into the command buffer and encoder provided by `params`.

[`func buffer(at: Int) -> (any MTLBuffer, bufferOffset: Int)?`](/documentation/ComputeGraph/ComputeGraphSimulation/buffer(at:))

[`func fastForward()`](/documentation/ComputeGraph/ComputeGraphSimulation/fastForward())

[`func fastForward(stepCount: Int, stepDeltaTime: Float)`](/documentation/ComputeGraph/ComputeGraphSimulation/fastForward(stepCount:stepDeltaTime:))

Advances the particle simulation by multiple steps in a single operation.

[`func isOutputEnabled(Int) -> Bool`](/documentation/ComputeGraph/ComputeGraphSimulation/isOutputEnabled(_:))

Returns whether the specified output is currently enabled for simulation.

[`func modifyUniforms<E, R>((UnsafeMutableRawBufferPointer) throws(E) -> R) throws(E) -> R`](/documentation/ComputeGraph/ComputeGraphSimulation/modifyUniforms(_:))

Provides read/write access to the entire uniforms buffer for CPU access.

[`func reset(encoder: any MTLComputeCommandEncoder)`](/documentation/ComputeGraph/ComputeGraphSimulation/reset(encoder:))

Resets the simulation to its initial state, clearing all live elements
and accumulated time.

[`func resetRandomSeeds(using: () -> UInt32)`](/documentation/ComputeGraph/ComputeGraphSimulation/resetRandomSeeds(using:))

Resets random seeds using the provided randomness function.

[`func setBuffer((any MTLBuffer)?, bufferOffset: Int, at: ComputeNodeGraph.Assembly.Location)`](/documentation/ComputeGraph/ComputeGraphSimulation/setBuffer(_:bufferOffset:at:)-772ch)

[`func setBuffer((any MTLBuffer)?, bufferOffset: Int, at: Int)`](/documentation/ComputeGraph/ComputeGraphSimulation/setBuffer(_:bufferOffset:at:)-bmmd)

[`func setBuffer(any MTLBuffer, bufferOffset: Int, elementCount: Int, at: ComputeNodeGraph.Assembly.Location)`](/documentation/ComputeGraph/ComputeGraphSimulation/setBuffer(_:bufferOffset:elementCount:at:))

[`func setBuffers([(any MTLBuffer)?], bufferOffsets: [Int]?)`](/documentation/ComputeGraph/ComputeGraphSimulation/setBuffers(_:bufferOffsets:))

[`func setOutputEnabled(Int, enabled: Bool)`](/documentation/ComputeGraph/ComputeGraphSimulation/setOutputEnabled(_:enabled:))

Enables or disables execution of the provided output stage, without
disabling the system it represents.

[`func setTexture((any MTLTexture)?, at: Int)`](/documentation/ComputeGraph/ComputeGraphSimulation/setTexture(_:at:))

Binds a Metal texture to the texture slot at the given index.

[`func setTextures([(any MTLTexture)?])`](/documentation/ComputeGraph/ComputeGraphSimulation/setTextures(_:))

[`func setUniform<V>(V, named: String) -> Bool`](/documentation/ComputeGraph/ComputeGraphSimulation/setUniform(_:named:))

Finds the named uniform and sets it to the given BitwiseCopyable value.

[`func setUniformData(Data, at: ComputeNodeGraph.Assembly.Location)`](/documentation/ComputeGraph/ComputeGraphSimulation/setUniformData(_:at:))

[`func setUniformValue<V>(V, at: ComputeNodeGraph.Assembly.Location)`](/documentation/ComputeGraph/ComputeGraphSimulation/setUniformValue(_:at:))

Copies the contents of `value` into the location specified by `relocation`

[`func setUserResources([any MTLResource])`](/documentation/ComputeGraph/ComputeGraphSimulation/setUserResources(_:))

Sets additional resources for residency on all command buffers used by this simulation,
replacing any previously added resources.

[`func spawn(elements: borrowing [ElementSpawnParameters], in: Int?, using: any MTLComputeCommandEncoder)`](/documentation/ComputeGraph/ComputeGraphSimulation/spawn(elements:in:using:))

Spawns new elements into the simulation with the given initial parameters.

[`func texture(at: Int) -> (any MTLTexture)?`](/documentation/ComputeGraph/ComputeGraphSimulation/texture(at:))

---

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)