Vulkan: Replace ShaderBinding& by ShaderBindingPtr
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#define NAZARA_VULKANRENDERER_VULKANRENDERPIPELINELAYOUT_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Bitset.hpp>
|
||||
#include <Nazara/Renderer/RenderPipelineLayout.hpp>
|
||||
#include <Nazara/VulkanRenderer/Config.hpp>
|
||||
#include <Nazara/VulkanRenderer/VulkanShaderBinding.hpp>
|
||||
@@ -16,17 +17,21 @@
|
||||
#include <Nazara/VulkanRenderer/Wrapper/DescriptorSet.hpp>
|
||||
#include <Nazara/VulkanRenderer/Wrapper/DescriptorSetLayout.hpp>
|
||||
#include <Nazara/VulkanRenderer/Wrapper/PipelineLayout.hpp>
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_VULKANRENDERER_API VulkanRenderPipelineLayout : public RenderPipelineLayout
|
||||
{
|
||||
friend VulkanShaderBinding;
|
||||
|
||||
public:
|
||||
VulkanRenderPipelineLayout() = default;
|
||||
~VulkanRenderPipelineLayout() = default;
|
||||
~VulkanRenderPipelineLayout();
|
||||
|
||||
VulkanShaderBinding& AllocateShaderBinding() override;
|
||||
ShaderBindingPtr AllocateShaderBinding() override;
|
||||
|
||||
bool Create(Vk::Device& device, RenderPipelineLayoutInfo layoutInfo);
|
||||
|
||||
@@ -36,10 +41,20 @@ namespace Nz
|
||||
inline const Vk::PipelineLayout& GetPipelineLayout() const;
|
||||
|
||||
private:
|
||||
struct DescriptorPool;
|
||||
|
||||
DescriptorPool& AllocatePool();
|
||||
ShaderBindingPtr AllocateFromPool(std::size_t poolIndex);
|
||||
void Release(ShaderBinding& binding);
|
||||
inline void TryToShrink();
|
||||
|
||||
struct DescriptorPool
|
||||
{
|
||||
using BindingStorage = std::aligned_storage_t<sizeof(VulkanShaderBinding), alignof(VulkanShaderBinding)>;
|
||||
|
||||
Bitset<UInt64> freeBindings;
|
||||
Vk::DescriptorPool descriptorPool;
|
||||
std::vector<VulkanShaderBinding> allocatedSets;
|
||||
std::unique_ptr<BindingStorage[]> storage;
|
||||
};
|
||||
|
||||
MovablePtr<Vk::Device> m_device;
|
||||
|
||||
@@ -21,6 +21,21 @@ namespace Nz
|
||||
{
|
||||
return m_pipelineLayout;
|
||||
}
|
||||
|
||||
inline void VulkanRenderPipelineLayout::TryToShrink()
|
||||
{
|
||||
std::size_t poolCount = m_descriptorPools.size();
|
||||
if (poolCount >= 2 && m_descriptorPools.back().freeBindings.TestAll())
|
||||
{
|
||||
for (std::size_t i = poolCount - 1; i > 0; ++i)
|
||||
{
|
||||
if (m_descriptorPools[i].freeBindings.TestAll())
|
||||
poolCount--;
|
||||
}
|
||||
|
||||
m_descriptorPools.resize(poolCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/DebugOff.hpp>
|
||||
|
||||
@@ -18,12 +18,14 @@ namespace Nz
|
||||
class NAZARA_VULKANRENDERER_API VulkanShaderBinding : public ShaderBinding
|
||||
{
|
||||
public:
|
||||
inline VulkanShaderBinding(VulkanRenderPipelineLayout& owner, Vk::DescriptorSet descriptorSet);
|
||||
inline VulkanShaderBinding(VulkanRenderPipelineLayout& owner, std::size_t poolIndex, std::size_t bindingIndex, Vk::DescriptorSet descriptorSet);
|
||||
VulkanShaderBinding(const VulkanShaderBinding&) = default;
|
||||
VulkanShaderBinding(VulkanShaderBinding&&) noexcept = default;
|
||||
~VulkanShaderBinding() = default;
|
||||
|
||||
inline std::size_t GetBindingIndex() const;
|
||||
inline Vk::DescriptorSet& GetDescriptorSet();
|
||||
inline std::size_t GetPoolIndex() const;
|
||||
inline VulkanRenderPipelineLayout& GetOwner();
|
||||
|
||||
void Update(std::initializer_list<Binding> bindings) override;
|
||||
@@ -32,8 +34,12 @@ namespace Nz
|
||||
VulkanShaderBinding& operator=(VulkanShaderBinding&&) = delete;
|
||||
|
||||
private:
|
||||
void Release() override;
|
||||
|
||||
Vk::AutoDescriptorSet m_descriptorSet;
|
||||
VulkanRenderPipelineLayout& m_owner;
|
||||
std::size_t m_bindingIndex;
|
||||
std::size_t m_poolIndex;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -7,12 +7,24 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline VulkanShaderBinding::VulkanShaderBinding(VulkanRenderPipelineLayout& owner, Vk::DescriptorSet descriptorSet) :
|
||||
inline VulkanShaderBinding::VulkanShaderBinding(VulkanRenderPipelineLayout& owner, std::size_t poolIndex, std::size_t bindingIndex, Vk::DescriptorSet descriptorSet) :
|
||||
m_descriptorSet(std::move(descriptorSet)),
|
||||
m_owner(owner)
|
||||
m_owner(owner),
|
||||
m_bindingIndex(bindingIndex),
|
||||
m_poolIndex(poolIndex)
|
||||
{
|
||||
}
|
||||
|
||||
inline std::size_t VulkanShaderBinding::GetBindingIndex() const
|
||||
{
|
||||
return m_bindingIndex;
|
||||
}
|
||||
|
||||
inline std::size_t VulkanShaderBinding::GetPoolIndex() const
|
||||
{
|
||||
return m_poolIndex;
|
||||
}
|
||||
|
||||
inline Vk::DescriptorSet& VulkanShaderBinding::GetDescriptorSet()
|
||||
{
|
||||
return m_descriptorSet;
|
||||
|
||||
Reference in New Issue
Block a user