Allocate command buffers from pools

This commit is contained in:
Jérôme Leclercq
2020-08-27 18:31:26 +02:00
parent cbdac32f5f
commit 7c9dcdfbe4
18 changed files with 333 additions and 23 deletions

View File

@@ -8,14 +8,19 @@
#define NAZARA_VULKANRENDERER_VULKANCOMMANDPOOL_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/Bitset.hpp>
#include <Nazara/Renderer/CommandPool.hpp>
#include <Nazara/VulkanRenderer/Config.hpp>
#include <Nazara/VulkanRenderer/VulkanCommandBuffer.hpp>
#include <Nazara/VulkanRenderer/Wrapper/CommandPool.hpp>
#include <vector>
namespace Nz
{
class NAZARA_VULKANRENDERER_API VulkanCommandPool final : public CommandPool
{
friend VulkanCommandBuffer;
public:
inline VulkanCommandPool(Vk::Device& device, QueueType queueType);
inline VulkanCommandPool(Vk::Device& device, UInt32 queueFamilyIndex);
@@ -23,12 +28,29 @@ namespace Nz
VulkanCommandPool(VulkanCommandPool&&) noexcept = default;
~VulkanCommandPool() = default;
std::unique_ptr<CommandBuffer> BuildCommandBuffer(const std::function<void(CommandBufferBuilder& builder)>& callback) override;
CommandBufferPtr BuildCommandBuffer(const std::function<void(CommandBufferBuilder& builder)>& callback) override;
VulkanCommandPool& operator=(const VulkanCommandPool&) = delete;
VulkanCommandPool& operator=(VulkanCommandPool&&) = delete;
private:
struct CommandPool;
CommandPool& AllocatePool();
template<typename... Args> CommandBufferPtr AllocateFromPool(std::size_t poolIndex, Args&&... args);
void Release(CommandBuffer& commandBuffer);
inline void TryToShrink();
struct CommandPool
{
using BindingStorage = std::aligned_storage_t<sizeof(VulkanCommandBuffer), alignof(VulkanCommandBuffer)>;
Bitset<UInt64> freeCommands;
std::unique_ptr<BindingStorage[]> storage;
};
MovablePtr<Vk::Device> m_device;
std::vector<CommandPool> m_commandPools;
Vk::CommandPool m_commandPool;
};
}