Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Descriptor bindings and binding numbers

Tags:

vulkan

I'm a bit confused by the language used in the spec concerning the descriptor bindings described by the VkDescriptorSetLayoutBinding struct. The binding element

is the binding number of this entry and corresponds to a resource of the same binding number in the shader stages.

As stated in 14.5.3

A variable identified with a DescriptorSet decoration of s and a Binding decoration of b indicates that this variable is associated with the VkDescriptorSetLayoutBinding that has a binding equal to b in pSetLayouts[s] that was specified in VkPipelineLayoutCreateInfo

So if I get this correctly the descriptor bindings described by the VkDescriptorSetLayoutBinding must have an entry for every active resource variable in that set. Which resource variable is referred to by each descriptor binding is dictated by the binding variable and the binding decoration of each variable.

So far so good. The confusing part is when calling vkUpdateDescriptorSets. Struct VkWriteDescriptorSet has element dstBindng which

is the descriptor binding within that set.

I'm confused by whether dstBindng's value must be the same with the binding number used as decoration in the variable resource, or it should be used as an index inside the VkDescriptorSetLayoutBinding array.

like image 858
hiddenbit Avatar asked Sep 07 '16 13:09

hiddenbit


1 Answers

dstBinding within VkWriteDescriptorSet is the binding# of the first VkDescriptorBufferInfo pointed to by pBufferInfo.

i.e. i want to write 4 buffers to the descriptor set, but they are of different types (3 storage buffers and a uniform buffer). I can write the 3 storage buffers starting at binding #0 (writing to bindings #0, #1, #2) and then write 1 uniform buffer starting at binding #3.

VkDescriptorBufferInfo descriptorBufferInfo[4];
...

VkWriteDescriptorSet writeDescriptorSet = {};
writeDescriptorSet.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
writeDescriptorSet.pNext = NULL;
writeDescriptorSet.dstSet = descriptorSet;
writeDescriptorSet.dstBinding = 0;
writeDescriptorSet.dstArrayElement = 0;
writeDescriptorSet.descriptorCount = 3;
writeDescriptorSet.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
writeDescriptorSet.pImageInfo = NULL;
writeDescriptorSet.pBufferInfo = descriptorBufferInfo;
writeDescriptorSet.pTexelBufferView = NULL;

vkUpdateDescriptorSets(device, 1, &writeDescriptorSet, NULL, NULL);

writeDescriptorSet.dstBinding = 3;
writeDescriptorSet.descriptorCount = 1;
writeDescriptorSet.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
writeDescriptorSet.pBufferInfo = &descriptorBufferInfo[3];

vkUpdateDescriptorSets(device, 1, &writeDescriptorSet, NULL, NULL);
like image 82
Jonathan Olson Avatar answered Oct 03 '22 07:10

Jonathan Olson