begenning the refactor

This commit is contained in:
Kbz-8
2024-03-27 23:03:54 +01:00
parent b5983ac24b
commit 0e04356ea7
131 changed files with 2135 additions and 1192 deletions

View File

@@ -0,0 +1,70 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* CommandBuffer.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/06 18:25:42 by maldavid #+# #+# */
/* Updated: 2024/03/27 22:44:58 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_VK_CMD_BUFFER__
#define __MLX_VK_CMD_BUFFER__
#include <Renderer/Core/Fence.h>
#include <Renderer/Enums.h>
namespace mlx
{
class Buffer;
class Image;
class CommandBuffer
{
public:
void Init(CommandBufferType type, NonOwningPtr<class CommandManager> manager);
void Init(CommandBufferType type, NonOwningPtr<class CommandPool> pool);
void Destroy() noexcept;
void BeginRecord(VkCommandBufferUsageFlags usage = 0);
void Submit(class Semaphore* semaphores) noexcept;
void SubmitIdle(bool shouldWaitForExecution = true) noexcept; // TODO : handle `shouldWaitForExecution` as false by default (needs to modify CmdResources lifetimes to do so)
void UpdateSubmitState() noexcept;
inline void WaitForExecution() noexcept { m_fence.wait(); UpdateSubmitState(); m_state = CommandBufferState::Ready; }
inline void Reset() noexcept { vkResetCommandBuffer(m_cmd_buffer, 0); }
void EndRecord();
void BindVertexBuffer(Buffer& buffer) noexcept;
void BindIndexBuffer(Buffer& buffer) noexcept;
void CopyBuffer(Buffer& dst, Buffer& src) noexcept;
void CopyBufferToImage(Buffer& buffer, Image& image) noexcept;
void CopyImagetoBuffer(Image& image, Buffer& buffer) noexcept;
void TransitionImageLayout(Image& image, VkImageLayout new_layout) noexcept;
inline bool IsInit() const noexcept { return m_state != CommandBufferState::Uninit; }
inline bool IsReadyToBeUsed() const noexcept { return m_state == CommandBufferState::Ready; }
inline bool IsRecording() const noexcept { return m_state == CommandBufferState::Recording; }
inline bool HasBeenSubmitted() const noexcept { return m_state == CommandBufferState::Submitted; }
inline CommandBufferState GetCurrentState() const noexcept { return m_state; }
inline VkCommandBuffer& operator()() noexcept { return m_cmd_buffer; }
inline VkCommandBuffer& Get() noexcept { return m_cmd_buffer; }
inline Fence& GetFence() noexcept { return m_fence; }
private:
void PreTransferBarrier() noexcept;
void PostTransferBarrier() noexcept;
private:
std::vector<class CmdResource*> m_cmd_resources;
Fence m_fence;
VkCommandBuffer m_cmd_buffer = VK_NULL_HANDLE;
NonOwningPtr<class CmdPool> m_pool;
CommandBufferState m_state = CommandBufferState::Uninit;
CommandBufferType m_type;
};
}
#endif // __MLX_VK_CMD_BUFFER__

View File

@@ -0,0 +1,43 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* CommandManager.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/02 17:48:52 by maldavid #+# #+# */
/* Updated: 2024/03/27 22:20:53 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_COMMAND_MANAGER__
#define __MLX_COMMAND_MANAGER__
#include <Renderer/Core/RenderCore.h>
#include <Renderer/Command/CommandPool.h>
#include <Renderer/Command/CommandBuffer.h>
namespace mlx
{
class CommandManager
{
public:
CommandManager() = default;
void Init() noexcept;
void BeginRecord(int active_image_index);
void EndRecord(int active_image_index);
void Destroy() noexcept;
inline CommandPool& GetCmdPool() noexcept { return m_cmd_pool; }
inline CommandBuffer& GetCmdBuffer(int i) noexcept { return m_cmd_buffers[i]; }
~CommandManager() = default;
private:
std::array<CommandBuffer, MAX_FRAMES_IN_FLIGHT> m_cmd_buffers;
CommandPool m_cmd_pool;
};
}
#endif

View File

@@ -0,0 +1,36 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* CommandPool.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/06 18:24:12 by maldavid #+# #+# */
/* Updated: 2024/03/27 22:33:15 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_VK_CMD_POOL__
#define __MLX_VK_CMD_POOL__
namespace mlx
{
class CommandPool
{
public:
CommandPool() = default;
void Init();
void Destroy() noexcept;
inline VkCommandPool& operator()() noexcept { return m_cmd_pool; }
inline VkCommandPool& Get() noexcept { return m_cmd_pool; }
~CommandPool() = default;
private:
VkCommandPool m_cmd_pool = VK_NULL_HANDLE;
};
}
#endif // __MLX_VK_CMD_POOL__

View File

@@ -0,0 +1,38 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* CommandResource.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/16 20:44:29 by maldavid #+# #+# */
/* Updated: 2024/03/27 22:37:06 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_COMMAND_RESOURCE__
#define __MLX_COMMAND_RESOURCE__
#include <Renderer/Enums.h>
#include <Core/UUID.h>
namespace mlx
{
class CommandResource
{
friend class SingleTimeCmdManager;
public:
CommandResource() : m_uuid() {}
inline void RecordedInCmdBuffer() noexcept { m_state = CommandResourceState::Held; }
inline void RemovedFromCmdBuffer() noexcept { m_state = CommandResourceState::Free; }
inline UUID GetUUID() const noexcept { return m_uuid; }
virtual ~CommandResource() = default;
private:
UUID m_uuid;
CommandResourceState m_state = CommandResourceState::Free;
};
}
#endif

View File

@@ -0,0 +1,49 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* SingleTimeCmdManager.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/15 18:25:57 by maldavid #+# #+# */
/* Updated: 2024/03/27 22:46:48 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_SINGLE_TIME_CMD_MANAGER__
#define __MLX_SINGLE_TIME_CMD_MANAGER__
#include <Renderer/Command/CommandBuffer.h>
#include <Renderer/Command/CommandPool.h>
namespace mlx
{
class CommandBuffer;
class SingleTimeCmdManager
{
friend class RenderCore;
public:
SingleTimeCmdManager() = default;
void Init() noexcept;
void Destroy() noexcept;
void UpdateSingleTimesCmdBuffersSubmitState() noexcept;
void WaitForAllExecutions() noexcept;
inline CommandPool& GetCmdPool() noexcept { return m_pool; }
CommanddBuffer& GetCmdBuffer() noexcept;
~SingleTimeCmdManager() = default;
inline static constexpr const std::uint8_t BASE_POOL_SIZE = 16;
private:
std::vector<CommanddBuffer> m_buffers;
CommanddPool m_pool;
};
}
#endif