Contents

writeCompactedSize(accelerationStructure:buffer:offset:sizeDataType:)

Encodes a command to calculate the compacted size of an acceleration structure, taking into account the size of the output data.

Declaration

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

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.

  • sizeDataType:

    The data type of the resulting data.

Discussion

The GPU writes the compacted size to the buffer, in bytes, using the sizeDataType parameter to determine the size of the output data. 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