Hi again and thank you for your thoughts,
I am using an M1 Mac Studio. I have included as simple and linear code sample as possible, borrowing the bare minimum geometry from a sample project. I get the error message mentioned earlier at the last line:
let commandBuffer: MTL4CommandBuffer = device.makeCommandBuffer()!
let commandAllocator: MTL4CommandAllocator = device.makeCommandAllocator()!
commandBuffer.beginCommandBuffer( allocator: commandAllocator )
let commandEncoder: MTL4ComputeCommandEncoder = commandBuffer.makeComputeCommandEncoder()!
// Create a Plane Object
let planeVertices: [vector_float3] = [ vector_float3( -4.5, -1.1, 0.0 ), vector_float3( -4.5, -1.1, 5.0 ), vector_float3( 4.5, -1.1, 5.0 ), vector_float3( 4.5, -1.1, 0.0 ) ]
var vertexIndices: [UInt16]
var vertexPositions: [vector_float3]
let v0 = planeVertices[0]
let v1 = planeVertices[1]
let v2 = planeVertices[2]
let v3 = planeVertices[3]
vertexIndices = [ 0, 1, 2, 0, 2, 3 ]
vertexPositions = [ v0, v1, v2, v3 ]
let indexBuffer = device.makeBuffer( length: MemoryLayout<UInt16>.stride * vertexIndices.count, options: .storageModeShared )!
var ptr = indexBuffer.contents()
let indexPointer = ptr.bindMemory( to: UInt16.self, capacity: 1 )
for i in 0..<( vertexIndices.count )
{
indexPointer[i] = vertexIndices[i]
}
let indexBufferRange = MTL4BufferRangeMake( indexBuffer.gpuAddress, UInt64(indexBuffer.length ) )
let positionBuffer = device.makeBuffer( length: MemoryLayout<vector_float3>.stride * vertexPositions.count, options: .storageModeShared )!
ptr = positionBuffer.contents()
let positionPointer = ptr.bindMemory( to: vector_float3.self, capacity: 1 )
for i in 0..<( vertexPositions.count )
{
positionPointer[i] = vertexPositions[i]
}
let positionBufferRange = MTL4BufferRangeMake( positionBuffer.gpuAddress, UInt64( positionBuffer.length ) )
let geometryDescriptor: MTL4AccelerationStructureTriangleGeometryDescriptor = MTL4AccelerationStructureTriangleGeometryDescriptor()
geometryDescriptor.indexBuffer = indexBufferRange
geometryDescriptor.indexType = MTLIndexType.uint16
geometryDescriptor.vertexBuffer = positionBufferRange
geometryDescriptor.vertexStride = MemoryLayout<vector_float3>.stride
geometryDescriptor.triangleCount = vertexIndices.count / 3
let accelerationDescriptor: MTL4PrimitiveAccelerationStructureDescriptor = MTL4PrimitiveAccelerationStructureDescriptor()
accelerationDescriptor.geometryDescriptors = [geometryDescriptor]
let accelerationStructureSizes = device.accelerationStructureSizes( descriptor: accelerationDescriptor )
let accelerationStructure = (device.makeAccelerationStructure( size: accelerationStructureSizes.accelerationStructureSize ))!
let scratchBuffer = device.makeBuffer( length: accelerationStructureSizes.buildScratchBufferSize, options: .storageModePrivate )
let scratchBufferRange = MTL4BufferRangeMake( scratchBuffer!.gpuAddress, UInt64( scratchBuffer!.length ) )
commandEncoder.build( destinationAccelerationStructure: accelerationStructure, descriptor: accelerationDescriptor, scratchBuffer: scratchBufferRange )