fixing some bad memory usage

This commit is contained in:
Kbz-8
2024-03-25 13:57:20 +01:00
parent 57c5ae5415
commit be52578d37
35 changed files with 1294 additions and 1298 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 17:55:21 by maldavid #+# #+# */
/* Updated: 2024/02/24 01:07:56 by maldavid ### ########.fr */
/* Updated: 2024/03/14 20:01:01 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -23,6 +23,8 @@ typedef struct
void* img;
} mlx_t;
void* img = NULL;
int update(void* param)
{
static int i = 0;
@@ -30,7 +32,13 @@ int update(void* param)
if(i == 200)
mlx_clear_window(mlx->mlx, mlx->win);
if(img)
mlx_destroy_image(mlx->mlx,img);
img = mlx_new_image(mlx->mlx, 800, 800);
mlx_set_image_pixel(mlx->mlx, img, 4, 4, 0xFF00FF00);
mlx_put_image_to_window(mlx->mlx, mlx->win, img, 0, 0);
if(i >= 250)
mlx_set_font_scale(mlx->mlx, mlx->win, "default", 16.f);
else

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 22:10:52 by maldavid #+# #+# */
/* Updated: 2024/02/25 07:52:04 by maldavid ### ########.fr */
/* Updated: 2024/03/24 14:39:23 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -89,10 +89,9 @@ namespace mlx::core
core::error::report(e_kind::error, "invalid image ptr (NULL)");
return;
}
else if(std::find_if(_textures.begin(), _textures.end(), [=](const Texture& texture)
{
return &texture == ptr;
}) == _textures.end())
auto it = std::find_if(_textures.begin(), _textures.end(), [=](const Texture& texture) { return &texture == ptr; });
if(it == _textures.end())
{
core::error::report(e_kind::error, "invalid image ptr");
return;
@@ -102,6 +101,9 @@ namespace mlx::core
core::error::report(e_kind::error, "trying to destroy a texture that has already been destroyed");
else
texture->destroy();
for(auto& gs : _graphics)
gs->tryEraseTextureFromManager(texture);
_textures.erase(it);
}
Application::~Application()

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/02 14:49:49 by maldavid #+# #+# */
/* Updated: 2024/01/11 15:47:05 by maldavid ### ########.fr */
/* Updated: 2024/03/24 14:43:09 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -14,7 +14,6 @@
#define __MLX_GRAPHICS__
#include <memory>
#include <unordered_set>
#include <filesystem>
#include <glm/glm.hpp>
@@ -33,7 +32,7 @@
namespace mlx
{
class GraphicsSupport : public non_copyable
class GraphicsSupport : public NonCopyable
{
public:
GraphicsSupport(std::size_t w, std::size_t h, Texture* render_target, int id);
@@ -49,6 +48,7 @@ namespace mlx
inline void stringPut(int x, int y, std::uint32_t color, std::string str);
inline void texturePut(Texture* texture, int x, int y);
inline void loadFont(const std::filesystem::path& filepath, float scale);
inline void tryEraseTextureFromManager(Texture* texture) noexcept;
inline bool hasWindow() const noexcept { return _has_window; }

View File

@@ -11,7 +11,6 @@
/* ************************************************************************** */
#include <core/graphics.h>
#include <iostream>
namespace mlx
{
@@ -64,4 +63,17 @@ namespace mlx
MLX_PROFILE_FUNCTION();
_text_manager.loadFont(*_renderer, filepath, scale);
}
void GraphicsSupport::tryEraseTextureFromManager(Texture* texture) noexcept
{
MLX_PROFILE_FUNCTION();
for(auto it = _drawlist.begin(); it != _drawlist.end();)
{
if(_texture_manager.isTextureKnown(texture))
it = _drawlist.erase(it);
else
++it;
}
_texture_manager.eraseTextures(texture);
}
}

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/10 13:35:45 by maldavid #+# #+# */
/* Updated: 2024/01/10 18:36:46 by maldavid ### ########.fr */
/* Updated: 2024/03/24 14:41:27 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -19,10 +19,10 @@
#include <string>
#include <thread>
#include <mutex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <unordered_map>
#include <sstream>
#include <iomanip>
namespace mlx
{
@@ -115,17 +115,17 @@ namespace mlx
{
ChangeResult<N> result = {};
std::size_t srcIndex = 0;
std::size_t dstIndex = 0;
while(srcIndex < N)
std::size_t src_index = 0;
std::size_t dst_index = 0;
while(src_index < N)
{
std::size_t matchIndex = 0;
while(matchIndex < K - 1 && srcIndex + matchIndex < N - 1 && expr[srcIndex + matchIndex] == remove[matchIndex])
matchIndex++;
if(matchIndex == K - 1)
srcIndex += matchIndex;
result.data[dstIndex++] = expr[srcIndex] == '"' ? '\'' : expr[srcIndex];
srcIndex++;
std::size_t match_index = 0;
while(match_index < K - 1 && src_index + match_index < N - 1 && expr[src_index + match_index] == remove[match_index])
match_index++;
if(match_index == K - 1)
src_index += match_index;
result.data[dst_index++] = expr[src_index] == '"' ? '\'' : expr[src_index];
src_index++;
}
return result;
}

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/08 18:55:57 by maldavid #+# #+# */
/* Updated: 2024/01/11 05:21:20 by maldavid ### ########.fr */
/* Updated: 2024/03/14 17:28:35 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -54,16 +54,11 @@ namespace mlx
void Buffer::destroy() noexcept
{
MLX_PROFILE_FUNCTION();
// not creating destroyer in `create` as some image may be copied (and so `this` will be invalid)
//CmdResource::setDestroyer([this]()
//{
if(_is_mapped)
unmapMem();
if(_buffer != VK_NULL_HANDLE)
Render_Core::get().getAllocator().destroyBuffer(_allocation, _buffer);
_buffer = VK_NULL_HANDLE;
//});
//CmdResource::requireDestroy();
if(_is_mapped)
unmapMem();
if(_buffer != VK_NULL_HANDLE)
Render_Core::get().getAllocator().destroyBuffer(_allocation, _buffer);
_buffer = VK_NULL_HANDLE;
}
void Buffer::createBuffer(VkBufferUsageFlags usage, VmaAllocationCreateInfo info, VkDeviceSize size, [[maybe_unused]] const char* name)

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/06 18:24:33 by maldavid #+# #+# */
/* Updated: 2024/01/03 13:13:25 by maldavid ### ########.fr */
/* Updated: 2024/03/14 17:23:20 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -20,7 +20,7 @@ namespace mlx
VkCommandPoolCreateInfo poolInfo{};
poolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
poolInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
poolInfo.queueFamilyIndex = Render_Core::get().getQueue().getFamilies().graphicsFamily.value();
poolInfo.queueFamilyIndex = Render_Core::get().getQueue().getFamilies().graphics_family.value();
VkResult res = vkCreateCommandPool(Render_Core::get().getDevice().get(), &poolInfo, nullptr, &_cmd_pool);
if(res != VK_SUCCESS)

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/16 20:44:29 by maldavid #+# #+# */
/* Updated: 2024/01/11 05:12:42 by maldavid ### ########.fr */
/* Updated: 2024/03/14 17:28:08 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -31,31 +31,13 @@ namespace mlx
public:
CmdResource() : _uuid() {}
inline void recordedInCmdBuffer() noexcept { _state = state::in_cmd_buffer; }
inline void removedFromCmdBuffer() noexcept
{
_state = state::out_cmd_buffer;
if(_destroy_required && _destroyer)
{
_destroyer();
_destroy_required = false;
}
}
inline void setDestroyer(func::function<void(void)> functor) { _destroyer = functor; }
inline void requireDestroy() noexcept
{
if(_state == state::out_cmd_buffer && _destroyer)
_destroyer();
else
_destroy_required = true;
}
inline void removedFromCmdBuffer() noexcept { _state = state::out_cmd_buffer; }
inline UUID getUUID() const noexcept { return _uuid; }
virtual ~CmdResource() = default;
private:
UUID _uuid;
state _state = state::out_cmd_buffer;
func::function<void(void)> _destroyer;
bool _destroy_required = false;
};
}

View File

@@ -6,14 +6,13 @@
/* By: kbz_8 <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/20 22:02:37 by kbz_8 #+# #+# */
/* Updated: 2024/01/18 10:11:02 by maldavid ### ########.fr */
/* Updated: 2024/03/14 16:34:53 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#include <mlx_profile.h>
#include <core/errors.h>
#include <core/profiler.h>
#include <cstdio>
#define VMA_STATIC_VULKAN_FUNCTIONS 0
#define VMA_DYNAMIC_VULKAN_FUNCTIONS 0
@@ -177,7 +176,7 @@ namespace mlx
file.close();
id++;
}
void GPUallocator::flush(VmaAllocation allocation, VkDeviceSize size, VkDeviceSize offset) noexcept
{
MLX_PROFILE_FUNCTION();
@@ -187,9 +186,11 @@ namespace mlx
void GPUallocator::destroy() noexcept
{
if(_active_images_allocations != 0)
core::error::report(e_kind::error, "Graphics allocator : some user-dependant allocations were not freed before destroying the display (%d active allocations)", _active_images_allocations);
core::error::report(e_kind::error, "Graphics allocator : some user-dependant allocations were not freed before destroying the display (%d active allocations). You may have not destroyed all the MLX resources you've created", _active_images_allocations);
else if(_active_buffers_allocations != 0)
core::error::report(e_kind::error, "Graphics allocator : some MLX-dependant allocations were not freed before destroying the display (%d active allocations), please report, this should not happen", _active_buffers_allocations);
core::error::report(e_kind::error, "Graphics allocator : some MLX-dependant allocations were not freed before destroying the display (%d active allocations). This is an error in the MLX, please report this should not happen", _active_buffers_allocations);
if(_active_images_allocations < 0 || _active_buffers_allocations < 0)
core::error::report(e_kind::warning, "Graphics allocator : the impossible happened, the MLX has freed more allocations than it has made (wtf)");
vmaDestroyAllocator(_allocator);
_active_buffers_allocations = 0;
_active_images_allocations = 0;

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/08 19:14:29 by maldavid #+# #+# */
/* Updated: 2024/01/20 05:34:15 by maldavid ### ########.fr */
/* Updated: 2024/03/14 17:23:45 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -17,8 +17,6 @@
#include <set>
#include <SDL2/SDL.h>
#include <SDL2/SDL_vulkan.h>
#include <iostream>
#include <algorithm>
namespace mlx
{
@@ -31,7 +29,7 @@ namespace mlx
Queues::QueueFamilyIndices indices = Render_Core::get().getQueue().getFamilies();
std::vector<VkDeviceQueueCreateInfo> queueCreateInfos;
std::set<std::uint32_t> uniqueQueueFamilies = { indices.graphicsFamily.value(), indices.presentFamily.value() };
std::set<std::uint32_t> uniqueQueueFamilies = { indices.graphics_family.value(), indices.present_family.value() };
float queuePriority = 1.0f;
for(std::uint32_t queueFamily : uniqueQueueFamilies)
@@ -59,7 +57,7 @@ namespace mlx
createInfo.enabledLayerCount = 0;
VkResult res;
if((res = vkCreateDevice(_physicalDevice, &createInfo, nullptr, &_device)) != VK_SUCCESS)
if((res = vkCreateDevice(_physical_device, &createInfo, nullptr, &_device)) != VK_SUCCESS)
core::error::report(e_kind::fatal_error, "Vulkan : failed to create logcal device, %s", RCore::verbaliseResultVk(res));
#ifdef DEBUG
core::error::report(e_kind::message, "Vulkan : created new logical device");
@@ -94,16 +92,16 @@ namespace mlx
}
if(devices_score.rbegin()->first > 0)
_physicalDevice = devices_score.rbegin()->second;
_physical_device = devices_score.rbegin()->second;
else
core::error::report(e_kind::fatal_error, "Vulkan : failed to find a suitable GPU");
#ifdef DEBUG
VkPhysicalDeviceProperties props;
vkGetPhysicalDeviceProperties(_physicalDevice, &props);
vkGetPhysicalDeviceProperties(_physical_device, &props);
core::error::report(e_kind::message, "Vulkan : picked a physical device, %s", props.deviceName);
#endif
Render_Core::get().getQueue().findQueueFamilies(_physicalDevice, surface); // update queue indicies to current physical device
Render_Core::get().getQueue().findQueueFamilies(_physical_device, surface); // update queue indicies to current physical device
vkDestroySurfaceKHR(Render_Core::get().getInstance().get(), surface, nullptr);
SDL_DestroyWindow(window);
}

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/08 19:13:42 by maldavid #+# #+# */
/* Updated: 2024/01/03 15:26:14 by maldavid ### ########.fr */
/* Updated: 2024/03/14 16:59:54 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -15,7 +15,6 @@
#include <mlx_profile.h>
#include <volk.h>
#include "vk_queues.h"
namespace mlx
{
@@ -28,7 +27,7 @@ namespace mlx
inline VkDevice& operator()() noexcept { return _device; }
inline VkDevice& get() noexcept { return _device; }
inline VkPhysicalDevice& getPhysicalDevice() noexcept { return _physicalDevice; }
inline VkPhysicalDevice& getPhysicalDevice() noexcept { return _physical_device; }
private:
void pickPhysicalDevice();
@@ -36,7 +35,7 @@ namespace mlx
int deviceScore(VkPhysicalDevice device, VkSurfaceKHR surface);
private:
VkPhysicalDevice _physicalDevice = VK_NULL_HANDLE;
VkPhysicalDevice _physical_device = VK_NULL_HANDLE;
VkDevice _device = VK_NULL_HANDLE;
};
}

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/08 19:02:42 by maldavid #+# #+# */
/* Updated: 2024/01/10 21:54:54 by maldavid ### ########.fr */
/* Updated: 2024/03/14 17:01:10 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -29,13 +29,13 @@ namespace mlx
for(const auto& queueFamily : queueFamilies)
{
if(queueFamily.queueFlags & VK_QUEUE_GRAPHICS_BIT)
_families->graphicsFamily = i;
_families->graphics_family = i;
VkBool32 presentSupport = false;
vkGetPhysicalDeviceSurfaceSupportKHR(device, i, surface, &presentSupport);
if(presentSupport)
_families->presentFamily = i;
_families->present_family = i;
if(_families->isComplete())
return *_families;
@@ -62,8 +62,8 @@ namespace mlx
vkDestroySurfaceKHR(Render_Core::get().getInstance().get(), surface, nullptr);
SDL_DestroyWindow(window);
}
vkGetDeviceQueue(Render_Core::get().getDevice().get(), _families->graphicsFamily.value(), 0, &_graphicsQueue);
vkGetDeviceQueue(Render_Core::get().getDevice().get(), _families->presentFamily.value(), 0, &_presentQueue);
vkGetDeviceQueue(Render_Core::get().getDevice().get(), _families->graphics_family.value(), 0, &_graphics_queue);
vkGetDeviceQueue(Render_Core::get().getDevice().get(), _families->present_family.value(), 0, &_present_queue);
#ifdef DEBUG
core::error::report(e_kind::message, "Vulkan : got graphics and present queues");
#endif

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/08 19:01:49 by maldavid #+# #+# */
/* Updated: 2024/01/08 23:46:23 by maldavid ### ########.fr */
/* Updated: 2024/03/14 17:00:48 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -26,18 +26,18 @@ namespace mlx
public:
struct QueueFamilyIndices
{
std::optional<std::uint32_t> graphicsFamily;
std::optional<std::uint32_t> presentFamily;
std::optional<std::uint32_t> graphics_family;
std::optional<std::uint32_t> present_family;
inline bool isComplete() { return graphicsFamily.has_value() && presentFamily.has_value(); }
inline bool isComplete() { return graphics_family.has_value() && present_family.has_value(); }
};
QueueFamilyIndices findQueueFamilies(VkPhysicalDevice device, VkSurfaceKHR surface);
void init();
inline VkQueue& getGraphic() noexcept { return _graphicsQueue; }
inline VkQueue& getPresent() noexcept { return _presentQueue; }
inline VkQueue& getGraphic() noexcept { return _graphics_queue; }
inline VkQueue& getPresent() noexcept { return _present_queue; }
inline QueueFamilyIndices getFamilies() noexcept
{
if(_families.has_value())
@@ -47,8 +47,8 @@ namespace mlx
}
private:
VkQueue _graphicsQueue;
VkQueue _presentQueue;
VkQueue _graphics_queue;
VkQueue _present_queue;
std::optional<QueueFamilyIndices> _families;
};
}

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/08 19:01:08 by maldavid #+# #+# */
/* Updated: 2024/01/10 21:55:12 by maldavid ### ########.fr */
/* Updated: 2024/03/14 17:02:36 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -22,8 +22,8 @@ namespace mlx
semaphoreInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
VkResult res;
if( (res = vkCreateSemaphore(Render_Core::get().getDevice().get(), &semaphoreInfo, nullptr, &_imageAvailableSemaphores)) != VK_SUCCESS ||
(res = vkCreateSemaphore(Render_Core::get().getDevice().get(), &semaphoreInfo, nullptr, &_renderFinishedSemaphores)) != VK_SUCCESS)
if( (res = vkCreateSemaphore(Render_Core::get().getDevice().get(), &semaphoreInfo, nullptr, &_image_available_semaphore)) != VK_SUCCESS ||
(res = vkCreateSemaphore(Render_Core::get().getDevice().get(), &semaphoreInfo, nullptr, &_render_finished_semaphore)) != VK_SUCCESS)
core::error::report(e_kind::fatal_error, "Vulkan : failed to create a synchronization object (semaphore), %s", RCore::verbaliseResultVk(res));
#ifdef DEBUG
core::error::report(e_kind::message, "Vulkan : created new semaphores");
@@ -32,10 +32,10 @@ namespace mlx
void Semaphore::destroy() noexcept
{
vkDestroySemaphore(Render_Core::get().getDevice().get(), _renderFinishedSemaphores, nullptr);
_renderFinishedSemaphores = VK_NULL_HANDLE;
vkDestroySemaphore(Render_Core::get().getDevice().get(), _imageAvailableSemaphores, nullptr);
_imageAvailableSemaphores = VK_NULL_HANDLE;
vkDestroySemaphore(Render_Core::get().getDevice().get(), _render_finished_semaphore, nullptr);
_render_finished_semaphore = VK_NULL_HANDLE;
vkDestroySemaphore(Render_Core::get().getDevice().get(), _image_available_semaphore, nullptr);
_image_available_semaphore = VK_NULL_HANDLE;
#ifdef DEBUG
core::error::report(e_kind::message, "Vulkan : destroyed semaphores");
#endif

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/08 18:59:38 by maldavid #+# #+# */
/* Updated: 2024/01/03 15:26:39 by maldavid ### ########.fr */
/* Updated: 2024/03/14 17:01:57 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -15,7 +15,6 @@
#include <mlx_profile.h>
#include <volk.h>
#include <vector>
namespace mlx
{
@@ -25,12 +24,12 @@ namespace mlx
void init();
void destroy() noexcept;
inline VkSemaphore& getImageSemaphore() noexcept { return _imageAvailableSemaphores; }
inline VkSemaphore& getRenderImageSemaphore() noexcept { return _renderFinishedSemaphores; }
inline VkSemaphore& getImageSemaphore() noexcept { return _image_available_semaphore; }
inline VkSemaphore& getRenderImageSemaphore() noexcept { return _render_finished_semaphore; }
private:
VkSemaphore _imageAvailableSemaphores = VK_NULL_HANDLE;
VkSemaphore _renderFinishedSemaphores = VK_NULL_HANDLE;
VkSemaphore _image_available_semaphore = VK_NULL_HANDLE;
VkSemaphore _render_finished_semaphore = VK_NULL_HANDLE;
};
}

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/19 14:05:25 by maldavid #+# #+# */
/* Updated: 2024/01/10 21:55:54 by maldavid ### ########.fr */
/* Updated: 2024/03/14 17:03:24 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -14,7 +14,6 @@
#include "vulkan/vulkan_core.h"
#include <core/errors.h>
#include <iostream>
#include <cstring>
#include <algorithm>
@@ -45,8 +44,8 @@ namespace mlx
core::error::report(e_kind::message, "Vulkan : enabled validation layers");
#endif
real_vkSetDebugUtilsObjectNameEXT = (PFN_vkSetDebugUtilsObjectNameEXT)vkGetInstanceProcAddr(Render_Core::get().getInstance().get(), "vkSetDebugUtilsObjectNameEXT");
if(!real_vkSetDebugUtilsObjectNameEXT)
_vkSetDebugUtilsObjectNameEXT = (PFN_vkSetDebugUtilsObjectNameEXT)vkGetInstanceProcAddr(Render_Core::get().getInstance().get(), "vkSetDebugUtilsObjectNameEXT");
if(!_vkSetDebugUtilsObjectNameEXT)
core::error::report(e_kind::warning, "Vulkan : failed to set up debug object names, %s", RCore::verbaliseResultVk(VK_ERROR_EXTENSION_NOT_PRESENT));
#ifdef DEBUG
else
@@ -75,7 +74,7 @@ namespace mlx
VkResult ValidationLayers::setDebugUtilsObjectNameEXT(VkObjectType object_type, std::uint64_t object_handle, const char* object_name)
{
if(!real_vkSetDebugUtilsObjectNameEXT)
if(!_vkSetDebugUtilsObjectNameEXT)
return VK_ERROR_EXTENSION_NOT_PRESENT;
VkDebugUtilsObjectNameInfoEXT name_info{};
@@ -83,7 +82,7 @@ namespace mlx
name_info.objectType = object_type;
name_info.objectHandle = object_handle;
name_info.pObjectName = object_name;
return real_vkSetDebugUtilsObjectNameEXT(Render_Core::get().getDevice().get(), &name_info);
return _vkSetDebugUtilsObjectNameEXT(Render_Core::get().getDevice().get(), &name_info);
}
void ValidationLayers::populateDebugMessengerCreateInfo(VkDebugUtilsMessengerCreateInfoEXT& createInfo)
@@ -109,7 +108,7 @@ namespace mlx
VkResult ValidationLayers::createDebugUtilsMessengerEXT(const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator)
{
auto func = (PFN_vkCreateDebugUtilsMessengerEXT)vkGetInstanceProcAddr(Render_Core::get().getInstance().get(), "vkCreateDebugUtilsMessengerEXT");
return func != nullptr ? func(Render_Core::get().getInstance().get(), pCreateInfo, pAllocator, &_debugMessenger) : VK_ERROR_EXTENSION_NOT_PRESENT;
return func != nullptr ? func(Render_Core::get().getInstance().get(), pCreateInfo, pAllocator, &_debug_messenger) : VK_ERROR_EXTENSION_NOT_PRESENT;
}
VKAPI_ATTR VkBool32 VKAPI_CALL ValidationLayers::debugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, [[maybe_unused]] VkDebugUtilsMessageTypeFlagsEXT messageType, const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData, [[maybe_unused]] void* pUserData)
@@ -125,7 +124,7 @@ namespace mlx
{
auto func = (PFN_vkDestroyDebugUtilsMessengerEXT)vkGetInstanceProcAddr(Render_Core::get().getInstance().get(), "vkDestroyDebugUtilsMessengerEXT");
if(func != nullptr)
func(Render_Core::get().getInstance().get(), _debugMessenger, pAllocator);
func(Render_Core::get().getInstance().get(), _debug_messenger, pAllocator);
}
}

View File

@@ -6,7 +6,7 @@
/* By: maldavid <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/19 14:04:25 by maldavid #+# #+# */
/* Updated: 2024/01/07 00:21:42 by maldavid ### ########.fr */
/* Updated: 2024/03/14 17:02:55 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -39,8 +39,8 @@ namespace mlx
void destroyDebugUtilsMessengerEXT(const VkAllocationCallbacks* pAllocator);
private:
VkDebugUtilsMessengerEXT _debugMessenger;
PFN_vkSetDebugUtilsObjectNameEXT real_vkSetDebugUtilsObjectNameEXT = nullptr;
VkDebugUtilsMessengerEXT _debug_messenger;
PFN_vkSetDebugUtilsObjectNameEXT _vkSetDebugUtilsObjectNameEXT = nullptr;
};
}

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/31 18:03:35 by maldavid #+# #+# */
/* Updated: 2024/02/24 03:51:59 by maldavid ### ########.fr */
/* Updated: 2024/03/14 19:07:01 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -20,8 +20,6 @@
#define STB_IMAGE_IMPLEMENTATION
#include <stb_image.h>
#include <iostream>
#ifdef IMAGE_OPTIMIZED
#define TILING VK_IMAGE_TILING_OPTIMAL
#else

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/08 02:24:58 by maldavid #+# #+# */
/* Updated: 2024/01/11 01:18:25 by maldavid ### ########.fr */
/* Updated: 2024/03/14 19:06:07 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -14,15 +14,15 @@
#define __MLX_TEXTURE__
#include <filesystem>
#include <memory>
#include <array>
#include <functional>
#include <renderer/images/vk_image.h>
#include <renderer/descriptors/vk_descriptor_set.h>
#include <renderer/buffers/vk_ibo.h>
#include <renderer/buffers/vk_vbo.h>
#include <mlx_profile.h>
#include <string>
#ifdef DEBUG
#include <string>
#endif
namespace mlx
{

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/07 16:36:33 by maldavid #+# #+# */
/* Updated: 2024/01/18 02:47:30 by maldavid ### ########.fr */
/* Updated: 2024/03/14 19:57:55 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -14,7 +14,6 @@
#define __MLX_TEXTURE_ATLAS__
#include <renderer/images/texture.h>
#include <array>
#include <glm/glm.hpp>
#include <mlx_profile.h>

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/11 00:56:15 by maldavid #+# #+# */
/* Updated: 2024/01/11 01:49:12 by maldavid ### ########.fr */
/* Updated: 2024/03/25 13:53:59 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -26,6 +26,7 @@ namespace mlx
TextureManager() = default;
inline void clear() { _texture_descriptors.clear(); }
inline std::pair<DrawableResource*, bool> registerTexture(Texture* texture, int x, int y)
{
MLX_PROFILE_FUNCTION();
@@ -33,6 +34,29 @@ namespace mlx
return std::make_pair(static_cast<DrawableResource*>(&const_cast<TextureRenderDescriptor&>(*res.first)), res.second);
}
inline bool isTextureKnown(Texture* texture) noexcept
{
MLX_PROFILE_FUNCTION();
for(const auto& desc : _texture_descriptors)
{
if(desc.texture == texture)
return true;
}
return false;
}
inline void eraseTextures(Texture* texture)
{
MLX_PROFILE_FUNCTION();
for(auto it = _texture_descriptors.begin(); it != _texture_descriptors.end();)
{
if(it->texture == texture)
it = _texture_descriptors.erase(it);
else
++it;
}
}
~TextureManager() = default;
private:

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/25 11:59:07 by maldavid #+# #+# */
/* Updated: 2024/02/25 08:03:47 by maldavid ### ########.fr */
/* Updated: 2024/03/14 17:28:25 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -251,17 +251,12 @@ namespace mlx
void Image::destroy() noexcept
{
// not creating destroyer in `create` as some image may be copied (and so `this` will be invalid)
//CmdResource::setDestroyer([this]()
//{
destroySampler();
destroyImageView();
destroySampler();
destroyImageView();
if(_image != VK_NULL_HANDLE)
Render_Core::get().getAllocator().destroyImage(_allocation, _image);
_image = VK_NULL_HANDLE;
//});
//CmdResource::requireDestroy();
if(_image != VK_NULL_HANDLE)
Render_Core::get().getAllocator().destroyImage(_allocation, _image);
_image = VK_NULL_HANDLE;
}
std::uint32_t formatSize(VkFormat format)

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/18 21:27:38 by maldavid #+# #+# */
/* Updated: 2024/01/16 07:45:15 by maldavid ### ########.fr */
/* Updated: 2024/03/14 17:05:21 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -286,7 +286,7 @@ namespace mlx
pipelineLayoutInfo.pushConstantRangeCount = 1;
pipelineLayoutInfo.pPushConstantRanges = &push_constant;
if(vkCreatePipelineLayout(Render_Core::get().getDevice().get(), &pipelineLayoutInfo, nullptr, &_pipelineLayout) != VK_SUCCESS)
if(vkCreatePipelineLayout(Render_Core::get().getDevice().get(), &pipelineLayoutInfo, nullptr, &_pipeline_layout) != VK_SUCCESS)
core::error::report(e_kind::fatal_error, "Vulkan : failed to create a graphics pipeline layout");
VkGraphicsPipelineCreateInfo pipelineInfo{};
@@ -300,12 +300,12 @@ namespace mlx
pipelineInfo.pMultisampleState = &multisampling;
pipelineInfo.pColorBlendState = &colorBlending;
pipelineInfo.pDynamicState = &dynamicStates;
pipelineInfo.layout = _pipelineLayout;
pipelineInfo.layout = _pipeline_layout;
pipelineInfo.renderPass = renderer.getRenderPass().get();
pipelineInfo.subpass = 0;
pipelineInfo.basePipelineHandle = VK_NULL_HANDLE;
VkResult res = vkCreateGraphicsPipelines(Render_Core::get().getDevice().get(), VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, &_graphicsPipeline);
VkResult res = vkCreateGraphicsPipelines(Render_Core::get().getDevice().get(), VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, &_graphics_pipeline);
if(res != VK_SUCCESS)
core::error::report(e_kind::fatal_error, "Vulkan : failed to create a graphics pipeline, %s", RCore::verbaliseResultVk(res));
#ifdef DEBUG
@@ -318,9 +318,9 @@ namespace mlx
void GraphicPipeline::destroy() noexcept
{
vkDestroyPipeline(Render_Core::get().getDevice().get(), _graphicsPipeline, nullptr);
vkDestroyPipelineLayout(Render_Core::get().getDevice().get(), _pipelineLayout, nullptr);
_graphicsPipeline = VK_NULL_HANDLE;
vkDestroyPipeline(Render_Core::get().getDevice().get(), _graphics_pipeline, nullptr);
vkDestroyPipelineLayout(Render_Core::get().getDevice().get(), _pipeline_layout, nullptr);
_graphics_pipeline = VK_NULL_HANDLE;
#ifdef DEBUG
core::error::report(e_kind::message, "Vulkan : destroyed a graphics pipeline");
#endif

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/18 21:23:52 by maldavid #+# #+# */
/* Updated: 2024/01/03 15:28:13 by maldavid ### ########.fr */
/* Updated: 2024/03/14 17:04:28 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -25,15 +25,14 @@ namespace mlx
void init(class Renderer& renderer);
void destroy() noexcept;
inline void bindPipeline(CmdBuffer& commandBuffer) noexcept { vkCmdBindPipeline(commandBuffer.get(), VK_PIPELINE_BIND_POINT_GRAPHICS, _graphicsPipeline); }
inline void bindPipeline(CmdBuffer& command_buffer) noexcept { vkCmdBindPipeline(command_buffer.get(), VK_PIPELINE_BIND_POINT_GRAPHICS, _graphics_pipeline); }
inline const VkPipeline& getPipeline() const noexcept { return _graphicsPipeline; }
inline const VkPipelineLayout& getPipelineLayout() const noexcept { return _pipelineLayout; }
inline const VkPipeline& getPipeline() const noexcept { return _graphics_pipeline; }
inline const VkPipelineLayout& getPipelineLayout() const noexcept { return _pipeline_layout; }
private:
VkPipeline _graphicsPipeline = VK_NULL_HANDLE;
VkPipelineCache _cache = VK_NULL_HANDLE;
VkPipelineLayout _pipelineLayout = VK_NULL_HANDLE;
VkPipeline _graphics_pipeline = VK_NULL_HANDLE;
VkPipelineLayout _pipeline_layout = VK_NULL_HANDLE;
};
}

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/18 17:25:16 by maldavid #+# #+# */
/* Updated: 2024/02/25 08:02:05 by maldavid ### ########.fr */
/* Updated: 2024/03/14 16:34:43 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -61,7 +61,7 @@ namespace mlx
_pipeline.init(*this);
_framebufferResized = false;
_framebuffer_resized = false;
}
bool Renderer::beginFrame()
@@ -136,9 +136,9 @@ namespace mlx
VkResult result = vkQueuePresentKHR(Render_Core::get().getQueue().getPresent(), &presentInfo);
if(result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR || _framebufferResized)
if(result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR || _framebuffer_resized)
{
_framebufferResized = false;
_framebuffer_resized = false;
recreateRenderData();
}
else if(result != VK_SUCCESS)

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/18 17:14:45 by maldavid #+# #+# */
/* Updated: 2024/01/20 08:18:53 by maldavid ### ########.fr */
/* Updated: 2024/03/14 16:34:20 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -109,7 +109,7 @@ namespace mlx
inline std::uint32_t getActiveImageIndex() noexcept { return _current_frame_index; }
inline std::uint32_t getImageIndex() noexcept { return _image_index; }
constexpr inline void requireFrameBufferResize() noexcept { _framebufferResized = true; }
constexpr inline void requireFrameBufferResize() noexcept { _framebuffer_resized = true; }
~Renderer() = default;
@@ -138,7 +138,7 @@ namespace mlx
std::uint32_t _current_frame_index = 0;
std::uint32_t _image_index = 0;
bool _framebufferResized = false;
bool _framebuffer_resized = false;
};
}

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/06 18:21:36 by maldavid #+# #+# */
/* Updated: 2024/01/16 08:22:39 by maldavid ### ########.fr */
/* Updated: 2024/03/14 17:06:01 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -71,7 +71,7 @@ namespace mlx
renderPassInfo.dependencyCount = static_cast<std::uint32_t>(subpassesDeps.size());
renderPassInfo.pDependencies = subpassesDeps.data();
VkResult res = vkCreateRenderPass(Render_Core::get().getDevice().get(), &renderPassInfo, nullptr, &_renderPass);
VkResult res = vkCreateRenderPass(Render_Core::get().getDevice().get(), &renderPassInfo, nullptr, &_render_pass);
if(res != VK_SUCCESS)
core::error::report(e_kind::fatal_error, "Vulkan : failed to create render pass, %s", RCore::verbaliseResultVk(res));
#ifdef DEBUG
@@ -87,7 +87,7 @@ namespace mlx
VkRenderPassBeginInfo renderPassInfo{};
renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
renderPassInfo.renderPass = _renderPass;
renderPassInfo.renderPass = _render_pass;
renderPassInfo.framebuffer = fb.get();
renderPassInfo.renderArea.offset = { 0, 0 };
renderPassInfo.renderArea.extent = { fb.getWidth(), fb.getHeight() };
@@ -110,8 +110,8 @@ namespace mlx
void RenderPass::destroy() noexcept
{
vkDestroyRenderPass(Render_Core::get().getDevice().get(), _renderPass, nullptr);
_renderPass = VK_NULL_HANDLE;
vkDestroyRenderPass(Render_Core::get().getDevice().get(), _render_pass, nullptr);
_render_pass = VK_NULL_HANDLE;
#ifdef DEBUG
core::error::report(e_kind::message, "Vulkan : destroyed a renderpass");
#endif

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/06 18:22:00 by maldavid #+# #+# */
/* Updated: 2024/01/03 15:28:25 by maldavid ### ########.fr */
/* Updated: 2024/03/14 17:05:40 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -27,11 +27,11 @@ namespace mlx
void begin(class CmdBuffer& cmd, class FrameBuffer& fb);
void end(class CmdBuffer& cmd);
inline VkRenderPass& operator()() noexcept { return _renderPass; }
inline VkRenderPass& get() noexcept { return _renderPass; }
inline VkRenderPass& operator()() noexcept { return _render_pass; }
inline VkRenderPass& get() noexcept { return _render_pass; }
private:
VkRenderPass _renderPass = VK_NULL_HANDLE;
VkRenderPass _render_pass = VK_NULL_HANDLE;
bool _is_running = false;
};
}

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/06 18:22:28 by maldavid #+# #+# */
/* Updated: 2024/01/03 13:18:25 by maldavid ### ########.fr */
/* Updated: 2024/03/14 17:08:19 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -23,18 +23,18 @@ namespace mlx
VkDevice device = Render_Core::get().getDevice().get();
_renderer = renderer;
_swapChainSupport = querySwapChainSupport(Render_Core::get().getDevice().getPhysicalDevice());
_swapchain_support = querySwapChainSupport(Render_Core::get().getDevice().getPhysicalDevice());
VkSurfaceFormatKHR surfaceFormat = renderer->getSurface().chooseSwapSurfaceFormat(_swapChainSupport.formats);
VkPresentModeKHR presentMode = chooseSwapPresentMode(_swapChainSupport.presentModes);
_extent = chooseSwapExtent(_swapChainSupport.capabilities);
VkSurfaceFormatKHR surfaceFormat = renderer->getSurface().chooseSwapSurfaceFormat(_swapchain_support.formats);
VkPresentModeKHR presentMode = chooseSwapPresentMode(_swapchain_support.present_modes);
_extent = chooseSwapExtent(_swapchain_support.capabilities);
std::uint32_t imageCount = _swapChainSupport.capabilities.minImageCount + 1;
if(_swapChainSupport.capabilities.maxImageCount > 0 && imageCount > _swapChainSupport.capabilities.maxImageCount)
imageCount = _swapChainSupport.capabilities.maxImageCount;
std::uint32_t imageCount = _swapchain_support.capabilities.minImageCount + 1;
if(_swapchain_support.capabilities.maxImageCount > 0 && imageCount > _swapchain_support.capabilities.maxImageCount)
imageCount = _swapchain_support.capabilities.maxImageCount;
Queues::QueueFamilyIndices indices = Render_Core::get().getQueue().findQueueFamilies(Render_Core::get().getDevice().getPhysicalDevice(), renderer->getSurface().get());
std::uint32_t queueFamilyIndices[] = { indices.graphicsFamily.value(), indices.presentFamily.value() };
std::uint32_t queueFamilyIndices[] = { indices.graphics_family.value(), indices.present_family.value() };
VkSwapchainCreateInfoKHR createInfo{};
createInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
@@ -45,12 +45,12 @@ namespace mlx
createInfo.imageExtent = _extent;
createInfo.imageArrayLayers = 1;
createInfo.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
createInfo.preTransform = _swapChainSupport.capabilities.currentTransform;
createInfo.preTransform = _swapchain_support.capabilities.currentTransform;
createInfo.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
createInfo.presentMode = presentMode;
createInfo.clipped = VK_TRUE;
createInfo.oldSwapchain = VK_NULL_HANDLE;
if(indices.graphicsFamily != indices.presentFamily)
if(indices.graphics_family != indices.present_family)
{
createInfo.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
createInfo.queueFamilyIndexCount = 2;
@@ -59,15 +59,15 @@ namespace mlx
else
createInfo.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
VkResult res = vkCreateSwapchainKHR(device, &createInfo, nullptr, &_swapChain);
VkResult res = vkCreateSwapchainKHR(device, &createInfo, nullptr, &_swapchain);
if(res != VK_SUCCESS)
core::error::report(e_kind::fatal_error, "Vulkan : failed to create the swapchain, %s", RCore::verbaliseResultVk(res));
std::vector<VkImage> tmp;
vkGetSwapchainImagesKHR(device, _swapChain, &imageCount, nullptr);
vkGetSwapchainImagesKHR(device, _swapchain, &imageCount, nullptr);
_images.resize(imageCount);
tmp.resize(imageCount);
vkGetSwapchainImagesKHR(device, _swapChain, &imageCount, tmp.data());
vkGetSwapchainImagesKHR(device, _swapchain, &imageCount, tmp.data());
for(std::size_t i = 0; i < imageCount; i++)
{
@@ -76,7 +76,7 @@ namespace mlx
_images[i].createImageView(VK_IMAGE_VIEW_TYPE_2D, VK_IMAGE_ASPECT_COLOR_BIT);
}
_swapChainImageFormat = surfaceFormat.format;
_swapchain_image_format = surfaceFormat.format;
#ifdef DEBUG
core::error::report(e_kind::message, "Vulkan : created new swapchain");
#endif
@@ -104,8 +104,8 @@ namespace mlx
if(presentModeCount != 0)
{
details.presentModes.resize(presentModeCount);
vkGetPhysicalDeviceSurfacePresentModesKHR(device, surface, &presentModeCount, details.presentModes.data());
details.present_modes.resize(presentModeCount);
vkGetPhysicalDeviceSurfacePresentModesKHR(device, surface, &presentModeCount, details.present_modes.data());
}
return details;
@@ -141,11 +141,11 @@ namespace mlx
void SwapChain::destroy() noexcept
{
if(_swapChain == VK_NULL_HANDLE)
if(_swapchain == VK_NULL_HANDLE)
return;
vkDeviceWaitIdle(Render_Core::get().getDevice().get());
vkDestroySwapchainKHR(Render_Core::get().getDevice().get(), _swapChain, nullptr);
_swapChain = VK_NULL_HANDLE;
vkDestroySwapchainKHR(Render_Core::get().getDevice().get(), _swapchain, nullptr);
_swapchain = VK_NULL_HANDLE;
for(Image& img : _images)
img.destroyImageView();
}

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/06 18:23:27 by maldavid #+# #+# */
/* Updated: 2024/01/03 15:28:39 by maldavid ### ########.fr */
/* Updated: 2024/03/14 17:06:41 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -31,7 +31,7 @@ namespace mlx
{
VkSurfaceCapabilitiesKHR capabilities;
std::vector<VkSurfaceFormatKHR> formats;
std::vector<VkPresentModeKHR> presentModes;
std::vector<VkPresentModeKHR> present_modes;
};
public:
@@ -45,21 +45,21 @@ namespace mlx
VkExtent2D chooseSwapExtent(const VkSurfaceCapabilitiesKHR& capabilities);
VkPresentModeKHR chooseSwapPresentMode([[maybe_unused]] const std::vector<VkPresentModeKHR> &availablePresentModes);
inline VkSwapchainKHR get() noexcept { return _swapChain; }
inline VkSwapchainKHR operator()() noexcept { return _swapChain; }
inline VkSwapchainKHR get() noexcept { return _swapchain; }
inline VkSwapchainKHR operator()() noexcept { return _swapchain; }
inline std::size_t getImagesNumber() const noexcept { return _images.size(); }
inline Image& getImage(std::size_t i) noexcept { return _images[i]; }
inline SwapChainSupportDetails getSupport() noexcept { return _swapChainSupport; }
inline SwapChainSupportDetails getSupport() noexcept { return _swapchain_support; }
inline VkExtent2D getExtent() noexcept { return _extent; }
inline VkFormat getImagesFormat() const noexcept { return _swapChainImageFormat; }
inline VkFormat getImagesFormat() const noexcept { return _swapchain_image_format; }
~SwapChain() = default;
private:
SwapChainSupportDetails _swapChainSupport;
VkSwapchainKHR _swapChain;
SwapChainSupportDetails _swapchain_support;
VkSwapchainKHR _swapchain;
std::vector<Image> _images;
VkFormat _swapChainImageFormat;
VkFormat _swapchain_image_format;
VkExtent2D _extent;
class Renderer* _renderer = nullptr;
};

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/10 11:59:57 by maldavid #+# #+# */
/* Updated: 2024/02/25 09:29:31 by maldavid ### ########.fr */
/* Updated: 2024/03/14 17:31:55 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -61,6 +61,6 @@ namespace mlx
text->destroy();
_invalid_ids.push_back(id);
}
// do not `_cache.clear();` as it releases the texts and may not destroy Vertex and Index buffers that are in use by command buffers
_cache.clear();
}
}

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/06 16:24:11 by maldavid #+# #+# */
/* Updated: 2024/02/25 07:58:36 by maldavid ### ########.fr */
/* Updated: 2024/03/14 17:08:43 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -19,12 +19,10 @@
#include <stb_truetype.h>
#include <cstdint>
#include <unordered_set>
#include <vector>
#include <mlx_profile.h>
#include <renderer/texts/text_descriptor.h>
#include <renderer/texts/text_library.h>
#include <renderer/texts/font_library.h>
#include <memory>
namespace mlx
{

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/08 19:20:13 by maldavid #+# #+# */
/* Updated: 2022/10/08 19:21:22 by maldavid ### ########.fr */
/* Updated: 2024/03/24 14:42:48 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -15,17 +15,17 @@
namespace mlx
{
class non_copyable
class NonCopyable
{
protected:
non_copyable() = default;
virtual ~non_copyable() = default;
NonCopyable() = default;
virtual ~NonCopyable() = default;
public:
non_copyable(const non_copyable&) = delete;
non_copyable(non_copyable&&) noexcept = default;
non_copyable &operator=(const non_copyable&) = delete;
non_copyable &operator=(non_copyable&&) noexcept = default;
NonCopyable(const NonCopyable&) = delete;
NonCopyable(NonCopyable&&) noexcept = default;
NonCopyable &operator=(const NonCopyable&) = delete;
NonCopyable &operator=(NonCopyable&&) noexcept = default;
};
}

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/08 19:18:46 by maldavid #+# #+# */
/* Updated: 2022/10/08 19:22:07 by maldavid ### ########.fr */
/* Updated: 2024/03/24 14:42:56 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -18,7 +18,7 @@
namespace mlx
{
template <typename T>
class Singleton : public non_copyable
class Singleton : public NonCopyable
{
public:
inline static T& get()