title: MTLBuffer containing array of int2 has incorrect values when read by compute shader
body: <p>I am attempting to pass a buffer with an array of <code>int2</code> to a kernel function, using the following class:</p>
  
  <pre><code>class MetalHelper {    
      lazy var device: MTLDevice! = { MTLCreateSystemDefaultDevice() }()
      lazy var defaultLibrary: MTLLibrary! = { self.device.newDefaultLibrary() }()
      lazy var commandQueue: MTLCommandQueue! = { return self.device.newCommandQueue() }()
      var pipelineState: MTLComputePipelineState!
  
      var inTexture: MTLTexture!
      var outTexture: MTLTexture!
      var testBuffer: [int2] = [int2(Int32(3), Int32(-1)), int2(Int32(0), Int32(7)), int2(Int32(2), Int32(-10))] // etc...
  
      // Additional setup of in and out textures, pipeline state....
  
      func compute() {
          commandQueue.insertDebugCaptureBoundary()
  
          let commandBuffer = commandQueue.commandBuffer()
          let commandEncoder = commandBuffer.computeCommandEncoder()
  
          commandEncoder.setComputePipelineState(pipelineState)
          commandEncoder.setTexture(inTexture, atIndex: 0)
          commandEncoder.setTexture(outTexture, atIndex: 1)
  
          let buffer = device.newBufferWithBytes(&amp;testBuffer, length: sizeof(int2) * testBuffer.count, options: [.StorageModeShared])
          commandEncoder.setBuffer(buffer, offset: 0, atIndex: 0)
  
          let threadsPerThreadgroup = MTLSizeMake(16, 16, 1);
          let width = Int(inTexture.width / threadsPerThreadgroup.width)
          let height = Int(inTexture.height / threadsPerThreadgroup.height)
          let threadgroupCount = MTLSizeMake(width, height, 1)
  
          commandEncoder.dispatchThreadgroups(threadgroupCount, threadsPerThreadgroup: threadsPerThreadgroup)
          commandEncoder.endEncoding()
  
          commandBuffer.commit()
          commandBuffer.waitUntilCompleted()
  
          commandQueue.insertDebugCaptureBoundary()
      }
  }
  </code></pre>
  
  <p>And in my shader function, read the values out of the buffer to get the color at a pixel. The buffer array length is known to be equal to the number of slices in <code>inTexture</code>.</p>
  
  <pre><code>kernel void average(texture2d_array&lt;float, access::read&gt; inTexture [[texture(0)]],
                       texture2d&lt;float, access::write&gt; outTexture [[texture(1)]],
                       const device int2 *testBuffer [[buffer(0)]],
                       uint2 gid [[thread_position_in_grid]])
  {
      uint total = inTexture.get_array_size();
  
      uint index;
      float4 averageColor = float4(0, 0, 0, 0);
  
      for (index = 0; index &lt; total; index++) {
          int2 offset = testBuffer[index];
          const uint2 coordinate = uint2(gid.x + offset[0], gid.y + offset[1]);
  
          const float4 colorAtPixel = inTexture.read(coordinate, index);
          averageColor += colorAtPixel;
      }
  
      averageColor = averageColor / total;
      outTexture.write(averageColor, gid);
  }
  </code></pre>
  
  <p>For some reason, the values in <code>testBuffer</code> are incorrect. Here is the GPU Frame:</p>
  
  <p><a href="http://i.stack.imgur.com/VnxYj.png" rel="nofollow">gputrace</a></p>
  
  <p>Any help or guidance would be much appreciated!</p>