From 6f72014f5e4c9a2b02d1ddf5647d00d5530bf61b Mon Sep 17 00:00:00 2001 From: Tim Moore Date: Wed, 19 Jul 2023 10:30:58 +0200 Subject: [PATCH] Deal with "missing" descriptor sets in ShaderSet::assignDescriptor Also, add a comment to createPipelineLayout --- include/vsg/utils/ShaderSet.h | 4 ++++ src/vsg/utils/GraphicsPipelineConfigurator.cpp | 18 +++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/include/vsg/utils/ShaderSet.h b/include/vsg/utils/ShaderSet.h index cf2ce61c5..04de004c9 100644 --- a/include/vsg/utils/ShaderSet.h +++ b/include/vsg/utils/ShaderSet.h @@ -167,6 +167,10 @@ namespace vsg inline ref_ptr createPipelineLayout(const std::set& defines) { return createPipelineLayout(defines, descriptorSetRange()); } /// create pipeline layout for specified range {minimum_set, maxiumum_set+1> of descriptor sets that are enabled by specified defines or required by default. + /// + /// Note: the underlying Vulkan call vkCreatePipelineLayout assumes that the array of + /// descriptor sets starts with set 0. Therefore the minimum_set argument should be 0 unless + /// you really know what you're doing. virtual ref_ptr createPipelineLayout(const std::set& defines, std::pair range) const; int compare(const Object& rhs) const override; diff --git a/src/vsg/utils/GraphicsPipelineConfigurator.cpp b/src/vsg/utils/GraphicsPipelineConfigurator.cpp index a0ccebc1f..9f4455377 100644 --- a/src/vsg/utils/GraphicsPipelineConfigurator.cpp +++ b/src/vsg/utils/GraphicsPipelineConfigurator.cpp @@ -152,17 +152,21 @@ bool DescriptorConfigurator::assignUniform(const std::string& name, const Buffer bool DescriptorConfigurator::assignDescriptor(uint32_t set, uint32_t binding, VkDescriptorType descriptorType, uint32_t descriptorCount, VkShaderStageFlags stageFlags, ref_ptr descriptor) { - if (set >= descriptorSets.size()) descriptorSets.resize(set + 1); - - auto& ds = descriptorSets[set]; - if (!ds) + if (auto currentSize = descriptorSets.size(); set >= currentSize) { - ds = vsg::DescriptorSet::create(); - ds->setLayout = DescriptorSetLayout::create(); + descriptorSets.resize(set + 1); + for (auto i = currentSize; i <= set; i++) + { + if (!descriptorSets[i]) + { + descriptorSets[i] = vsg::DescriptorSet::create(); + descriptorSets[i]->setLayout = DescriptorSetLayout::create(); + } + } } + auto& ds = descriptorSets[set]; ds->descriptors.push_back(descriptor); - auto& descriptorBindings = ds->setLayout->bindings; descriptorBindings.push_back(VkDescriptorSetLayoutBinding{binding, descriptorType, descriptorCount, stageFlags, nullptr});