I want to split this question into 3 parts:-
what is the concept of limits.minUniformBufferOffsetAlignment why do we need to use this to get our required alignment and derive the offset of the buffer from it? can't Vulkan distinguish different data types and their respective alignment automatically?
in Sascha Willems example he calculates the Dynamic alignment for one 4X4 matrix as follows
size_t uboAlignment = vulkanDevice->properties.limits.minUniformBufferOffsetAlignment dynamicAlignment = (sizeof(glm::mat4) / uboAlignment) * uboAlignment + ((sizeof(glm::mat4) % uboAlignment) > 0 ? uboAlignment : 0);One 4X4 matrix is 64 bytes and the minimum alignment size allowed is 256 bytes but as far as i know his dynamicAlignment calculation results in (64+256 = 320 //which i believe is not allowed in vulkan) i dont quite get how this dynamicAlignment calculation works
how this dynamicAlignment variable reflects to
VkBufferCreateInfo bufferInfo = {}; bufferInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; bufferInfo.size = size;and memory mapping something like
void * data; vkMapMemory(device, uniformStagingBufferMemory, 0, sizeof(matrix), 0, &data); memcpy(data, &matrix, sizeof(matrix)); vkUnmapMemory(device, uniformStagingBufferMemory); copyBuffer(uniformStagingBuffer, uniformBuffer, sizeof(matrix));