https://www.khronos.org/registry/vulkan/specs/1.0/man/html/VkVertexInputBindingDescription.html
- binding is the binding number that this structure describes.
I am not sure what this means for example from https://github.com/SaschaWillems/Vulkan/blob/master/triangle/triangle.cpp
#define VERTEX_BUFFER_BIND_ID 0
....
vertices.inputAttributes[0].binding = VERTEX_BUFFER_BIND_ID;
vertices.inputAttributes[0].location = 0;
vertices.inputAttributes[0].format = VK_FORMAT_R32G32B32_SFLOAT;
vertices.inputAttributes[0].offset = offsetof(Vertex, position);
// Attribute location 1: Color
vertices.inputAttributes[1].binding = VERTEX_BUFFER_BIND_ID;
vertices.inputAttributes[1].location = 1;
vertices.inputAttributes[1].format = VK_FORMAT_R32G32B32_SFLOAT;
vertices.inputAttributes[1].offset = offsetof(Vertex, color);
and the vertex shader looks like this
#version 450
#extension GL_ARB_separate_shader_objects : enable
#extension GL_ARB_shading_language_420pack : enable
layout (location = 0) in vec3 inPos;
layout (location = 1) in vec3 inColor;
layout (binding = 0) uniform UBO
{
mat4 projectionMatrix;
mat4 modelMatrix;
mat4 viewMatrix;
} ubo;
layout (location = 0) out vec3 outColor;
out gl_PerVertex
{
vec4 gl_Position;
};
void main()
{
outColor = inColor;
gl_Position = ubo.projectionMatrix * ubo.viewMatrix * ubo.modelMatrix * vec4(inPos.xyz, 1.0);
}
Why is the binding
0? When will it have a different value than 0? What is the purpose of binding
?
My first idea was that it might have been a special qualifier in glsl https://www.opengl.org/wiki/Layout_Qualifier_(GLSL)#Binding_points .
But this doesn't seem to work for the vertex input qualifiers.
Update:
I think I have figured out what the purpose of binding is
void vkCmdBindVertexBuffers(
VkCommandBuffer commandBuffer,
uint32_t firstBinding,
uint32_t bindingCount,
const VkBuffer* pBuffers,
const VkDeviceSize* pOffsets);
I assume that you can have a pipeline with some backed state but it can still change the vertex input layout so that you can have different shaders per pipeline.
And then the binding
is just a unique identifier to change the vertex layout "on the fly".