Skip to content

Commit

Permalink
Merge pull request #878 from timoore/MultiDescriptorSetConfiguration
Browse files Browse the repository at this point in the history
Deal with "missing" descriptor sets in ShaderSet::assignDescriptor
  • Loading branch information
robertosfield authored Jul 19, 2023
2 parents a03e5b5 + 6f72014 commit 3ba3955
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
4 changes: 4 additions & 0 deletions include/vsg/utils/ShaderSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ namespace vsg
inline ref_ptr<PipelineLayout> createPipelineLayout(const std::set<std::string>& 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<PipelineLayout> createPipelineLayout(const std::set<std::string>& defines, std::pair<uint32_t, uint32_t> range) const;

int compare(const Object& rhs) const override;
Expand Down
18 changes: 11 additions & 7 deletions src/vsg/utils/GraphicsPipelineConfigurator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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> 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});

Expand Down

0 comments on commit 3ba3955

Please sign in to comment.