title: MTLBuffer allocation + CPU/GPU synchronisation
body: <p>I am using a metal performance shader(<code>MPSImageHistogram</code>) to compute something in an <code>MTLBuffer</code> that I grab, perform computations, and then display via <code>MTKView</code>. The <code>MTLBuffer</code> output from the shader is small (~4K bytes). So I am allocating a new <code>MTLBuffer</code> object for every render pass, and there are atleast 30 renders per second for every video frame.</p>
  
  <pre><code>calculation = MPSImageHistogram(device: device, histogramInfo: &amp;histogramInfo)
  let bufferLength = calculation.histogramSize(forSourceFormat: MTLPixelFormat.bgra8Unorm)
  let buffer = device.makeBuffer(length: bufferLength, options: .storageModeShared)
  let commandBuffer = commandQueue?.makeCommandBuffer()
  
  calculation.encode(to: commandBuffer!, sourceTexture: metalTexture!, histogram: buffer!, histogramOffset: 0)
  commandBuffer?.commit()
  
  commandBuffer?.addCompletedHandler({ (cmdBuffer) in
      let dataPtr = buffer!.contents().assumingMemoryBound(to: UInt32.self)
      ...
      ...
  
  }
  </code></pre>
  
  <p>My questions - </p>
  
  <ol>
  <li><p>Is it okay to make a new buffer every time using <code>device.makeBuffer(..)</code>, or better to statically allocate 
  few buffers and implement reuse those buffers? If reuse is better, what do we do for synchronizing CPU/GPU data write/read on these buffers?</p></li>
  <li><p>Another unrelated question, is it okay to draw in <code>MTKView</code> the results on a non-main thread? Or <code>MTKView</code> draws must only be in main thread (even though I read Metal is truly multithreaded)?</p></li>
  </ol>