Allow error message to be formatted

This commit is contained in:
SirLynix
2023-08-14 23:16:37 +02:00
committed by Jérôme Leclercq
parent 25957c4b7f
commit a741672a51
119 changed files with 707 additions and 490 deletions

View File

@@ -322,7 +322,7 @@ namespace Nz
if (!s_instance.Create(validationLevel, instanceInfo))
{
NazaraError("Failed to create instance: " + TranslateVulkanError(s_instance.GetLastErrorCode()));
NazaraError("failed to create instance: {0}", TranslateVulkanError(s_instance.GetLastErrorCode()));
return false;
}
@@ -606,7 +606,7 @@ namespace Nz
std::shared_ptr<VulkanDevice> device = std::make_shared<VulkanDevice>(s_instance, enabledFeatures, BuildRenderDeviceInfo(deviceInfo));
if (!device->Create(deviceInfo, createInfo))
{
NazaraError("Failed to create Vulkan Device: " + TranslateVulkanError(device->GetLastErrorCode()));
NazaraError("failed to create Vulkan Device: {0}", TranslateVulkanError(device->GetLastErrorCode()));
return {};
}

View File

@@ -79,7 +79,7 @@ namespace Nz
VkResult result = vmaMapMemory(m_device.GetMemoryAllocator(), m_allocation, &mappedPtr);
if (result != VK_SUCCESS)
{
NazaraError("Failed to map buffer: " + TranslateVulkanError(result));
NazaraError("failed to map buffer: {0}", TranslateVulkanError(result));
return nullptr;
}
@@ -101,7 +101,7 @@ namespace Nz
VkResult result = vmaCreateBuffer(m_device.GetMemoryAllocator(), &createInfo, &allocInfo, &m_stagingBuffer, &m_stagingAllocation, &allocationInfo);
if (result != VK_SUCCESS)
{
NazaraError("Failed to allocate staging buffer: " + TranslateVulkanError(result));
NazaraError("failed to allocate staging buffer: {0}", TranslateVulkanError(result));
return nullptr;
}

View File

@@ -483,7 +483,7 @@ namespace Nz
if (!framebuffer.Create(*m_swapchain.GetDevice(), frameBufferCreate))
{
NazaraError("Failed to create framebuffer for image #" + NumberToString(i) + ": " + TranslateVulkanError(framebuffer.GetLastErrorCode()));
NazaraError("failed to create framebuffer for image #{0}: {1}", i, TranslateVulkanError(framebuffer.GetLastErrorCode()));
return false;
}
@@ -495,10 +495,11 @@ namespace Nz
bool VulkanSwapchain::SetupRenderPass()
{
NazaraError("Test");
std::optional<PixelFormat> colorFormat = FromVulkan(m_surfaceFormat.format);
if (!colorFormat)
{
NazaraError("unhandled vulkan pixel format (0x" + NumberToString(m_surfaceFormat.format, 16) + ")");
NazaraError("unhandled vulkan pixel format ({0:#x})", UnderlyingCast(m_surfaceFormat.format));
return false;
}
@@ -508,7 +509,7 @@ namespace Nz
depthStencilFormat = FromVulkan(m_depthStencilFormat);
if (!depthStencilFormat)
{
NazaraError("unhandled vulkan pixel format (0x" + NumberToString(m_depthStencilFormat, 16) + ")");
NazaraError("unhandled vulkan pixel format ({0:#x})", UnderlyingCast(m_depthStencilFormat));
return false;
}
}
@@ -579,7 +580,7 @@ namespace Nz
if (!success)
{
NazaraError("Failed to create Vulkan surface: " + TranslateVulkanError(m_surface.GetLastErrorCode()));
NazaraError("failed to create Vulkan surface: {0}", TranslateVulkanError(m_surface.GetLastErrorCode()));
return false;
}
@@ -640,7 +641,7 @@ namespace Nz
Vk::Swapchain newSwapchain;
if (!newSwapchain.Create(m_device, swapchainInfo))
{
NazaraError("failed to create swapchain: " + TranslateVulkanError(newSwapchain.GetLastErrorCode()));
NazaraError("failed to create swapchain: {0}", TranslateVulkanError(newSwapchain.GetLastErrorCode()));
return false;
}

View File

@@ -57,7 +57,7 @@ namespace Nz
m_lastErrorCode = m_instance.vkCreateDevice(deviceInfo.physDevice, &createInfo, allocator, &m_device);
if (m_lastErrorCode != VkResult::VK_SUCCESS)
{
NazaraError("Failed to create Vulkan device: " + TranslateVulkanError(m_lastErrorCode));
NazaraError("failed to create Vulkan device: {0}", TranslateVulkanError(m_lastErrorCode));
return false;
}
@@ -81,7 +81,7 @@ namespace Nz
// Load all device-related functions
try
{
ErrorFlags flags(ErrorMode::ThrowException, true);
ErrorFlags flags(ErrorMode::ThrowException);
UInt32 deviceVersion = deviceInfo.properties.apiVersion;
@@ -103,7 +103,7 @@ namespace Nz
}
catch (const std::exception& e)
{
NazaraError(std::string("Failed to query device function: ") + e.what());
NazaraError("Failed to query device function: {0}", e.what());
return false;
}
@@ -173,7 +173,7 @@ namespace Nz
Vk::CommandPool& commandPool = m_internalData->commandPools[queueType];
if (!commandPool.Create(*this, m_defaultQueues[queueType], VK_COMMAND_POOL_CREATE_TRANSIENT_BIT))
{
NazaraError("Failed to create command pool: " + TranslateVulkanError(commandPool.GetLastErrorCode()));
NazaraError("failed to create command pool: {0}", TranslateVulkanError(commandPool.GetLastErrorCode()));
return false;
}
}
@@ -237,7 +237,7 @@ namespace Nz
m_lastErrorCode = vmaCreateAllocator(&allocatorInfo, &m_memAllocator);
if (m_lastErrorCode != VK_SUCCESS)
{
NazaraError("Failed to initialize Vulkan Memory Allocator (VMA): " + TranslateVulkanError(m_lastErrorCode));
NazaraError("failed to initialize Vulkan Memory Allocator (VMA): {0}", TranslateVulkanError(m_lastErrorCode));
return false;
}

View File

@@ -144,7 +144,7 @@ namespace Nz::Vk
m_lastErrorCode = Loader::vkCreateInstance(&createInfo, allocator, &m_instance);
if (m_lastErrorCode != VkResult::VK_SUCCESS)
{
NazaraError("Failed to create Vulkan instance: " + TranslateVulkanError(m_lastErrorCode));
NazaraError("failed to create Vulkan instance: {0}", TranslateVulkanError(m_lastErrorCode));
return false;
}
@@ -167,7 +167,7 @@ namespace Nz::Vk
// And now load everything
try
{
ErrorFlags flags(ErrorMode::ThrowException, true);
ErrorFlags flags(ErrorMode::ThrowException);
#define NAZARA_VULKANRENDERER_INSTANCE_EXT_BEGIN(ext) if (IsExtensionLoaded(#ext)) { \
NazaraDebug(#ext " extension is supported");
@@ -186,7 +186,7 @@ namespace Nz::Vk
}
catch (const std::exception& e)
{
NazaraError(std::string("Failed to query instance function: ") + e.what());
NazaraError("Failed to query instance function: {0}", e.what());
return false;
}
@@ -205,7 +205,7 @@ namespace Nz::Vk
m_lastErrorCode = vkEnumeratePhysicalDevices(m_instance, &deviceCount, nullptr);
if (m_lastErrorCode != VkResult::VK_SUCCESS || deviceCount == 0)
{
NazaraError("Failed to query physical device count: " + TranslateVulkanError(m_lastErrorCode));
NazaraError("failed to query physical device count: {0}", TranslateVulkanError(m_lastErrorCode));
return false;
}
@@ -214,7 +214,7 @@ namespace Nz::Vk
m_lastErrorCode = vkEnumeratePhysicalDevices(m_instance, &deviceCount, devices->data());
if (m_lastErrorCode != VkResult::VK_SUCCESS)
{
NazaraError("Failed to query physical devices: " + TranslateVulkanError(m_lastErrorCode));
NazaraError("failed to query physical devices: {0}", TranslateVulkanError(m_lastErrorCode));
return false;
}
@@ -230,7 +230,7 @@ namespace Nz::Vk
m_lastErrorCode = vkEnumerateDeviceExtensionProperties(device, nullptr, &extensionPropertyCount, nullptr);
if (m_lastErrorCode != VkResult::VK_SUCCESS)
{
NazaraError("Failed to query extension properties count: " + TranslateVulkanError(m_lastErrorCode));
NazaraError("failed to query extension properties count: {0}", TranslateVulkanError(m_lastErrorCode));
return false;
}
@@ -242,7 +242,7 @@ namespace Nz::Vk
m_lastErrorCode = vkEnumerateDeviceExtensionProperties(device, nullptr, &extensionPropertyCount, extensionProperties->data());
if (m_lastErrorCode != VkResult::VK_SUCCESS)
{
NazaraError("Failed to query extension properties count: " + TranslateVulkanError(m_lastErrorCode));
NazaraError("failed to query extension properties count: {0}", TranslateVulkanError(m_lastErrorCode));
return false;
}

View File

@@ -21,7 +21,7 @@ namespace Nz
s_lastErrorCode = vkEnumerateInstanceExtensionProperties(layerName, &propertyCount, nullptr);
if (s_lastErrorCode != VkResult::VK_SUCCESS)
{
NazaraError("Failed to get instance extension properties count: " + TranslateVulkanError(s_lastErrorCode));
NazaraError("failed to get instance extension properties count: {0}", TranslateVulkanError(s_lastErrorCode));
return false;
}
@@ -30,7 +30,7 @@ namespace Nz
s_lastErrorCode = vkEnumerateInstanceExtensionProperties(layerName, &propertyCount, properties->data());
if (s_lastErrorCode != VkResult::VK_SUCCESS)
{
NazaraError("Failed to enumerate instance extension properties: " + TranslateVulkanError(s_lastErrorCode));
NazaraError("failed to enumerate instance extension properties: {0}", TranslateVulkanError(s_lastErrorCode));
return false;
}
@@ -46,7 +46,7 @@ namespace Nz
s_lastErrorCode = vkEnumerateInstanceLayerProperties(&propertyCount, nullptr);
if (s_lastErrorCode != VkResult::VK_SUCCESS)
{
NazaraError("Failed to get instance layer properties count: " + TranslateVulkanError(s_lastErrorCode));
NazaraError("failed to get instance layer properties count: {0}", TranslateVulkanError(s_lastErrorCode));
return false;
}
@@ -55,7 +55,7 @@ namespace Nz
s_lastErrorCode = vkEnumerateInstanceLayerProperties(&propertyCount, properties->data());
if (s_lastErrorCode != VkResult::VK_SUCCESS)
{
NazaraError("Failed to enumerate instance layer properties: " + TranslateVulkanError(s_lastErrorCode));
NazaraError("failed to enumerate instance layer properties: {0}", TranslateVulkanError(s_lastErrorCode));
return false;
}
@@ -76,7 +76,7 @@ namespace Nz
if (!s_vulkanLib.IsLoaded())
{
NazaraError("Failed to open vulkan library: " + s_vulkanLib.GetLastError());
NazaraError("failed to open vulkan library: {0}", s_vulkanLib.GetLastError());
return false;
}
@@ -84,7 +84,7 @@ namespace Nz
vkGetInstanceProcAddr = reinterpret_cast<PFN_vkGetInstanceProcAddr>(s_vulkanLib.GetSymbol("vkGetInstanceProcAddr"));
if (!vkGetInstanceProcAddr)
{
NazaraError("Failed to get symbol \"vkGetInstanceProcAddr\": " + s_vulkanLib.GetLastError());
NazaraError("Failed to get symbol \"vkGetInstanceProcAddr\": {0}", s_vulkanLib.GetLastError());
return false;
}
@@ -92,7 +92,7 @@ namespace Nz
{
PFN_vkVoidFunction func = vkGetInstanceProcAddr(nullptr, name);
if (!func && !opt)
NazaraError("Failed to get " + std::string(name) + " address");
NazaraError("Failed to get {0} address", name);
return func;
};
@@ -101,7 +101,7 @@ namespace Nz
#define NAZARA_VULKANRENDERER_LOAD_GLOBAL(func) func = reinterpret_cast<PFN_##func>(GetProcAddr(#func))
try
{
ErrorFlags flags(ErrorMode::ThrowException, true);
ErrorFlags flags(ErrorMode::ThrowException);
#define NAZARA_VULKANRENDERER_GLOBAL_FUNCTION(func) func = reinterpret_cast<PFN_##func>(GetProcAddr(#func, false));
#define NAZARA_VULKANRENDERER_GLOBAL_FUNCTION_OPT(func) func = reinterpret_cast<PFN_##func>(GetProcAddr(#func, true));
@@ -111,7 +111,7 @@ namespace Nz
}
catch (const std::exception& e)
{
NazaraError(std::string("Failed to query device function: ") + e.what());
NazaraError("Failed to query device function: {0}", e.what());
return false;
}