You define the vertex descriptor on the Swift side, a struct on the GPU side, and the
[[stage_in]] attribute links the two. This linking means that when the vertex buffer described by the vertex descriptor is transferred from RAM to video RAM, the “gremlins” can automatically make that
You don’t have to use vertex descriptors. If you create an
MTLBuffer without one, you make sure that the struct in your shaders file exactly matches the layout of the
MTLBuffer. The vertex descriptor is a convenience.
A vertex descriptor describes how one or more vertex buffers are laid out. However, as I just said, not all vertex buffers use vertex descriptors. For example
uniforms go into an
MTLBuffer. That buffer is described by the Uniforms struct in
Common.h, which both Swift and the shaders use.
setVertexBytes is a convenience which automatically creates an
MTLBuffer so you don’t have to.
With that explanation, I hope that you can see that the 31 attributes for the vertex descriptor are plenty. In chapter 8, you’ll use a few more for joint animation.
I hope you are not getting confused with the 31 slots in the GPU buffer argument table. When you set the index of the vertex buffer on the render command encoder, you are setting the slot into the buffer argument table, and that has nothing at all to do with vertex descriptors.