Vulkan: Improve error handling

This commit is contained in:
Lynix
2016-10-12 15:08:02 +02:00
parent 61c8a2108a
commit 01a812a5de
14 changed files with 163 additions and 24 deletions

View File

@@ -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 <Nazara/Prerequesites.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/VulkanRenderer/VkLoader.hpp>
namespace Nz
{
NAZARA_VULKANRENDERER_API String TranslateVulkanError(VkResult code);
}
#endif // NAZARA_UTILS_VULKAN_HPP

View File

@@ -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;
}

View File

@@ -4,6 +4,7 @@
#include <Nazara/VulkanRenderer/VkDevice.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/VulkanRenderer/Utils.hpp>
#include <Nazara/VulkanRenderer/VkInstance.hpp>
#include <Nazara/VulkanRenderer/VkQueue.hpp>
#include <Nazara/VulkanRenderer/Debug.hpp>
@@ -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;
}

View File

@@ -4,6 +4,7 @@
#include <Nazara/VulkanRenderer/VkDeviceMemory.hpp>
#include <Nazara/VulkanRenderer/VkPhysicalDevice.hpp>
#include <Nazara/VulkanRenderer/Utils.hpp>
#include <Nazara/VulkanRenderer/Vulkan.hpp>
#include <Nazara/VulkanRenderer/Debug.hpp>
@@ -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;
}

View File

@@ -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 <Nazara/VulkanRenderer/VkCommandPool.hpp>
#include <Nazara/VulkanRenderer/VkDeviceObject.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/VulkanRenderer/Utils.hpp>
#include <Nazara/VulkanRenderer/VkCommandPool.hpp>
#include <Nazara/VulkanRenderer/VkDevice.hpp>
#include <Nazara/VulkanRenderer/Debug.hpp>
@@ -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 <Nazara/VulkanRenderer/DebugOff.hpp>
#include "VkDeviceObject.hpp"

View File

@@ -3,6 +3,7 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/VulkanRenderer/VkImage.hpp>
#include <Nazara/VulkanRenderer/Utils.hpp>
#include <Nazara/VulkanRenderer/Debug.hpp>
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;
}

View File

@@ -4,6 +4,7 @@
#include <Nazara/VulkanRenderer/VkInstance.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/VulkanRenderer/Utils.hpp>
#include <Nazara/VulkanRenderer/Debug.hpp>
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;
}

View File

@@ -3,6 +3,7 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/VulkanRenderer/VkPipeline.hpp>
#include <Nazara/VulkanRenderer/Utils.hpp>
#include <Nazara/VulkanRenderer/Debug.hpp>
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;
}

View File

@@ -4,6 +4,7 @@
#include <Nazara/VulkanRenderer/VkQueue.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/VulkanRenderer/Utils.hpp>
#include <Nazara/VulkanRenderer/VkDevice.hpp>
#include <Nazara/VulkanRenderer/Debug.hpp>
@@ -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;
}

View File

@@ -4,6 +4,7 @@
#include <Nazara/VulkanRenderer/VkSurface.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/VulkanRenderer/Utils.hpp>
#include <Nazara/VulkanRenderer/VkInstance.hpp>
#include <Nazara/VulkanRenderer/Debug.hpp>
@@ -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;
}

View File

@@ -4,6 +4,7 @@
#include <Nazara/VulkanRenderer/VkSwapchain.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/VulkanRenderer/Utils.hpp>
#include <Nazara/VulkanRenderer/VkDevice.hpp>
#include <Nazara/VulkanRenderer/Debug.hpp>
@@ -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;
}