improving vulkan error messages

This commit is contained in:
Kbz-8
2024-01-03 15:15:38 +01:00
parent d0a19c5312
commit 53048bd82a
15 changed files with 149 additions and 59 deletions

View File

@@ -6,7 +6,7 @@
/* By: kbz_8 <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/20 22:02:37 by kbz_8 #+# #+# */
/* Updated: 2023/12/27 21:31:04 by maldavid ### ########.fr */
/* Updated: 2024/01/03 13:09:40 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -76,18 +76,20 @@ namespace mlx
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 graphics memory allocator");
VkResult res = vmaCreateAllocator(&allocatorCreateInfo, &_allocator);
if(res != VK_SUCCESS)
core::error::report(e_kind::fatal_error, "Graphics allocator : failed to create graphics memory allocator, %s", RCore::verbaliseResultVk(res));
#ifdef DEBUG
core::error::report(e_kind::message, "Vulkan : created new allocator");
core::error::report(e_kind::message, "Graphics allocator : created new allocator");
#endif
}
VmaAllocation GPUallocator::createBuffer(const VkBufferCreateInfo* binfo, const VmaAllocationCreateInfo* vinfo, VkBuffer& buffer, const char* name) 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");
VkResult res = vmaCreateBuffer(_allocator, binfo, vinfo, &buffer, &allocation, nullptr);
if(res != VK_SUCCESS)
core::error::report(e_kind::fatal_error, "Graphics allocator : failed to allocate a buffer, %s", RCore::verbaliseResultVk(res));
if(name != nullptr)
vmaSetAllocationName(_allocator, allocation, name);
#ifdef DEBUG
@@ -110,8 +112,9 @@ namespace mlx
VmaAllocation GPUallocator::createImage(const VkImageCreateInfo* iminfo, const VmaAllocationCreateInfo* vinfo, VkImage& image, const char* name) 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");
VkResult res = vmaCreateImage(_allocator, iminfo, vinfo, &image, &allocation, nullptr);
if(res != VK_SUCCESS)
core::error::report(e_kind::fatal_error, "Graphics allocator : failed to allocate an image, %s", RCore::verbaliseResultVk(res));
if(name != nullptr)
vmaSetAllocationName(_allocator, allocation, name);
#ifdef DEBUG
@@ -133,8 +136,9 @@ namespace mlx
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");
VkResult res = vmaMapMemory(_allocator, allocation, data);
if(res != VK_SUCCESS)
core::error::report(e_kind::fatal_error, "Graphics allocator : unable to map GPU memory to CPU memory, %s", RCore::verbaliseResultVk(res));
}
void GPUallocator::unmapMemory(VmaAllocation allocation) noexcept

View File

@@ -6,30 +6,34 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/17 23:33:34 by maldavid #+# #+# */
/* Updated: 2023/12/15 20:32:01 by maldavid ### ########.fr */
/* Updated: 2024/01/03 13:47:13 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#define VOLK_IMPLEMENTATION
#if defined(_WIN32) || defined(_WIN64)
#if defined(MLX_PLAT_WINDOWS)
#define VK_USE_PLATFORM_WIN32_KHR
#elif defined(__APPLE__) || defined(__MACH__)
constexpr const char* VULKAN_LIB_NAME = "vulkan-1.dll";
#elif defined(MLX_PLAT_MACOS)
#define VK_USE_PLATFORM_MACOS_MVK
#define VK_USE_PLATFORM_METAL_EXT
constexpr const char* VULKAN_LIB_NAME = "libvulkan.dylib / libvulkan.1.dylib / libMoltenVK.dylib";
#else
#define VK_USE_PLATFORM_XLIB_KHR
#define VK_USE_PLATFORM_WAYLAND_KHR
constexpr const char* VULKAN_LIB_NAME = "libvulkan.so / libvulkan.so.1";
#endif
#include "render_core.h"
#include <mlx_profile.h>
#include <renderer/core/render_core.h>
#include <mutex>
#ifdef DEBUG
#ifndef MLX_COMPILER_MSVC
#warning "MLX is being compiled in debug mode, this activates Vulkan's validation layers and debug messages which may impact rendering performances"
#else
#ifdef MLX_COMPILER_MSVC
#pragma NOTE("MLX is being compiled in debug mode, this activates Vulkan's validation layers and debug messages which may impact rendering performances")
#else
#warning "MLX is being compiled in debug mode, this activates Vulkan's validation layers and debug messages which may impact rendering performances"
#endif
#endif
@@ -88,7 +92,8 @@ namespace mlx
void Render_Core::init()
{
volkInitialize();
if(volkInitialize() != VK_SUCCESS)
core::error::report(e_kind::fatal_error, "Vulkan loader : cannot load %s, are you sure Vulkan is installed on your system ?", VULKAN_LIB_NAME);
_instance.init();
volkLoadInstance(_instance.get());

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/19 14:05:25 by maldavid #+# #+# */
/* Updated: 2023/12/31 00:41:39 by maldavid ### ########.fr */
/* Updated: 2024/01/03 13:11:27 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -27,8 +27,9 @@ namespace mlx
VkDebugUtilsMessengerCreateInfoEXT createInfo{};
populateDebugMessengerCreateInfo(createInfo);
if(createDebugUtilsMessengerEXT(&createInfo, nullptr) != VK_SUCCESS)
core::error::report(e_kind::warning, "Vulkan : failed to set up debug messenger");
VkResult res = createDebugUtilsMessengerEXT(&createInfo, nullptr);
if(res != VK_SUCCESS)
core::error::report(e_kind::warning, "Vulkan : failed to set up debug messenger, %s", RCore::verbaliseResultVk(res));
#ifdef DEBUG
else
core::error::report(e_kind::message, "Vulkan : enabled validation layers");