VulkanRenderer: Handle VulkanRenderPass destruction
This commit is contained in:
parent
1c77a5e549
commit
40ecdda3cd
|
|
@ -8,6 +8,7 @@
|
||||||
#define NAZARA_VULKANRENDERER_VULKANRENDERPASS_HPP
|
#define NAZARA_VULKANRENDERER_VULKANRENDERPASS_HPP
|
||||||
|
|
||||||
#include <Nazara/Prerequisites.hpp>
|
#include <Nazara/Prerequisites.hpp>
|
||||||
|
#include <Nazara/Core/Signal.hpp>
|
||||||
#include <Nazara/Renderer/RenderPass.hpp>
|
#include <Nazara/Renderer/RenderPass.hpp>
|
||||||
#include <Nazara/VulkanRenderer/Config.hpp>
|
#include <Nazara/VulkanRenderer/Config.hpp>
|
||||||
#include <Nazara/VulkanRenderer/Wrapper/RenderPass.hpp>
|
#include <Nazara/VulkanRenderer/Wrapper/RenderPass.hpp>
|
||||||
|
|
@ -21,7 +22,7 @@ namespace Nz
|
||||||
VulkanRenderPass(Vk::Device& device, std::vector<Attachment> attachments, std::vector<SubpassDescription> subpassDescriptions, std::vector<SubpassDependency> subpassDependencies);
|
VulkanRenderPass(Vk::Device& device, std::vector<Attachment> attachments, std::vector<SubpassDescription> subpassDescriptions, std::vector<SubpassDependency> subpassDependencies);
|
||||||
VulkanRenderPass(const VulkanRenderPass&) = delete;
|
VulkanRenderPass(const VulkanRenderPass&) = delete;
|
||||||
VulkanRenderPass(VulkanRenderPass&&) noexcept = default;
|
VulkanRenderPass(VulkanRenderPass&&) noexcept = default;
|
||||||
~VulkanRenderPass() = default;
|
~VulkanRenderPass();
|
||||||
|
|
||||||
inline Vk::RenderPass& GetRenderPass();
|
inline Vk::RenderPass& GetRenderPass();
|
||||||
inline const Vk::RenderPass& GetRenderPass() const;
|
inline const Vk::RenderPass& GetRenderPass() const;
|
||||||
|
|
@ -29,6 +30,8 @@ namespace Nz
|
||||||
VulkanRenderPass& operator=(const VulkanRenderPass&) = delete;
|
VulkanRenderPass& operator=(const VulkanRenderPass&) = delete;
|
||||||
VulkanRenderPass& operator=(VulkanRenderPass&&) noexcept = default;
|
VulkanRenderPass& operator=(VulkanRenderPass&&) noexcept = default;
|
||||||
|
|
||||||
|
NazaraSignal(OnRenderPassRelease, const VulkanRenderPass* /*renderPass*/);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Vk::RenderPass m_renderPass;
|
Vk::RenderPass m_renderPass;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -27,12 +27,17 @@ namespace Nz
|
||||||
struct CreateInfo;
|
struct CreateInfo;
|
||||||
|
|
||||||
VulkanRenderPipeline(VulkanDevice& device, RenderPipelineInfo pipelineInfo);
|
VulkanRenderPipeline(VulkanDevice& device, RenderPipelineInfo pipelineInfo);
|
||||||
|
VulkanRenderPipeline(const VulkanRenderPipeline&) = delete;
|
||||||
|
VulkanRenderPipeline(VulkanRenderPipeline&&) = delete;
|
||||||
~VulkanRenderPipeline() = default;
|
~VulkanRenderPipeline() = default;
|
||||||
|
|
||||||
VkPipeline Get(const VulkanRenderPass& renderPass, std::size_t subpassIndex) const;
|
VkPipeline Get(const VulkanRenderPass& renderPass, std::size_t subpassIndex) const;
|
||||||
|
|
||||||
inline const RenderPipelineInfo& GetPipelineInfo() const override;
|
inline const RenderPipelineInfo& GetPipelineInfo() const override;
|
||||||
|
|
||||||
|
VulkanRenderPipeline& operator=(const VulkanRenderPipeline&) = delete;
|
||||||
|
VulkanRenderPipeline& operator=(VulkanRenderPipeline&&) = delete;
|
||||||
|
|
||||||
static std::vector<VkPipelineColorBlendAttachmentState> BuildColorBlendAttachmentStateList(const RenderPipelineInfo& pipelineInfo);
|
static std::vector<VkPipelineColorBlendAttachmentState> BuildColorBlendAttachmentStateList(const RenderPipelineInfo& pipelineInfo);
|
||||||
static VkPipelineColorBlendStateCreateInfo BuildColorBlendInfo(const RenderPipelineInfo& pipelineInfo, const std::vector<VkPipelineColorBlendAttachmentState>& attachmentState);
|
static VkPipelineColorBlendStateCreateInfo BuildColorBlendInfo(const RenderPipelineInfo& pipelineInfo, const std::vector<VkPipelineColorBlendAttachmentState>& attachmentState);
|
||||||
static VkPipelineDepthStencilStateCreateInfo BuildDepthStencilInfo(const RenderPipelineInfo& pipelineInfo);
|
static VkPipelineDepthStencilStateCreateInfo BuildDepthStencilInfo(const RenderPipelineInfo& pipelineInfo);
|
||||||
|
|
@ -81,7 +86,14 @@ namespace Nz
|
||||||
inline std::size_t operator()(const std::pair<VkRenderPass, std::size_t>& renderPass) const;
|
inline std::size_t operator()(const std::pair<VkRenderPass, std::size_t>& renderPass) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
mutable std::unordered_map<std::pair<VkRenderPass, std::size_t>, Vk::Pipeline, PipelineHasher> m_pipelines;
|
struct PipelineData
|
||||||
|
{
|
||||||
|
NazaraSlot(VulkanRenderPass, OnRenderPassRelease, onRenderPassRelease);
|
||||||
|
|
||||||
|
Vk::Pipeline pipeline;
|
||||||
|
};
|
||||||
|
|
||||||
|
mutable std::unordered_map<std::pair<VkRenderPass, std::size_t>, PipelineData, PipelineHasher> m_pipelines;
|
||||||
MovablePtr<Vk::Device> m_device;
|
MovablePtr<Vk::Device> m_device;
|
||||||
mutable CreateInfo m_pipelineCreateInfo;
|
mutable CreateInfo m_pipelineCreateInfo;
|
||||||
RenderPipelineInfo m_pipelineInfo;
|
RenderPipelineInfo m_pipelineInfo;
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
inline VulkanRenderPass::VulkanRenderPass(Vk::Device& device, std::vector<Attachment> attachments, std::vector<SubpassDescription> subpassDescriptions, std::vector<SubpassDependency> subpassDependencies) :
|
VulkanRenderPass::VulkanRenderPass(Vk::Device& device, std::vector<Attachment> attachments, std::vector<SubpassDescription> subpassDescriptions, std::vector<SubpassDependency> subpassDependencies) :
|
||||||
RenderPass(std::move(attachments), std::move(subpassDescriptions), std::move(subpassDependencies))
|
RenderPass(std::move(attachments), std::move(subpassDescriptions), std::move(subpassDependencies))
|
||||||
{
|
{
|
||||||
std::size_t totalAttachmentReference = 0;
|
std::size_t totalAttachmentReference = 0;
|
||||||
|
|
@ -128,4 +128,9 @@ namespace Nz
|
||||||
if (!m_renderPass.Create(device, renderPassInfo))
|
if (!m_renderPass.Create(device, renderPassInfo))
|
||||||
throw std::runtime_error("failed to instantiate Vulkan render pass: " + TranslateVulkanError(m_renderPass.GetLastErrorCode()));
|
throw std::runtime_error("failed to instantiate Vulkan render pass: " + TranslateVulkanError(m_renderPass.GetLastErrorCode()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VulkanRenderPass::~VulkanRenderPass()
|
||||||
|
{
|
||||||
|
OnRenderPassRelease(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,19 +35,24 @@ namespace Nz
|
||||||
std::pair<VkRenderPass, std::size_t> key = { renderPassHandle, colorAttachmentCount };
|
std::pair<VkRenderPass, std::size_t> key = { renderPassHandle, colorAttachmentCount };
|
||||||
|
|
||||||
if (auto it = m_pipelines.find(key); it != m_pipelines.end())
|
if (auto it = m_pipelines.find(key); it != m_pipelines.end())
|
||||||
return it->second;
|
return it->second.pipeline;
|
||||||
|
|
||||||
UpdateCreateInfo(colorAttachmentCount);
|
UpdateCreateInfo(colorAttachmentCount);
|
||||||
|
|
||||||
VkGraphicsPipelineCreateInfo pipelineCreateInfo = m_pipelineCreateInfo.pipelineInfo;
|
VkGraphicsPipelineCreateInfo pipelineCreateInfo = m_pipelineCreateInfo.pipelineInfo;
|
||||||
pipelineCreateInfo.renderPass = renderPassHandle;
|
pipelineCreateInfo.renderPass = renderPassHandle;
|
||||||
|
|
||||||
Vk::Pipeline newPipeline;
|
PipelineData pipelineData;
|
||||||
if (!newPipeline.CreateGraphics(*m_device, pipelineCreateInfo))
|
pipelineData.onRenderPassRelease.Connect(renderPass.OnRenderPassRelease, [this, key](const VulkanRenderPass*)
|
||||||
|
{
|
||||||
|
m_pipelines.erase(key);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!pipelineData.pipeline.CreateGraphics(*m_device, pipelineCreateInfo))
|
||||||
return VK_NULL_HANDLE;
|
return VK_NULL_HANDLE;
|
||||||
|
|
||||||
auto it = m_pipelines.emplace(key, std::move(newPipeline)).first;
|
auto it = m_pipelines.emplace(key, std::move(pipelineData)).first;
|
||||||
return it->second;
|
return it->second.pipeline;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<VkPipelineColorBlendAttachmentState> VulkanRenderPipeline::BuildColorBlendAttachmentStateList(const RenderPipelineInfo& pipelineInfo)
|
std::vector<VkPipelineColorBlendAttachmentState> VulkanRenderPipeline::BuildColorBlendAttachmentStateList(const RenderPipelineInfo& pipelineInfo)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue