<!--
{
  "availability" : [
    "iOS: 14.0.0 -",
    "iPadOS: 14.0.0 -",
    "macCatalyst: 14.0.0 -",
    "macOS: 11.0.0 -",
    "tvOS: 16.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Metal",
  "identifier" : "/documentation/Metal/MTLAccelerationStructureCommandEncoder/writeCompactedSize(accelerationStructure:buffer:offset:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Metal"
    ],
    "preciseIdentifier" : "c:objc(pl)MTLAccelerationStructureCommandEncoder(im)writeCompactedAccelerationStructureSize:toBuffer:offset:"
  },
  "title" : "writeCompactedSize(accelerationStructure:buffer:offset:)"
}
-->

# writeCompactedSize(accelerationStructure:buffer:offset:)

Encodes a command to calculate the compacted size of an acceleration structure.

```
func writeCompactedSize(accelerationStructure: any MTLAccelerationStructure, buffer: any MTLBuffer, offset: Int)
```

## Parameters

`accelerationStructure`

The acceleration structure to measure.

`buffer`

The buffer to write the size into.

`offset`

An offset, in bytes, where the GPU should write the result.

## Discussion

The GPU writes the compacted size to the buffer as a 32-bit unsigned integer representing the compacted size in bytes. The compacted size may be smaller than the source acceleration structure.

To compact an acceleration structure, encode a command to get the minimum size. After the command completes, read the size from the buffer and allocate a new acceleration structure with at least that much storage. Then create another encoder and call the  [`copyAndCompact(sourceAccelerationStructure:destinationAccelerationStructure:)`](/documentation/Metal/MTLAccelerationStructureCommandEncoder/copyAndCompact(sourceAccelerationStructure:destinationAccelerationStructure:)) method to copy it into the new structure.

---

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)