Stringify error values

This commit is contained in:
Attila Uygun 2023-05-16 09:06:58 +02:00
parent 0a2f1bd7c3
commit beba055645
2 changed files with 77 additions and 62 deletions

View File

@ -18,6 +18,7 @@
#include "third_party/glslang/glslang/Include/Types.h"
#include "third_party/glslang/glslang/Public/ShaderLang.h"
#include "third_party/spirv-reflect/spirv_reflect.h"
#include "third_party/vulkan/vk_enum_string_helper.h"
using namespace base;
@ -345,7 +346,7 @@ std::pair<int, int> GetBlockSizeForImageFormat(VkFormat format) {
default:
break;
}
NOTREACHED << "Invalid format: " << format;
NOTREACHED << "Invalid format: " << string_VkFormat(format);
return {0, 0};
}
@ -361,7 +362,7 @@ std::pair<int, int> GetNumBlocksForImageFormat(VkFormat format,
default:
break;
}
NOTREACHED << "Invalid format: " << format;
NOTREACHED << "Invalid format: " << string_VkFormat(format);
return {width, height};
}
@ -865,14 +866,14 @@ bool RendererVulkan::InitializeInternal() {
VkResult err = vkCreateCommandPool(device_, &cmd_pool_info, nullptr,
&frames_[i].setup_command_pool);
if (err) {
DLOG << "vkCreateCommandPool failed with error " << std::to_string(err);
DLOG << "vkCreateCommandPool failed with error " << string_VkResult(err);
return false;
}
err = vkCreateCommandPool(device_, &cmd_pool_info, nullptr,
&frames_[i].draw_command_pool);
if (err) {
DLOG << "vkCreateCommandPool failed with error " << std::to_string(err);
DLOG << "vkCreateCommandPool failed with error " << string_VkResult(err);
return false;
}
@ -888,7 +889,7 @@ bool RendererVulkan::InitializeInternal() {
&frames_[i].setup_command_buffer);
if (err) {
DLOG << "vkAllocateCommandBuffers failed with error "
<< std::to_string(err);
<< string_VkResult(err);
continue;
}
@ -897,7 +898,7 @@ bool RendererVulkan::InitializeInternal() {
&frames_[i].draw_command_buffer);
if (err) {
DLOG << "vkAllocateCommandBuffers failed with error "
<< std::to_string(err);
<< string_VkResult(err);
continue;
}
}
@ -918,10 +919,10 @@ bool RendererVulkan::InitializeInternal() {
ds_layout_info.bindingCount = 1;
ds_layout_info.pBindings = &ds_layout_binding;
VkResult res = vkCreateDescriptorSetLayout(device_, &ds_layout_info, nullptr,
VkResult err = vkCreateDescriptorSetLayout(device_, &ds_layout_info, nullptr,
&descriptor_set_layout_);
if (res) {
DLOG << "Error (" << std::to_string(res)
if (err) {
DLOG << "Error (" << string_VkResult(err)
<< ") creating descriptor set layout for set";
return false;
}
@ -947,9 +948,9 @@ bool RendererVulkan::InitializeInternal() {
sampler_info.borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK;
sampler_info.unnormalizedCoordinates = VK_FALSE;
res = vkCreateSampler(device_, &sampler_info, nullptr, &sampler_);
if (res) {
DLOG << "vkCreateSampler failed with error " << std::to_string(res);
err = vkCreateSampler(device_, &sampler_info, nullptr, &sampler_);
if (err) {
DLOG << "vkCreateSampler failed with error " << string_VkResult(err);
return false;
}
@ -1036,14 +1037,14 @@ void RendererVulkan::BeginFrame() {
VkResult err = vkBeginCommandBuffer(
frames_[current_frame_].setup_command_buffer, &cmdbuf_begin);
if (err) {
DLOG << "vkBeginCommandBuffer failed with error " << std::to_string(err);
DLOG << "vkBeginCommandBuffer failed with error " << string_VkResult(err);
return;
}
err = vkBeginCommandBuffer(frames_[current_frame_].draw_command_buffer,
&cmdbuf_begin);
if (err) {
DLOG << "vkBeginCommandBuffer failed with error " << std::to_string(err);
DLOG << "vkBeginCommandBuffer failed with error " << string_VkResult(err);
return;
}
@ -1074,7 +1075,7 @@ void RendererVulkan::FlushSetupBuffer() {
VkResult err = vkBeginCommandBuffer(
frames_[current_frame_].setup_command_buffer, &cmdbuf_begin);
if (err) {
DLOG << "vkBeginCommandBuffer failed with error " << std::to_string(err);
DLOG << "vkBeginCommandBuffer failed with error " << string_VkResult(err);
return;
}
context_.AppendCommandBuffer(frames_[current_frame_].setup_command_buffer,
@ -1287,7 +1288,7 @@ bool RendererVulkan::InsertStagingBuffer() {
&std::get<0>(block.buffer),
&std::get<1>(block.buffer), &block.alloc_info);
if (err) {
DLOG << "vmaCreateBuffer failed with error " << std::to_string(err);
DLOG << "vmaCreateBuffer failed with error " << string_VkResult(err);
return false;
}
@ -1325,11 +1326,11 @@ RendererVulkan::DescPool* RendererVulkan::AllocateDescriptorPool() {
descriptor_pool_create_info.pPoolSizes = &sizes;
VkDescriptorPool desc_pool;
VkResult res = vkCreateDescriptorPool(device_, &descriptor_pool_create_info,
VkResult err = vkCreateDescriptorPool(device_, &descriptor_pool_create_info,
nullptr, &desc_pool);
if (res) {
if (err) {
DLOG << "vkCreateDescriptorPool failed with error "
<< std::to_string(res);
<< string_VkResult(err);
return VK_NULL_HANDLE;
}
@ -1385,7 +1386,7 @@ bool RendererVulkan::AllocateBuffer(Buffer<VkBuffer>& buffer,
&vk_buffer, &allocation, nullptr);
if (err) {
DLOG << "Can't create buffer of size: " << std::to_string(size)
<< ", error " << std::to_string(err);
<< ", error " << string_VkResult(err);
return false;
}
@ -1501,7 +1502,7 @@ bool RendererVulkan::AllocateImage(Buffer<VkImage>& image,
VkResult err = vmaCreateImage(allocator_, &image_create_info, &allocInfo,
&vk_image, &allocation, nullptr);
if (err) {
DLOG << "vmaCreateImage failed with error " << std::to_string(err);
DLOG << "vmaCreateImage failed with error " << string_VkResult(err);
return false;
}
@ -1527,7 +1528,7 @@ bool RendererVulkan::AllocateImage(Buffer<VkImage>& image,
if (err) {
vmaDestroyImage(allocator_, vk_image, allocation);
DLOG << "vkCreateImageView failed with error " << std::to_string(err);
DLOG << "vkCreateImageView failed with error " << string_VkResult(err);
return false;
}
@ -1544,11 +1545,11 @@ bool RendererVulkan::AllocateImage(Buffer<VkImage>& image,
descriptor_set_allocate_info.pSetLayouts = &descriptor_set_layout_;
VkDescriptorSet descriptor_set;
VkResult res = vkAllocateDescriptorSets(
device_, &descriptor_set_allocate_info, &descriptor_set);
if (res) {
err = vkAllocateDescriptorSets(device_, &descriptor_set_allocate_info,
&descriptor_set);
if (err) {
--std::get<1>(*desc_pool);
DLOG << "Cannot allocate descriptor sets, error " << std::to_string(res);
DLOG << "Cannot allocate descriptor sets, error " << string_VkResult(err);
return false;
}

View File

@ -214,7 +214,8 @@ bool VulkanContext::CreateValidationLayers() {
uint32_t instance_layer_count = 0;
err = vkEnumerateInstanceLayerProperties(&instance_layer_count, nullptr);
if (err) {
DLOG << "vkEnumerateInstanceLayerProperties failed. Error: " << err;
DLOG << "vkEnumerateInstanceLayerProperties failed. Error: "
<< string_VkResult(err);
return false;
}
@ -227,7 +228,8 @@ bool VulkanContext::CreateValidationLayers() {
err = vkEnumerateInstanceLayerProperties(&instance_layer_count,
instance_layers.get());
if (err) {
DLOG << "vkEnumerateInstanceLayerProperties failed. Error: " << err;
DLOG << "vkEnumerateInstanceLayerProperties failed. Error: "
<< string_VkResult(err);
return false;
}
@ -283,7 +285,8 @@ bool VulkanContext::InitializeExtensions() {
err = vkEnumerateInstanceExtensionProperties(
nullptr, &instance_extension_count, nullptr);
if (err) {
DLOG << "vkEnumerateInstanceExtensionProperties failed. Error: " << err;
DLOG << "vkEnumerateInstanceExtensionProperties failed. Error: "
<< string_VkResult(err);
return false;
}
@ -293,7 +296,8 @@ bool VulkanContext::InitializeExtensions() {
err = vkEnumerateInstanceExtensionProperties(
nullptr, &instance_extension_count, instance_extensions.get());
if (err) {
DLOG << "vkEnumerateInstanceExtensionProperties failed. Error: " << err;
DLOG << "vkEnumerateInstanceExtensionProperties failed. Error: "
<< string_VkResult(err);
return false;
}
for (uint32_t i = 0; i < instance_extension_count; i++) {
@ -408,7 +412,7 @@ bool VulkanContext::CreatePhysicalDevice() {
return false;
}
if (err) {
DLOG << "vkCreateInstance failed. Error: " << err;
DLOG << "vkCreateInstance failed. Error: " << string_VkResult(err);
return false;
}
}
@ -418,7 +422,8 @@ bool VulkanContext::CreatePhysicalDevice() {
// Make initial call to query gpu_count.
VkResult err = vkEnumeratePhysicalDevices(instance_, &gpu_count, nullptr);
if (err) {
DLOG << "vkEnumeratePhysicalDevices failed. Error: " << err;
DLOG << "vkEnumeratePhysicalDevices failed. Error: "
<< string_VkResult(err);
return false;
}
@ -431,7 +436,8 @@ bool VulkanContext::CreatePhysicalDevice() {
err =
vkEnumeratePhysicalDevices(instance_, &gpu_count, physical_devices.get());
if (err) {
DLOG << "vkEnumeratePhysicalDevices failed. Error: " << err;
DLOG << "vkEnumeratePhysicalDevices failed. Error: "
<< string_VkResult(err);
return false;
}
// Grab the first physical device for now.
@ -446,7 +452,8 @@ bool VulkanContext::CreatePhysicalDevice() {
err = vkEnumerateDeviceExtensionProperties(gpu_, nullptr,
&device_extension_count, nullptr);
if (err) {
DLOG << "vkEnumerateDeviceExtensionProperties failed. Error: " << err;
DLOG << "vkEnumerateDeviceExtensionProperties failed. Error: "
<< string_VkResult(err);
return false;
}
@ -456,7 +463,8 @@ bool VulkanContext::CreatePhysicalDevice() {
err = vkEnumerateDeviceExtensionProperties(
gpu_, nullptr, &device_extension_count, device_extensions.get());
if (err) {
DLOG << "vkEnumerateDeviceExtensionProperties failed. Error: " << err;
DLOG << "vkEnumerateDeviceExtensionProperties failed. Error: "
<< string_VkResult(err);
return false;
}
@ -600,7 +608,7 @@ bool VulkanContext::CreateDevice() {
}
err = vkCreateDevice(gpu_, &sdevice, nullptr, &device_);
if (err) {
DLOG << "vkCreateDevice failed. Error: " << err;
DLOG << "vkCreateDevice failed. Error: " << string_VkResult(err);
return false;
}
return true;
@ -678,14 +686,16 @@ bool VulkanContext::InitializeQueues(VkSurfaceKHR surface) {
VkResult err =
GetPhysicalDeviceSurfaceFormatsKHR(gpu_, surface, &format_count, nullptr);
if (err) {
DLOG << "GetPhysicalDeviceSurfaceFormatsKHR failed. Error: " << err;
DLOG << "GetPhysicalDeviceSurfaceFormatsKHR failed. Error: "
<< string_VkResult(err);
return false;
}
auto surf_formats = std::make_unique<VkSurfaceFormatKHR[]>(format_count);
err = GetPhysicalDeviceSurfaceFormatsKHR(gpu_, surface, &format_count,
surf_formats.get());
if (err) {
DLOG << "GetPhysicalDeviceSurfaceFormatsKHR failed. Error: " << err;
DLOG << "GetPhysicalDeviceSurfaceFormatsKHR failed. Error: "
<< string_VkResult(err);
return false;
}
@ -743,26 +753,26 @@ bool VulkanContext::CreateSemaphores() {
for (uint32_t i = 0; i < kFrameLag; i++) {
err = vkCreateFence(device_, &fence_ci, nullptr, &fences_[i]);
if (err) {
DLOG << "vkCreateFence failed. Error: " << err;
DLOG << "vkCreateFence failed. Error: " << string_VkResult(err);
return false;
}
err = vkCreateSemaphore(device_, &semaphoreCreateInfo, nullptr,
&image_acquired_semaphores_[i]);
if (err) {
DLOG << "vkCreateSemaphore failed. Error: " << err;
DLOG << "vkCreateSemaphore failed. Error: " << string_VkResult(err);
return false;
}
err = vkCreateSemaphore(device_, &semaphoreCreateInfo, nullptr,
&draw_complete_semaphores_[i]);
if (err) {
DLOG << "vkCreateSemaphore failed. Error: " << err;
DLOG << "vkCreateSemaphore failed. Error: " << string_VkResult(err);
return false;
}
if (separate_present_queue_) {
err = vkCreateSemaphore(device_, &semaphoreCreateInfo, nullptr,
&image_ownership_semaphores_[i]);
if (err) {
DLOG << "vkCreateSemaphore failed. Error: " << err;
DLOG << "vkCreateSemaphore failed. Error: " << string_VkResult(err);
return false;
}
}
@ -834,7 +844,8 @@ bool VulkanContext::UpdateSwapChain(Window* window) {
err = GetPhysicalDeviceSurfaceCapabilitiesKHR(gpu_, window->surface,
&surf_capabilities);
if (err) {
DLOG << "GetPhysicalDeviceSurfaceCapabilitiesKHR failed. Error: " << err;
DLOG << "GetPhysicalDeviceSurfaceCapabilitiesKHR failed. Error: "
<< string_VkResult(err);
return false;
}
@ -842,7 +853,8 @@ bool VulkanContext::UpdateSwapChain(Window* window) {
err = GetPhysicalDeviceSurfacePresentModesKHR(gpu_, window->surface,
&present_mode_count, nullptr);
if (err) {
DLOG << "GetPhysicalDeviceSurfacePresentModesKHR failed. Error: " << err;
DLOG << "GetPhysicalDeviceSurfacePresentModesKHR failed. Error: "
<< string_VkResult(err);
return false;
}
@ -851,7 +863,8 @@ bool VulkanContext::UpdateSwapChain(Window* window) {
err = GetPhysicalDeviceSurfacePresentModesKHR(
gpu_, window->surface, &present_mode_count, present_modes.get());
if (err) {
DLOG << "GetPhysicalDeviceSurfacePresentModesKHR failed. Error: " << err;
DLOG << "GetPhysicalDeviceSurfacePresentModesKHR failed. Error: "
<< string_VkResult(err);
return false;
}
@ -998,7 +1011,7 @@ bool VulkanContext::UpdateSwapChain(Window* window) {
err = CreateSwapchainKHR(device_, &swapchain_ci, nullptr, &window->swapchain);
if (err) {
DLOG << "CreateSwapchainKHR failed. Error: " << err;
DLOG << "CreateSwapchainKHR failed. Error: " << string_VkResult(err);
return false;
}
@ -1006,7 +1019,7 @@ bool VulkanContext::UpdateSwapChain(Window* window) {
err = GetSwapchainImagesKHR(device_, window->swapchain, &sp_image_count,
nullptr);
if (err) {
DLOG << "CreateSwapchainKHR failed. Error: " << err;
DLOG << "CreateSwapchainKHR failed. Error: " << string_VkResult(err);
return false;
}
@ -1023,7 +1036,7 @@ bool VulkanContext::UpdateSwapChain(Window* window) {
err = GetSwapchainImagesKHR(device_, window->swapchain,
&swapchain_image_count_, swapchain_images.get());
if (err) {
DLOG << "GetSwapchainImagesKHR failed. Error: " << err;
DLOG << "GetSwapchainImagesKHR failed. Error: " << string_VkResult(err);
return false;
}
@ -1060,7 +1073,7 @@ bool VulkanContext::UpdateSwapChain(Window* window) {
err = vkCreateImageView(device_, &color_image_view, nullptr,
&window->swapchain_image_resources[i].view);
if (err) {
DLOG << "vkCreateImageView failed. Error: " << err;
DLOG << "vkCreateImageView failed. Error: " << string_VkResult(err);
return false;
}
}
@ -1144,7 +1157,7 @@ bool VulkanContext::UpdateSwapChain(Window* window) {
err = vkCreateRenderPass(device_, &rp_info, nullptr, &window->render_pass);
if (err) {
DLOG << "vkCreateRenderPass failed. Error: " << err;
DLOG << "vkCreateRenderPass failed. Error: " << string_VkResult(err);
return false;
}
@ -1169,7 +1182,7 @@ bool VulkanContext::UpdateSwapChain(Window* window) {
device_, &fb_info, nullptr,
&window->swapchain_image_resources[i].frame_buffer);
if (err) {
DLOG << "vkCreateFramebuffer failed. Error: " << err;
DLOG << "vkCreateFramebuffer failed. Error: " << string_VkResult(err);
return false;
}
}
@ -1187,7 +1200,7 @@ bool VulkanContext::UpdateSwapChain(Window* window) {
err = vkCreateCommandPool(device_, &present_cmd_pool_info, nullptr,
&window->present_cmd_pool);
if (err) {
DLOG << "vkCreateCommandPool failed. Error: " << err;
DLOG << "vkCreateCommandPool failed. Error: " << string_VkResult(err);
return false;
}
@ -1203,7 +1216,8 @@ bool VulkanContext::UpdateSwapChain(Window* window) {
device_, &present_cmd_info,
&window->swapchain_image_resources[i].graphics_to_present_cmd);
if (err) {
DLOG << "vkAllocateCommandBuffers failed. Error: " << err;
DLOG << "vkAllocateCommandBuffers failed. Error: "
<< string_VkResult(err);
return false;
}
@ -1217,7 +1231,7 @@ bool VulkanContext::UpdateSwapChain(Window* window) {
window->swapchain_image_resources[i].graphics_to_present_cmd,
&cmd_buf_info);
if (err) {
DLOG << "vkBeginCommandBuffer failed. Error: " << err;
DLOG << "vkBeginCommandBuffer failed. Error: " << string_VkResult(err);
return false;
}
@ -1241,7 +1255,7 @@ bool VulkanContext::UpdateSwapChain(Window* window) {
err = vkEndCommandBuffer(
window->swapchain_image_resources[i].graphics_to_present_cmd);
if (err) {
DLOG << "vkEndCommandBuffer failed. Error: " << err;
DLOG << "vkEndCommandBuffer failed. Error: " << string_VkResult(err);
return false;
}
}
@ -1280,7 +1294,7 @@ bool VulkanContext::CreateDepthImage(Window* window) {
VkResult err =
vkCreateImage(device_, &depth_image_ci, nullptr, &window->depth_image);
if (err) {
DLOG << "vkCreateImage failed. Error: " << err;
DLOG << "vkCreateImage failed. Error: " << string_VkResult(err);
return false;
}
@ -1312,7 +1326,7 @@ bool VulkanContext::CreateDepthImage(Window* window) {
err = vkAllocateMemory(device_, &alloc_info, nullptr,
&window->depth_image_memory);
if (err) {
DLOG << "vkAllocateMemory failed. Error: " << err;
DLOG << "vkAllocateMemory failed. Error: " << string_VkResult(err);
return false;
}
@ -1382,7 +1396,7 @@ void VulkanContext::Flush(bool all) {
vkQueueSubmit(graphics_queue_, 1, &submit_info, VK_NULL_HANDLE);
command_buffers_[0] = nullptr;
if (err) {
DLOG << "vkQueueSubmit failed. Error: " << err;
DLOG << "vkQueueSubmit failed. Error: " << string_VkResult(err);
return;
}
@ -1426,7 +1440,7 @@ bool VulkanContext::PrepareBuffers() {
UpdateSwapChain(&window_);
break;
} else if (err != VK_SUCCESS) {
DLOG << "AcquireNextImageKHR failed. Error: " << err;
DLOG << "AcquireNextImageKHR failed. Error: " << string_VkResult(err);
return false;
}
} while (err != VK_SUCCESS);
@ -1463,7 +1477,7 @@ bool VulkanContext::SwapBuffers() {
submit_info.pSignalSemaphores = &draw_complete_semaphores_[frame_index_];
err = vkQueueSubmit(graphics_queue_, 1, &submit_info, fences_[frame_index_]);
if (err) {
DLOG << "vkQueueSubmit failed. Error: " << err;
DLOG << "vkQueueSubmit failed. Error: " << string_VkResult(err);
return false;
}
@ -1494,7 +1508,7 @@ bool VulkanContext::SwapBuffers() {
submit_info.pSignalSemaphores = &image_ownership_semaphores_[frame_index_];
err = vkQueueSubmit(present_queue_, 1, &submit_info, null_fence);
if (err) {
DLOG << "vkQueueSubmit failed. Error: " << err;
DLOG << "vkQueueSubmit failed. Error: " << string_VkResult(err);
return false;
}
}
@ -1541,7 +1555,7 @@ bool VulkanContext::SwapBuffers() {
// presentation engine will still present the image correctly.
DLOG << "Swapchain is Suboptimal.";
} else if (err) {
DLOG << "QueuePresentKHR failed. Error: " << err;
DLOG << "QueuePresentKHR failed. Error: " << string_VkResult(err);
return false;
}