adding debug messages to renderer, working on VMA implementation

This commit is contained in:
2023-11-09 09:07:03 +01:00
parent be8caa922c
commit 4e5fb2648a
282 changed files with 900 additions and 139 deletions

View File

@@ -10,8 +10,6 @@
/* */
/* ************************************************************************** */
#include <core/application.h>
namespace mlx::core
{
void Application::getMousePos(int* x, int* y) noexcept
@@ -42,7 +40,7 @@ namespace mlx::core
void* Application::newGraphicsSuport(std::size_t w, std::size_t h, std::string title)
{
_graphics.emplace_back(std::make_unique<GraphicsSupport>(w, h, std::move(title), _graphics.size()));
_graphics.emplace_back(std::make_unique<GraphicsSupport>(w, h, title, _graphics.size()));
_in->addWindow(_graphics.back()->getWindow());
return static_cast<void*>(&_graphics.back()->getID());
}

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/02 15:13:55 by maldavid #+# #+# */
/* Updated: 2023/04/08 00:19:18 by maldavid ### ########.fr */
/* Updated: 2023/11/08 21:02:22 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -14,8 +14,8 @@
namespace mlx
{
GraphicsSupport::GraphicsSupport(std::size_t w, std::size_t h, std::string title, int id) :
_window(std::make_shared<MLX_Window>(w, h, std::move(title))),
GraphicsSupport::GraphicsSupport(std::size_t w, std::size_t h, const std::string& title, int id) :
_window(std::make_shared<MLX_Window>(w, h, title)),
_renderer(std::make_unique<Renderer>()), _text_put_pipeline(std::make_unique<TextPutPipeline>()),
_id(id)
{
@@ -29,8 +29,10 @@ namespace mlx
{
auto cmd_buff = _renderer->getActiveCmdBuffer().get();
std::vector<VkDescriptorSet> sets;
sets.push_back(_renderer->getVertDescriptorSet().get());
static std::array<VkDescriptorSet, 2> sets = {
_renderer->getVertDescriptorSet().get(),
VK_NULL_HANDLE
};
for(auto& data : _textures_to_render)
{
@@ -38,20 +40,18 @@ namespace mlx
data.texture->setDescriptor(_renderer->getFragDescriptorSet().duplicate());
if(!data.texture->hasBeenUpdated())
data.texture->updateSet(0);
sets.push_back(data.texture->getSet());
sets[1] = data.texture->getSet();
vkCmdBindDescriptorSets(cmd_buff, VK_PIPELINE_BIND_POINT_GRAPHICS, _renderer->getPipeline().getPipelineLayout(), 0, sets.size(), sets.data(), 0, nullptr);
data.texture->render(*_renderer, data.x, data.y);
sets.pop_back();
}
_pixel_put_pipeline.present();
sets.push_back(_pixel_put_pipeline.getDescriptorSet());
sets[1] = _pixel_put_pipeline.getDescriptorSet();
vkCmdBindDescriptorSets(cmd_buff, VK_PIPELINE_BIND_POINT_GRAPHICS, _renderer->getPipeline().getPipelineLayout(), 0, sets.size(), sets.data(), 0, nullptr);
_pixel_put_pipeline.render(*_renderer);
sets.pop_back();
sets.push_back(_text_put_pipeline->getDescriptorSet());
sets[1] = _text_put_pipeline->getDescriptorSet();
vkCmdBindDescriptorSets(cmd_buff, VK_PIPELINE_BIND_POINT_GRAPHICS, _renderer->getPipeline().getPipelineLayout(), 0, sets.size(), sets.data(), 0, nullptr);
_text_put_pipeline->render();

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/02 14:49:49 by maldavid #+# #+# */
/* Updated: 2023/04/21 18:43:38 by maldavid ### ########.fr */
/* Updated: 2023/11/08 20:41:29 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -32,7 +32,7 @@ namespace mlx
class GraphicsSupport : public non_copyable
{
public:
GraphicsSupport(std::size_t w, std::size_t h, std::string title, int id);
GraphicsSupport(std::size_t w, std::size_t h, const std::string& title, int id);
inline int& getID() noexcept;
inline std::shared_ptr<MLX_Window> getWindow();

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 17:36:44 by maldavid #+# #+# */
/* Updated: 2023/04/12 18:45:05 by maldavid ### ########.fr */
/* Updated: 2023/11/08 20:24:38 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -15,7 +15,7 @@
namespace mlx
{
MLX_Window::MLX_Window(std::size_t w, std::size_t h, std::string title) : _width(w), _height(h)
MLX_Window::MLX_Window(std::size_t w, std::size_t h, const std::string& title) : _width(w), _height(h)
{
_win = SDL_CreateWindow(title.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, w, h, SDL_WINDOW_VULKAN | SDL_WINDOW_SHOWN);
if(!_win)

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 21:53:12 by maldavid #+# #+# */
/* Updated: 2023/04/12 19:06:24 by maldavid ### ########.fr */
/* Updated: 2023/11/08 20:24:46 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -21,7 +21,7 @@ namespace mlx
class MLX_Window
{
public:
MLX_Window(std::size_t w, std::size_t h, std::string title);
MLX_Window(std::size_t w, std::size_t h, const std::string& title);
inline SDL_Window* getNativeWindow() const noexcept { return _win; }
inline int getWidth() const noexcept { return _width; }

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/08 18:55:57 by maldavid #+# #+# */
/* Updated: 2023/10/20 02:02:24 by maldavid ### ########.fr */
/* Updated: 2023/11/08 22:40:00 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -20,6 +20,7 @@ namespace mlx
{
void Buffer::create(Buffer::kind type, VkDeviceSize size, VkBufferUsageFlags usage, const void* data)
{
VmaAllocationCreateInfo alloc_info{};
if(type == Buffer::kind::constant)
{
if(data == nullptr)
@@ -28,22 +29,22 @@ namespace mlx
return;
}
_usage = usage | VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
_flags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
alloc_info.usage = VMA_MEMORY_USAGE_GPU_ONLY;
}
else if(type == Buffer::kind::uniform)
{
_usage = usage;
_flags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
alloc_info.usage = VMA_MEMORY_USAGE_CPU_TO_GPU;
}
else
{
_usage = usage;
_flags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
alloc_info.usage = VMA_MEMORY_USAGE_GPU_TO_CPU;
}
_size = size;
createBuffer(_usage, _flags);
createBuffer(_usage, alloc_info);
if(type == Buffer::kind::constant || data != nullptr)
{
@@ -59,11 +60,10 @@ namespace mlx
void Buffer::destroy() noexcept
{
vkDestroyBuffer(Render_Core::get().getDevice().get(), _buffer, nullptr);
vkFreeMemory(Render_Core::get().getDevice().get(), _memory, nullptr);
Render_Core::get().getAllocator().destroyBuffer(_allocation, _buffer);
}
void Buffer::createBuffer(VkBufferUsageFlags usage, VkMemoryPropertyFlags properties)
void Buffer::createBuffer(VkBufferUsageFlags usage, VmaAllocationCreateInfo info)
{
VkBufferCreateInfo bufferInfo{};
bufferInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
@@ -71,32 +71,18 @@ namespace mlx
bufferInfo.usage = usage;
bufferInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
auto device = Render_Core::get().getDevice().get();
if(vkCreateBuffer(device, &bufferInfo, nullptr, &_buffer) != VK_SUCCESS)
core::error::report(e_kind::fatal_error, "Vulkan : failed to create buffer");
VkMemoryRequirements memRequirements;
vkGetBufferMemoryRequirements(device, _buffer, &memRequirements);
VkMemoryAllocateInfo allocInfo{};
allocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
allocInfo.allocationSize = memRequirements.size;
allocInfo.memoryTypeIndex = *RCore::findMemoryType(memRequirements.memoryTypeBits, properties);
if(vkAllocateMemory(device, &allocInfo, nullptr, &_memory) != VK_SUCCESS)
core::error::report(e_kind::fatal_error, "Vulkan : failed to allocate buffer memory");
if(vkBindBufferMemory(device, _buffer, _memory, _offset) != VK_SUCCESS)
core::error::report(e_kind::fatal_error, "Vulkan : unable to bind device memory to a buffer object");
_allocation = Render_Core::get().getAllocator().createBuffer(&bufferInfo, &info, _buffer);
}
void Buffer::pushToGPU() noexcept
{
VmaAllocationCreateInfo alloc_info{};
alloc_info.usage = VMA_MEMORY_USAGE_GPU_ONLY;
Buffer newBuffer;
newBuffer._size = _size;
newBuffer._usage = (this->_usage & 0xFFFFFFFC) | VK_BUFFER_USAGE_TRANSFER_DST_BIT;
newBuffer._flags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
newBuffer.createBuffer(newBuffer._usage, newBuffer._flags);
newBuffer.createBuffer(newBuffer._usage, alloc_info);
CmdPool cmdpool;
cmdpool.init();
@@ -150,30 +136,12 @@ namespace mlx
buffer._size = _size;
_size = temp_size;
VkDeviceSize temp_offset = buffer._offset;
buffer._offset = _offset;
_offset = temp_offset;
VkDeviceMemory temp_memory = buffer._memory;
buffer._memory = _memory;
_memory = temp_memory;
VkBufferUsageFlags temp_u = _usage;
_usage = buffer._usage;
buffer._usage = temp_u;
VkMemoryPropertyFlags temp_f = _flags;
_flags = buffer._flags;
buffer._flags = temp_f;
}
void Buffer::flush(VkDeviceSize size, VkDeviceSize offset)
{
VkMappedMemoryRange mappedRange{};
mappedRange.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
mappedRange.memory = _memory;
mappedRange.offset = offset;
mappedRange.size = size;
vkFlushMappedMemoryRanges(Render_Core::get().getDevice().get(), 1, &mappedRange);
}
}

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/06 23:18:52 by maldavid #+# #+# */
/* Updated: 2023/04/22 19:51:47 by maldavid ### ########.fr */
/* Updated: 2023/11/08 22:33:18 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -26,37 +26,34 @@ namespace mlx
void create(kind type, VkDeviceSize size, VkBufferUsageFlags usage, const void* data = nullptr);
void destroy() noexcept;
inline void mapMem(void** data = nullptr, VkDeviceSize size = VK_WHOLE_SIZE, VkDeviceSize offset = 0) noexcept
inline void mapMem(void** data = nullptr) noexcept
{
if(vkMapMemory(Render_Core::get().getDevice().get(), _memory, _offset + offset, size, 0, data) != VK_SUCCESS)
core::error::report(e_kind::fatal_error, "Vulkan : failed to map a buffer");
Render_Core::get().getAllocator().mapMemory(_allocation, data);
_is_mapped = true;
}
inline bool isMapped() const noexcept { return _is_mapped; }
inline void unmapMem() noexcept { vkUnmapMemory(Render_Core::get().getDevice().get(), _memory); _is_mapped = false; }
inline void unmapMem() noexcept { Render_Core::get().getAllocator().unmapMemory(_allocation);_is_mapped = false; }
void flush(VkDeviceSize size = VK_WHOLE_SIZE, VkDeviceSize offset = 0);
inline unsigned int getSize() noexcept { return _size; }
inline unsigned int getOffset() noexcept { return _offset; }
inline VkDeviceMemory getDeviceMemory() noexcept { return _memory; }
inline VkBuffer& operator()() noexcept { return _buffer; }
inline VkBuffer& get() noexcept { return _buffer; }
inline VkDeviceSize getSize() const noexcept { return _size; }
protected:
void pushToGPU() noexcept;
void swap(Buffer& buffer) noexcept;
VkDeviceMemory _memory = VK_NULL_HANDLE;
VkDeviceSize _offset = 0;
VkDeviceSize _size = 0;
protected:
VmaAllocation _allocation;
VkBuffer _buffer = VK_NULL_HANDLE;
VkDeviceSize _size = 0;
private:
void createBuffer(VkBufferUsageFlags usage, VkMemoryPropertyFlags properties);
void createBuffer(VkBufferUsageFlags usage, VmaAllocationCreateInfo info);
private:
VkBufferUsageFlags _usage = 0;
VkMemoryPropertyFlags _flags = 0;
bool _is_mapped = false;
};
}

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/06 18:26:06 by maldavid #+# #+# */
/* Updated: 2023/04/23 15:19:08 by maldavid ### ########.fr */
/* Updated: 2023/11/08 20:17:49 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -34,6 +34,9 @@ namespace mlx
if(vkAllocateCommandBuffers(Render_Core::get().getDevice().get(), &allocInfo, &_cmd_buffer) != VK_SUCCESS)
core::error::report(e_kind::fatal_error, "Vulkan : failed to allocate command buffer");
#ifdef DEBUG
core::error::report(e_kind::message, "Vulkan : created new command buffer");
#endif
_fence.init();
}

103
src/renderer/core/memory.cpp git.filemode.normal_file
View File

@@ -0,0 +1,103 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* memory.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kbz_8 <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/20 22:02:37 by kbz_8 #+# #+# */
/* Updated: 2023/11/08 22:31:27 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#define VMA_STATIC_VULKAN_FUNCTIONS 0
#define VMA_DYNAMIC_VULKAN_FUNCTIONS 0
#define VMA_VULKAN_VERSION 1002000
#include <renderer/core/memory.h>
#include <renderer/core/render_core.h>
namespace mlx
{
void GPUallocator::init() noexcept
{
VmaVulkanFunctions vma_vulkan_func{};
vma_vulkan_func.vkAllocateMemory = vkAllocateMemory;
vma_vulkan_func.vkBindBufferMemory = vkBindBufferMemory;
vma_vulkan_func.vkBindImageMemory = vkBindImageMemory;
vma_vulkan_func.vkCreateBuffer = vkCreateBuffer;
vma_vulkan_func.vkCreateImage = vkCreateImage;
vma_vulkan_func.vkDestroyBuffer = vkDestroyBuffer;
vma_vulkan_func.vkDestroyImage = vkDestroyImage;
vma_vulkan_func.vkFlushMappedMemoryRanges = vkFlushMappedMemoryRanges;
vma_vulkan_func.vkFreeMemory = vkFreeMemory;
vma_vulkan_func.vkGetBufferMemoryRequirements = vkGetBufferMemoryRequirements;
vma_vulkan_func.vkGetImageMemoryRequirements = vkGetImageMemoryRequirements;
vma_vulkan_func.vkGetPhysicalDeviceMemoryProperties = vkGetPhysicalDeviceMemoryProperties;
vma_vulkan_func.vkGetPhysicalDeviceProperties = vkGetPhysicalDeviceProperties;
vma_vulkan_func.vkInvalidateMappedMemoryRanges = vkInvalidateMappedMemoryRanges;
vma_vulkan_func.vkMapMemory = vkMapMemory;
vma_vulkan_func.vkUnmapMemory = vkUnmapMemory;
vma_vulkan_func.vkCmdCopyBuffer = vkCmdCopyBuffer;
VmaAllocatorCreateInfo allocatorCreateInfo{};
allocatorCreateInfo.vulkanApiVersion = VK_API_VERSION_1_2;
allocatorCreateInfo.physicalDevice = Render_Core::get().getDevice().getPhysicalDevice();
allocatorCreateInfo.device = Render_Core::get().getDevice().get();
allocatorCreateInfo.instance = Render_Core::get().getInstance().get();
allocatorCreateInfo.pVulkanFunctions = &vma_vulkan_func;
if(vmaCreateAllocator(&allocatorCreateInfo, &_allocator) != VK_SUCCESS)
core::error::report(e_kind::fatal_error, "Vulkan : failed to create allocator");
#ifdef DEBUG
core::error::report(e_kind::message, "Vulkan : created new allocator");
#endif
}
VmaAllocation GPUallocator::createBuffer(const VkBufferCreateInfo* binfo, const VmaAllocationCreateInfo* vinfo, VkBuffer& buffer) noexcept
{
VmaAllocation allocation;
if(vmaCreateBuffer(_allocator, binfo, vinfo, &buffer, &allocation, nullptr) != VK_SUCCESS)
core::error::report(e_kind::fatal_error, "Vulkan : failed to allocate a buffer");
#ifdef DEBUG
core::error::report(e_kind::message, "Graphics Allocator : created new buffer");
#endif
return allocation;
}
void GPUallocator::destroyBuffer(VmaAllocation allocation, VkBuffer buffer) noexcept
{
vmaDestroyBuffer(_allocator, buffer, allocation);
}
VmaAllocation GPUallocator::createImage(const VkImageCreateInfo* iminfo, const VmaAllocationCreateInfo* vinfo, VkImage& image) noexcept
{
VmaAllocation allocation;
if(vmaCreateImage(_allocator, iminfo, vinfo, &image, &allocation, nullptr) != VK_SUCCESS)
core::error::report(e_kind::fatal_error, "Vulkan : failed to allocate an image");
#ifdef DEBUG
core::error::report(e_kind::message, "Graphics Allocator : created new image");
#endif
return allocation;
}
void GPUallocator::destroyImage(VmaAllocation allocation, VkImage image) noexcept
{
vmaDestroyImage(_allocator, image, allocation);
}
void GPUallocator::mapMemory(VmaAllocation allocation, void** data) noexcept
{
if(vmaMapMemory(_allocator, allocation, data) != VK_SUCCESS)
core::error::report(e_kind::fatal_error, "Graphics allocator : unable to map GPU memory to CPU memory");
}
void GPUallocator::unmapMemory(VmaAllocation allocation) noexcept
{
vmaUnmapMemory(_allocator, allocation);
}
void GPUallocator::destroy() noexcept
{
vmaDestroyAllocator(_allocator);
}
}

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/20 02:13:03 by maldavid #+# #+# */
/* Updated: 2023/10/20 03:33:28 by maldavid ### ########.fr */
/* Updated: 2023/11/08 22:41:46 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -15,22 +15,27 @@
#include <volk.h>
#include <vma.h>
#include <cstdint>
namespace mlx
{
enum class gpu_allocation_type
{
buffer,
image,
};
class GPUallocator
{
public:
GPUallocator() = default;
void init() noexcept;
VkDeviceMemory alloc(gpu_allocation_type type, VkDeviceSize size);
void destroy() noexcept;
VmaAllocation createBuffer(const VkBufferCreateInfo* binfo, const VmaAllocationCreateInfo* vinfo, VkBuffer& buffer) noexcept;
void destroyBuffer(VmaAllocation allocation, VkBuffer buffer) noexcept;
VmaAllocation createImage(const VkImageCreateInfo* iminfo, const VmaAllocationCreateInfo* vinfo, VkImage& image) noexcept;
void destroyImage(VmaAllocation allocation, VkImage image) noexcept;
void mapMemory(VmaAllocation allocation, void** data) noexcept;
void unmapMemory(VmaAllocation allocation) noexcept;
~GPUallocator() = default;
private:

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/17 23:33:34 by maldavid #+# #+# */
/* Updated: 2023/04/23 19:09:21 by maldavid ### ########.fr */
/* Updated: 2023/10/21 00:06:36 by kbz_8 ### ########.fr */
/* */
/* ************************************************************************** */
@@ -24,7 +24,7 @@
#include <mutex>
#ifdef DEBUG
#warning "MLX is being compiled in debug mode, this activates Vulkan's validation layers and debug messages and may impact rendering performances"
#warning "MLX is being compiled in debug mode, this activates Vulkan's validation layers and debug messages which may impact rendering performances"
#endif
namespace mlx
@@ -57,6 +57,7 @@ namespace mlx
_device.init();
volkLoadDevice(_device.get());
_queues.init();
_allocator.init();
_is_init = true;
}
@@ -67,6 +68,7 @@ namespace mlx
vkDeviceWaitIdle(_device());
_allocator.destroy();
_device.destroy();
_layers.destroy();
_instance.destroy();

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/08 19:16:32 by maldavid #+# #+# */
/* Updated: 2023/04/23 12:31:42 by maldavid ### ########.fr */
/* Updated: 2023/10/21 00:04:39 by kbz_8 ### ########.fr */
/* */
/* ************************************************************************** */
@@ -20,6 +20,7 @@
#include "vk_device.h"
#include "vk_instance.h"
#include "vk_validation_layers.h"
#include "memory.h"
#include <utils/singleton.h>
#include <core/errors.h>
@@ -52,6 +53,7 @@ namespace mlx
inline Instance& getInstance() noexcept { return _instance; }
inline Device& getDevice() noexcept { return _device; }
inline Queues& getQueue() noexcept { return _queues; }
inline GPUallocator& getAllocator() noexcept { return _allocator; }
inline ValidationLayers& getLayers() noexcept { return _layers; }
~Render_Core() = default;
@@ -61,6 +63,7 @@ namespace mlx
Queues _queues;
Device _device;
Instance _instance;
GPUallocator _allocator;
bool _is_init = false;
};
}

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/08 19:14:29 by maldavid #+# #+# */
/* Updated: 2022/12/18 22:56:47 by maldavid ### ########.fr */
/* Updated: 2023/11/08 20:14:08 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -57,6 +57,9 @@ namespace mlx
if(vkCreateDevice(_physicalDevice, &createInfo, nullptr, &_device) != VK_SUCCESS)
core::error::report(e_kind::fatal_error, "Vulkan : failed to create logcal device");
#ifdef DEBUG
core::error::report(e_kind::message, "Vulkan : created new logical device");
#endif
}
void Device::pickPhysicalDevice()
@@ -92,6 +95,9 @@ namespace mlx
if(_physicalDevice == VK_NULL_HANDLE)
core::error::report(e_kind::fatal_error, "Vulkan : failed to find a suitable GPU");
#ifdef DEBUG
core::error::report(e_kind::message, "Vulkan : picked a physical device");
#endif
}
bool Device::isDeviceSuitable(VkPhysicalDevice device, VkSurfaceKHR surface)

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/02 17:53:06 by maldavid #+# #+# */
/* Updated: 2023/04/02 17:54:14 by maldavid ### ########.fr */
/* Updated: 2023/11/08 20:14:23 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -25,6 +25,9 @@ namespace mlx
if(vkCreateFence(Render_Core::get().getDevice().get(), &fenceInfo, nullptr, &_fence) != VK_SUCCESS)
core::error::report(e_kind::fatal_error, "Vulkan : failed to create CPU synchronization object");
#ifdef DEBUG
core::error::report(e_kind::message, "Vulkan : created new fence");
#endif
}
void Fence::wait() noexcept

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/08 19:04:21 by maldavid #+# #+# */
/* Updated: 2023/10/20 03:12:07 by maldavid ### ########.fr */
/* Updated: 2023/11/08 20:13:30 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -19,25 +19,25 @@ namespace mlx
{
void Instance::init()
{
VkApplicationInfo appInfo{};
appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
appInfo.pApplicationName = "MacroLibX";
appInfo.applicationVersion = VK_MAKE_VERSION(1, 0, 0);
appInfo.pEngineName = "MacroLibX";
appInfo.engineVersion = VK_MAKE_VERSION(1, 0, 0);
appInfo.apiVersion = VK_API_VERSION_1_2;
VkApplicationInfo appInfo{};
appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
appInfo.pApplicationName = "MacroLibX";
appInfo.applicationVersion = VK_MAKE_VERSION(1, 0, 0);
appInfo.pEngineName = "MacroLibX";
appInfo.engineVersion = VK_MAKE_VERSION(1, 0, 0);
appInfo.apiVersion = VK_API_VERSION_1_2;
VkInstanceCreateInfo createInfo{};
createInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
createInfo.pApplicationInfo = &appInfo;
VkInstanceCreateInfo createInfo{};
createInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
createInfo.pApplicationInfo = &appInfo;
auto extensions = getRequiredExtensions();
createInfo.enabledExtensionCount = static_cast<uint32_t>(extensions.size());
createInfo.ppEnabledExtensionNames = extensions.data();
auto extensions = getRequiredExtensions();
createInfo.enabledExtensionCount = static_cast<uint32_t>(extensions.size());
createInfo.ppEnabledExtensionNames = extensions.data();
VkDebugUtilsMessengerCreateInfoEXT debugCreateInfo;
if constexpr(enableValidationLayers)
{
{
if(Render_Core::get().getLayers().checkValidationLayerSupport())
{
createInfo.enabledLayerCount = static_cast<uint32_t>(validationLayers.size());
@@ -45,45 +45,48 @@ namespace mlx
Render_Core::get().getLayers().populateDebugMessengerCreateInfo(debugCreateInfo);
createInfo.pNext = (VkDebugUtilsMessengerCreateInfoEXT*) &debugCreateInfo;
}
}
else
{
createInfo.enabledLayerCount = 0;
createInfo.pNext = nullptr;
}
}
else
{
createInfo.enabledLayerCount = 0;
createInfo.pNext = nullptr;
}
VkResult res;
if((res = vkCreateInstance(&createInfo, nullptr, &_instance)) != VK_SUCCESS)
if((res = vkCreateInstance(&createInfo, nullptr, &_instance)) != VK_SUCCESS)
core::error::report(e_kind::fatal_error, "Vulkan : failed to create Vulkan instance");
volkLoadInstance(_instance);
#ifdef DEBUG
core::error::report(e_kind::message, "Vulkan : created new instance");
#endif
}
std::vector<const char*> Instance::getRequiredExtensions()
{
unsigned int count = 0;
{
unsigned int count = 0;
SDL_Window* window = SDL_CreateWindow("", 0, 0, 1, 1, SDL_WINDOW_VULKAN | SDL_WINDOW_HIDDEN);
if(!window)
core::error::report(e_kind::fatal_error, "Vulkan : cannot get instance extentions from window : %s", SDL_GetError());
if(!SDL_Vulkan_GetInstanceExtensions(window, &count, nullptr))
if(!SDL_Vulkan_GetInstanceExtensions(window, &count, nullptr))
core::error::report(e_kind::fatal_error, "Vulkan : cannot get instance extentions from window : %s", SDL_GetError());
std::vector<const char*> extensions = { VK_EXT_DEBUG_REPORT_EXTENSION_NAME };
size_t additional_extension_count = extensions.size();
extensions.resize(additional_extension_count + count);
std::vector<const char*> extensions = { VK_EXT_DEBUG_REPORT_EXTENSION_NAME };
size_t additional_extension_count = extensions.size();
extensions.resize(additional_extension_count + count);
if(!SDL_Vulkan_GetInstanceExtensions(window, &count, extensions.data() + additional_extension_count))
if(!SDL_Vulkan_GetInstanceExtensions(window, &count, extensions.data() + additional_extension_count))
core::error::report(e_kind::error, "Vulkan : cannot get instance extentions from window : %s", SDL_GetError());
if constexpr(enableValidationLayers)
extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
SDL_DestroyWindow(window);
return extensions;
}
return extensions;
}
void Instance::destroy() noexcept
{
vkDestroyInstance(_instance, nullptr);
}
void Instance::destroy() noexcept
{
vkDestroyInstance(_instance, nullptr);
}
}

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/08 19:01:08 by maldavid #+# #+# */
/* Updated: 2023/04/02 17:55:58 by maldavid ### ########.fr */
/* Updated: 2023/11/08 20:14:36 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -24,6 +24,9 @@ namespace mlx
if( vkCreateSemaphore(Render_Core::get().getDevice().get(), &semaphoreInfo, nullptr, &_imageAvailableSemaphores) != VK_SUCCESS ||
vkCreateSemaphore(Render_Core::get().getDevice().get(), &semaphoreInfo, nullptr, &_renderFinishedSemaphores) != VK_SUCCESS)
core::error::report(e_kind::fatal_error, "Vulkan : failed to create GPU synchronization object");
#ifdef DEBUG
core::error::report(e_kind::message, "Vulkan : created new semaphore");
#endif
}
void Semaphore::destroy() noexcept

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/08 18:58:49 by maldavid #+# #+# */
/* Updated: 2022/12/18 22:20:57 by maldavid ### ########.fr */
/* Updated: 2023/11/08 20:14:48 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -22,6 +22,9 @@ namespace mlx
{
if(SDL_Vulkan_CreateSurface(renderer.getWindow()->getNativeWindow(), Render_Core::get().getInstance().get(), &_surface) != SDL_TRUE)
core::error::report(e_kind::fatal_error, "Vulkan : failed to create a surface : %s", SDL_GetError());
#ifdef DEBUG
core::error::report(e_kind::message, "Vulkan : created new surface");
#endif
}
VkSurfaceFormatKHR Surface::chooseSwapSurfaceFormat(const std::vector<VkSurfaceFormatKHR>& availableFormats)

View File

@@ -6,7 +6,7 @@
/* By: maldavid <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/19 14:05:25 by maldavid #+# #+# */
/* Updated: 2022/12/19 14:11:12 by maldavid ### ########.fr */
/* Updated: 2023/11/08 20:15:36 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -28,6 +28,10 @@ namespace mlx
populateDebugMessengerCreateInfo(createInfo);
if(createDebugUtilsMessengerEXT(&createInfo, nullptr) != VK_SUCCESS)
core::error::report(e_kind::error, "Vulkan : failed to set up debug messenger");
#ifdef DEBUG
else
core::error::report(e_kind::message, "Vulkan : enabled validation layers");
#endif
}
bool ValidationLayers::checkValidationLayerSupport()

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/23 18:40:44 by maldavid #+# #+# */
/* Updated: 2023/04/22 19:52:08 by maldavid ### ########.fr */
/* Updated: 2023/11/08 20:16:32 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -37,6 +37,9 @@ namespace mlx
if(vkAllocateDescriptorSets(device, &allocInfo, _desc_set.data()) != VK_SUCCESS)
core::error::report(e_kind::fatal_error, "Vulkan : failed to allocate descriptor set");
#ifdef DEBUG
core::error::report(e_kind::message, "Vulkan : created new descriptor set");
#endif
}
void DescriptorSet::writeDescriptor(int binding, UBO* ubo) noexcept

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/18 21:27:38 by maldavid #+# #+# */
/* Updated: 2023/04/13 14:52:57 by maldavid ### ########.fr */
/* Updated: 2023/11/08 20:36:18 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -301,6 +301,9 @@ namespace mlx
if(vkCreateGraphicsPipelines(Render_Core::get().getDevice().get(), VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, &_graphicsPipeline) != VK_SUCCESS)
core::error::report(e_kind::fatal_error, "Vulkan : failed to create a graphics pipeline");
#ifdef DEBUG
core::error::report(e_kind::message, "Vulkan : created new graphic pipeline");
#endif
vkDestroyShaderModule(Render_Core::get().getDevice().get(), fshader, nullptr);
vkDestroyShaderModule(Render_Core::get().getDevice().get(), vshader, nullptr);

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/06 18:18:06 by maldavid #+# #+# */
/* Updated: 2022/12/18 20:01:51 by maldavid ### ########.fr */
/* Updated: 2023/11/08 20:36:54 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -31,6 +31,9 @@ namespace mlx
if(vkCreateFramebuffer(Render_Core::get().getDevice().get(), &framebufferInfo, nullptr, &_framebuffer) != VK_SUCCESS)
core::error::report(e_kind::fatal_error, "Vulkan : failed to create a framebuffer");
#ifdef DEBUG
core::error::report(e_kind::message, "Vulkan : created new framebuffer");
#endif
}
void FrameBuffer::destroy() noexcept

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/06 18:20:49 by maldavid #+# #+# */
/* Updated: 2022/12/18 19:55:03 by maldavid ### ########.fr */
/* Updated: 2023/11/08 20:37:17 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -35,6 +35,9 @@ namespace mlx
if(vkCreateImageView(Render_Core::get().getDevice().get(), &createInfo, nullptr, &_image) != VK_SUCCESS)
core::error::report(e_kind::fatal_error, "Vulkan : failed to create an image view");
#ifdef DEBUG
core::error::report(e_kind::message, "Vulkan : created new swapchain image view");
#endif
}
void ImageView::destroy() noexcept

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/06 18:21:36 by maldavid #+# #+# */
/* Updated: 2022/12/19 00:06:34 by maldavid ### ########.fr */
/* Updated: 2023/11/08 20:37:32 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -50,6 +50,9 @@ namespace mlx
if(vkCreateRenderPass(Render_Core::get().getDevice().get(), &renderPassInfo, nullptr, &_renderPass) != VK_SUCCESS)
core::error::report(e_kind::fatal_error, "Vulkan : failed to create render pass");
#ifdef DEBUG
core::error::report(e_kind::message, "Vulkan : created new render pass");
#endif
}
void RenderPass::begin()

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/06 18:22:28 by maldavid #+# #+# */
/* Updated: 2023/01/25 11:39:01 by maldavid ### ########.fr */
/* Updated: 2023/11/08 20:37:53 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -66,6 +66,9 @@ namespace mlx
if(vkCreateSwapchainKHR(device, &createInfo, nullptr, &_swapChain) != VK_SUCCESS)
core::error::report(e_kind::fatal_error, "Vulkan : failed to create swapchain");
#ifdef DEBUG
core::error::report(e_kind::message, "Vulkan : created new swapchain");
#endif
vkGetSwapchainImagesKHR(device, _swapChain, &imageCount, nullptr);
_swapChainImages.resize(imageCount);

View File

@@ -6,16 +6,16 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/11 16:20:25 by maldavid #+# #+# */
/* Updated: 2023/04/11 16:20:27 by maldavid ### ########.fr */
/* Updated: 2023/11/08 20:23:23 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_DOGICA_TTF__
#define __MLX_DOGICA_TTF__
unsigned int dogica_ttf_len = 33860;
inline unsigned int dogica_ttf_len = 33860;
unsigned char dogica_ttf[] = {
inline unsigned char dogica_ttf[] = {
0x00, 0x01, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x80, 0x00, 0x03, 0x00, 0x60,
0x46, 0x46, 0x54, 0x4d, 0x8f, 0xe1, 0x5b, 0x60, 0x00, 0x00, 0x84, 0x28,
0x00, 0x00, 0x00, 0x1c, 0x47, 0x44, 0x45, 0x46, 0x00, 0x15, 0x00, 0x14,