Set all descriptor sets when calling Pipeline::SetDescriptorSets

- When calling Pipeline::SetDescriptorSets, it now sets all
  descriptor sets for all frames that can be in flight. Meaning
  SetDescriptorSets doesn't need to be called each render pass.
This commit is contained in:
Thraix
2025-08-12 22:18:23 +02:00
parent aca495960f
commit 717f452908
4 changed files with 21 additions and 7 deletions
@@ -114,6 +114,11 @@ namespace Copium
return bindings.begin()->set;
}
VkDescriptorSet DescriptorSet::GetVkDescriptorSet(int flightIndex) const
{
return descriptorSets[flightIndex];
}
DescriptorSet::operator VkDescriptorSet() const
{
return descriptorSets[Vulkan::GetSwapChain().GetFlightIndex()];
@@ -138,4 +143,4 @@ namespace Copium
}
}
}
}
@@ -36,6 +36,7 @@ namespace Copium
void SetSamplersDynamic(const std::vector<const Sampler*>& samplers, uint32_t binding);
UniformBuffer& GetUniformBuffer(const std::string& uniformBuffer);
uint32_t GetSetIndex() const;
VkDescriptorSet GetVkDescriptorSet(int flightIndex) const;
operator VkDescriptorSet() const;
private:
+12 -5
View File
@@ -83,13 +83,16 @@ namespace Copium
void Pipeline::SetDescriptorSet(const DescriptorSet& descriptorSet)
{
CP_ASSERT(descriptorSet.GetSetIndex() < boundDescriptorSets.size(), "DescriptorSet index is out of bounds");
boundDescriptorSets[descriptorSet.GetSetIndex()] = descriptorSet;
CP_ASSERT(descriptorSet.GetSetIndex() < GetDescriptorSetCount(), "DescriptorSet index is out of bounds");
for (int i = 0; i < SwapChain::MAX_FRAMES_IN_FLIGHT; i++)
{
boundDescriptorSetsPerFlightIndex[i][descriptorSet.GetSetIndex()] = descriptorSet.GetVkDescriptorSet(i);
}
}
void Pipeline::BindDescriptorSets(const CommandBuffer& commandBuffer)
{
vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, boundDescriptorSets.size(), boundDescriptorSets.data(), 0, nullptr);
vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, GetDescriptorSetCount(), boundDescriptorSetsPerFlightIndex[Vulkan::GetSwapChain().GetFlightIndex()].data(), 0, nullptr);
}
std::unique_ptr<DescriptorSet> Pipeline::CreateDescriptorSet(DescriptorPool& descriptorPool, int setIndex) const
@@ -121,12 +124,16 @@ namespace Copium
int Pipeline::GetDescriptorSetCount() const
{
return boundDescriptorSets.size();
return boundDescriptorSetsPerFlightIndex.front().size();
}
void Pipeline::InitializeDescriptorSetLayout(const PipelineCreator& creator)
{
boundDescriptorSets.resize(creator.descriptorSetLayouts.size());
boundDescriptorSetsPerFlightIndex.resize(SwapChain::MAX_FRAMES_IN_FLIGHT);
for (auto&& boundDescriptorSets : boundDescriptorSetsPerFlightIndex)
{
boundDescriptorSets.resize(creator.descriptorSetLayouts.size());
}
descriptorSetLayouts.resize(creator.descriptorSetLayouts.size());
int i = 0;
for (auto&& bindings : creator.descriptorSetLayouts)
+2 -1
View File
@@ -19,7 +19,7 @@ namespace Copium
private:
ShaderReflector shaderReflector;
std::vector<VkDescriptorSetLayout> descriptorSetLayouts{};
std::vector<VkDescriptorSet> boundDescriptorSets;
std::vector<std::vector<VkDescriptorSet>> boundDescriptorSetsPerFlightIndex;
VkPipelineLayout pipelineLayout;
VkPipeline graphicsPipeline;
AssetRef<Framebuffer> framebuffer;
@@ -31,6 +31,7 @@ namespace Copium
~Pipeline();
void Bind(const CommandBuffer& commandBuffer);
void SetDescriptorSet(const DescriptorSet& descriptorSet);
void SetDescriptorSetDynamic(const DescriptorSet& descriptorSet);
void BindDescriptorSets(const CommandBuffer& commandBuffer);
std::unique_ptr<DescriptorSet> CreateDescriptorSet(DescriptorPool& descriptorPool, int setIndex) const;