Reputation: 4663
I have a big chunk of device memory and multiple uniform buffers which I want to bind. Obviously, I need an offset. Let's see what the documentation for vkBindBufferMemory
says:
memoryOffset
is the start offset of the region of memory which is to be bound to the buffer...
memoryOffset
must be an integer multiple of thealignment
member of theVkMemoryRequirements
structure returned from a call tovkGetBufferMemoryRequirements
with buffer
Ok, that's clear - I have multiple uniform buffers created with the same flags so I can use the same alignment for all of them. But wait, there's another usage note for vkBindBufferMemory
in specs:
If buffer was created with the
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT
,memoryOffset
must be a multiple ofVkPhysicalDeviceLimits::minUniformBufferOffsetAlignment
That's confuing. Can I safely use VkPhysicalDeviceLimits::minUniformBufferOffsetAlignment
for my case or should I compare it with VkMemoryRequirements::alignment
and choose the lowest?
Upvotes: 4
Views: 2008
Reputation: 3437
First, a quick note: if You want to compare VkPhysicalDeviceLimits::minUniformBufferOffsetAlignment
with VkMemoryRequirements::alignment
then You should choose the largest of these two values, not the lowest (smallest) value.
But in the spec we can also read:
The implementation guarantees certain properties about the memory requirements returned by
vkGetBufferMemoryRequirements
andvkGetImageMemoryRequirements
:
- The alignment member is identical for all
VkBuffer
objects created with the same combination of values for theusage
andflags
members in theVkBufferCreateInfo
structure passed tovkCreateBuffer
.- The alignment member satisfies the buffer descriptor offset alignment requirements associated with the
VkBuffer
’susage
:
- If usage included
VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT
orVK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT
,alignment
must be an integer multiple ofVkPhysicalDeviceLimits::minTexelBufferOffsetAlignment
.- If usage included
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT
,alignment
must be an integer multiple ofVkPhysicalDeviceLimits::minUniformBufferOffsetAlignment
.- If usage included
VK_BUFFER_USAGE_STORAGE_BUFFER_BIT
,alignment
must be an integer multiple ofVkPhysicalDeviceLimits::minStorageBufferOffsetAlignment
.
So You don't have to compare them but only take the (multiple of the) alignment value returned by the vkGetBufferMemoryRequirements()
function in the VkMemoryRequirements
structure.
Based on the above information, I think that VkPhysicalDeviceLimits::minUniformBufferOffsetAlignment
value is more important when using dynamic uniform buffers as the offset value provided during the vkCmdBindDescriptorSets()
function call must also be a multiple of the above value.
Upvotes: 5