Looking to use Tier 2 AB in Swift. Since the struct can't be shared properly between header and Swift file like in Obj-C I have 2 structs:
In Swift:
struct VertexShaderArguments {
var uniforms: MTLBuffer
var materials: MTLBuffer
}
In Header:
struct VertexShaderArguments {
device Uniforms &uniforms;
device Material *materials;
};
And I construct and populate the argument buffer like so:
let vertexShaderArgumentBuffer = Renderer.device.makeBuffer(length: MemoryLayout<VertexShaderArguments>.stride)!
vertexShaderArgumentBuffer.label = "Vertex Shader Argument Buffer"
self.vertexShaderArgumentBuffer = vertexShaderArgumentBuffer
let vertexShaderArgumentBufferContents = vertexShaderArgumentBuffer.contents().assumingMemoryBound(to: VertexShaderArguments.self)
vertexShaderArgumentBufferContents.pointee.uniforms = uniformsBuffer
vertexShaderArgumentBufferContents.pointee.materials = scene.materialsBuffer
I've followed this example closely (https://developer.apple.com/documentation/metal/buffers/managing_groups_of_resources_with_argument_buffers) and consulted other resources.
Examining the VertexShaderArgumentBuffer in the Metal debugger reveals the error: "Not a valid buffer" for both members.
I would appreciate any assistance, and ask that Apple please try to provide more examples in Swift in the future. The fact that virtually all Metal examples are only Objective-C is baffling.