I recently made the jump from OpenGL to vulkan.
Following a tutorial i was able to display a simple colored triangle on the screen.
Now, given that the tutorial was creating unique buffers for each allocation (vertex/Indexbuffer) i started implementing the vulkan memory allocator from AMD.
The allocator seems to work, but i'm currently stumbling upon an issue in binding the vertex- and index buffer.
Originally the buffers where bound with this code:
VkBuffer vertexBuffers[] = { vertexBuffer };
VkDeviceSize offsets[] = { 0 };//offset is in both cases zero, as the vertex and indexbuffer have seperate buffers
vkCmdBindVertexBuffers(commandBuffers[i], 0, 1, vertexBuffers, offsets);
vkCmdBindIndexBuffer(commandBuffers[i], indexBuffer, 0, VK_INDEX_TYPE_UINT16);
But after using the vulkan memory allocator, the memory was sub-allocated and thus buffers could be reused between object but the offset/startingposition of the specific data has to be taken into account.
So i rewrote the code like this:
//in this case the vertex and indexbuffer share the same VkBuffer object but the offset is different
VkBuffer vertexBuffers[] = { vertexBuffer.buffer };
VkDeviceSize offsets[] = { vertexBuffer.allocationInfo.offset };
vkCmdBindVertexBuffers(commandBuffers[i], 0, 1, vertexBuffers, offsets);
vkCmdBindIndexBuffer(commandBuffers[i], indexBuffer.buffer, indexBuffer.allocationInfo.offset, VK_INDEX_TYPE_UINT16);
//=======
//uniforms
vkCmdBindDescriptorSets(commandBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, &descriptorSets[i], 0, nullptr);
//-------
vkCmdDrawIndexed(commandBuffers[i], static_cast<uint32_t>(indices.size()), 1, 0, 0, 0);
vkCmdEndRenderPass(commandBuffers[i]);
Starting the c++ project does render the triangle correctly, but the validation layers throw this message:
validation layer: vkCmdDrawIndexed() index size (2) * (firstIndex (0) + indexCount (6)) + binding offset (256) = an ending offset of 268 bytes,
which is greater than the index buffer size (12). The Vulkan spec states: (indexSize * (firstIndex + indexCount) + offset) must be less than or
equal to the size of the bound index buffer, with indexSize being based on the type specified by indexType, where the index buffer, indexType, and
offset are specified via vkCmdBindIndexBuffer (https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#VUID-
vkCmdDrawIndexed-indexSize-00463)
I'm confused why it compares the index size * index Count + offset with the index buffer size. (which in this case is 12 bytes). The offset itself should be just an offset and not be counted towards the buffer size. Am i setting the parameters incorrectly? Are the offset parameters the offset for the starting position in the buffer for the information?
I looked up the function calls in the vulkan documentation but i can't seem to find the issue here. (Unless i'm mixing up the offsets somehow).