Skip to content
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
2 changes: 2 additions & 0 deletions include/vsg/state/DescriptorSetLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ namespace vsg
/// VkDescriptorSetLayoutCreateInfo settings
DescriptorSetLayoutBindings bindings;

virtual bool empty() const { return bindings.empty(); }

/// map the descriptor bindings to the descriptor pool sizes that will be required to represent them.
void getDescriptorPoolSizes(DescriptorPoolSizes& descriptorPoolSizes);

Expand Down
1 change: 1 addition & 0 deletions include/vsg/state/PipelineLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ namespace vsg
VkPipelineLayoutCreateFlags flags = 0;
DescriptorSetLayouts setLayouts;
PushConstantRanges pushConstantRanges;
std::vector<bool> descriptorSetSlots;

/// Vulkan VkPipelineLayout handle
VkPipelineLayout vk(uint32_t deviceID) const { return _implementation[deviceID]->_pipelineLayout; }
Expand Down
2 changes: 2 additions & 0 deletions include/vsg/state/ViewDependentState.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ namespace vsg
public:
ViewDescriptorSetLayout();

bool empty() const override { return false; }

VkDescriptorSetLayout vk(uint32_t deviceID) const override { return _viewDescriptorSetLayout ? _viewDescriptorSetLayout->vk(deviceID) : 0; }

int compare(const Object& rhs_object) const override;
Expand Down
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
2 changes: 2 additions & 0 deletions include/vsg/vk/CommandBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ namespace vsg
void setCurrentPipelineLayout(const PipelineLayout* pipelineLayout);

VkPipelineLayout getCurrentPipelineLayout() const { return _currentPipelineLayout; }
const std::vector<bool>& getCurrentDescriptorSetSlots() const { return _currentDescriptorSetSlots; }
VkShaderStageFlags getCurrentPushConstantStageFlags() const { return _currentPushConstantStageFlags; }

ref_ptr<ScratchMemory> scratchMemory;
Expand All @@ -73,6 +74,7 @@ namespace vsg
ref_ptr<Device> _device;
ref_ptr<CommandPool> _commandPool;
VkPipelineLayout _currentPipelineLayout;
std::vector<bool> _currentDescriptorSetSlots;
VkShaderStageFlags _currentPushConstantStageFlags;
};
VSG_type_name(vsg::CommandBuffer);
Expand Down
18 changes: 14 additions & 4 deletions src/vsg/state/BindDescriptorSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ void BindDescriptorSets::compile(Context& context)
void BindDescriptorSets::record(CommandBuffer& commandBuffer) const
{
//info("BindDescriptorSets::record() ", dynamicOffsets.size(), ", ", dynamicOffsets.data());
if (commandBuffer.getCurrentDescriptorSetSlots().size() < firstSet + descriptorSets.size())
return;
for (size_t slot = firstSet; slot < firstSet + descriptorSets.size(); ++slot)
{
if (!commandBuffer.getCurrentDescriptorSetSlots()[slot])
return;
}
auto& vkd = _vulkanData[commandBuffer.deviceID];
vkCmdBindDescriptorSets(commandBuffer, pipelineBindPoint, vkd._vkPipelineLayout, firstSet,
static_cast<uint32_t>(vkd._vkDescriptorSets.size()), vkd._vkDescriptorSets.data(),
Expand Down Expand Up @@ -209,8 +216,11 @@ void BindDescriptorSet::compile(Context& context)
void BindDescriptorSet::record(CommandBuffer& commandBuffer) const
{
//info("BindDescriptorSet::record() ", dynamicOffsets.size(), ", ", dynamicOffsets.data());
auto& vkd = _vulkanData[commandBuffer.deviceID];
vkCmdBindDescriptorSets(commandBuffer, pipelineBindPoint, vkd._vkPipelineLayout, firstSet,
1, &(vkd._vkDescriptorSet),
static_cast<uint32_t>(dynamicOffsets.size()), dynamicOffsets.data());
if (commandBuffer.getCurrentDescriptorSetSlots().size() > firstSet && commandBuffer.getCurrentDescriptorSetSlots()[firstSet])
{
auto& vkd = _vulkanData[commandBuffer.deviceID];
vkCmdBindDescriptorSets(commandBuffer, pipelineBindPoint, vkd._vkPipelineLayout, firstSet,
1, &(vkd._vkDescriptorSet),
static_cast<uint32_t>(dynamicOffsets.size()), dynamicOffsets.data());
}
}
7 changes: 6 additions & 1 deletion src/vsg/state/PipelineLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ PipelineLayout::PipelineLayout(const PipelineLayout& rhs, const CopyOp& copyop)
Inherit(rhs, copyop),
flags(rhs.flags),
setLayouts(rhs.setLayouts),
pushConstantRanges(rhs.pushConstantRanges)
pushConstantRanges(rhs.pushConstantRanges),
descriptorSetSlots(rhs.descriptorSetSlots)
{
}

Expand Down Expand Up @@ -123,9 +124,13 @@ void PipelineLayout::compile(Context& context)
{
if (!_implementation[context.deviceID])
{
descriptorSetSlots.clear();
descriptorSetSlots.reserve(setLayouts.size());

for (auto dsl : setLayouts)
{
if (dsl) dsl->compile(context);
descriptorSetSlots.push_back(dsl != nullptr && !dsl->empty());
}
_implementation[context.deviceID] = PipelineLayout::Implementation::create(context.device, setLayouts, pushConstantRanges, flags);
}
Expand Down
2 changes: 1 addition & 1 deletion src/vsg/state/ViewDependentState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ void BindViewDescriptorSets::compile(Context& context)

void BindViewDescriptorSets::record(CommandBuffer& commandBuffer) const
{
if (commandBuffer.viewDependentState)
if (commandBuffer.viewDependentState && commandBuffer.getCurrentDescriptorSetSlots().size() > firstSet && commandBuffer.getCurrentDescriptorSetSlots()[firstSet])
{
commandBuffer.viewDependentState->bindDescriptorSets(commandBuffer, pipelineBindPoint, layout->vk(commandBuffer.deviceID), firstSet);
}
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
3 changes: 3 additions & 0 deletions src/vsg/vk/CommandBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ CommandBuffer::CommandBuffer(CommandPool* commandPool, VkCommandBuffer commandBu
_device(commandPool->getDevice()),
_commandPool(commandPool),
_currentPipelineLayout(VK_NULL_HANDLE),
_currentDescriptorSetSlots(),
_currentPushConstantStageFlags(0)
{
}
Expand All @@ -45,6 +46,7 @@ CommandBuffer::~CommandBuffer()
void CommandBuffer::reset()
{
_currentPipelineLayout = VK_NULL_HANDLE;
_currentDescriptorSetSlots.clear();
_currentPushConstantStageFlags = 0;

_commandPool->reset();
Expand All @@ -59,6 +61,7 @@ void CommandBuffer::setCurrentPipelineLayout(const PipelineLayout* pipelineLayou
state->dirtyStateStacks();

_currentPipelineLayout = newLayout;
_currentDescriptorSetSlots = pipelineLayout->descriptorSetSlots;
if (pipelineLayout->pushConstantRanges.empty())
_currentPushConstantStageFlags = 0;
else
Expand Down
Loading