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,23 +8,45 @@
#define NAZARA_OPENGLRENDERER_OPENGLCOMMANDPOOL_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/Bitset.hpp>
#include <Nazara/Renderer/CommandPool.hpp>
#include <Nazara/OpenGLRenderer/Config.hpp>
#include <Nazara/OpenGLRenderer/OpenGLCommandBuffer.hpp>
namespace Nz
{
class NAZARA_OPENGLRENDERER_API OpenGLCommandPool final : public CommandPool
{
friend OpenGLCommandBuffer;
public:
OpenGLCommandPool() = default;
OpenGLCommandPool(const OpenGLCommandPool&) = delete;
OpenGLCommandPool(OpenGLCommandPool&&) noexcept = default;
~OpenGLCommandPool() = default;
std::unique_ptr<CommandBuffer> BuildCommandBuffer(const std::function<void(CommandBufferBuilder& builder)>& callback) override;
CommandBufferPtr BuildCommandBuffer(const std::function<void(CommandBufferBuilder& builder)>& callback) override;
OpenGLCommandPool& operator=(const OpenGLCommandPool&) = delete;
OpenGLCommandPool& operator=(OpenGLCommandPool&&) = delete;
private:
struct CommandPool;
CommandPool& AllocatePool();
CommandBufferPtr AllocateFromPool(std::size_t poolIndex);
void Release(CommandBuffer& commandBuffer);
inline void TryToShrink();
struct CommandPool
{
using BindingStorage = std::aligned_storage_t<sizeof(OpenGLCommandBuffer), alignof(OpenGLCommandBuffer)>;
Bitset<UInt64> freeCommands;
std::unique_ptr<BindingStorage[]> storage;
};
std::vector<CommandPool> m_commandPools;
};
}