Split error macro into two versions (format vs non-formating) to allow format checking at compile-time

This commit is contained in:
SirLynix
2023-11-02 15:18:03 +01:00
parent 8fb53f467b
commit 4b8a475bbd
133 changed files with 570 additions and 557 deletions

View File

@@ -92,7 +92,7 @@ namespace Nz
break;
default:
NazaraWarning("Device {0} has handled device type ({1:#x})", deviceInfo.name, UnderlyingCast(physDevice.properties.deviceType));
NazaraWarningFmt("Device {0} has handled device type ({1:#x})", deviceInfo.name, UnderlyingCast(physDevice.properties.deviceType));
[[fallthrough]];
case VK_PHYSICAL_DEVICE_TYPE_OTHER:
deviceInfo.type = RenderDeviceType::Unknown;
@@ -121,7 +121,7 @@ namespace Nz
}
// This cannot happen if physDevice is valid, as we retrieved every physical device
NazaraInternalError("Invalid physical device: {0}", static_cast<void*>(physDevice));
NazaraInternalErrorFmt("Invalid physical device: {0}", static_cast<void*>(physDevice));
static Vk::PhysicalDevice dummy;
return dummy;
@@ -206,7 +206,7 @@ namespace Nz
enabledLayers.push_back(additionalLayers.back().c_str());
}
else
NazaraWarning("missing parameter {0}", parameterName);
NazaraWarningFmt("missing parameter {0}", parameterName);
}
}
@@ -269,7 +269,7 @@ namespace Nz
enabledExtensions.push_back(additionalExtensions.back().c_str());
}
else
NazaraWarning("missing parameter {0}", parameterName);
NazaraWarningFmt("missing parameter {0}", parameterName);
}
}
@@ -323,7 +323,7 @@ namespace Nz
if (!s_instance.Create(validationLevel, instanceInfo))
{
NazaraError("failed to create instance: {0}", TranslateVulkanError(s_instance.GetLastErrorCode()));
NazaraErrorFmt("failed to create instance: {0}", TranslateVulkanError(s_instance.GetLastErrorCode()));
return false;
}
@@ -340,7 +340,7 @@ namespace Nz
Vk::PhysicalDevice deviceInfo;
if (!s_instance.GetPhysicalDeviceQueueFamilyProperties(physDevice, &deviceInfo.queueFamilies))
{
NazaraWarning("failed to query physical device queue family properties for {0} ({1:#x})", deviceInfo.properties.deviceName, deviceInfo.properties.deviceID);
NazaraWarningFmt("failed to query physical device queue family properties for {0} ({1:#x})", deviceInfo.properties.deviceName, deviceInfo.properties.deviceID);
continue;
}
@@ -357,7 +357,7 @@ namespace Nz
deviceInfo.extensions.emplace(extProperty.extensionName);
}
else
NazaraWarning("failed to query physical device extensions for {0} ({1:#x})", deviceInfo.properties.deviceName, deviceInfo.properties.deviceID);
NazaraWarningFmt("failed to query physical device extensions for {0} ({1:#x})", deviceInfo.properties.deviceName, deviceInfo.properties.deviceID);
s_physDevices.emplace_back(std::move(deviceInfo));
}
@@ -430,7 +430,7 @@ namespace Nz
{
bool supportPresentation = false;
if (!surface.GetSupportPresentation(deviceInfo.physDevice, i, &supportPresentation))
NazaraWarning("failed to get presentation support of queue family #{0}", i);
NazaraWarningFmt("failed to get presentation support of queue family #{0}", i);
if (deviceInfo.queueFamilies[i].queueFlags & VK_QUEUE_GRAPHICS_BIT)
{
@@ -540,7 +540,7 @@ namespace Nz
enabledLayers.push_back(additionalLayers.back().c_str());
}
else
NazaraWarning("missing parameter {0}", parameterName);
NazaraWarningFmt("missing parameter {0}", parameterName);
}
}
@@ -577,7 +577,7 @@ namespace Nz
enabledExtensions.push_back(additionalExtensions.back().c_str());
}
else
NazaraWarning("missing parameter {0}", parameterName);
NazaraWarningFmt("missing parameter {0}", parameterName);
}
}
@@ -607,7 +607,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: {0}", TranslateVulkanError(device->GetLastErrorCode()));
NazaraErrorFmt("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: {0}", TranslateVulkanError(result));
NazaraErrorFmt("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: {0}", TranslateVulkanError(result));
NazaraErrorFmt("failed to allocate staging buffer: {0}", TranslateVulkanError(result));
return nullptr;
}

View File

@@ -274,13 +274,13 @@ namespace Nz
{
if (!SetupSwapchain(m_device.GetPhysicalDeviceInfo()))
{
NazaraError("Failed to create swapchain");
NazaraError("failed to create swapchain");
return false;
}
if (m_depthStencilFormat != VK_FORMAT_MAX_ENUM && !SetupDepthBuffer())
{
NazaraError("Failed to create depth buffer");
NazaraError("failed to create depth buffer");
return false;
}
@@ -402,20 +402,20 @@ namespace Nz
if (!m_depthBuffer.Create(m_device, imageCreateInfo))
{
NazaraError("Failed to create depth buffer");
NazaraError("failed to create depth buffer");
return false;
}
VkMemoryRequirements memoryReq = m_depthBuffer.GetMemoryRequirements();
if (!m_depthBufferMemory.Create(m_device, memoryReq.size, memoryReq.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT))
{
NazaraError("Failed to allocate depth buffer memory");
NazaraError("failed to allocate depth buffer memory");
return false;
}
if (!m_depthBuffer.BindImageMemory(m_depthBufferMemory))
{
NazaraError("Failed to bind depth buffer to buffer");
NazaraError("failed to bind depth buffer to buffer");
return false;
}
@@ -451,7 +451,7 @@ namespace Nz
if (!m_depthBufferView.Create(m_device, imageViewCreateInfo))
{
NazaraError("Failed to create depth buffer view");
NazaraError("failed to create depth buffer view");
return false;
}
@@ -484,7 +484,7 @@ namespace Nz
if (!framebuffer.Create(*m_swapchain.GetDevice(), frameBufferCreate))
{
NazaraError("failed to create framebuffer for image #{0}: {1}", i, TranslateVulkanError(framebuffer.GetLastErrorCode()));
NazaraErrorFmt("failed to create framebuffer for image #{0}: {1}", i, TranslateVulkanError(framebuffer.GetLastErrorCode()));
return false;
}
@@ -499,7 +499,7 @@ namespace Nz
std::optional<PixelFormat> colorFormat = FromVulkan(m_surfaceFormat.format);
if (!colorFormat)
{
NazaraError("unhandled vulkan pixel format ({0:#x})", UnderlyingCast(m_surfaceFormat.format));
NazaraErrorFmt("unhandled vulkan pixel format ({0:#x})", UnderlyingCast(m_surfaceFormat.format));
return false;
}
@@ -509,7 +509,7 @@ namespace Nz
depthStencilFormat = FromVulkan(m_depthStencilFormat);
if (!depthStencilFormat)
{
NazaraError("unhandled vulkan pixel format ({0:#x})", UnderlyingCast(m_depthStencilFormat));
NazaraErrorFmt("unhandled vulkan pixel format ({0:#x})", UnderlyingCast(m_depthStencilFormat));
return false;
}
}
@@ -580,7 +580,7 @@ namespace Nz
if (!success)
{
NazaraError("failed to create Vulkan surface: {0}", TranslateVulkanError(m_surface.GetLastErrorCode()));
NazaraErrorFmt("failed to create Vulkan surface: {0}", TranslateVulkanError(m_surface.GetLastErrorCode()));
return false;
}
@@ -592,7 +592,7 @@ namespace Nz
VkSurfaceCapabilitiesKHR surfaceCapabilities;
if (!m_surface.GetCapabilities(deviceInfo.physDevice, &surfaceCapabilities))
{
NazaraError("Failed to query surface capabilities");
NazaraError("failed to query surface capabilities");
return false;
}
@@ -641,7 +641,7 @@ namespace Nz
Vk::Swapchain newSwapchain;
if (!newSwapchain.Create(m_device, swapchainInfo))
{
NazaraError("failed to create swapchain: {0}", TranslateVulkanError(newSwapchain.GetLastErrorCode()));
NazaraErrorFmt("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: {0}", TranslateVulkanError(m_lastErrorCode));
NazaraErrorFmt("failed to create Vulkan device: {0}", TranslateVulkanError(m_lastErrorCode));
return false;
}
@@ -103,7 +103,7 @@ namespace Nz
}
catch (const std::exception& e)
{
NazaraError("Failed to query device function: {0}", e.what());
NazaraErrorFmt("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: {0}", TranslateVulkanError(commandPool.GetLastErrorCode()));
NazaraErrorFmt("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): {0}", TranslateVulkanError(m_lastErrorCode));
NazaraErrorFmt("failed to initialize Vulkan Memory Allocator (VMA): {0}", TranslateVulkanError(m_lastErrorCode));
return false;
}

View File

@@ -131,7 +131,7 @@ namespace Nz::Vk
m_lastErrorCode = Loader::vkCreateInstance(&createInfo, allocator, &m_instance);
if (m_lastErrorCode != VkResult::VK_SUCCESS)
{
NazaraError("failed to create Vulkan instance: {0}", TranslateVulkanError(m_lastErrorCode));
NazaraErrorFmt("failed to create Vulkan instance: {0}", TranslateVulkanError(m_lastErrorCode));
return false;
}
@@ -173,7 +173,7 @@ namespace Nz::Vk
}
catch (const std::exception& e)
{
NazaraError("Failed to query instance function: {0}", e.what());
NazaraErrorFmt("Failed to query instance function: {0}", e.what());
return false;
}
@@ -192,7 +192,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: {0}", TranslateVulkanError(m_lastErrorCode));
NazaraErrorFmt("failed to query physical device count: {0}", TranslateVulkanError(m_lastErrorCode));
return false;
}
@@ -201,7 +201,7 @@ namespace Nz::Vk
m_lastErrorCode = vkEnumeratePhysicalDevices(m_instance, &deviceCount, devices->data());
if (m_lastErrorCode != VkResult::VK_SUCCESS)
{
NazaraError("failed to query physical devices: {0}", TranslateVulkanError(m_lastErrorCode));
NazaraErrorFmt("failed to query physical devices: {0}", TranslateVulkanError(m_lastErrorCode));
return false;
}
@@ -217,7 +217,7 @@ namespace Nz::Vk
m_lastErrorCode = vkEnumerateDeviceExtensionProperties(device, nullptr, &extensionPropertyCount, nullptr);
if (m_lastErrorCode != VkResult::VK_SUCCESS)
{
NazaraError("failed to query extension properties count: {0}", TranslateVulkanError(m_lastErrorCode));
NazaraErrorFmt("failed to query extension properties count: {0}", TranslateVulkanError(m_lastErrorCode));
return false;
}
@@ -229,7 +229,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: {0}", TranslateVulkanError(m_lastErrorCode));
NazaraErrorFmt("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: {0}", TranslateVulkanError(s_lastErrorCode));
NazaraErrorFmt("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: {0}", TranslateVulkanError(s_lastErrorCode));
NazaraErrorFmt("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: {0}", TranslateVulkanError(s_lastErrorCode));
NazaraErrorFmt("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: {0}", TranslateVulkanError(s_lastErrorCode));
NazaraErrorFmt("failed to enumerate instance layer properties: {0}", TranslateVulkanError(s_lastErrorCode));
return false;
}
@@ -97,7 +97,7 @@ namespace Nz
vkGetInstanceProcAddr = reinterpret_cast<PFN_vkGetInstanceProcAddr>(s_vulkanLib.GetSymbol("vkGetInstanceProcAddr"));
if (!vkGetInstanceProcAddr)
{
NazaraError("Failed to get symbol \"vkGetInstanceProcAddr\": {0}", s_vulkanLib.GetLastError());
NazaraErrorFmt("Failed to get symbol \"vkGetInstanceProcAddr\": {0}", s_vulkanLib.GetLastError());
continue;
}
@@ -105,7 +105,7 @@ namespace Nz
{
PFN_vkVoidFunction func = vkGetInstanceProcAddr(nullptr, name);
if (!func && !opt)
NazaraError("Failed to get {0} address", name);
NazaraErrorFmt("Failed to get {0} address", name);
return func;
};
@@ -123,7 +123,7 @@ namespace Nz
}
catch (const std::exception& e)
{
NazaraError("Failed to query device function: {0}", e.what());
NazaraErrorFmt("Failed to query device function: {0}", e.what());
return false;
}
}