Search code examples
gpushadervulkan

what's the difference between .descriptorCount in VkDescriptorPoolSize and in VkDescriptorSetLayoutBinding(VkDescriptorSetLayoutCreateInfo)? how set?


what's the difference between .descriptorCount in VkDescriptorPoolSize and in VkDescriptorSetLayoutBinding(VkDescriptorSetLayoutCreateInfo)? how to set them when there are many shaders, how to set them correctly?

eg.

layout(binding = 0) uniform Buffers {
    uint x[];
} buffers[5];

then:

VkDescriptorSetLayoutBinding.descriptorCount = 5,//not 1,
VkDescriptorPoolSize.descriptorCount = 5,//not 1,

what if this same uniform Buffers are in many shaders? should add 5 to descriptorCount when it exist in 1 more shader?


Solution

  • In the case of VkDescriptorSetLayoutBinding::descriptorCount. The spec says:

    descriptorCount is the number of descriptors contained in the binding, accessed in a shader as an array, except if descriptorType is VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK in which case descriptorCount is the size in bytes of the inline uniform block. If descriptorCount is zero this binding entry is reserved and the resource must not be accessed from any stage via this binding within any pipeline using the set layout.

    So most likely be 1, unless you have an array of textures or array of uniform buffers (which is not very common).


    VkDescriptorPoolSize::descriptorCount has nothing to do with the previous one. A descriptor pool is used for allocating descriptors. So descriptorCount here is how many descriptors this pool can provide. The spec says:

    descriptorCount is the number of descriptors of that type to allocate. If type is VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK then descriptorCount is the number of bytes to allocate for descriptors of this type.

    You can use the same pool for allocating multiple descriptor sets of multiple different layouts. So this most likely needs to be a fairly large number.


    Anyways, I think you need to keep studying the general basic concepts around descriptors!