I want to draw two objects in vulkan. To achieve this I follow the procedure where you create two different descriptor sets for each model. However, I am confused about the structs that specify the required descriptor set count. The points that confuses me are as follows:
specifying the descriptor count at VkDescriptorSetLayoutBinding
VkDescriptorSetLayoutBinding stagingLayoutBinding = {}; ... stagingLayoutBinding.descriptorCount = 1; <- i have one mat4 element for each descriptors
specifying the descriptor count at VkDescriptorPoolSize
VkDescriptorPoolSize stagingPoolSize = {}; ... stagingPoolSize.descriptorCount = static_cast<uint32_t>(model.size()); <- allocate two descriptor sets from one descriptor pool
specifying the max sets at VkDescriptorPoolCreateInfo
VkDescriptorPoolCreateInfo poolInfo = {}; ... poolInfo.maxSets = model.size(); <- max descriptor sets = 2
finally specifying the descriptor set creation at VkDescriptorSetAllocateInfo
VkDescriptorSetAllocateInfo allocInfo = {}; ... allocInfo.descriptorSetCount = static_cast<uint32_t>(model.size());
however, an exception is thrown at vkAllocateDescriptorSets(device, &allocInfo, descriptorSet.data())
and the debugging message in validation layer is as follows:-
validation Layer: Object: 0xcccccccccccccccc (Type = 20) | Invalid DescriptorSetLayout Object 0xcccccccccccccccc. The spec valid usage text states 'pSetLayouts must be a valid pointer to an array of descriptorSetCount valid VkDescriptorSetLayout handles' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-VkDescriptorSetAllocateInfo-pSetLayouts-parameter)
my descriptor creation code is as follows:
VkDescriptorSetLayout layouts[] = { descriptorSetLayout };
descriptorSet.resize(model.size());
VkDescriptorSetAllocateInfo allocInfo = {};
allocInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
allocInfo.descriptorPool = descriptorPool[0];
allocInfo.descriptorSetCount = static_cast<uint32_t>(model.size());
allocInfo.pSetLayouts = layouts;
if (vkAllocateDescriptorSets(device, &allocInfo, descriptorSet.data()) != VK_SUCCESS)
{
throw std::runtime_error("failed to allocate descriptor set !");
}
I presume I am feeding the wrong descriptor set count somewhere.