Hey guys,
I create one dynamic uniform VkBuffer to upload uniforms. The memory managed by the VkBuffer is internally split into 3 chunks, where 3 is the maximum number of buffered frames. At frame start, I switch to the next chunk to suballocate memory from it during the frame. Each chunk occupies 1024 bytes. The total size occupied by VkBuffer is 3072 bytes.
I create one VkDescriptorSet, which contains one buffer descriptor of type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC pointing the uniform buffer.
VkDescriptorBufferInfo descriptorInfo;
descriptorInfo.buffer = uniformBuffer;
descriptorInfo.offset = 0;
descriptorInfo.range = 3072; // The total size of memory occupied by VkBuffer
On frame start
RotateBuffer(uniformBuffer, frameIndex);
// internalOffsetInBytes = frameIndex * chunkSizeInBytes;
On render
uint32_t uniformDataOffsetInBytes = SuballocateFromBuffer(uniformBuffer, uniformDataSizeInBytes);
// Update uniform data at uniformDataOffsetInBytes
vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS,
pipelineLayout, descriptorSetIndex, 1, &descriptorSet, 1, &uniformDataOffsetInBytes);
I am receiving the following validation error "Descriptor in binding #0 index 0 is uses buffer VkBuffer 0xfe25f60000000013[Sample::m_pUniformBuffer] with dynamic offset 1024 combined with offset 0 and range 3072 that oversteps the buffer size of 3072."
Apperently, the validator is using dynamic offset with the range specificied on the descriptorInfo.
- Should I set descriptorInfo.range to the size of one chunk? In this case, offset 0 is not valid anymore. Do I need to create a descriptor for each chunk then to have proper offset as well?
- If I do more suballocations from each chunk, do I need to create a dedicated descriptor for each suballocation?
- Can I use just one descriptor per chunk and set dynamic offset? If the validator uses dynamic offset in the 3rd chunk + size of the chunk itself, it will certainly go beyond the buffer limit as well.
In essence, I would like to suballocate memory from VkBuffer to upload the data. Is there possibility to do this with dynamicOffsets without creating descriptor for each allocation?
Thanks