<!--
{
  "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/writeCompactedSize(sourceAccelerationStructure:destinationBuffer:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Metal"
    ],
    "preciseIdentifier" : "c:objc(pl)MTL4ComputeCommandEncoder(im)writeCompactedAccelerationStructureSize:toBuffer:"
  },
  "title" : "writeCompactedSize(sourceAccelerationStructure:destinationBuffer:)"
}
-->

# writeCompactedSize(sourceAccelerationStructure:destinationBuffer:)

Encodes a command to compute the size an acceleration structure can compact into, writing the result
into a buffer.

```
func writeCompactedSize(sourceAccelerationStructure accelerationStructure: any MTLAccelerationStructure, destinationBuffer buffer: MTL4BufferRange)
```

## Parameters

`accelerationStructure`

Source acceleration structure.

`buffer`

Destination size buffer. Metal writes the compacted size as a 64-bit unsigned integer
value, representing the compacted size in bytes.

## Discussion

This size is potentially smaller than the acceleration structure. To perform compaction, you typically read
this size from the buffer once the command buffer completes. You then use it to allocate a new, potentially
smaller acceleration structure. Finally, you call the [`copyAndCompact(sourceAccelerationStructure:destinationAccelerationStructure:)`](/documentation/Metal/MTL4ComputeCommandEncoder/copyAndCompact(sourceAccelerationStructure:destinationAccelerationStructure:))
method to perform the copy.

---

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)