title: How to pass texture buffer data to Shader with Metal?
body: <p>I would like to work with texture data as a 1D array in a compute shader. I read that the best way is to pass it as a buffer instead of a 1D texture.</p>
  
  <p>I am loading the texture with:</p>
  
  <pre><code>let textureLoader = MTKTextureLoader(device: device)
  
  do {
      if let image = UIImage(named: "testImage") {
          let options = [ MTKTextureLoaderOptionSRGB : NSNumber(value: false) ]
          try kernelSourceTexture = textureLoader.newTexture(with: image.cgImage!, options: options)
              kernelDestTexture = device.makeTexture(descriptor: kernelSourceTexture!.matchingDescriptor())
      } else {
          print("Failed to load texture image from main bundle")
      }
  }
  catch let error {
      print("Failed to create texture from image, error \(error)")
  }
  </code></pre>
  
  <p>And I am creating the buffer with (not sure if this is correct):</p>
  
  <pre><code>var textureBuffer: MTLBuffer! = nil
  var currentVertPtr = kernelSourceTexture!.buffer!.contents()
  textureBuffer = device.makeBuffer(bytes: &amp;currentVertPtr, length: kernelSourceTexture!.buffer!.length, options: [])
  uniformBuffer.label = "textureData"
  </code></pre>
  
  <p>How do I pass the buffer to a compute shader? Do I pass it as an argument or as a uniform? What would the buffer's data type be?</p>
  
  <p>Sorry if these are dumb questions, I am just getting started with Metal and I can't find much for reading. I bought and read "Metal by Example: High-performance graphics and data-parallel programming for iOS". Side question, can anyone recommend more books on Metal?</p>