<!--
{
  "availability" : [
    "iOS: 26.0.0 -",
    "iPadOS: 26.0.0 -",
    "macCatalyst: 26.0.0 -",
    "macOS: 26.0.0 -",
    "tvOS: 26.0.0 -",
    "visionOS: 26.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Metal",
  "identifier" : "/documentation/Metal/MTL4ComputeCommandEncoder/build(destinationAccelerationStructure:descriptor:scratchBuffer:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Metal"
    ],
    "preciseIdentifier" : "c:objc(pl)MTL4ComputeCommandEncoder(im)buildAccelerationStructure:descriptor:scratchBuffer:"
  },
  "title" : "build(destinationAccelerationStructure:descriptor:scratchBuffer:)"
}
-->

# build(destinationAccelerationStructure:descriptor:scratchBuffer:)

Encodes an acceleration structure build into the command buffer.

```
func build(destinationAccelerationStructure accelerationStructure: any MTLAccelerationStructure, descriptor: MTL4AccelerationStructureDescriptor, scratchBuffer: MTL4BufferRange)
```

## Parameters

`accelerationStructure`

Acceleration structure storage to build into.

`descriptor`

A descriptor for the acceleration structure Metal builds.

`scratchBuffer`

Scratch buffer Metal can use while building the acceleration structure.
Metal may overwrite the contents of this buffer, and you should consider
them “undefined” after the refit operation starts and completes.

## Discussion

Before you build an instance acceleration structure, you are responsible for ensuring the build operations for all
primitive acceleration structures is complete. The built acceleration structure doesn’t retain any references to
the input buffers of the descriptor, such as the vertex buffer or instance buffer, among others.

The acceleration structure build process may continue as long as the command buffer is not completed. However,
you can safely encode ray tracing work against the acceleration structure if you schedule and synchronize the
command buffers that contain this ray tracing work such that the command buffer with the build command is complete
by the time ray tracing starts.

You are responsible for ensuring that the acceleration structure and scratch buffer are at least the size
that the query [`accelerationStructureSizes(descriptor:)`](/documentation/Metal/MTLDevice/accelerationStructureSizes(descriptor:)) returns.

Use an instance of [`MTLResidencySet`](/documentation/Metal/MTLResidencySet) to mark residency of the scratch buffer the `scratchBuffer` parameter references,
as well as for all the primitive acceleration structures you directly and indirectly reference.

---

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)