Is it possible to change the buffer size at runtime? We allocate the buffer size during the register our device
:
device = MTLCreateSystemDefaultDevice()
queue = device!.makeCommandQueue()
do {
let library = device!.newDefaultLibrary()!
let kernel = library.makeFunction(name: "compute")!
cps = try device!.makeComputePipelineState(function: kernel)
} catch let e {
Swift.print("\(e)")
}
paramBuffer = device!.makeBuffer(length: MemoryLayout<Float>.size*2, options: [])
then we update it accordingly at run time:
override public func draw(_ dirtyRect: NSRect) {
super.draw(dirtyRect)
if let drawable = currentDrawable {
let command_buffer = queue.makeCommandBuffer()
let command_encoder = command_buffer.makeComputeCommandEncoder()
command_encoder.setComputePipelineState(cps)
command_encoder.setTexture(drawable.texture, at: 0)
command_encoder.setBuffer(paramBuffer, offset: 0, at: 0)
It works for now. But what if I have a scenario that, Have particles, at different state have different counts. For example, at the beginning I have 500 particles, After a while, the particles slowly increase by 10 at a time, say 510, 520, 530, ...
How should I approach this scenario? should I redo the queue
every time there is a changes on the particle counts?:
queue = device!.makeCommandQueue()
do {
let library = device!.newDefaultLibrary()!
let kernel = library.makeFunction(name: "compute")!
cps = try device!.makeComputePipelineState(function: kernel)
} catch let e {
Swift.print("\(e)")
}
paramBuffer = device!.makeBuffer(length: MemoryLayout<Float>.size*particleCount, options: [])//<--particleCount
Or any better way to do this?