title: iOS Metal buffer not honouring stride value
body: <p>I have a per-instance uniform buffer where each element in the buffer is 64-bytes but I only use the first 16-bytes (float3) of each element in the vertex shader. I set the stride up to describe this. The problem is it does not stride over the other 48 bytes <strong>unless</strong> I add padding to the struct in the shader so that it is also 64 bytes.</p>
  
  <pre><code>// Particle Instance Position
  vertexDescriptor.attributes[2].format = .Float3   // 16 bytes with padding.     
  vertexDescriptor.attributes[2].offset = 0
  vertexDescriptor.attributes[2].bufferIndex = 2
  vertexDescriptor.layouts[2].stride = strideof(Particle)
  vertexDescriptor.layouts[2].stepFunction = .PerInstance
  
  ...
  
  commandEncoder.setVertexBuffer(instanceUniformBuffer, offset:0, atIndex:2)
  </code></pre>
  
  <p>App side particle struct:</p>
  
  <pre><code>struct Particle {
  
      var position = float3()
      var prevPos = float3()
      var attractPoint = float3()
  
      var ref: DataRef!
      var state = State.Free
  
      enum State: Int {
          case Free = 0
          case Active
      }
  }
  </code></pre>
  
  <p>And here's the corresponding Metal struct, i.e. <code>Particle.position</code> corresponds to <code>InstanceUniforms.instanceTranslate</code> in the shader. I expect the stride setup above to mean that this gets loaded with the <code>Particle.position</code> for each instance and the other 48 bytes of each <code>Particle</code> in the buffer is skipped over.</p>
  
  <pre><code>struct InstanceUniforms
  {
      float3 instanceTranslate [[ attribute(2) ]];
  };
  </code></pre>
  
  <p>Some sanity checks, everything makes sense:</p>
  
  <pre><code>sizeof(float3) 16
  alignof(float3) 16
  sizeof(Particle) 57
  alignof(Particle) 16
  strideof(Particle) 64
  </code></pre>
  
  <p>But it doesn't work unless I pad the shader struct out to 64 bytes:</p>
  
  <pre><code>struct InstanceUniforms
  {
      float3 instanceTranslate [[ attribute(2) ]];
      float4 pad[3];
  };
  </code></pre>
  
  <p>Otherwise for the second instance the shader actually sets <code>instanceTranslate</code> to the <code>Particle.prevPos</code> of the <strong>first</strong> element in the buffer, like it only strides over the size of the <code>InstanceUniforms</code> struct, regardless of what the stride is set to in the vertex descriptor.</p>
  
  <p>I'm sure I must be doing something wrong here, it seems like you shouldn't need to pad your shader structs.</p>