1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| let device = MTLCreateSystemDefaultDevice()! let queue = device.makeCommandQueue()! let textureDescriptor = MTLTextureDescriptor() textureDescriptor.textureType = .type2D textureDescriptor.pixelFormat = .r16Uint textureDescriptor.width = bufferWidth textureDescriptor.height = 256 textureDescriptor.usage = [.shaderRead, .shaderWrite]
let texture = buffer?.makeTexture(descriptor: textureDescriptor, offset: 0, bytesPerRow: bufferWidth*MemoryLayout<UInt16>.stride)
let texture = device.makeTexture(descriptor: textureDescriptor) texture?.replace(region: MTLRegionMake2D(0, 0, w, h), mipmapLevel: 0, withBytes: data, bytesPerRow: 4 * w)
# buffer let count = 1500 var myVector = [Float](repeating: 0, count: count) var length = count * MemoryLayout< Float >.stride var outBuffer = device.makeBuffer(bytes: myVector, length: length, options: []) for (index, value) in myVector.enumerated() { myVector[index] = Float(index) } var inBuffer = device.makeBuffer(bytes: myVector, length: length, options: [])
|