From 9bd9cf119f125bbc95a9546eaad24192217fc9a0 Mon Sep 17 00:00:00 2001 From: Simeon Hermann <shermann04@uni-koblenz.de> Date: Thu, 1 Jul 2021 22:27:32 +0200 Subject: [PATCH] [#76] implement reflection of descriptors in multiple shader stages --- src/vkcv/ShaderProgram.cpp | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/vkcv/ShaderProgram.cpp b/src/vkcv/ShaderProgram.cpp index 59bc70ea..134ba7af 100644 --- a/src/vkcv/ShaderProgram.cpp +++ b/src/vkcv/ShaderProgram.cpp @@ -138,12 +138,6 @@ namespace vkcv { m_VertexAttachments.emplace_back(attachment_loc, attachment_name, attachment_format); } } - - ShaderStages stages; - stages |= ShaderStage::VERTEX; - stages |= ShaderStage::FRAGMENT; - - vk::ShaderStageFlags flags = vk::ShaderStageFlagBits::eVertex | vk::ShaderStageFlagBits::eFragment; //reflect descriptor sets (uniform buffer, storage buffer, sampler, sampled image, storage image) std::vector<std::pair<uint32_t, DescriptorBinding>> bindings; @@ -201,7 +195,25 @@ namespace vkcv { if (maxSetID != -1) { if((int32_t)m_DescriptorSets.size() <= maxSetID) m_DescriptorSets.resize(maxSetID + 1); for (const auto &binding : bindings) { - m_DescriptorSets[binding.first].push_back(binding.second); + //checking if descriptor has already been reflected in another shader stage + bool bindingFound = false; + uint32_t pos = 0; + for (const auto& descriptor : m_DescriptorSets[binding.first]) { + if (binding.second.bindingID == descriptor.bindingID) { + if (binding.second.descriptorType == descriptor.descriptorType && binding.second.descriptorCount == descriptor.descriptorCount) { + //updating descriptor binding with another shader stage + ShaderStages updatedShaders = descriptor.shaderStages | shaderStage; + DescriptorBinding newBinding = DescriptorBinding(binding.second.bindingID, binding.second.descriptorType, binding.second.descriptorCount, updatedShaders); + m_DescriptorSets[binding.first][pos] = newBinding; + bindingFound = true; + break; + } + else vkcv_log(LogLevel::ERROR, "Included shaders contain resources with same identifier but different type or count"); + } + pos++; + } + //append new descriptor if it has not been reflected yet + if(!bindingFound) m_DescriptorSets[binding.first].push_back(binding.second); } } -- GitLab