---
title: "writeCompactedSize(accelerationStructure:buffer:offset:)"
framework: metal
role: symbol
role_heading: Instance Method
path: "metal/mtlaccelerationstructurecommandencoder/writecompactedsize(accelerationstructure:buffer:offset:)"
---

# writeCompactedSize(accelerationStructure:buffer:offset:)

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

## Declaration

```swift
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

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:) method to copy it into the new structure.

## See Also

### Copying an acceleration structure

- [copy(sourceAccelerationStructure:destinationAccelerationStructure:)](metal/mtlaccelerationstructurecommandencoder/copy(sourceaccelerationstructure:destinationaccelerationstructure:).md)
- [writeCompactedSize(accelerationStructure:buffer:offset:sizeDataType:)](metal/mtlaccelerationstructurecommandencoder/writecompactedsize(accelerationstructure:buffer:offset:sizedatatype:).md)
- [copyAndCompact(sourceAccelerationStructure:destinationAccelerationStructure:)](metal/mtlaccelerationstructurecommandencoder/copyandcompact(sourceaccelerationstructure:destinationaccelerationstructure:).md)
