This is described in Apple’s documentation:
However, that really only explains it if you know it already.
Imagine that you have a buffer of three vertices containing:
position, normal, position, normal, position, normal
That is one single buffer.
That set of vertices could be described with two buffers though:
position, position, position
normal, normal, normal
MDLVertexAttribute would use buffer index 0 for the first, and buffer index 1 for the second.
You would describe the Vertex Descriptor layout stride for each buffer. The stride is how many bytes between each vertex.
The first example in one buffer would have a
layout.stride of float3 + float3.
The second example in two buffers would have
layout.stride as float3 and
layout.stride as float3.
When you send your vertex buffers to the GPU, in the final project, in
draw(in:), you are only sending the first vertex buffer, described by buffer index 0 in the
let vertexBuffer = mesh.mtkMesh.vertexBuffers.buffer
renderEncoder.setVertexBuffer(vertexBuffer, offset: 0,
Later on, when you add tangent normals (chapter 6 textures), you’ll add a second vertex descriptor buffer, and you’ll loop through the
mtkMesh.vertexBuffers to make sure that both buffers are sent to the GPU.
I wrote this before I realised that you were talking about the buffer index on the vertex attributes :D, so I’ll just leave it here. Ignore it if you want to
MTLBuffers contain chunks of data that you can pass to the GPU.
The GPU has a very strict IO interface, and when you transfer the
MTLBuffer from RAM to GPU RAM, you assign buffers to indexed slots in an argument table on the GPU.
Depending on the device, there are limits on how many of these slots are available.
MTLBuffers to an indexed slot in the buffer argument table,
MTLTextures to the texture argument table, and sampler states to the sampler state argument table.
There are 31 slots in the texture argument table on early iOS devices, whereas there are 128 slots on macOS. Meaning that you can render with a lot more textures on macOS than iOS.
You can see limits in Apple’s Feature Set document: