From what I can gather based on error messages, for VkVertexInputAttributeDescription
's both binding and locations must be distinct, but I can't seem to understand the purpose of binding or how to use it. I understand location relates to where the input for the vertex shader goes, but what is binding used for? It's some sort of index based on search results, but an index for what? In what would one use the binding number as a reference? How is it useful and what does it do?

- 6,560
- 10
- 51
- 87

- 45
- 4
-
2The meaning of `binding` parameter is the same in both structs, so I don't see the distinction. – krOoze Aug 08 '20 at 13:07
2 Answers
VkVertexInputBindingDescription
has a member
inputRate
with the type of
VkVertexInputRate
and
inputRate
could be one of the two values:
VK_VERTEX_INPUT_RATE_VERTEX, VK_VERTEX_INPUT_RATE_INSTANCE
that is to say,you could use binding index to distinguish between per-vertex data and per-instance data

- 43
- 7
According to the spec (version 1.2):
location is the shader binding location number for this attribute.
binding is the binding number which this attribute takes its data from.
for example imagine that our Vertex structure is like below:
struct Vertex
{
float pos[3];
float normal[3];
float texcoord[2];
float color[4];
};
Here, we have four attributes with different sizes and offsets. each of them has to have its own location. for example location 0 goes for the first attribute which is the position. you specify these information in separate VkVertexInputAttributeDescription
(s).
Later you need to populate a struct called VkVertexInputBindingDescription
. it specifies its binding point and the stride (total size of the vertex attributes) of a vertex which it can contain.
So VkVertexInputAttributeDescription
and VkVertexInputBindingDescription
are different concepts. You only combine them upon creating your VkPipelineVertexInputStateCreateInfo
. This is where the binding value that is specified in your VkVertexInputAttributeDescription
will be used. Basically, Vulkan will check if such binding points described in your VkVertexInputAttributeDescription
exist in the defined VkVertexInputBindingDescription(s). If yes, it connect them together for the shading stage.
Spec points this out as well
For every binding specified by each element of pVertexAttributeDescriptions, a VkVertexInputBindingDescription must exist in pVertexBindingDescriptions with the same value of binding
All elements of pVertexBindingDescriptions must describe distinct binding numbers
All elements of pVertexAttributeDescriptions must describe distinct attribute locations

- 543
- 7
- 12