diff --git a/include/Nazara/VulkanRenderer/Utils.hpp b/include/Nazara/VulkanRenderer/Utils.hpp new file mode 100644 index 000000000..eb195b16c --- /dev/null +++ b/include/Nazara/VulkanRenderer/Utils.hpp @@ -0,0 +1,19 @@ +// Copyright (C) 2016 Jérôme Leclercq +// This file is part of the "Nazara Engine - Vulkan Renderer" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_UTILS_VULKAN_HPP +#define NAZARA_UTILS_VULKAN_HPP + +#include +#include +#include + +namespace Nz +{ + NAZARA_VULKANRENDERER_API String TranslateVulkanError(VkResult code); +} + +#endif // NAZARA_UTILS_VULKAN_HPP diff --git a/include/Nazara/VulkanRenderer/VkCommandBuffer.inl b/include/Nazara/VulkanRenderer/VkCommandBuffer.inl index 1e425f114..7721a7a74 100644 --- a/include/Nazara/VulkanRenderer/VkCommandBuffer.inl +++ b/include/Nazara/VulkanRenderer/VkCommandBuffer.inl @@ -42,7 +42,7 @@ namespace Nz m_lastErrorCode = m_pool->GetDevice()->vkBeginCommandBuffer(m_handle, &info); if (m_lastErrorCode != VkResult::VK_SUCCESS) { - NazaraError("Failed to begin command buffer"); + NazaraError("Failed to begin command buffer: " + TranslateVulkanError(m_lastErrorCode)); return false; } @@ -208,7 +208,7 @@ namespace Nz m_lastErrorCode = m_pool->GetDevice()->vkEndCommandBuffer(m_handle); if (m_lastErrorCode != VkResult::VK_SUCCESS) { - NazaraError("Failed to end command buffer"); + NazaraError("Failed to end command buffer: " + TranslateVulkanError(m_lastErrorCode)); return false; } diff --git a/include/Nazara/VulkanRenderer/VkDevice.inl b/include/Nazara/VulkanRenderer/VkDevice.inl index f18fde6a7..b5574958b 100644 --- a/include/Nazara/VulkanRenderer/VkDevice.inl +++ b/include/Nazara/VulkanRenderer/VkDevice.inl @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -91,7 +92,7 @@ namespace Nz m_lastErrorCode = vkDeviceWaitIdle(m_device); if (m_lastErrorCode != VkResult::VK_SUCCESS) { - NazaraError("Failed to wait for device idle"); + NazaraError("Failed to wait for device idle: " + TranslateVulkanError(m_lastErrorCode)); return false; } diff --git a/include/Nazara/VulkanRenderer/VkDeviceMemory.inl b/include/Nazara/VulkanRenderer/VkDeviceMemory.inl index 19ed76ccd..2b66fc1c5 100644 --- a/include/Nazara/VulkanRenderer/VkDeviceMemory.inl +++ b/include/Nazara/VulkanRenderer/VkDeviceMemory.inl @@ -4,6 +4,7 @@ #include #include +#include #include #include @@ -66,7 +67,7 @@ namespace Nz m_lastErrorCode = m_device->vkMapMemory(*m_device, m_handle, offset, size, flags, &m_mappedPtr); if (m_lastErrorCode != VK_SUCCESS) { - NazaraError("Failed to map device memory"); + NazaraError("Failed to map device memory: " + TranslateVulkanError(m_lastErrorCode)); return false; } diff --git a/include/Nazara/VulkanRenderer/VkDeviceObject.inl b/include/Nazara/VulkanRenderer/VkDeviceObject.inl index f238d199a..f46cfd256 100644 --- a/include/Nazara/VulkanRenderer/VkDeviceObject.inl +++ b/include/Nazara/VulkanRenderer/VkDeviceObject.inl @@ -2,8 +2,10 @@ // This file is part of the "Nazara Engine - Vulkan Renderer" // For conditions of distribution and use, see copyright notice in Config.hpp -#include +#include #include +#include +#include #include #include @@ -40,7 +42,7 @@ namespace Nz m_lastErrorCode = C::CreateHelper(m_device, &createInfo, allocator, &m_handle); if (m_lastErrorCode != VkResult::VK_SUCCESS) { - NazaraError("Failed to create Vulkan object"); + NazaraError("Failed to create Vulkan object: " + TranslateVulkanError(m_lastErrorCode)); return false; } @@ -90,4 +92,3 @@ namespace Nz } #include -#include "VkDeviceObject.hpp" diff --git a/include/Nazara/VulkanRenderer/VkImage.inl b/include/Nazara/VulkanRenderer/VkImage.inl index b4e0332cb..e7a675f26 100644 --- a/include/Nazara/VulkanRenderer/VkImage.inl +++ b/include/Nazara/VulkanRenderer/VkImage.inl @@ -3,6 +3,7 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include +#include #include namespace Nz @@ -14,7 +15,7 @@ namespace Nz m_lastErrorCode = m_device->vkBindImageMemory(*m_device, m_handle, memory, offset); if (m_lastErrorCode != VK_SUCCESS) { - NazaraError("Failed to bind buffer memory"); + NazaraError("Failed to bind image memory: " + TranslateVulkanError(m_lastErrorCode)); return false; } diff --git a/include/Nazara/VulkanRenderer/VkInstance.inl b/include/Nazara/VulkanRenderer/VkInstance.inl index 6de0929e9..5a842031b 100644 --- a/include/Nazara/VulkanRenderer/VkInstance.inl +++ b/include/Nazara/VulkanRenderer/VkInstance.inl @@ -4,6 +4,7 @@ #include #include +#include #include namespace Nz @@ -106,7 +107,7 @@ namespace Nz m_lastErrorCode = vkGetPhysicalDeviceImageFormatProperties(physicalDevice, format, type, tiling, usage, flags, imageFormatProperties); if (m_lastErrorCode != VkResult::VK_SUCCESS) { - NazaraError("Failed to get physical device image format properties"); + NazaraError("Failed to get physical device image format properties: " + TranslateVulkanError(m_lastErrorCode)); return false; } diff --git a/include/Nazara/VulkanRenderer/VkPipeline.inl b/include/Nazara/VulkanRenderer/VkPipeline.inl index 42c758f46..936a003a7 100644 --- a/include/Nazara/VulkanRenderer/VkPipeline.inl +++ b/include/Nazara/VulkanRenderer/VkPipeline.inl @@ -3,6 +3,7 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include +#include #include namespace Nz @@ -68,7 +69,7 @@ namespace Nz m_lastErrorCode = result; if (m_lastErrorCode != VkResult::VK_SUCCESS) { - NazaraError("Failed to create Vulkan object"); + NazaraError("Failed to create Vulkan object: " + TranslateVulkanError(m_lastErrorCode)); return false; } diff --git a/include/Nazara/VulkanRenderer/VkQueue.inl b/include/Nazara/VulkanRenderer/VkQueue.inl index 62b0c7984..c1d06ec4e 100644 --- a/include/Nazara/VulkanRenderer/VkQueue.inl +++ b/include/Nazara/VulkanRenderer/VkQueue.inl @@ -4,6 +4,7 @@ #include #include +#include #include #include @@ -51,7 +52,10 @@ namespace Nz { m_lastErrorCode = m_device->vkQueuePresentKHR(m_handle, &presentInfo); if (m_lastErrorCode != VkResult::VK_SUCCESS) + { + NazaraError("Failed to present queue: " + TranslateVulkanError(m_lastErrorCode)); return false; + } return true; } @@ -82,7 +86,10 @@ namespace Nz { m_lastErrorCode = m_device->vkQueueSubmit(m_handle, submitCount, submits, fence); if (m_lastErrorCode != VkResult::VK_SUCCESS) + { + NazaraError("Failed to submit queue: " + TranslateVulkanError(m_lastErrorCode)); return false; + } return true; } @@ -91,7 +98,10 @@ namespace Nz { m_lastErrorCode = m_device->vkQueueWaitIdle(m_handle); if (m_lastErrorCode != VkResult::VK_SUCCESS) + { + NazaraError("Failed to wait for queue: " + TranslateVulkanError(m_lastErrorCode)); return false; + } return true; } diff --git a/include/Nazara/VulkanRenderer/VkSurface.inl b/include/Nazara/VulkanRenderer/VkSurface.inl index efec9a34c..8b5ea7369 100644 --- a/include/Nazara/VulkanRenderer/VkSurface.inl +++ b/include/Nazara/VulkanRenderer/VkSurface.inl @@ -4,6 +4,7 @@ #include #include +#include #include #include @@ -181,7 +182,7 @@ namespace Nz m_lastErrorCode = m_instance.vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevice, m_surface, surfaceCapabilities); if (m_lastErrorCode != VkResult::VK_SUCCESS) { - NazaraError("Failed to query surface capabilities"); + NazaraError("Failed to query surface capabilities: " + TranslateVulkanError(m_lastErrorCode)); return false; } @@ -195,7 +196,7 @@ namespace Nz m_lastErrorCode = m_instance.vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, m_surface, &surfaceCount, nullptr); if (m_lastErrorCode != VkResult::VK_SUCCESS || surfaceCount == 0) { - NazaraError("Failed to query format count"); + NazaraError("Failed to query format count: " + TranslateVulkanError(m_lastErrorCode)); return false; } @@ -204,7 +205,7 @@ namespace Nz m_lastErrorCode = m_instance.vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, m_surface, &surfaceCount, surfaceFormats->data()); if (m_lastErrorCode != VkResult::VK_SUCCESS) { - NazaraError("Failed to query formats"); + NazaraError("Failed to query formats: " + TranslateVulkanError(m_lastErrorCode)); return false; } @@ -227,7 +228,7 @@ namespace Nz m_lastErrorCode = m_instance.vkGetPhysicalDeviceSurfacePresentModesKHR(physicalDevice, m_surface, &presentModeCount, presentModes->data()); if (m_lastErrorCode != VkResult::VK_SUCCESS) { - NazaraError("Failed to query present modes"); + NazaraError("Failed to query present modes: " + TranslateVulkanError(m_lastErrorCode)); return false; } @@ -240,7 +241,7 @@ namespace Nz m_lastErrorCode = m_instance.vkGetPhysicalDeviceSurfaceSupportKHR(physicalDevice, queueFamilyIndex, m_surface, &presentationSupported); if (m_lastErrorCode != VkResult::VK_SUCCESS) { - NazaraError("Failed to query surface capabilities"); + NazaraError("Failed to query surface capabilities: " + TranslateVulkanError(m_lastErrorCode)); return false; } @@ -296,7 +297,7 @@ namespace Nz { if (m_lastErrorCode != VkResult::VK_SUCCESS) { - NazaraError("Failed to create Vulkan surface"); + NazaraError("Failed to create Vulkan surface: " + TranslateVulkanError(m_lastErrorCode)); return false; } diff --git a/include/Nazara/VulkanRenderer/VkSwapchain.inl b/include/Nazara/VulkanRenderer/VkSwapchain.inl index a8e0ead36..363807859 100644 --- a/include/Nazara/VulkanRenderer/VkSwapchain.inl +++ b/include/Nazara/VulkanRenderer/VkSwapchain.inl @@ -4,6 +4,7 @@ #include #include +#include #include #include @@ -21,7 +22,10 @@ namespace Nz return true; default: + { + NazaraError("Failed to acquire next swapchain image: " + TranslateVulkanError(m_lastErrorCode)); return false; + } } } @@ -34,7 +38,7 @@ namespace Nz m_lastErrorCode = m_device->vkGetSwapchainImagesKHR(*m_device, m_handle, &imageCount, nullptr); if (m_lastErrorCode != VkResult::VK_SUCCESS || imageCount == 0) { - NazaraError("Failed to query swapchain image count"); + NazaraError("Failed to query swapchain image count: " + TranslateVulkanError(m_lastErrorCode)); return false; } @@ -42,7 +46,7 @@ namespace Nz m_lastErrorCode = m_device->vkGetSwapchainImagesKHR(*m_device, m_handle, &imageCount, images.data()); if (m_lastErrorCode != VkResult::VK_SUCCESS) { - NazaraError("Failed to query swapchain images"); + NazaraError("Failed to query swapchain images: " + TranslateVulkanError(m_lastErrorCode)); return false; } diff --git a/src/Nazara/VulkanRenderer/Utils_VulkanRenderer.cpp b/src/Nazara/VulkanRenderer/Utils_VulkanRenderer.cpp new file mode 100644 index 000000000..9d81fb4e5 --- /dev/null +++ b/src/Nazara/VulkanRenderer/Utils_VulkanRenderer.cpp @@ -0,0 +1,97 @@ +// Copyright (C) 2016 Jérôme Leclercq +// This file is part of the "Nazara Engine - Vulkan Renderer" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include + +namespace Nz +{ + String TranslateVulkanError(VkResult code) + { + // From https://www.khronos.org/registry/vulkan/specs/1.0-wsi_extensions/xhtml/vkspec.html#VkResult + switch (code) + { + case VK_SUCCESS: + return "No error"; + + case VK_NOT_READY: + return "A fence or query has not yet completed"; + + case VK_TIMEOUT: + return "A wait operation has not completed in the specified time"; + + case VK_EVENT_SET: + return "An event is signaled"; + + case VK_EVENT_RESET: + return "An event is unsignaled"; + + case VK_INCOMPLETE: + return "A return array was too small for the result"; + + case VK_ERROR_OUT_OF_HOST_MEMORY: + return "A host memory allocation has failed"; + + case VK_ERROR_OUT_OF_DEVICE_MEMORY: + return "A device memory allocation has failed"; + + case VK_ERROR_INITIALIZATION_FAILED: + return "Initialization of an object could not be completed for implementation-specific reasons"; + + case VK_ERROR_DEVICE_LOST: + return "The logical or physical device has been lost"; + + case VK_ERROR_MEMORY_MAP_FAILED: + return "Mapping of the memory object has failed"; + + case VK_ERROR_LAYER_NOT_PRESENT: + return "A requested layer is not present or could not be loaded"; + + case VK_ERROR_EXTENSION_NOT_PRESENT: + return "A requested extension is not supported"; + + case VK_ERROR_FEATURE_NOT_PRESENT: + return "A requested feature is not supported"; + + case VK_ERROR_INCOMPATIBLE_DRIVER: + return "The requested version of Vulkan is not supported by the driver or is otherwise incompatible for implementation-specific reasons"; + + case VK_ERROR_TOO_MANY_OBJECTS: + return "Too many objects of the type have already been created"; + + case VK_ERROR_FORMAT_NOT_SUPPORTED: + return "A requested format is not supported on this device"; + + case VK_ERROR_FRAGMENTED_POOL: + return "A requested pool allocation has failed due to fragmentation of the pool’s memory"; + + case VK_ERROR_SURFACE_LOST_KHR: + return "A surface is no longer available"; + + case VK_ERROR_NATIVE_WINDOW_IN_USE_KHR: + return "The requested window is already connected to a VkSurfaceKHR, or to some other non-Vulkan API"; + + case VK_SUBOPTIMAL_KHR: + return "A swapchain no longer matches the surface properties exactly, but can still be used to present to the surface successfully"; + + case VK_ERROR_OUT_OF_DATE_KHR: + return "A surface has changed in such a way that it is no longer compatible with the swapchain, and further presentation requests using the swapchain will fail. Applications must query the new surface properties and recreate their swapchain if they wish to continue presenting to the surface"; + + case VK_ERROR_INCOMPATIBLE_DISPLAY_KHR: + return "The display used by a swapchain does not use the same presentable image layout, or is incompatible in a way that prevents sharing an image"; + + case VK_ERROR_VALIDATION_FAILED_EXT: + return "A validation layer found an error"; + + case VK_ERROR_INVALID_SHADER_NV: + return "One or more shaders failed to compile or link"; + + default: + break; + } + + return "Unknown Vulkan error (0x" + String::Number(code, 16) + ')'; + } +} + diff --git a/src/Nazara/VulkanRenderer/VkInstance.cpp b/src/Nazara/VulkanRenderer/VkInstance.cpp index 411b8fa68..7daced8f1 100644 --- a/src/Nazara/VulkanRenderer/VkInstance.cpp +++ b/src/Nazara/VulkanRenderer/VkInstance.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include namespace Nz @@ -153,7 +154,7 @@ namespace Nz m_lastErrorCode = vkEnumeratePhysicalDevices(m_instance, &deviceCount, nullptr); if (m_lastErrorCode != VkResult::VK_SUCCESS || deviceCount == 0) { - NazaraError("Failed to query physical device count"); + NazaraError("Failed to query physical device count: " + TranslateVulkanError(m_lastErrorCode)); return false; } @@ -162,7 +163,7 @@ namespace Nz m_lastErrorCode = vkEnumeratePhysicalDevices(m_instance, &deviceCount, devices->data()); if (m_lastErrorCode != VkResult::VK_SUCCESS) { - NazaraError("Failed to query physical devices"); + NazaraError("Failed to query physical devices: " + TranslateVulkanError(m_lastErrorCode)); return false; } diff --git a/src/Nazara/VulkanRenderer/VkLoader.cpp b/src/Nazara/VulkanRenderer/VkLoader.cpp index 0da9a930a..8bc2bd05b 100644 --- a/src/Nazara/VulkanRenderer/VkLoader.cpp +++ b/src/Nazara/VulkanRenderer/VkLoader.cpp @@ -3,6 +3,7 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include +#include #include namespace Nz @@ -18,7 +19,7 @@ namespace Nz s_lastErrorCode = vkEnumerateInstanceExtensionProperties(layerName, &propertyCount, properties->data()); if (s_lastErrorCode != VkResult::VK_SUCCESS) { - NazaraError("Failed to get instance extension properties count"); + NazaraError("Failed to get instance extension properties count: " + TranslateVulkanError(s_lastErrorCode)); return false; } @@ -27,7 +28,7 @@ namespace Nz s_lastErrorCode = vkEnumerateInstanceExtensionProperties(layerName, &propertyCount, properties->data()); if (s_lastErrorCode != VkResult::VK_SUCCESS) { - NazaraError("Failed to enumerate instance extension properties"); + NazaraError("Failed to enumerate instance extension properties: " + TranslateVulkanError(s_lastErrorCode)); return false; } @@ -43,7 +44,7 @@ namespace Nz s_lastErrorCode = vkEnumerateInstanceLayerProperties(&propertyCount, properties->data()); if (s_lastErrorCode != VkResult::VK_SUCCESS) { - NazaraError("Failed to get instance layer properties count"); + NazaraError("Failed to get instance layer properties count: " + TranslateVulkanError(s_lastErrorCode)); return false; } @@ -52,7 +53,7 @@ namespace Nz s_lastErrorCode = vkEnumerateInstanceLayerProperties(&propertyCount, properties->data()); if (s_lastErrorCode != VkResult::VK_SUCCESS) { - NazaraError("Failed to enumerate instance layer properties"); + NazaraError("Failed to enumerate instance layer properties: " + TranslateVulkanError(s_lastErrorCode)); return false; }