Contents

refit(sourceAccelerationStructure:descriptor:destinationAccelerationStructure:scratchBuffer:scratchBufferOffset:)

Updates an acceleration structure with new geometry or instance data.

Declaration

func refit(sourceAccelerationStructure: any MTLAccelerationStructure, descriptor: MTLAccelerationStructureDescriptor, destinationAccelerationStructure: (any MTLAccelerationStructure)?, scratchBuffer: (any MTLBuffer)?, scratchBufferOffset: Int)

Parameters

  • sourceAccelerationStructure:

    The source acceleration structure.

  • descriptor:

    A description of the updated acceleration structure.

  • destinationAccelerationStructure:

    The destination to write the new acceleration structure to. Pass the same acceleration structure or nil to refit the structure in place.

  • scratchBuffer:

    A buffer used to hold data while building the acceleration structure. Pass nil if Refitscratchbuffersize returns zero.

  • scratchBufferOffset:

    An offset, in bytes, in the scratch buffer where the scratch memory starts.

Discussion

Use refitting to update an acceleration structure when you make small changes to the underlying geometry. Refitting performs much faster than rebuilding an acceleration structure from scratch. However, ray-tracing performance may degrade, based on how many changes you make to the geometry data.

You can’t use refitting to add or remove geometry in the acceleration structure.

If the source and destination acceleration structures aren’t the same, they can’t overlap in memory. The destination acceleration structure and the scratch buffer need to have enough space in memory to hold the acceleration structure data. Get the minimum amount of space it needs by calling the accelerationStructureSizes(descriptor:) method of the Metal device instance. If you’re compacting the source structure, the destination needs to be at least as large as the compact size of the source acceleration structure.

See Also

Refitting an acceleration structure