Multiple Vertex Buffers with different strides

I have an issue with a metal vertex function - I'm just using it to transfrorm vertices from one verex buffer and store them in another (in lieu of using a compute stage).


The input buffer has a vertex stride of 32-bytes and the output buffer has a stride of 48-bytes.


The problem I'm having is that Metal seems to assume the wrong stride for the input buffer. No matter what I do, it seems to use the same stride as the output buffer. So when I capture a GPU frame and inspect the buffer contents, it only contains 5 items of 48-bytes each instead of 8 items of 32-bytes each.


Any ideas on what might eb the cause?

Accepted Reply

I;ce manafed t solve this myself. I wasn't paying attention to struct member alignment/size rules. I had the following struct for my input;


struct vertex {

float3 pos;

float3 norm;

float2 tex;

};


In. a normal vertex layout, the members would all be tightly packed, but when accessing GPU memory, each member is going to be 4 floats in size, hence the weird looking view in the GPU debugger. Re-jigging the struct so that tex is contained in the 4th elements of pos and norms fixes the issue. So my vertex struct now looks like this;


struct vertex {

float4 posTexU;

float4 normTexV;

};

Replies

I;ce manafed t solve this myself. I wasn't paying attention to struct member alignment/size rules. I had the following struct for my input;


struct vertex {

float3 pos;

float3 norm;

float2 tex;

};


In. a normal vertex layout, the members would all be tightly packed, but when accessing GPU memory, each member is going to be 4 floats in size, hence the weird looking view in the GPU debugger. Re-jigging the struct so that tex is contained in the 4th elements of pos and norms fixes the issue. So my vertex struct now looks like this;


struct vertex {

float4 posTexU;

float4 normTexV;

};