- use I_Error for throwing errors in the Vulkan backend and print the message if one gets thrown during init.

This commit is contained in:
Christoph Oelckers 2019-04-08 23:48:46 +02:00
parent 2694b0a167
commit ab256945aa
7 changed files with 59 additions and 56 deletions

View file

@ -121,33 +121,33 @@ static void LoadShaders()
FString path = CreateProgramCacheName(false); FString path = CreateProgramCacheName(false);
FileReader fr; FileReader fr;
if (!fr.OpenFile(path)) if (!fr.OpenFile(path))
throw std::runtime_error("Could not open shader file"); I_Error("Could not open shader file");
char magic[4]; char magic[4];
fr.Read(magic, 4); fr.Read(magic, 4);
if (memcmp(magic, ShaderMagic, 4) != 0) if (memcmp(magic, ShaderMagic, 4) != 0)
throw std::runtime_error("Not a shader cache file"); I_Error("Not a shader cache file");
uint32_t count = fr.ReadUInt32(); uint32_t count = fr.ReadUInt32();
if (count > 512) if (count > 512)
throw std::runtime_error("Too many shaders cached"); I_Error("Too many shaders cached");
for (uint32_t i = 0; i < count; i++) for (uint32_t i = 0; i < count; i++)
{ {
char hexdigest[33]; char hexdigest[33];
if (fr.Read(hexdigest, 32) != 32) if (fr.Read(hexdigest, 32) != 32)
throw std::runtime_error("Read error"); I_Error("Read error");
hexdigest[32] = 0; hexdigest[32] = 0;
std::unique_ptr<ProgramBinary> binary(new ProgramBinary()); std::unique_ptr<ProgramBinary> binary(new ProgramBinary());
binary->format = fr.ReadUInt32(); binary->format = fr.ReadUInt32();
uint32_t size = fr.ReadUInt32(); uint32_t size = fr.ReadUInt32();
if (size > 1024 * 1024) if (size > 1024 * 1024)
throw std::runtime_error("Shader too big, probably file corruption"); I_Error("Shader too big, probably file corruption");
binary->data.Resize(size); binary->data.Resize(size);
if (fr.Read(binary->data.Data(), binary->data.Size()) != binary->data.Size()) if (fr.Read(binary->data.Data(), binary->data.Size()) != binary->data.Size())
throw std::runtime_error("Read error"); I_Error("Read error");
ShaderCache[hexdigest] = std::move(binary); ShaderCache[hexdigest] = std::move(binary);
} }

View file

@ -157,7 +157,7 @@ std::unique_ptr<VulkanShader> ShaderBuilder::create(VulkanDevice *device)
glslang::TIntermediate *intermediate = program.getIntermediate(stage); glslang::TIntermediate *intermediate = program.getIntermediate(stage);
if (!intermediate) if (!intermediate)
{ {
throw std::runtime_error("Internal shader compiler error"); I_Error("Internal shader compiler error");
} }
glslang::SpvOptions spvOptions; glslang::SpvOptions spvOptions;
@ -177,7 +177,7 @@ std::unique_ptr<VulkanShader> ShaderBuilder::create(VulkanDevice *device)
VkShaderModule shaderModule; VkShaderModule shaderModule;
VkResult result = vkCreateShaderModule(device->device, &createInfo, nullptr, &shaderModule); VkResult result = vkCreateShaderModule(device->device, &createInfo, nullptr, &shaderModule);
if (result != VK_SUCCESS) if (result != VK_SUCCESS)
throw std::runtime_error("Could not create vulkan shader module"); I_Error("Could not create vulkan shader module");
return std::make_unique<VulkanShader>(device, shaderModule); return std::make_unique<VulkanShader>(device, shaderModule);
} }

View file

@ -408,7 +408,7 @@ inline std::unique_ptr<VulkanImage> ImageBuilder::create(VulkanDevice *device)
VkResult result = vmaCreateImage(device->allocator, &imageInfo, &allocInfo, &image, &allocation, nullptr); VkResult result = vmaCreateImage(device->allocator, &imageInfo, &allocInfo, &image, &allocation, nullptr);
if (result != VK_SUCCESS) if (result != VK_SUCCESS)
throw std::runtime_error("Could not create vulkan image"); I_Error("Could not create vulkan image");
return std::make_unique<VulkanImage>(device, image, allocation, imageInfo.extent.width, imageInfo.extent.height, imageInfo.mipLevels); return std::make_unique<VulkanImage>(device, image, allocation, imageInfo.extent.width, imageInfo.extent.height, imageInfo.mipLevels);
} }
@ -438,7 +438,7 @@ inline std::unique_ptr<VulkanImageView> ImageViewBuilder::create(VulkanDevice *d
VkImageView view; VkImageView view;
VkResult result = vkCreateImageView(device->device, &viewInfo, nullptr, &view); VkResult result = vkCreateImageView(device->device, &viewInfo, nullptr, &view);
if (result != VK_SUCCESS) if (result != VK_SUCCESS)
throw std::runtime_error("Could not create texture image view"); I_Error("Could not create texture image view");
return std::make_unique<VulkanImageView>(device, view); return std::make_unique<VulkanImageView>(device, view);
} }
@ -510,7 +510,7 @@ inline std::unique_ptr<VulkanSampler> SamplerBuilder::create(VulkanDevice *devic
VkSampler sampler; VkSampler sampler;
VkResult result = vkCreateSampler(device->device, &samplerInfo, nullptr, &sampler); VkResult result = vkCreateSampler(device->device, &samplerInfo, nullptr, &sampler);
if (result != VK_SUCCESS) if (result != VK_SUCCESS)
throw std::runtime_error("Could not create texture sampler"); I_Error("Could not create texture sampler");
return std::make_unique<VulkanSampler>(device, sampler); return std::make_unique<VulkanSampler>(device, sampler);
} }
@ -541,7 +541,7 @@ inline std::unique_ptr<VulkanBuffer> BufferBuilder::create(VulkanDevice *device)
VkResult result = vmaCreateBuffer(device->allocator, &bufferInfo, &allocInfo, &buffer, &allocation, nullptr); VkResult result = vmaCreateBuffer(device->allocator, &bufferInfo, &allocInfo, &buffer, &allocation, nullptr);
if (result != VK_SUCCESS) if (result != VK_SUCCESS)
throw std::runtime_error("could not allocate memory for vulkan buffer"); I_Error("could not allocate memory for vulkan buffer");
return std::make_unique<VulkanBuffer>(device, buffer, allocation, bufferInfo.size); return std::make_unique<VulkanBuffer>(device, buffer, allocation, bufferInfo.size);
} }
@ -601,7 +601,7 @@ inline std::unique_ptr<VulkanDescriptorSetLayout> DescriptorSetLayoutBuilder::cr
VkDescriptorSetLayout layout; VkDescriptorSetLayout layout;
VkResult result = vkCreateDescriptorSetLayout(device->device, &layoutInfo, nullptr, &layout); VkResult result = vkCreateDescriptorSetLayout(device->device, &layoutInfo, nullptr, &layout);
if (result != VK_SUCCESS) if (result != VK_SUCCESS)
throw std::runtime_error("Could not create descriptor set layout"); I_Error("Could not create descriptor set layout");
return std::make_unique<VulkanDescriptorSetLayout>(device, layout); return std::make_unique<VulkanDescriptorSetLayout>(device, layout);
} }
@ -635,7 +635,7 @@ inline std::unique_ptr<VulkanDescriptorPool> DescriptorPoolBuilder::create(Vulka
VkDescriptorPool descriptorPool; VkDescriptorPool descriptorPool;
VkResult result = vkCreateDescriptorPool(device->device, &poolInfo, nullptr, &descriptorPool); VkResult result = vkCreateDescriptorPool(device->device, &poolInfo, nullptr, &descriptorPool);
if (result != VK_SUCCESS) if (result != VK_SUCCESS)
throw std::runtime_error("Could not create descriptor pool"); I_Error("Could not create descriptor pool");
return std::make_unique<VulkanDescriptorPool>(device, descriptorPool); return std::make_unique<VulkanDescriptorPool>(device, descriptorPool);
} }
@ -679,7 +679,7 @@ inline std::unique_ptr<VulkanFramebuffer> FramebufferBuilder::create(VulkanDevic
VkFramebuffer framebuffer = 0; VkFramebuffer framebuffer = 0;
VkResult result = vkCreateFramebuffer(device->device, &framebufferInfo, nullptr, &framebuffer); VkResult result = vkCreateFramebuffer(device->device, &framebufferInfo, nullptr, &framebuffer);
if (result != VK_SUCCESS) if (result != VK_SUCCESS)
throw std::runtime_error("Failed to create framebuffer"); I_Error("Failed to create framebuffer");
return std::make_unique<VulkanFramebuffer>(device, framebuffer); return std::make_unique<VulkanFramebuffer>(device, framebuffer);
} }
@ -972,7 +972,7 @@ inline std::unique_ptr<VulkanPipeline> GraphicsPipelineBuilder::create(VulkanDev
VkPipeline pipeline = 0; VkPipeline pipeline = 0;
VkResult result = vkCreateGraphicsPipelines(device->device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, &pipeline); VkResult result = vkCreateGraphicsPipelines(device->device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, &pipeline);
if (result != VK_SUCCESS) if (result != VK_SUCCESS)
throw std::runtime_error("Could not create graphics pipeline"); I_Error("Could not create graphics pipeline");
return std::make_unique<VulkanPipeline>(device, pipeline); return std::make_unique<VulkanPipeline>(device, pipeline);
} }
@ -1006,7 +1006,7 @@ inline std::unique_ptr<VulkanPipelineLayout> PipelineLayoutBuilder::create(Vulka
VkPipelineLayout pipelineLayout; VkPipelineLayout pipelineLayout;
VkResult result = vkCreatePipelineLayout(device->device, &pipelineLayoutInfo, nullptr, &pipelineLayout); VkResult result = vkCreatePipelineLayout(device->device, &pipelineLayoutInfo, nullptr, &pipelineLayout);
if (result != VK_SUCCESS) if (result != VK_SUCCESS)
throw std::runtime_error("Could not create pipeline layout"); I_Error("Could not create pipeline layout");
return std::make_unique<VulkanPipelineLayout>(device, pipelineLayout); return std::make_unique<VulkanPipelineLayout>(device, pipelineLayout);
} }
@ -1102,7 +1102,7 @@ inline std::unique_ptr<VulkanRenderPass> RenderPassBuilder::create(VulkanDevice
VkRenderPass renderPass = 0; VkRenderPass renderPass = 0;
VkResult result = vkCreateRenderPass(device->device, &renderPassInfo, nullptr, &renderPass); VkResult result = vkCreateRenderPass(device->device, &renderPassInfo, nullptr, &renderPass);
if (result != VK_SUCCESS) if (result != VK_SUCCESS)
throw std::runtime_error("Could not create render pass"); I_Error("Could not create render pass");
return std::make_unique<VulkanRenderPass>(device, renderPass); return std::make_unique<VulkanRenderPass>(device, renderPass);
} }
@ -1235,7 +1235,7 @@ inline void QueueSubmit::execute(VulkanDevice *device, VkQueue queue, VulkanFenc
{ {
VkResult result = vkQueueSubmit(device->graphicsQueue, 1, &submitInfo, fence ? fence->fence : VK_NULL_HANDLE); VkResult result = vkQueueSubmit(device->graphicsQueue, 1, &submitInfo, fence ? fence->fence : VK_NULL_HANDLE);
if (result < VK_SUCCESS) if (result < VK_SUCCESS)
throw std::runtime_error("Failed to submit command buffer"); I_Error("Failed to submit command buffer");
} }
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////

View file

@ -163,7 +163,7 @@ void VulkanDevice::SelectPhysicalDevice()
} }
if (SupportedDevices.empty()) if (SupportedDevices.empty())
throw std::runtime_error("No Vulkan device supports the minimum requirements of this application"); I_Error("No Vulkan device supports the minimum requirements of this application");
// The device order returned by Vulkan can be anything. Prefer discrete > integrated > virtual gpu > cpu > other // The device order returned by Vulkan can be anything. Prefer discrete > integrated > virtual gpu > cpu > other
std::stable_sort(SupportedDevices.begin(), SupportedDevices.end(), [&](const auto &a, const auto b) { std::stable_sort(SupportedDevices.begin(), SupportedDevices.end(), [&](const auto &a, const auto b) {
@ -215,7 +215,7 @@ void VulkanDevice::CreateAllocator()
allocinfo.device = device; allocinfo.device = device;
allocinfo.preferredLargeHeapBlockSize = 64 * 1024 * 1024; allocinfo.preferredLargeHeapBlockSize = 64 * 1024 * 1024;
if (vmaCreateAllocator(&allocinfo, &allocator) != VK_SUCCESS) if (vmaCreateAllocator(&allocinfo, &allocator) != VK_SUCCESS)
throw std::runtime_error("Unable to create allocator"); I_Error("Unable to create allocator");
} }
void VulkanDevice::CreateDevice() void VulkanDevice::CreateDevice()
@ -248,7 +248,7 @@ void VulkanDevice::CreateDevice()
VkResult result = vkCreateDevice(PhysicalDevice.Device, &deviceCreateInfo, nullptr, &device); VkResult result = vkCreateDevice(PhysicalDevice.Device, &deviceCreateInfo, nullptr, &device);
if (result != VK_SUCCESS) if (result != VK_SUCCESS)
throw std::runtime_error("Could not create vulkan device"); I_Error("Could not create vulkan device");
volkLoadDevice(device); volkLoadDevice(device);
@ -260,7 +260,7 @@ void VulkanDevice::CreateSurface()
{ {
if (!I_CreateVulkanSurface(instance, &surface)) if (!I_CreateVulkanSurface(instance, &surface))
{ {
throw std::runtime_error("Could not create vulkan surface"); I_Error("Could not create vulkan surface");
} }
} }
@ -313,7 +313,7 @@ void VulkanDevice::CreateInstance()
VkResult result = vkCreateInstance(&createInfo, nullptr, &instance); VkResult result = vkCreateInstance(&createInfo, nullptr, &instance);
if (result != VK_SUCCESS) if (result != VK_SUCCESS)
throw std::runtime_error("Could not create vulkan instance"); I_Error("Could not create vulkan instance");
volkLoadInstance(instance); volkLoadInstance(instance);
@ -334,7 +334,7 @@ void VulkanDevice::CreateInstance()
createInfo.pUserData = this; createInfo.pUserData = this;
result = vkCreateDebugUtilsMessengerEXT(instance, &createInfo, nullptr, &debugMessenger); result = vkCreateDebugUtilsMessengerEXT(instance, &createInfo, nullptr, &debugMessenger);
if (result != VK_SUCCESS) if (result != VK_SUCCESS)
throw std::runtime_error("vkCreateDebugUtilsMessengerEXT failed"); I_Error("vkCreateDebugUtilsMessengerEXT failed");
DebugLayerActive = true; DebugLayerActive = true;
} }
@ -427,14 +427,14 @@ std::vector<VulkanPhysicalDevice> VulkanDevice::GetPhysicalDevices(VkInstance in
uint32_t deviceCount = 0; uint32_t deviceCount = 0;
VkResult result = vkEnumeratePhysicalDevices(instance, &deviceCount, nullptr); VkResult result = vkEnumeratePhysicalDevices(instance, &deviceCount, nullptr);
if (result != VK_SUCCESS) if (result != VK_SUCCESS)
throw std::runtime_error("vkEnumeratePhysicalDevices failed"); I_Error("vkEnumeratePhysicalDevices failed");
if (deviceCount == 0) if (deviceCount == 0)
return {}; return {};
std::vector<VkPhysicalDevice> devices(deviceCount); std::vector<VkPhysicalDevice> devices(deviceCount);
result = vkEnumeratePhysicalDevices(instance, &deviceCount, devices.data()); result = vkEnumeratePhysicalDevices(instance, &deviceCount, devices.data());
if (result != VK_SUCCESS) if (result != VK_SUCCESS)
throw std::runtime_error("vkEnumeratePhysicalDevices failed (2)"); I_Error("vkEnumeratePhysicalDevices failed (2)");
std::vector<VulkanPhysicalDevice> devinfo(deviceCount); std::vector<VulkanPhysicalDevice> devinfo(deviceCount);
for (size_t i = 0; i < devices.size(); i++) for (size_t i = 0; i < devices.size(); i++)
@ -463,11 +463,11 @@ std::vector<const char *> VulkanDevice::GetPlatformExtensions()
{ {
uint32_t extensionCount = 0; uint32_t extensionCount = 0;
if (!I_GetVulkanPlatformExtensions(&extensionCount, nullptr)) if (!I_GetVulkanPlatformExtensions(&extensionCount, nullptr))
throw std::runtime_error("Cannot obtain number of Vulkan extensions"); I_Error("Cannot obtain number of Vulkan extensions");
std::vector<const char *> extensions(extensionCount); std::vector<const char *> extensions(extensionCount);
if (!I_GetVulkanPlatformExtensions(&extensionCount, extensions.data())) if (!I_GetVulkanPlatformExtensions(&extensionCount, extensions.data()))
throw std::runtime_error("Cannot obtain list of Vulkan extensions"); I_Error("Cannot obtain list of Vulkan extensions");
return extensions; return extensions;
} }
@ -475,12 +475,12 @@ void VulkanDevice::InitVolk()
{ {
if (volkInitialize() != VK_SUCCESS) if (volkInitialize() != VK_SUCCESS)
{ {
throw std::runtime_error("Unable to find Vulkan"); I_Error("Unable to find Vulkan");
} }
auto iver = volkGetInstanceVersion(); auto iver = volkGetInstanceVersion();
if (iver == 0) if (iver == 0)
{ {
throw std::runtime_error("Vulkan not supported"); I_Error("Vulkan not supported");
} }
} }
@ -516,5 +516,6 @@ uint32_t VulkanDevice::FindMemoryType(uint32_t typeFilter, VkMemoryPropertyFlags
return i; return i;
} }
throw std::runtime_error("failed to find suitable memory type!"); I_Error("failed to find suitable memory type!");
return 0;
} }

View file

@ -1,6 +1,7 @@
#pragma once #pragma once
#include "vk_device.h" #include "vk_device.h"
#include "doomerrors.h"
class VulkanCommandPool; class VulkanCommandPool;
class VulkanDescriptorPool; class VulkanDescriptorPool;
@ -369,7 +370,7 @@ inline VulkanSemaphore::VulkanSemaphore(VulkanDevice *device) : device(device)
semaphoreInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; semaphoreInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
VkResult result = vkCreateSemaphore(device->device, &semaphoreInfo, nullptr, &semaphore); VkResult result = vkCreateSemaphore(device->device, &semaphoreInfo, nullptr, &semaphore);
if (result != VK_SUCCESS) if (result != VK_SUCCESS)
throw std::runtime_error("Failed to create semaphore!"); I_Error("Failed to create semaphore!");
} }
inline VulkanSemaphore::~VulkanSemaphore() inline VulkanSemaphore::~VulkanSemaphore()
@ -385,7 +386,7 @@ inline VulkanFence::VulkanFence(VulkanDevice *device) : device(device)
fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
VkResult result = vkCreateFence(device->device, &fenceInfo, nullptr, &fence); VkResult result = vkCreateFence(device->device, &fenceInfo, nullptr, &fence);
if (result != VK_SUCCESS) if (result != VK_SUCCESS)
throw std::runtime_error("Failed to create fence!"); I_Error("Failed to create fence!");
} }
inline VulkanFence::~VulkanFence() inline VulkanFence::~VulkanFence()
@ -427,7 +428,7 @@ inline VulkanCommandPool::VulkanCommandPool(VulkanDevice *device, int queueFamil
VkResult result = vkCreateCommandPool(device->device, &poolInfo, nullptr, &pool); VkResult result = vkCreateCommandPool(device->device, &poolInfo, nullptr, &pool);
if (result != VK_SUCCESS) if (result != VK_SUCCESS)
throw std::runtime_error("Could not create command pool"); I_Error("Could not create command pool");
} }
inline VulkanCommandPool::~VulkanCommandPool() inline VulkanCommandPool::~VulkanCommandPool()
@ -518,7 +519,7 @@ inline VulkanCommandBuffer::VulkanCommandBuffer(VulkanCommandPool *pool) : pool(
VkResult result = vkAllocateCommandBuffers(pool->device->device, &allocInfo, &buffer); VkResult result = vkAllocateCommandBuffers(pool->device->device, &allocInfo, &buffer);
if (result != VK_SUCCESS) if (result != VK_SUCCESS)
throw std::runtime_error("Could not create command buffer"); I_Error("Could not create command buffer");
} }
inline VulkanCommandBuffer::~VulkanCommandBuffer() inline VulkanCommandBuffer::~VulkanCommandBuffer()
@ -535,14 +536,14 @@ inline void VulkanCommandBuffer::begin()
VkResult result = vkBeginCommandBuffer(buffer, &beginInfo); VkResult result = vkBeginCommandBuffer(buffer, &beginInfo);
if (result != VK_SUCCESS) if (result != VK_SUCCESS)
throw std::runtime_error("Failed to begin recording command buffer!"); I_Error("Failed to begin recording command buffer!");
} }
inline void VulkanCommandBuffer::end() inline void VulkanCommandBuffer::end()
{ {
VkResult result = vkEndCommandBuffer(buffer); VkResult result = vkEndCommandBuffer(buffer);
if (result != VK_SUCCESS) if (result != VK_SUCCESS)
throw std::runtime_error("Failed to record command buffer!"); I_Error("Failed to record command buffer!");
} }
inline void VulkanCommandBuffer::debugFullPipelineBarrier() inline void VulkanCommandBuffer::debugFullPipelineBarrier()
@ -894,7 +895,7 @@ inline std::unique_ptr<VulkanDescriptorSet> VulkanDescriptorPool::allocate(Vulka
VkDescriptorSet descriptorSet; VkDescriptorSet descriptorSet;
VkResult result = vkAllocateDescriptorSets(device->device, &allocInfo, &descriptorSet); VkResult result = vkAllocateDescriptorSets(device->device, &allocInfo, &descriptorSet);
if (result != VK_SUCCESS) if (result != VK_SUCCESS)
throw std::runtime_error("Could not allocate descriptor sets"); I_Error("Could not allocate descriptor sets");
return std::make_unique<VulkanDescriptorSet>(device, this, descriptorSet); return std::make_unique<VulkanDescriptorSet>(device, this, descriptorSet);
} }

View file

@ -20,7 +20,7 @@ VulkanSwapChain::VulkanSwapChain(VulkanDevice *device) : vsync(vid_vsync), devic
SelectFormat(); SelectFormat();
SelectPresentMode(); SelectPresentMode();
if (!CreateSwapChain()) if (!CreateSwapChain())
throw std::runtime_error("Could not create vulkan swapchain"); I_Error("Could not create vulkan swapchain");
GetImages(); GetImages();
CreateViews(); CreateViews();
} }
@ -70,7 +70,7 @@ uint32_t VulkanSwapChain::AcquireImage(int width, int height, VulkanSemaphore *s
} }
else else
{ {
throw std::runtime_error("Failed to acquire next image!"); I_Error("Failed to acquire next image!");
} }
} }
return imageIndex; return imageIndex;
@ -97,19 +97,19 @@ void VulkanSwapChain::QueuePresent(uint32_t imageIndex, VulkanSemaphore *semapho
// The spec says we can recover from this. // The spec says we can recover from this.
// However, if we are out of memory it is better to crash now than in some other weird place further away from the source of the problem. // However, if we are out of memory it is better to crash now than in some other weird place further away from the source of the problem.
throw std::runtime_error("vkQueuePresentKHR failed: out of memory"); I_Error("vkQueuePresentKHR failed: out of memory");
} }
else if (result == VK_ERROR_DEVICE_LOST) else if (result == VK_ERROR_DEVICE_LOST)
{ {
throw std::runtime_error("vkQueuePresentKHR failed: device lost"); I_Error("vkQueuePresentKHR failed: device lost");
} }
else if (result == VK_ERROR_SURFACE_LOST_KHR) else if (result == VK_ERROR_SURFACE_LOST_KHR)
{ {
throw std::runtime_error("vkQueuePresentKHR failed: surface lost"); I_Error("vkQueuePresentKHR failed: surface lost");
} }
else if (result != VK_SUCCESS) else if (result != VK_SUCCESS)
{ {
throw std::runtime_error("vkQueuePresentKHR failed"); I_Error("vkQueuePresentKHR failed");
} }
} }
@ -213,7 +213,7 @@ void VulkanSwapChain::CreateViews()
VkImageView view; VkImageView view;
VkResult result = vkCreateImageView(device->device, &createInfo, nullptr, &view); VkResult result = vkCreateImageView(device->device, &createInfo, nullptr, &view);
if (result != VK_SUCCESS) if (result != VK_SUCCESS)
throw std::runtime_error("Could not create image view for swapchain image"); I_Error("Could not create image view for swapchain image");
device->SetDebugObjectName("SwapChainImageView", (uint64_t)view, VK_OBJECT_TYPE_IMAGE_VIEW); device->SetDebugObjectName("SwapChainImageView", (uint64_t)view, VK_OBJECT_TYPE_IMAGE_VIEW);
@ -225,7 +225,7 @@ void VulkanSwapChain::SelectFormat()
{ {
std::vector<VkSurfaceFormatKHR> surfaceFormats = GetSurfaceFormats(); std::vector<VkSurfaceFormatKHR> surfaceFormats = GetSurfaceFormats();
if (surfaceFormats.empty()) if (surfaceFormats.empty())
throw std::runtime_error("No surface formats supported"); I_Error("No surface formats supported");
if (surfaceFormats.size() == 1 && surfaceFormats.front().format == VK_FORMAT_UNDEFINED) if (surfaceFormats.size() == 1 && surfaceFormats.front().format == VK_FORMAT_UNDEFINED)
{ {
@ -263,7 +263,7 @@ void VulkanSwapChain::SelectPresentMode()
std::vector<VkPresentModeKHR> presentModes = GetPresentModes(); std::vector<VkPresentModeKHR> presentModes = GetPresentModes();
if (presentModes.empty()) if (presentModes.empty())
throw std::runtime_error("No surface present modes supported"); I_Error("No surface present modes supported");
swapChainPresentMode = VK_PRESENT_MODE_FIFO_KHR; swapChainPresentMode = VK_PRESENT_MODE_FIFO_KHR;
if (vsync) if (vsync)
@ -315,12 +315,12 @@ void VulkanSwapChain::GetImages()
uint32_t imageCount; uint32_t imageCount;
VkResult result = vkGetSwapchainImagesKHR(device->device, swapChain, &imageCount, nullptr); VkResult result = vkGetSwapchainImagesKHR(device->device, swapChain, &imageCount, nullptr);
if (result != VK_SUCCESS) if (result != VK_SUCCESS)
throw std::runtime_error("vkGetSwapchainImagesKHR failed"); I_Error("vkGetSwapchainImagesKHR failed");
swapChainImages.resize(imageCount); swapChainImages.resize(imageCount);
result = vkGetSwapchainImagesKHR(device->device, swapChain, &imageCount, swapChainImages.data()); result = vkGetSwapchainImagesKHR(device->device, swapChain, &imageCount, swapChainImages.data());
if (result != VK_SUCCESS) if (result != VK_SUCCESS)
throw std::runtime_error("vkGetSwapchainImagesKHR failed (2)"); I_Error("vkGetSwapchainImagesKHR failed (2)");
} }
void VulkanSwapChain::ReleaseViews() void VulkanSwapChain::ReleaseViews()
@ -344,7 +344,7 @@ VkSurfaceCapabilitiesKHR VulkanSwapChain::GetSurfaceCapabilities()
VkSurfaceCapabilitiesKHR surfaceCapabilities; VkSurfaceCapabilitiesKHR surfaceCapabilities;
VkResult result = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(device->PhysicalDevice.Device, device->surface, &surfaceCapabilities); VkResult result = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(device->PhysicalDevice.Device, device->surface, &surfaceCapabilities);
if (result != VK_SUCCESS) if (result != VK_SUCCESS)
throw std::runtime_error("vkGetPhysicalDeviceSurfaceCapabilitiesKHR failed"); I_Error("vkGetPhysicalDeviceSurfaceCapabilitiesKHR failed");
return surfaceCapabilities; return surfaceCapabilities;
} }
@ -353,14 +353,14 @@ std::vector<VkSurfaceFormatKHR> VulkanSwapChain::GetSurfaceFormats()
uint32_t surfaceFormatCount = 0; uint32_t surfaceFormatCount = 0;
VkResult result = vkGetPhysicalDeviceSurfaceFormatsKHR(device->PhysicalDevice.Device, device->surface, &surfaceFormatCount, nullptr); VkResult result = vkGetPhysicalDeviceSurfaceFormatsKHR(device->PhysicalDevice.Device, device->surface, &surfaceFormatCount, nullptr);
if (result != VK_SUCCESS) if (result != VK_SUCCESS)
throw std::runtime_error("vkGetPhysicalDeviceSurfaceFormatsKHR failed"); I_Error("vkGetPhysicalDeviceSurfaceFormatsKHR failed");
else if (surfaceFormatCount == 0) else if (surfaceFormatCount == 0)
return {}; return {};
std::vector<VkSurfaceFormatKHR> surfaceFormats(surfaceFormatCount); std::vector<VkSurfaceFormatKHR> surfaceFormats(surfaceFormatCount);
result = vkGetPhysicalDeviceSurfaceFormatsKHR(device->PhysicalDevice.Device, device->surface, &surfaceFormatCount, surfaceFormats.data()); result = vkGetPhysicalDeviceSurfaceFormatsKHR(device->PhysicalDevice.Device, device->surface, &surfaceFormatCount, surfaceFormats.data());
if (result != VK_SUCCESS) if (result != VK_SUCCESS)
throw std::runtime_error("vkGetPhysicalDeviceSurfaceFormatsKHR failed"); I_Error("vkGetPhysicalDeviceSurfaceFormatsKHR failed");
return surfaceFormats; return surfaceFormats;
} }
@ -369,13 +369,13 @@ std::vector<VkPresentModeKHR> VulkanSwapChain::GetPresentModes()
uint32_t presentModeCount = 0; uint32_t presentModeCount = 0;
VkResult result = vkGetPhysicalDeviceSurfacePresentModesKHR(device->PhysicalDevice.Device, device->surface, &presentModeCount, nullptr); VkResult result = vkGetPhysicalDeviceSurfacePresentModesKHR(device->PhysicalDevice.Device, device->surface, &presentModeCount, nullptr);
if (result != VK_SUCCESS) if (result != VK_SUCCESS)
throw std::runtime_error("vkGetPhysicalDeviceSurfacePresentModesKHR failed"); I_Error("vkGetPhysicalDeviceSurfacePresentModesKHR failed");
else if (presentModeCount == 0) else if (presentModeCount == 0)
return {}; return {};
std::vector<VkPresentModeKHR> presentModes(presentModeCount); std::vector<VkPresentModeKHR> presentModes(presentModeCount);
vkGetPhysicalDeviceSurfacePresentModesKHR(device->PhysicalDevice.Device, device->surface, &presentModeCount, presentModes.data()); vkGetPhysicalDeviceSurfacePresentModesKHR(device->PhysicalDevice.Device, device->surface, &presentModeCount, presentModes.data());
if (result != VK_SUCCESS) if (result != VK_SUCCESS)
throw std::runtime_error("vkGetPhysicalDeviceSurfacePresentModesKHR failed"); I_Error("vkGetPhysicalDeviceSurfacePresentModesKHR failed");
return presentModes; return presentModes;
} }

View file

@ -137,8 +137,9 @@ void I_InitGraphics ()
{ {
Video = new Win32VulkanVideo(); Video = new Win32VulkanVideo();
} }
catch (CRecoverableError &) catch (CRecoverableError &error)
{ {
Printf(TEXTCOLOR_RED "Initialization of Vulkan failed: %s\n", error.what());
Video = new Win32GLVideo(); Video = new Win32GLVideo();
} }
} }