Skip to content

Allow descriptor sets to be inherited even if the pipeline layout isn't exactly identical #1438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion include/vsg/utils/ShaderSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,12 @@ namespace vsg
/// create the descriptor set layout.
virtual ref_ptr<DescriptorSetLayout> createDescriptorSetLayout(const std::set<std::string>& defines, uint32_t set) const;

/// return true of specified pipeline layout is compatible with what is required for this ShaderSet
/// return true if specified pipeline layout is compatible with what is required for this ShaderSet
virtual bool compatiblePipelineLayout(const PipelineLayout& layout, const std::set<std::string>& defines) const;

/// return true if specified pipeline layout is partially compatible with what is required for this ShaderSet
virtual bool partiallyCompatiblePipelineLayout(const PipelineLayout& layout, const std::set<std::string>& defines, bool onlyPushConstants, uint32_t descriptorSet) const;

/// create the pipeline layout for all descriptor sets enabled by specified defines or required by default.
inline ref_ptr<PipelineLayout> createPipelineLayout(const std::set<std::string>& defines) { return createPipelineLayout(defines, descriptorSetRange()); }

Expand Down
10 changes: 5 additions & 5 deletions src/vsg/utils/GraphicsPipelineConfigurator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,19 +552,19 @@ void GraphicsPipelineConfigurator::_assignInheritedSets()

void apply(const BindDescriptorSet& bds) override
{
if (!bds.descriptorSet || !bds.descriptorSet->setLayout || !gpc.descriptorConfigurator) return;
if (!bds.layout || !gpc.descriptorConfigurator) return;

if (gpc.shaderSet->compatiblePipelineLayout(*bds.layout, gpc.shaderHints->defines))
if (gpc.shaderSet->partiallyCompatiblePipelineLayout(*bds.layout, gpc.shaderHints->defines, false, bds.firstSet))
{
gpc.inheritedSets.insert(bds.firstSet);
}
}

void apply(const BindDescriptorSets& bds) override
{
if (!gpc.descriptorConfigurator) return;
if (!bds.layout || !gpc.descriptorConfigurator) return;

if (gpc.shaderSet->compatiblePipelineLayout(*bds.layout, gpc.shaderHints->defines))
if (gpc.shaderSet->partiallyCompatiblePipelineLayout(*bds.layout, gpc.shaderHints->defines, false, bds.firstSet + static_cast<uint32_t>(bds.descriptorSets.size()) - 1))
{
for (size_t i = 0; i < bds.descriptorSets.size(); ++i)
{
Expand All @@ -575,7 +575,7 @@ void GraphicsPipelineConfigurator::_assignInheritedSets()

void apply(const BindViewDescriptorSets& bvds) override
{
if (!gpc.shaderSet->compatiblePipelineLayout(*bvds.layout, gpc.shaderHints->defines))
if (!gpc.shaderSet->partiallyCompatiblePipelineLayout(*bvds.layout, gpc.shaderHints->defines, false, bvds.firstSet))
{
return;
}
Expand Down
46 changes: 46 additions & 0 deletions src/vsg/utils/ShaderSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,13 @@ bool ShaderSet::compatiblePipelineLayout(const PipelineLayout& layout, const std
++set;
}

#ifdef VK_EXT_graphics_pipeline_library
if (layout.flags & VK_PIPELINE_LAYOUT_CREATE_INDEPENDENT_SETS_BIT_EXT)
{
return false;
}
#endif

PushConstantRanges ranges;
for (auto& pcr : pushConstantRanges)
{
Expand All @@ -578,6 +585,45 @@ bool ShaderSet::compatiblePipelineLayout(const PipelineLayout& layout, const std
return true;
}

bool vsg::ShaderSet::partiallyCompatiblePipelineLayout(const PipelineLayout& layout, const std::set<std::string>& defines, bool onlyPushConstants, uint32_t descriptorSet) const
{
PushConstantRanges ranges;
for (auto& pcr : pushConstantRanges)
{
if (pcr.define.empty() || defines.count(pcr.define) == 1)
{
ranges.push_back(pcr.range);
}
}

if (compare_value_container(layout.pushConstantRanges, ranges) != 0)
{
return false;
}

if (onlyPushConstants)
{
return true;
}

#ifdef VK_EXT_graphics_pipeline_library
if (layout.flags & VK_PIPELINE_LAYOUT_CREATE_INDEPENDENT_SETS_BIT_EXT)
{
return false;
}
#endif

for (uint32_t set = 0; set <= std::min(layout.setLayouts.size() - 1, size_t(descriptorSet)); ++set)
{
if (layout.setLayouts[set] && !compatibleDescriptorSetLayout(*layout.setLayouts[set], defines, set))
{
return false;
}
}

return true;
}

ref_ptr<PipelineLayout> ShaderSet::createPipelineLayout(const std::set<std::string>& defines, std::pair<uint32_t, uint32_t> range) const
{
DescriptorSetLayouts descriptorSetLayouts;
Expand Down
Loading