From 26dd3bdb906a0dab63aee44e186a8f6b321979f0 Mon Sep 17 00:00:00 2001 From: squidbus <175574877+squidbus@users.noreply.github.com> Date: Fri, 20 Sep 2024 00:53:42 -0700 Subject: [PATCH] vulkan: Enable VULKAN_HPP_NO_EXCEPTIONS broadly. --- src/imgui/renderer/imgui_impl_vulkan.h | 1 - src/video_core/buffer_cache/buffer.cpp | 6 ++- .../renderer_vulkan/renderer_vulkan.cpp | 10 +++- src/video_core/renderer_vulkan/vk_common.h | 1 + .../renderer_vulkan/vk_compute_pipeline.cpp | 22 +++++--- .../renderer_vulkan/vk_graphics_pipeline.cpp | 21 +++++--- .../renderer_vulkan/vk_instance.cpp | 41 +++++++++----- .../renderer_vulkan/vk_master_semaphore.cpp | 13 ++++- .../renderer_vulkan/vk_pipeline_cache.cpp | 5 +- .../renderer_vulkan/vk_platform.cpp | 37 ++++++++----- .../renderer_vulkan/vk_rasterizer.cpp | 1 - .../renderer_vulkan/vk_rasterizer.h | 1 - .../renderer_vulkan/vk_resource_pool.cpp | 10 +++- .../renderer_vulkan/vk_scheduler.cpp | 7 +-- .../renderer_vulkan/vk_shader_util.cpp | 11 ++-- .../renderer_vulkan/vk_swapchain.cpp | 54 ++++++++++++------- src/video_core/texture_cache/image.cpp | 1 - src/video_core/texture_cache/image_view.cpp | 5 +- src/video_core/texture_cache/sampler.cpp | 5 +- src/video_core/texture_cache/tile_manager.cpp | 12 +++-- 20 files changed, 172 insertions(+), 92 deletions(-) diff --git a/src/imgui/renderer/imgui_impl_vulkan.h b/src/imgui/renderer/imgui_impl_vulkan.h index e68b8723f5..97609a9405 100644 --- a/src/imgui/renderer/imgui_impl_vulkan.h +++ b/src/imgui/renderer/imgui_impl_vulkan.h @@ -5,7 +5,6 @@ #pragma once -#define VULKAN_HPP_NO_EXCEPTIONS #include "video_core/renderer_vulkan/vk_common.h" struct ImDrawData; diff --git a/src/video_core/buffer_cache/buffer.cpp b/src/video_core/buffer_cache/buffer.cpp index 7029580344..7476f80343 100644 --- a/src/video_core/buffer_cache/buffer.cpp +++ b/src/video_core/buffer_cache/buffer.cpp @@ -129,9 +129,11 @@ vk::BufferView Buffer::View(u32 offset, u32 size, bool is_written, AmdGpu::DataF .range = size, }; const auto view = instance->GetDevice().createBufferView(view_ci); + ASSERT_MSG(view.result == vk::Result::eSuccess, "Failed to create buffer view: {}", + vk::to_string(view.result)); scheduler->DeferOperation( - [view, device = instance->GetDevice()] { device.destroyBufferView(view); }); - return view; + [view, device = instance->GetDevice()] { device.destroyBufferView(view.value); }); + return view.value; } constexpr u64 WATCHES_INITIAL_RESERVE = 0x4000; diff --git a/src/video_core/renderer_vulkan/renderer_vulkan.cpp b/src/video_core/renderer_vulkan/renderer_vulkan.cpp index d019ff0346..f3403fd980 100644 --- a/src/video_core/renderer_vulkan/renderer_vulkan.cpp +++ b/src/video_core/renderer_vulkan/renderer_vulkan.cpp @@ -82,7 +82,10 @@ RendererVulkan::RendererVulkan(Frontend::WindowSDL& window_, AmdGpu::Liverpool* present_frames.resize(num_images); for (u32 i = 0; i < num_images; i++) { Frame& frame = present_frames[i]; - frame.present_done = device.createFence({.flags = vk::FenceCreateFlagBits::eSignaled}); + auto fence_result = device.createFence({.flags = vk::FenceCreateFlagBits::eSignaled}); + ASSERT_MSG(fence_result.result == vk::Result::eSuccess, + "Failed to create present done fence: {}", vk::to_string(fence_result.result)); + frame.present_done = fence_result.value; free_queue.push(&frame); } @@ -157,7 +160,10 @@ void RendererVulkan::RecreateFrame(Frame* frame, u32 width, u32 height) { .layerCount = 1, }, }; - frame->image_view = device.createImageView(view_info); + auto view_result = device.createImageView(view_info); + ASSERT_MSG(view_result.result == vk::Result::eSuccess, "Failed to create frame image view: {}", + vk::to_string(view_result.result)); + frame->image_view = view_result.value; frame->width = width; frame->height = height; } diff --git a/src/video_core/renderer_vulkan/vk_common.h b/src/video_core/renderer_vulkan/vk_common.h index a2f9cbcaf7..e23de78e0d 100644 --- a/src/video_core/renderer_vulkan/vk_common.h +++ b/src/video_core/renderer_vulkan/vk_common.h @@ -14,6 +14,7 @@ #define VULKAN_HPP_NO_CONSTRUCTORS #define VULKAN_HPP_NO_STRUCT_SETTERS #define VULKAN_HPP_HAS_SPACESHIP_OPERATOR +#define VULKAN_HPP_NO_EXCEPTIONS #include #define VMA_STATIC_VULKAN_FUNCTIONS 0 diff --git a/src/video_core/renderer_vulkan/vk_compute_pipeline.cpp b/src/video_core/renderer_vulkan/vk_compute_pipeline.cpp index 96358bf67a..3760c3fe06 100644 --- a/src/video_core/renderer_vulkan/vk_compute_pipeline.cpp +++ b/src/video_core/renderer_vulkan/vk_compute_pipeline.cpp @@ -77,7 +77,12 @@ ComputePipeline::ComputePipeline(const Instance& instance_, Scheduler& scheduler .bindingCount = static_cast(bindings.size()), .pBindings = bindings.data(), }; - desc_layout = instance.GetDevice().createDescriptorSetLayoutUnique(desc_layout_ci); + auto descriptor_set_result = + instance.GetDevice().createDescriptorSetLayoutUnique(desc_layout_ci); + ASSERT_MSG(descriptor_set_result.result == vk::Result::eSuccess, + "Failed to create compute descriptor set layout: {}", + vk::to_string(descriptor_set_result.result)); + desc_layout = std::move(descriptor_set_result.value); const vk::DescriptorSetLayout set_layout = *desc_layout; const vk::PipelineLayoutCreateInfo layout_info = { @@ -86,19 +91,20 @@ ComputePipeline::ComputePipeline(const Instance& instance_, Scheduler& scheduler .pushConstantRangeCount = 1U, .pPushConstantRanges = &push_constants, }; - pipeline_layout = instance.GetDevice().createPipelineLayoutUnique(layout_info); + auto layout_result = instance.GetDevice().createPipelineLayoutUnique(layout_info); + ASSERT_MSG(layout_result.result == vk::Result::eSuccess, + "Failed to create compute pipeline layout: {}", vk::to_string(layout_result.result)); + pipeline_layout = std::move(layout_result.value); const vk::ComputePipelineCreateInfo compute_pipeline_ci = { .stage = shader_ci, .layout = *pipeline_layout, }; - auto result = + auto pipeline_result = instance.GetDevice().createComputePipelineUnique(pipeline_cache, compute_pipeline_ci); - if (result.result == vk::Result::eSuccess) { - pipeline = std::move(result.value); - } else { - UNREACHABLE_MSG("Graphics pipeline creation failed!"); - } + ASSERT_MSG(pipeline_result.result == vk::Result::eSuccess, + "Failed to create compute pipeline: {}", vk::to_string(pipeline_result.result)); + pipeline = std::move(pipeline_result.value); } ComputePipeline::~ComputePipeline() = default; diff --git a/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp b/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp index f7474b24ec..8c5a59483d 100644 --- a/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp +++ b/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp @@ -39,7 +39,11 @@ GraphicsPipeline::GraphicsPipeline(const Instance& instance_, Scheduler& schedul .pushConstantRangeCount = 1, .pPushConstantRanges = &push_constants, }; - pipeline_layout = instance.GetDevice().createPipelineLayoutUnique(layout_info); + auto layout_result = instance.GetDevice().createPipelineLayoutUnique(layout_info); + ASSERT_MSG(layout_result.result == vk::Result::eSuccess, + "Failed to create graphics pipeline layout: {}", + vk::to_string(layout_result.result)); + pipeline_layout = std::move(layout_result.value); boost::container::static_vector bindings; boost::container::static_vector attributes; @@ -280,12 +284,10 @@ GraphicsPipeline::GraphicsPipeline(const Instance& instance_, Scheduler& schedul .layout = *pipeline_layout, }; - auto result = device.createGraphicsPipelineUnique(pipeline_cache, pipeline_info); - if (result.result == vk::Result::eSuccess) { - pipeline = std::move(result.value); - } else { - UNREACHABLE_MSG("Graphics pipeline creation failed!"); - } + auto pipeline_result = device.createGraphicsPipelineUnique(pipeline_cache, pipeline_info); + ASSERT_MSG(pipeline_result.result == vk::Result::eSuccess, + "Failed to create graphics pipeline: {}", vk::to_string(pipeline_result.result)); + pipeline = std::move(pipeline_result.value); } GraphicsPipeline::~GraphicsPipeline() = default; @@ -343,7 +345,10 @@ void GraphicsPipeline::BuildDescSetLayout() { .bindingCount = static_cast(bindings.size()), .pBindings = bindings.data(), }; - desc_layout = instance.GetDevice().createDescriptorSetLayoutUnique(desc_layout_ci); + auto result = instance.GetDevice().createDescriptorSetLayoutUnique(desc_layout_ci); + ASSERT_MSG(result.result == vk::Result::eSuccess, + "Failed to create graphics descriptor set layout: {}", vk::to_string(result.result)); + desc_layout = std::move(result.value); } void GraphicsPipeline::BindResources(const Liverpool::Regs& regs, diff --git a/src/video_core/renderer_vulkan/vk_instance.cpp b/src/video_core/renderer_vulkan/vk_instance.cpp index d88d432915..dabcf8c605 100644 --- a/src/video_core/renderer_vulkan/vk_instance.cpp +++ b/src/video_core/renderer_vulkan/vk_instance.cpp @@ -23,11 +23,23 @@ namespace Vulkan { namespace { +std::vector EnumeratePhysicalDevices(vk::UniqueInstance& instance) { + auto devices_result = instance->enumeratePhysicalDevices(); + ASSERT_MSG(devices_result.result == vk::Result::eSuccess, + "Failed to enumerate physical devices: {}", vk::to_string(devices_result.result)); + return std::move(devices_result.value); +} + std::vector GetSupportedExtensions(vk::PhysicalDevice physical) { - const std::vector extensions = physical.enumerateDeviceExtensionProperties(); + const auto extensions = physical.enumerateDeviceExtensionProperties(); + if (extensions.result != vk::Result::eSuccess) { + LOG_ERROR(Render_Vulkan, "Could not query supported extensions: {}", + vk::to_string(extensions.result)); + return {}; + } std::vector supported_extensions; - supported_extensions.reserve(extensions.size()); - for (const auto& extension : extensions) { + supported_extensions.reserve(extensions.value.size()); + for (const auto& extension : extensions.value) { supported_extensions.emplace_back(extension.extensionName.data()); } return supported_extensions; @@ -52,13 +64,13 @@ std::string GetReadableVersion(u32 version) { Instance::Instance(bool enable_validation, bool enable_crash_diagnostic) : instance{CreateInstance(Frontend::WindowSystemType::Headless, enable_validation, enable_crash_diagnostic)}, - physical_devices{instance->enumeratePhysicalDevices()} {} + physical_devices{EnumeratePhysicalDevices(instance)} {} Instance::Instance(Frontend::WindowSDL& window, s32 physical_device_index, bool enable_validation /*= false*/, bool enable_crash_diagnostic /*= false*/) : instance{CreateInstance(window.getWindowInfo().type, enable_validation, enable_crash_diagnostic)}, - physical_devices{instance->enumeratePhysicalDevices()} { + physical_devices{EnumeratePhysicalDevices(instance)} { if (enable_validation) { debug_callback = CreateDebugCallback(*instance); } @@ -385,15 +397,13 @@ bool Instance::CreateDevice() { device_chain.unlink(); } - try { - device = physical_device.createDeviceUnique(device_chain.get()); - } catch (vk::ExtensionNotPresentError& err) { - LOG_CRITICAL(Render_Vulkan, "Some required extensions are not available {}", err.what()); - return false; - } catch (vk::FeatureNotPresentError& err) { - LOG_CRITICAL(Render_Vulkan, "Some required features are not available {}", err.what()); + auto device_result = physical_device.createDeviceUnique(device_chain.get()); + if (device_result.result != vk::Result::eSuccess) { + LOG_CRITICAL(Render_Vulkan, "Failed to create device: {}", + vk::to_string(device_result.result)); return false; } + device = std::move(device_result.value); VULKAN_HPP_DEFAULT_DISPATCHER.init(*device); @@ -478,7 +488,12 @@ void Instance::CollectToolingInfo() { return; } const auto tools = physical_device.getToolPropertiesEXT(); - for (const vk::PhysicalDeviceToolProperties& tool : tools) { + if (tools.result != vk::Result::eSuccess) { + LOG_ERROR(Render_Vulkan, "Could not get Vulkan tool properties: {}", + vk::to_string(tools.result)); + return; + } + for (const vk::PhysicalDeviceToolProperties& tool : tools.value) { const std::string_view name = tool.name; LOG_INFO(Render_Vulkan, "Attached debugging tool: {}", name); has_renderdoc = has_renderdoc || name == "RenderDoc"; diff --git a/src/video_core/renderer_vulkan/vk_master_semaphore.cpp b/src/video_core/renderer_vulkan/vk_master_semaphore.cpp index 753f2bbdf5..0787d8ff20 100644 --- a/src/video_core/renderer_vulkan/vk_master_semaphore.cpp +++ b/src/video_core/renderer_vulkan/vk_master_semaphore.cpp @@ -5,6 +5,8 @@ #include "video_core/renderer_vulkan/vk_instance.h" #include "video_core/renderer_vulkan/vk_master_semaphore.h" +#include "common/assert.h" + namespace Vulkan { constexpr u64 WAIT_TIMEOUT = std::numeric_limits::max(); @@ -17,7 +19,10 @@ MasterSemaphore::MasterSemaphore(const Instance& instance_) : instance{instance_ .initialValue = 0, }, }; - semaphore = instance.GetDevice().createSemaphoreUnique(semaphore_chain.get()); + auto result = instance.GetDevice().createSemaphoreUnique(semaphore_chain.get()); + ASSERT_MSG(result.result == vk::Result::eSuccess, "Failed to create master semaphore: {}", + vk::to_string(result.result)); + semaphore = std::move(result.value); } MasterSemaphore::~MasterSemaphore() = default; @@ -27,7 +32,11 @@ void MasterSemaphore::Refresh() { u64 counter{}; do { this_tick = gpu_tick.load(std::memory_order_acquire); - counter = instance.GetDevice().getSemaphoreCounterValue(*semaphore); + auto counter_result = instance.GetDevice().getSemaphoreCounterValue(*semaphore); + ASSERT_MSG(counter_result.result == vk::Result::eSuccess, + "Failed to get master semaphore value: {}", + vk::to_string(counter_result.result)); + counter = counter_result.value; if (counter < this_tick) { return; } diff --git a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp index 7f6079a5c7..73a115b4a6 100644 --- a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp +++ b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp @@ -136,7 +136,10 @@ PipelineCache::PipelineCache(const Instance& instance_, Scheduler& scheduler_, .subgroup_size = instance.SubgroupSize(), .support_explicit_workgroup_layout = true, }; - pipeline_cache = instance.GetDevice().createPipelineCacheUnique({}); + auto cache_result = instance.GetDevice().createPipelineCacheUnique({}); + ASSERT_MSG(cache_result.result == vk::Result::eSuccess, "Failed to create pipeline cache: {}", + vk::to_string(cache_result.result)); + pipeline_cache = std::move(cache_result.value); } PipelineCache::~PipelineCache() = default; diff --git a/src/video_core/renderer_vulkan/vk_platform.cpp b/src/video_core/renderer_vulkan/vk_platform.cpp index feadda96c8..f85644a53e 100644 --- a/src/video_core/renderer_vulkan/vk_platform.cpp +++ b/src/video_core/renderer_vulkan/vk_platform.cpp @@ -135,11 +135,13 @@ vk::SurfaceKHR CreateSurface(vk::Instance instance, const Frontend::WindowSDL& e std::vector GetInstanceExtensions(Frontend::WindowSystemType window_type, bool enable_debug_utils) { - const auto properties = vk::enumerateInstanceExtensionProperties(); - if (properties.empty()) { - LOG_ERROR(Render_Vulkan, "Failed to query extension properties"); + const auto properties_result = vk::enumerateInstanceExtensionProperties(); + if (properties_result.result != vk::Result::eSuccess || properties_result.value.empty()) { + LOG_ERROR(Render_Vulkan, "Failed to query extension properties: {}", + vk::to_string(properties_result.result)); return {}; } + const auto& properties = properties_result.value; // Add the windowing system specific extension std::vector extensions; @@ -208,14 +210,16 @@ vk::UniqueInstance CreateInstance(Frontend::WindowSystemType window_type, bool e #endif VULKAN_HPP_DEFAULT_DISPATCHER.init(vkGetInstanceProcAddr); - const u32 available_version = VULKAN_HPP_DEFAULT_DISPATCHER.vkEnumerateInstanceVersion - ? vk::enumerateInstanceVersion() - : VK_API_VERSION_1_0; - - ASSERT_MSG(available_version >= TargetVulkanApiVersion, + const auto available_version = VULKAN_HPP_DEFAULT_DISPATCHER.vkEnumerateInstanceVersion + ? vk::enumerateInstanceVersion() + : vk::ResultValue(vk::Result::eSuccess, VK_API_VERSION_1_0); + ASSERT_MSG(available_version.result == vk::Result::eSuccess, + "Failed to query Vulkan API version: {}", vk::to_string(available_version.result)); + ASSERT_MSG(available_version.value >= TargetVulkanApiVersion, "Vulkan {}.{} is required, but only {}.{} is supported by instance!", VK_VERSION_MAJOR(TargetVulkanApiVersion), VK_VERSION_MINOR(TargetVulkanApiVersion), - VK_VERSION_MAJOR(available_version), VK_VERSION_MINOR(available_version)); + VK_VERSION_MAJOR(available_version.value), + VK_VERSION_MINOR(available_version.value)); const auto extensions = GetInstanceExtensions(window_type, true); @@ -224,7 +228,7 @@ vk::UniqueInstance CreateInstance(Frontend::WindowSystemType window_type, bool e .applicationVersion = VK_MAKE_VERSION(1, 0, 0), .pEngineName = "shadPS4 Vulkan", .engineVersion = VK_MAKE_VERSION(1, 0, 0), - .apiVersion = available_version, + .apiVersion = available_version.value, }; u32 num_layers = 0; @@ -342,11 +346,13 @@ vk::UniqueInstance CreateInstance(Frontend::WindowSystemType window_type, bool e }, }; - auto instance = vk::createInstanceUnique(instance_ci_chain.get()); + auto instance_result = vk::createInstanceUnique(instance_ci_chain.get()); + ASSERT_MSG(instance_result.result == vk::Result::eSuccess, "Failed to create instance: {}", + vk::to_string(instance_result.result)); - VULKAN_HPP_DEFAULT_DISPATCHER.init(*instance); + VULKAN_HPP_DEFAULT_DISPATCHER.init(*instance_result.value); - return instance; + return std::move(instance_result.value); } vk::UniqueDebugUtilsMessengerEXT CreateDebugCallback(vk::Instance instance) { @@ -360,7 +366,10 @@ vk::UniqueDebugUtilsMessengerEXT CreateDebugCallback(vk::Instance instance) { vk::DebugUtilsMessageTypeFlagBitsEXT::ePerformance, .pfnUserCallback = DebugUtilsCallback, }; - return instance.createDebugUtilsMessengerEXTUnique(msg_ci); + auto result = instance.createDebugUtilsMessengerEXTUnique(msg_ci); + ASSERT_MSG(result.result == vk::Result::eSuccess, "Failed to create debug callback: {}", + vk::to_string(result.result)); + return std::move(result.value); } } // namespace Vulkan diff --git a/src/video_core/renderer_vulkan/vk_rasterizer.cpp b/src/video_core/renderer_vulkan/vk_rasterizer.cpp index 23f60da13f..debedbd234 100644 --- a/src/video_core/renderer_vulkan/vk_rasterizer.cpp +++ b/src/video_core/renderer_vulkan/vk_rasterizer.cpp @@ -24,7 +24,6 @@ Rasterizer::Rasterizer(const Instance& instance_, Scheduler& scheduler_, liverpool->BindRasterizer(this); } memory->SetRasterizer(this); - wfi_event = instance.GetDevice().createEventUnique({}); } Rasterizer::~Rasterizer() = default; diff --git a/src/video_core/renderer_vulkan/vk_rasterizer.h b/src/video_core/renderer_vulkan/vk_rasterizer.h index 5aa90c5ccc..9056bd921c 100644 --- a/src/video_core/renderer_vulkan/vk_rasterizer.h +++ b/src/video_core/renderer_vulkan/vk_rasterizer.h @@ -67,7 +67,6 @@ class Rasterizer { AmdGpu::Liverpool* liverpool; Core::MemoryManager* memory; PipelineCache pipeline_cache; - vk::UniqueEvent wfi_event; }; } // namespace Vulkan diff --git a/src/video_core/renderer_vulkan/vk_resource_pool.cpp b/src/video_core/renderer_vulkan/vk_resource_pool.cpp index a5ee22c252..ab6f405d1e 100644 --- a/src/video_core/renderer_vulkan/vk_resource_pool.cpp +++ b/src/video_core/renderer_vulkan/vk_resource_pool.cpp @@ -69,7 +69,10 @@ CommandPool::CommandPool(const Instance& instance, MasterSemaphore* master_semap .queueFamilyIndex = instance.GetGraphicsQueueFamilyIndex(), }; const vk::Device device = instance.GetDevice(); - cmd_pool = device.createCommandPoolUnique(pool_create_info); + auto result = device.createCommandPoolUnique(pool_create_info); + ASSERT_MSG(result.result == vk::Result::eSuccess, "Failed to create command pool: {}", + vk::to_string(result.result)); + cmd_pool = std::move(result.value); if (instance.HasDebuggingToolAttached()) { SetObjectName(device, *cmd_pool, "CommandPool"); } @@ -182,7 +185,10 @@ void DescriptorHeap::CreateDescriptorPool() { .poolSizeCount = static_cast(pool_sizes.size()), .pPoolSizes = pool_sizes.data(), }; - curr_pool = device.createDescriptorPool(pool_info); + auto result = device.createDescriptorPool(pool_info); + ASSERT_MSG(result.result == vk::Result::eSuccess, "Failed to create descriptor pool: {}", + vk::to_string(result.result)); + curr_pool = result.value; } } // namespace Vulkan diff --git a/src/video_core/renderer_vulkan/vk_scheduler.cpp b/src/video_core/renderer_vulkan/vk_scheduler.cpp index 9ff332aefe..7506ad6ddf 100644 --- a/src/video_core/renderer_vulkan/vk_scheduler.cpp +++ b/src/video_core/renderer_vulkan/vk_scheduler.cpp @@ -189,11 +189,8 @@ void Scheduler::SubmitExecution(SubmitInfo& info) { .pSignalSemaphores = info.signal_semas.data(), }; - try { - instance.GetGraphicsQueue().submit(submit_info, info.fence); - } catch (vk::DeviceLostError& err) { - UNREACHABLE_MSG("Device lost during submit: {}", err.what()); - } + auto submit_result = instance.GetGraphicsQueue().submit(submit_info, info.fence); + ASSERT_MSG(submit_result != vk::Result::eErrorDeviceLost, "Device lost during submit"); master_semaphore.Refresh(); AllocateWorkerCommandBuffers(); diff --git a/src/video_core/renderer_vulkan/vk_shader_util.cpp b/src/video_core/renderer_vulkan/vk_shader_util.cpp index 687760110c..9985014053 100644 --- a/src/video_core/renderer_vulkan/vk_shader_util.cpp +++ b/src/video_core/renderer_vulkan/vk_shader_util.cpp @@ -218,13 +218,10 @@ vk::ShaderModule CompileSPV(std::span code, vk::Device device) { .pCode = code.data(), }; - try { - return device.createShaderModule(shader_info); - } catch (vk::SystemError& err) { - UNREACHABLE_MSG("{}", err.what()); - } - - return {}; + auto result = device.createShaderModule(shader_info); + ASSERT_MSG(result.result == vk::Result::eSuccess, "Failed to compile SPIR-V shader: {}", + vk::to_string(result.result)); + return result.value; } } // namespace Vulkan diff --git a/src/video_core/renderer_vulkan/vk_swapchain.cpp b/src/video_core/renderer_vulkan/vk_swapchain.cpp index dcc19bf3b1..9360d69cdc 100644 --- a/src/video_core/renderer_vulkan/vk_swapchain.cpp +++ b/src/video_core/renderer_vulkan/vk_swapchain.cpp @@ -39,11 +39,14 @@ void Swapchain::Create(u32 width_, u32 height_, vk::SurfaceKHR surface_) { const auto modes = instance.GetPhysicalDevice().getSurfacePresentModesKHR(surface); const auto find_mode = [&modes](vk::PresentModeKHR requested) { + if (modes.result != vk::Result::eSuccess) { + return false; + } const auto it = - std::find_if(modes.begin(), modes.end(), + std::find_if(modes.value.begin(), modes.value.end(), [&requested](vk::PresentModeKHR mode) { return mode == requested; }); - return it != modes.end(); + return it != modes.value.end(); }; const bool has_mailbox = find_mode(vk::PresentModeKHR::eMailbox); @@ -70,12 +73,10 @@ void Swapchain::Create(u32 width_, u32 height_, vk::SurfaceKHR surface_) { .oldSwapchain = nullptr, }; - try { - swapchain = instance.GetDevice().createSwapchainKHR(swapchain_info); - } catch (vk::SystemError& err) { - LOG_CRITICAL(Render_Vulkan, "{}", err.what()); - UNREACHABLE(); - } + auto swapchain_result = instance.GetDevice().createSwapchainKHR(swapchain_info); + ASSERT_MSG(swapchain_result.result == vk::Result::eSuccess, "Failed to create swapchain: {}", + vk::to_string(swapchain_result.result)); + swapchain = std::move(swapchain_result.value); SetupImages(); RefreshSemaphores(); @@ -119,20 +120,22 @@ void Swapchain::Present() { .pImageIndices = &image_index, }; - try { - [[maybe_unused]] vk::Result result = instance.GetPresentQueue().presentKHR(present_info); - } catch (vk::OutOfDateKHRError&) { + auto result = instance.GetPresentQueue().presentKHR(present_info); + if (result == vk::Result::eErrorOutOfDateKHR) { needs_recreation = true; - } catch (const vk::SystemError& err) { - LOG_CRITICAL(Render_Vulkan, "Swapchain presentation failed {}", err.what()); - UNREACHABLE(); + } else { + ASSERT_MSG(result == vk::Result::eSuccess, "Swapchain presentation failed: {}", + vk::to_string(result)); } frame_index = (frame_index + 1) % image_count; } void Swapchain::FindPresentFormat() { - const auto formats = instance.GetPhysicalDevice().getSurfaceFormatsKHR(surface); + const auto formats_result = instance.GetPhysicalDevice().getSurfaceFormatsKHR(surface); + ASSERT_MSG(formats_result.result == vk::Result::eSuccess, "Failed to query surface formats: {}", + vk::to_string(formats_result.result)); + const auto& formats = formats_result.value; // If there is a single undefined surface format, the device doesn't care, so we'll just use // RGBA sRGB. @@ -158,8 +161,12 @@ void Swapchain::FindPresentFormat() { } void Swapchain::SetSurfaceProperties() { - const vk::SurfaceCapabilitiesKHR capabilities = + const auto capabilities_result = instance.GetPhysicalDevice().getSurfaceCapabilitiesKHR(surface); + ASSERT_MSG(capabilities_result.result == vk::Result::eSuccess, + "Failed to query surface capabilities: {}", + vk::to_string(capabilities_result.result)); + const auto& capabilities = capabilities_result.value; extent = capabilities.currentExtent; if (capabilities.currentExtent.width == std::numeric_limits::max()) { @@ -207,10 +214,16 @@ void Swapchain::RefreshSemaphores() { present_ready.resize(image_count); for (vk::Semaphore& semaphore : image_acquired) { - semaphore = device.createSemaphore({}); + auto result = device.createSemaphore({}); + ASSERT_MSG(result.result == vk::Result::eSuccess, + "Failed to create image acquired semaphore: {}", vk::to_string(result.result)); + semaphore = result.value; } for (vk::Semaphore& semaphore : present_ready) { - semaphore = device.createSemaphore({}); + auto result = device.createSemaphore({}); + ASSERT_MSG(result.result == vk::Result::eSuccess, + "Failed to create present ready semaphore: {}", vk::to_string(result.result)); + semaphore = result.value; } if (instance.HasDebuggingToolAttached()) { @@ -223,7 +236,10 @@ void Swapchain::RefreshSemaphores() { void Swapchain::SetupImages() { vk::Device device = instance.GetDevice(); - images = device.getSwapchainImagesKHR(swapchain); + auto images_result = device.getSwapchainImagesKHR(swapchain); + ASSERT_MSG(images_result.result == vk::Result::eSuccess, + "Failed to create swapchain images: {}", vk::to_string(images_result.result)); + images = std::move(images_result.value); image_count = static_cast(images.size()); if (instance.HasDebuggingToolAttached()) { diff --git a/src/video_core/texture_cache/image.cpp b/src/video_core/texture_cache/image.cpp index 9e8c38f0de..c242015a54 100644 --- a/src/video_core/texture_cache/image.cpp +++ b/src/video_core/texture_cache/image.cpp @@ -1,7 +1,6 @@ // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later -#define VULKAN_HPP_NO_EXCEPTIONS #include "common/assert.h" #include "video_core/renderer_vulkan/liverpool_to_vk.h" #include "video_core/renderer_vulkan/vk_instance.h" diff --git a/src/video_core/texture_cache/image_view.cpp b/src/video_core/texture_cache/image_view.cpp index f94c1a37b6..7457986fd6 100644 --- a/src/video_core/texture_cache/image_view.cpp +++ b/src/video_core/texture_cache/image_view.cpp @@ -152,7 +152,10 @@ ImageView::ImageView(const Vulkan::Instance& instance, const ImageViewInfo& info .layerCount = info.range.extent.layers - info.range.base.layer, }, }; - image_view = instance.GetDevice().createImageViewUnique(image_view_ci); + auto result = instance.GetDevice().createImageViewUnique(image_view_ci); + ASSERT_MSG(result.result == vk::Result::eSuccess, "Failed to create image view: {}", + vk::to_string(result.result)); + image_view = std::move(result.value); } ImageView::~ImageView() = default; diff --git a/src/video_core/texture_cache/sampler.cpp b/src/video_core/texture_cache/sampler.cpp index 19c92712cb..72cb727a2e 100644 --- a/src/video_core/texture_cache/sampler.cpp +++ b/src/video_core/texture_cache/sampler.cpp @@ -24,7 +24,10 @@ Sampler::Sampler(const Vulkan::Instance& instance, const AmdGpu::Sampler& sample .borderColor = LiverpoolToVK::BorderColor(sampler.border_color_type), .unnormalizedCoordinates = bool(sampler.force_unnormalized), }; - handle = instance.GetDevice().createSamplerUnique(sampler_ci); + auto result = instance.GetDevice().createSamplerUnique(sampler_ci); + ASSERT_MSG(result.result == vk::Result::eSuccess, "Failed to create sampler: {}", + vk::to_string(result.result)); + handle = std::move(result.value); } Sampler::~Sampler() = default; diff --git a/src/video_core/texture_cache/tile_manager.cpp b/src/video_core/texture_cache/tile_manager.cpp index 7e06291e73..7f9b078b25 100644 --- a/src/video_core/texture_cache/tile_manager.cpp +++ b/src/video_core/texture_cache/tile_manager.cpp @@ -298,8 +298,11 @@ TileManager::TileManager(const Vulkan::Instance& instance, Vulkan::Scheduler& sc .bindingCount = static_cast(bindings.size()), .pBindings = bindings.data(), }; - static auto desc_layout = + static auto desc_layout_result = instance.GetDevice().createDescriptorSetLayoutUnique(desc_layout_ci); + ASSERT_MSG(desc_layout_result.result == vk::Result::eSuccess, + "Failed to create descriptor set layout: {}", + vk::to_string(desc_layout_result.result)); const vk::PushConstantRange push_constants = { .stageFlags = vk::ShaderStageFlagBits::eCompute, @@ -307,14 +310,17 @@ TileManager::TileManager(const Vulkan::Instance& instance, Vulkan::Scheduler& sc .size = sizeof(DetilerParams), }; - const vk::DescriptorSetLayout set_layout = *desc_layout; + const vk::DescriptorSetLayout set_layout = *desc_layout_result.value; const vk::PipelineLayoutCreateInfo layout_info = { .setLayoutCount = 1U, .pSetLayouts = &set_layout, .pushConstantRangeCount = 1, .pPushConstantRanges = &push_constants, }; - ctx.pl_layout = instance.GetDevice().createPipelineLayoutUnique(layout_info); + auto layout_result = instance.GetDevice().createPipelineLayoutUnique(layout_info); + ASSERT_MSG(layout_result.result == vk::Result::eSuccess, + "Failed to create pipeline layout: {}", vk::to_string(layout_result.result)); + ctx.pl_layout = std::move(layout_result.value); const vk::ComputePipelineCreateInfo compute_pipeline_ci = { .stage = shader_ci,