7
votes

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.

1
You sound like you're confused as to whether two things with the same name refer to the same thing. - Nicol Bolas
Well shouldn't they? I know that the correct answer is the first one (dstBindng's value must be the same with the binding number used as decoration in the variable resource). Probably I got stuck in my head that VkWriteDescriptorSet's dstBinding should refer to the elements of the VkDescriptorSetLayoutBinding as an index. - hiddenbit
The Vulkan specification is very carefully written to make it clear when it's talking about a binding in a descriptor set and an index of some user-provided array. - Nicol Bolas
It is indeed and in the specific matter there is no reference that dstBinding should be used as an index. Still I find it somewhat confusing. - hiddenbit
Have a look at Intel's tutorial about descriptor sets. There You can find an explanation about bindings and I hope it is more clear than the specification. - Ekzuzy

1 Answers

1
votes

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);