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

40
runtime/Includes/Renderer/Core/Device.h git.filemode.normal_file
View File

@@ -0,0 +1,40 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Device.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/08 19:13:42 by maldavid #+# #+# */
/* Updated: 2024/03/27 22:47:21 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_VK_DEVICE__
#define __MLX_VK_DEVICE__
namespace mlx
{
class Device
{
public:
void Init();
void Destroy() noexcept;
inline VkDevice& operator()() noexcept { return m_device; }
inline VkDevice& Get() noexcept { return m_device; }
inline VkPhysicalDevice& GetPhysicalDevice() noexcept { return m_physical_device; }
private:
void PickPhysicalDevice();
bool CheckDeviceExtensionSupport(VkPhysicalDevice device);
int DeviceScore(VkPhysicalDevice device);
private:
VkPhysicalDevice m_physical_device = VK_NULL_HANDLE;
VkDevice m_device = VK_NULL_HANDLE;
};
}
#endif // __MLX_VK_DEVICE__

View File

@@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* DrawableResource.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/10 21:00:37 by maldavid #+# #+# */
/* Updated: 2024/03/27 22:47:32 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_DRAWABLE_RESOURCE__
#define __MLX_DRAWABLE_RESOURCE__
namespace mlx
{
class DrawableResource
{
public:
DrawableResource() = default;
virtual void Render(std::array<VkDescriptorSet, 2>& sets, class Renderer& renderer) = 0;
virtual void ResetUpdate() {}
virtual ~DrawableResource() = default;
};
}
#endif

40
runtime/Includes/Renderer/Core/Fence.h git.filemode.normal_file
View File

@@ -0,0 +1,40 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Fence.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/02 17:52:09 by maldavid #+# #+# */
/* Updated: 2024/03/27 22:48:31 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_VK_FENCE__
#define __MLX_VK_FENCE__
namespace mlx
{
class Fence
{
public:
Fence() = default;
void Init();
inline VkFence& Get() noexcept { return m_fence; }
void Wait() noexcept;
void Reset() noexcept;
bool IsReady() const noexcept;
MLX_FORCEINLINE void WaitAndReset() noexcept { Wait(); Reset(); }
void Destroy() noexcept;
~Fence() = default;
private:
VkFence m_fence = VK_NULL_HANDLE;
};
}
#endif

35
runtime/Includes/Renderer/Core/Instance.h git.filemode.normal_file
View File

@@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Instance.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/08 19:03:04 by maldavid #+# #+# */
/* Updated: 2024/03/27 22:48:55 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_VK_INSTANCE__
#define __MLX_VK_INSTANCE__
namespace mlx
{
class Instance
{
public:
void Init();
void Destroy() noexcept;
inline VkInstance& operator()() noexcept { return m_instance; }
inline VkInstance& Get() noexcept { return m_instance; }
private:
std::vector<const char*> GetRequiredExtensions();
private:
VkInstance m_instance = VK_NULL_HANDLE;
};
}
#endif // __MLX_VK_INSTANCE__

48
runtime/Includes/Renderer/Core/Memory.h git.filemode.normal_file
View File

@@ -0,0 +1,48 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Memory.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/20 02:13:03 by maldavid #+# #+# */
/* Updated: 2024/03/27 22:49:57 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_VK_MEMORY__
#define __MLX_VK_MEMORY__
namespace mlx
{
class GPUallocator
{
public:
GPUallocator() = default;
void Init() noexcept;
void Destroy() noexcept;
VmaAllocation CreateBuffer(const VkBufferCreateInfo* binfo, const VmaAllocationCreateInfo* vinfo, VkBuffer& buffer, const char* name = nullptr) noexcept;
void DestroyBuffer(VmaAllocation allocation, VkBuffer buffer) noexcept;
VmaAllocation CreateImage(const VkImageCreateInfo* iminfo, const VmaAllocationCreateInfo* vinfo, VkImage& image, const char* name = nullptr) noexcept;
void DestroyImage(VmaAllocation allocation, VkImage image) noexcept;
void MapMemory(VmaAllocation allocation, void** data) noexcept;
void UnmapMemory(VmaAllocation allocation) noexcept;
void DumpMemoryToJson();
void Flush(VmaAllocation allocation, VkDeviceSize size, VkDeviceSize offset) noexcept;
~GPUallocator() = default;
private:
VmaAllocator m_allocator;
std::int32_t m_active_buffers_allocations = 0;
std::int32_t m_active_images_allocations = 0;
};
}
#endif

51
runtime/Includes/Renderer/Core/Queues.h git.filemode.normal_file
View File

@@ -0,0 +1,51 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Queues.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/08 19:01:49 by maldavid #+# #+# */
/* Updated: 2024/03/27 22:50:52 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_VK_QUEUES__
#define __MLX_VK_QUEUES__
namespace mlx
{
class Queues
{
public:
struct QueueFamilyIndices
{
std::optional<std::uint32_t> graphics_family;
std::optional<std::uint32_t> present_family;
inline bool isComplete() { return graphics_family.has_value() && present_family.has_value(); }
};
public:
QueueFamilyIndices FindQueueFamilies(VkPhysicalDevice device);
void Init();
inline VkQueue& GetGraphic() noexcept { return _graphics_queue; }
inline VkQueue& GetPresent() noexcept { return _present_queue; }
inline QueueFamilyIndices GetFamilies() noexcept
{
if(m_families.has_value())
return *m_families;
FatalError("Vulkan : cannot get queue families, not init");
return {}; // just to avoid warnings
}
private:
VkQueue m_graphics_queue;
VkQueue m_present_queue;
std::optional<QueueFamilyIndices> m_families;
};
}
#endif // __MLX_VK_QUEUES__

78
runtime/Includes/Renderer/Core/RenderCore.h git.filemode.normal_file
View File

@@ -0,0 +1,78 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* RenderCore.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/08 19:16:32 by maldavid #+# #+# */
/* Updated: 2024/03/27 22:55:43 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_RENDER_CORE__
#define __MLX_RENDER_CORE__
#include <Renderer/Command/SingleTimeCmdManager.h>
#include <Renderer/Descriptors/DescriptorPoolManager.h>
#include <Renderer/Descriptors/DescriptorPool.h>
#include <Renderer/Core/Queues.h>
#include <Renderer/Core/Device.h>
#include <Renderer/Core/Instance.h>
#include <Renderer/Core/ValidationLayers.h>
#include <Renderer/Core/memory.h>
#include <Utils/Singleton.h>
namespace mlx
{
const char* VerbaliseVkResult(VkResult result);
VkPipelineStageFlags AccessFlagsToPipelineStage(VkAccessFlags access_flags, VkPipelineStageFlags stage_flags);
#ifdef DEBUG
constexpr const bool enable_validation_layers = true;
#else
constexpr const bool enable_validation_layers = false;
#endif
const std::vector<const char*> validation_layers = { "VK_LAYER_KHRONOS_validation" };
constexpr const int MAX_FRAMES_IN_FLIGHT = 3;
constexpr const int MAX_SETS_PER_POOL = 512;
constexpr const int NUMBER_OF_UNIFORM_BUFFERS = 1; // change this if for wathever reason more than one uniform buffer is needed
class RenderCore : public Singleton<RenderCore>
{
friend class Singleton<RenderCore>;
public:
void Init();
void Destroy();
inline bool IsInit() const noexcept { return m_is_init; }
inline Instance& GetInstance() noexcept { return m_instance; }
inline Device& GetDevice() noexcept { return m_device; }
inline Queues& GetQueue() noexcept { return m_queues; }
inline GPUallocator& GetAllocator() noexcept { return m_allocator; }
inline ValidationLayers& GetLayers() noexcept { return m_layers; }
inline CommandBuffer& GetSingleTimeCmdBuffer() noexcept { return m_cmd_manager.GetCmdBuffer(); }
inline SingleTimeCmdManager& GetSingleTimeCmdManager() noexcept { return m_cmd_manager; }
inline DescriptorPool& GetDescriptorPool() { return m_pool_manager.GetAvailablePool(); }
private:
RenderCore() = default;
~RenderCore() = default;
private:
ValidationLayers m_layers;
SingleTimeCmdManager m_cmd_manager;
Queues m_queues;
DescriptorPoolManager m_pool_manager;
Device m_device;
Instance m_instance;
GPUallocator m_allocator;
bool m_is_init = false;
};
}
#endif // __MLX_RENDER_CORE__

31
runtime/Includes/Renderer/Core/Semaphore.h git.filemode.normal_file
View File

@@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Semaphore.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/08 18:59:38 by maldavid #+# #+# */
/* Updated: 2024/03/27 22:56:51 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_VK_SEMAPHORE__
#define __MLX_VK_SEMAPHORE__
namespace mlx
{
class Semaphore
{
public:
void Init();
void Destroy() noexcept;
inline VkSemaphore& Get() noexcept { return m_semaphore; }
private:
VkSemaphore m_semaphore = VK_NULL_HANDLE;
};
}
#endif // __MLX_VK_SEMAPHORE__

34
runtime/Includes/Renderer/Core/Surface.h git.filemode.normal_file
View File

@@ -0,0 +1,34 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Surface.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/08 18:57:55 by maldavid #+# #+# */
/* Updated: 2024/03/27 22:58:15 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_VK_SURFACE__
#define __MLX_VK_SURFACE__
namespace mlx
{
class Surface
{
public:
void Create(class Renderer& renderer);
void Destroy() noexcept;
VkSurfaceFormatKHR ChooseSwapSurfaceFormat(const std::vector<VkSurfaceFormatKHR>& available_formats);
inline VkSurfaceKHR& operator()() noexcept { return m_surface; }
inline VkSurfaceKHR& Get() noexcept { return m_surface; }
private:
VkSurfaceKHR m_surface = VK_NULL_HANDLE;
};
}
#endif // __MLX_VK_SURFACE__

View File

@@ -0,0 +1,44 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ValidationLayers.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/19 14:04:25 by maldavid #+# #+# */
/* Updated: 2024/03/27 22:59:00 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __VK_VALIDATION_LAYERS__
#define __VK_VALIDATION_LAYERS__
namespace mlx
{
class ValidationLayers
{
public:
ValidationLayers() = default;
void Init();
void Destroy();
bool CheckValidationLayerSupport();
void PopulateDebugMessengerCreateInfo(VkDebugUtilsMessengerCreateInfoEXT& create_info);
VkResult SetDebugUtilsObjectNameEXT(VkObjectType object_type, std::uint64_t object_handle, const char* object_name);
~ValidationLayers() = default;
private:
VkResult CreateDebugUtilsMessengerEXT(const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator);
static VKAPI_ATTR VkBool32 VKAPI_CALL DebugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT message_severity, VkDebugUtilsMessageTypeFlagsEXT message_type, const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData, void* pUserData);
void DestroyDebugUtilsMessengerEXT(const VkAllocationCallbacks* pAllocator);
private:
VkDebugUtilsMessengerEXT m_debug_messenger;
PFN_vkSetDebugUtilsObjectNameEXT f_vkSetDebugUtilsObjectNameEXT = nullptr;
};
}
#endif