Here is my code :
colorVBO = device.makeBuffer(bytesNoCopy: &colorVAO, length: MemoryLayout<MetalRenderer_VertexOut>.stride * colorVAO.count, options: .storageModeShared, deallocator: nil)
colorVAO
is an array.
how to resolve it ?
Here is my code :
colorVBO = device.makeBuffer(bytesNoCopy: &colorVAO, length: MemoryLayout<MetalRenderer_VertexOut>.stride * colorVAO.count, options: .storageModeShared, deallocator: nil)
colorVAO
is an array.
how to resolve it ?
This thread should explain the error: newBufferWithBytesNoCopy:pointer i… | Apple Developer Forums
but how to get a page-aligned pointer from an array in swift ?
@008v - Are you having a problem with something in the Metal by Tutorials book?
You don’t just need a page-aligned pointer, the memory has to be page aligned too.
Depending on what you’re doing, I did find this in stack overflow: ios - Pointer (memory) alignment to 16K in Swift for Metal buffer creation - Stack Overflow - there’s a project that creates page aligned arrays. But I haven’t used it, and I don’t know if it’s up-to-date
Or, just thinking aloud, and I haven’t tried this - to get rid of the page alignment issue you could set up a new MTLBuffer with the desired capacity and do the work directly in the buffer. (Obviously you wouldn’t be able to append to it in this case.) For example something like (untested):
struct CreatedStruct {
var value: Float = 0
}
let buffer = device.makeBuffer(length: count * MemoryLayout<CreatedStruct>.stride, options: [])
var pointer = buffer.contents().bindMemory(to: CreatedStruct.self, capacity: count)
for _ in 0..< count {
pointer.pointee.value = newValue
pointer = pointer.advanced(by: 1)
}