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:
@@ -114,6 +114,11 @@ namespace Copium
|
|||||||
return bindings.begin()->set;
|
return bindings.begin()->set;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VkDescriptorSet DescriptorSet::GetVkDescriptorSet(int flightIndex) const
|
||||||
|
{
|
||||||
|
return descriptorSets[flightIndex];
|
||||||
|
}
|
||||||
|
|
||||||
DescriptorSet::operator VkDescriptorSet() const
|
DescriptorSet::operator VkDescriptorSet() const
|
||||||
{
|
{
|
||||||
return descriptorSets[Vulkan::GetSwapChain().GetFlightIndex()];
|
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);
|
void SetSamplersDynamic(const std::vector<const Sampler*>& samplers, uint32_t binding);
|
||||||
UniformBuffer& GetUniformBuffer(const std::string& uniformBuffer);
|
UniformBuffer& GetUniformBuffer(const std::string& uniformBuffer);
|
||||||
uint32_t GetSetIndex() const;
|
uint32_t GetSetIndex() const;
|
||||||
|
VkDescriptorSet GetVkDescriptorSet(int flightIndex) const;
|
||||||
|
|
||||||
operator VkDescriptorSet() const;
|
operator VkDescriptorSet() const;
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -83,13 +83,16 @@ namespace Copium
|
|||||||
|
|
||||||
void Pipeline::SetDescriptorSet(const DescriptorSet& descriptorSet)
|
void Pipeline::SetDescriptorSet(const DescriptorSet& descriptorSet)
|
||||||
{
|
{
|
||||||
CP_ASSERT(descriptorSet.GetSetIndex() < boundDescriptorSets.size(), "DescriptorSet index is out of bounds");
|
CP_ASSERT(descriptorSet.GetSetIndex() < GetDescriptorSetCount(), "DescriptorSet index is out of bounds");
|
||||||
boundDescriptorSets[descriptorSet.GetSetIndex()] = descriptorSet;
|
for (int i = 0; i < SwapChain::MAX_FRAMES_IN_FLIGHT; i++)
|
||||||
|
{
|
||||||
|
boundDescriptorSetsPerFlightIndex[i][descriptorSet.GetSetIndex()] = descriptorSet.GetVkDescriptorSet(i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Pipeline::BindDescriptorSets(const CommandBuffer& commandBuffer)
|
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
|
std::unique_ptr<DescriptorSet> Pipeline::CreateDescriptorSet(DescriptorPool& descriptorPool, int setIndex) const
|
||||||
@@ -121,12 +124,16 @@ namespace Copium
|
|||||||
|
|
||||||
int Pipeline::GetDescriptorSetCount() const
|
int Pipeline::GetDescriptorSetCount() const
|
||||||
{
|
{
|
||||||
return boundDescriptorSets.size();
|
return boundDescriptorSetsPerFlightIndex.front().size();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Pipeline::InitializeDescriptorSetLayout(const PipelineCreator& creator)
|
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());
|
descriptorSetLayouts.resize(creator.descriptorSetLayouts.size());
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (auto&& bindings : creator.descriptorSetLayouts)
|
for (auto&& bindings : creator.descriptorSetLayouts)
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ namespace Copium
|
|||||||
private:
|
private:
|
||||||
ShaderReflector shaderReflector;
|
ShaderReflector shaderReflector;
|
||||||
std::vector<VkDescriptorSetLayout> descriptorSetLayouts{};
|
std::vector<VkDescriptorSetLayout> descriptorSetLayouts{};
|
||||||
std::vector<VkDescriptorSet> boundDescriptorSets;
|
std::vector<std::vector<VkDescriptorSet>> boundDescriptorSetsPerFlightIndex;
|
||||||
VkPipelineLayout pipelineLayout;
|
VkPipelineLayout pipelineLayout;
|
||||||
VkPipeline graphicsPipeline;
|
VkPipeline graphicsPipeline;
|
||||||
AssetRef<Framebuffer> framebuffer;
|
AssetRef<Framebuffer> framebuffer;
|
||||||
@@ -31,6 +31,7 @@ namespace Copium
|
|||||||
~Pipeline();
|
~Pipeline();
|
||||||
void Bind(const CommandBuffer& commandBuffer);
|
void Bind(const CommandBuffer& commandBuffer);
|
||||||
void SetDescriptorSet(const DescriptorSet& descriptorSet);
|
void SetDescriptorSet(const DescriptorSet& descriptorSet);
|
||||||
|
void SetDescriptorSetDynamic(const DescriptorSet& descriptorSet);
|
||||||
void BindDescriptorSets(const CommandBuffer& commandBuffer);
|
void BindDescriptorSets(const CommandBuffer& commandBuffer);
|
||||||
|
|
||||||
std::unique_ptr<DescriptorSet> CreateDescriptorSet(DescriptorPool& descriptorPool, int setIndex) const;
|
std::unique_ptr<DescriptorSet> CreateDescriptorSet(DescriptorPool& descriptorPool, int setIndex) const;
|
||||||
|
|||||||
Reference in New Issue
Block a user