KhronosGroup / Vulkan-Docs

The Vulkan API Specification and related tools
Other
2.77k stars 465 forks source link

Vulkan Descriptor buffers custom offsets #2381

Open Agrael1 opened 3 months ago

Agrael1 commented 3 months ago

Hello, I have been working with descriptor buffers for quite some time, and I'd like to see them as a standard way to do decriptors. They allow for so much flexibility!

However there are some points I would like to discuss. 1) vkCmdSetDescriptorBufferOffsetsEXT offset is only allowed with alignment: I have 3 images, which I'd like to offset on a frame basis, similar to swapchain. However for that I have to allocate 3 padding bytes for descriptors, and indexing from `index desc_size` becomes a pain to manage.

2) Querying the offsets for specific descriptors within desc set with vkGetDescriptorSetLayoutBindingOffsetEXT is yet another API call. Could it be substituted with concrete values from VkPhysicalDeviceDescriptorBufferPropertiesEXT? This would make predicting size of the sets with variable descriptor count more feasible and will essentially remove a need for vkGetDescriptorSetLayoutSizeEXT.

3) Would something like vkSetDescriptorAddressIncrement be a feasible feature to have? This would come as a refinement for mutable descriptors and allow for better control over descriptor buffers, since it would provide a mean to shift indexing of descriptors.

What do you think?

Tobski commented 3 months ago

Hi @Agrael1! Thanks for your feedback! We are actually working towards standardising something in this area in the roadmap, and while I can't go into any details yet, all of what you've asked for is covered in what we're working on already (at least based on your descriptions). I'll keep this open until it's released to make sure we don't accidentally drop any of this functionality before then.

HansKristian-Work commented 3 months ago

As for existing API:

  1. Binding a descriptor buffer is similar to binding a UBO in some hardware, so UBO-style alignment is required. To avoid that case, descriptor indexing is the way to go.

  2. In descriptor sets, drivers are free to optimize the memory layout. Again, for consistent layouts, descriptor indexing is the way to go.

  3. Can be solved with spec constants in theory, but it is very ugly, yes.

Agrael1 commented 3 months ago

@HansKristian-Work I haven't seen any possibility of descriptor shifting using desc indexing. You are essentially forced into non-uniform resource indexing.

Now I'm thinking, how well would descriptor shifting fit into descriptor indexing? It seems quite logical to index into offset of descriptor set. May be a good extension?