🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Using VkDescriptorSet with dynamic offsets

Started by
3 comments, last by _void_ 3 years, 6 months ago

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.

  1. 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?
  2. If I do more suballocations from each chunk, do I need to create a dedicated descriptor for each suballocation?
  3. 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

Advertisement

The descriptor range should be 1024 in this case. You can think of it as the amount of data you're making available to the shader, and in most cases should be equal to the size of the uniform/constant buffer declared in your shader code. You can reuse the same descriptor for all 3 suballocations and just change the dynamic offset every frame.

@mjp Excellent, it works! Thanks

To add more info, 1024 is the byte size of the memory chunk, from which I do suballocation.

If I suballocate 256 bytes, I cannot use dynamic offset with a descriptor covering the whole 1024 byte range. Suppose I suballocate 256 bytes (now range [0..256) is occupied) and then suballocate 256 bytes more (range [256, 512)). In the second case, the check against 1024 bytes range will not succeed.

The size covered by the descriptor should be equal to the size of the suballocation.

This topic is closed to new replies.

Advertisement