Group Group Group Group Group Group Group Group Group

MDLVertexBufferLayout

Hello Caroline, I understand all of matrix with your help. This week I start to study The Chapter 5. When I read starter source code and Lighting Fundamentals, the Initializers of MDLVertexBufferLayout makes me puzzle. For example , I do not know the reason why stride parameter is 12. If I use 16 bytes whether does lead to GPU compute slow.

You decide what is sensible for your layout.

I’ve used MemoryLayout<float3>.stride, which is 16 bytes long, but a float3 also fits into 12 bytes. Try changing the offset to 32, which also works, but will put padding in the buffer.

Because you’re using a vertex descriptor and in your shader file you’re using [[attribute(0)]], the vertex function will use [[stage_in]] and automatically know from the vertex descriptor what layout you’re using.

I think the book should probably be using 12 here.

P.S. I’m glad you got your matrix sorted - matrices is the essence of where to put your vertices, so it’s probably the most important topic :slight_smile: