What is the purpose of `binding` from` VkVertexInputBindingDescription`?

https://www.khronos.org/registry/vulkan/specs/1.0/man/html/VkVertexInputBindingDescription.html

  • binding is the binding number that this structure describes.

I'm 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 is as follows

#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 binding0? When will it have a different value than 0? What is the purpose binding?

My first idea was that it could be a special qualifier in glsl https://www.opengl.org/wiki/Layout_Qualifier_(GLSL)#Binding_points .

But this is not like vertex input qualifiers.

Update:

I think I realized that the purpose of binding

void vkCmdBindVertexBuffers(
    VkCommandBuffer                             commandBuffer,
    uint32_t                                    firstBinding,
    uint32_t                                    bindingCount,
    const VkBuffer*                             pBuffers,
    const VkDeviceSize*                         pOffsets);

, , , .

binding " ".

+4
1

, ,

, , .

, OpenGL. , . , , . , .

Vulkan . . , , . .

binding - pBuffers, vkCmdBindVertexBuffers. binding, , . . vkCmdBindVertexBuffers.

, binding binding, glVertexAttribBinding.

+3

Source: https://habr.com/ru/post/1659989/


All Articles