Search code examples
vulkan

Why Vulkan VkVertexInputBindingDescription stride is uint32_t, but vkCmdBindVertexBuffers offset is VkDeviceSize uint64_t?


In my understanding, VkVertexInputBindingDescription stride is the size of the vertex buffer elements block, and vkCmdBindVertexBuffers offset is the offset from the vertex buffer elements block.

vkCmdBindVertexBuffers offset can't be more than VkVertexInputBindingDescription stride size.

I checked the WebGPU and DX12 graphic API, and the API stride and offset size are the same.

Is Vulkan missing something? or did I miss something?


Solution

  • The stride is the size of each element and the offset is where to start reading from the buffer.

    This way you can hold data with different strides:

    | 4 | 4 | 4 | 4 | 8 | 8 | 8 | 8 |
    -----offset-----
    

    then for reading the elements with stride 4 set offset=0, and for reading the elements with stride 8 offset=4*4.

    The buffer could potentially be larger than 4 GiB, that's why uint64_t is used for the offset.