vulkan: Enable VULKAN_HPP_NO_EXCEPTIONS broadly. (#995)

* vulkan: Enable VULKAN_HPP_NO_EXCEPTIONS broadly.

* vulkan: Use structured bindings for result where possible.
This commit is contained in:
squidbus 2024-09-25 02:19:38 -07:00 committed by GitHub
parent 36ef61908d
commit b2de662d67
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
22 changed files with 205 additions and 106 deletions

View file

@ -98,7 +98,11 @@ void OnResize() {
} }
void Shutdown(const vk::Device& device) { void Shutdown(const vk::Device& device) {
device.waitIdle(); auto result = device.waitIdle();
if (result != vk::Result::eSuccess) {
LOG_WARNING(ImGui, "Failed to wait for Vulkan device idle on shutdown: {}",
vk::to_string(result));
}
TextureManager::StopWorker(); TextureManager::StopWorker();

View file

@ -5,7 +5,6 @@
#pragma once #pragma once
#define VULKAN_HPP_NO_EXCEPTIONS
#include "common/types.h" #include "common/types.h"
#include "video_core/renderer_vulkan/vk_common.h" #include "video_core/renderer_vulkan/vk_common.h"

View file

@ -128,7 +128,9 @@ vk::BufferView Buffer::View(u32 offset, u32 size, bool is_written, AmdGpu::DataF
.offset = offset, .offset = offset,
.range = size, .range = size,
}; };
const auto view = instance->GetDevice().createBufferView(view_ci); const auto [view_result, 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( scheduler->DeferOperation(
[view, device = instance->GetDevice()] { device.destroyBufferView(view); }); [view, device = instance->GetDevice()] { device.destroyBufferView(view); });
return view; return view;

View file

@ -82,7 +82,11 @@ RendererVulkan::RendererVulkan(Frontend::WindowSDL& window_, AmdGpu::Liverpool*
present_frames.resize(num_images); present_frames.resize(num_images);
for (u32 i = 0; i < num_images; i++) { for (u32 i = 0; i < num_images; i++) {
Frame& frame = present_frames[i]; Frame& frame = present_frames[i];
frame.present_done = device.createFence({.flags = vk::FenceCreateFlagBits::eSignaled}); auto [fence_result, fence] =
device.createFence({.flags = vk::FenceCreateFlagBits::eSignaled});
ASSERT_MSG(fence_result == vk::Result::eSuccess, "Failed to create present done fence: {}",
vk::to_string(fence_result));
frame.present_done = fence;
free_queue.push(&frame); free_queue.push(&frame);
} }
@ -157,7 +161,10 @@ void RendererVulkan::RecreateFrame(Frame* frame, u32 width, u32 height) {
.layerCount = 1, .layerCount = 1,
}, },
}; };
frame->image_view = device.createImageView(view_info); auto [view_result, view] = device.createImageView(view_info);
ASSERT_MSG(view_result == vk::Result::eSuccess, "Failed to create frame image view: {}",
vk::to_string(view_result));
frame->image_view = view;
frame->width = width; frame->width = width;
frame->height = height; frame->height = height;
} }

View file

@ -14,6 +14,9 @@
#define VULKAN_HPP_NO_CONSTRUCTORS #define VULKAN_HPP_NO_CONSTRUCTORS
#define VULKAN_HPP_NO_STRUCT_SETTERS #define VULKAN_HPP_NO_STRUCT_SETTERS
#define VULKAN_HPP_HAS_SPACESHIP_OPERATOR #define VULKAN_HPP_HAS_SPACESHIP_OPERATOR
#define VULKAN_HPP_NO_EXCEPTIONS
// Define assert-on-result to nothing to instead return the result for our handling.
#define VULKAN_HPP_ASSERT_ON_RESULT
#include <vulkan/vulkan.hpp> #include <vulkan/vulkan.hpp>
#define VMA_STATIC_VULKAN_FUNCTIONS 0 #define VMA_STATIC_VULKAN_FUNCTIONS 0

View file

@ -78,7 +78,12 @@ ComputePipeline::ComputePipeline(const Instance& instance_, Scheduler& scheduler
.bindingCount = static_cast<u32>(bindings.size()), .bindingCount = static_cast<u32>(bindings.size()),
.pBindings = bindings.data(), .pBindings = bindings.data(),
}; };
desc_layout = instance.GetDevice().createDescriptorSetLayoutUnique(desc_layout_ci); auto [descriptor_set_result, descriptor_set] =
instance.GetDevice().createDescriptorSetLayoutUnique(desc_layout_ci);
ASSERT_MSG(descriptor_set_result == vk::Result::eSuccess,
"Failed to create compute descriptor set layout: {}",
vk::to_string(descriptor_set_result));
desc_layout = std::move(descriptor_set);
const vk::DescriptorSetLayout set_layout = *desc_layout; const vk::DescriptorSetLayout set_layout = *desc_layout;
const vk::PipelineLayoutCreateInfo layout_info = { const vk::PipelineLayoutCreateInfo layout_info = {
@ -87,19 +92,20 @@ ComputePipeline::ComputePipeline(const Instance& instance_, Scheduler& scheduler
.pushConstantRangeCount = 1U, .pushConstantRangeCount = 1U,
.pPushConstantRanges = &push_constants, .pPushConstantRanges = &push_constants,
}; };
pipeline_layout = instance.GetDevice().createPipelineLayoutUnique(layout_info); auto [layout_result, layout] = instance.GetDevice().createPipelineLayoutUnique(layout_info);
ASSERT_MSG(layout_result == vk::Result::eSuccess,
"Failed to create compute pipeline layout: {}", vk::to_string(layout_result));
pipeline_layout = std::move(layout);
const vk::ComputePipelineCreateInfo compute_pipeline_ci = { const vk::ComputePipelineCreateInfo compute_pipeline_ci = {
.stage = shader_ci, .stage = shader_ci,
.layout = *pipeline_layout, .layout = *pipeline_layout,
}; };
auto result = auto [pipeline_result, pipe] =
instance.GetDevice().createComputePipelineUnique(pipeline_cache, compute_pipeline_ci); instance.GetDevice().createComputePipelineUnique(pipeline_cache, compute_pipeline_ci);
if (result.result == vk::Result::eSuccess) { ASSERT_MSG(pipeline_result == vk::Result::eSuccess, "Failed to create compute pipeline: {}",
pipeline = std::move(result.value); vk::to_string(pipeline_result));
} else { pipeline = std::move(pipe);
UNREACHABLE_MSG("Graphics pipeline creation failed!");
}
} }
ComputePipeline::~ComputePipeline() = default; ComputePipeline::~ComputePipeline() = default;

View file

@ -39,7 +39,10 @@ GraphicsPipeline::GraphicsPipeline(const Instance& instance_, Scheduler& schedul
.pushConstantRangeCount = 1, .pushConstantRangeCount = 1,
.pPushConstantRanges = &push_constants, .pPushConstantRanges = &push_constants,
}; };
pipeline_layout = instance.GetDevice().createPipelineLayoutUnique(layout_info); auto [layout_result, layout] = instance.GetDevice().createPipelineLayoutUnique(layout_info);
ASSERT_MSG(layout_result == vk::Result::eSuccess,
"Failed to create graphics pipeline layout: {}", vk::to_string(layout_result));
pipeline_layout = std::move(layout);
boost::container::static_vector<vk::VertexInputBindingDescription, 32> vertex_bindings; boost::container::static_vector<vk::VertexInputBindingDescription, 32> vertex_bindings;
boost::container::static_vector<vk::VertexInputAttributeDescription, 32> vertex_attributes; boost::container::static_vector<vk::VertexInputAttributeDescription, 32> vertex_attributes;
@ -281,12 +284,11 @@ GraphicsPipeline::GraphicsPipeline(const Instance& instance_, Scheduler& schedul
.layout = *pipeline_layout, .layout = *pipeline_layout,
}; };
auto result = device.createGraphicsPipelineUnique(pipeline_cache, pipeline_info); auto [pipeline_result, pipe] =
if (result.result == vk::Result::eSuccess) { device.createGraphicsPipelineUnique(pipeline_cache, pipeline_info);
pipeline = std::move(result.value); ASSERT_MSG(pipeline_result == vk::Result::eSuccess, "Failed to create graphics pipeline: {}",
} else { vk::to_string(pipeline_result));
UNREACHABLE_MSG("Graphics pipeline creation failed!"); pipeline = std::move(pipe);
}
} }
GraphicsPipeline::~GraphicsPipeline() = default; GraphicsPipeline::~GraphicsPipeline() = default;
@ -345,7 +347,11 @@ void GraphicsPipeline::BuildDescSetLayout() {
.bindingCount = static_cast<u32>(bindings.size()), .bindingCount = static_cast<u32>(bindings.size()),
.pBindings = bindings.data(), .pBindings = bindings.data(),
}; };
desc_layout = instance.GetDevice().createDescriptorSetLayoutUnique(desc_layout_ci); auto [layout_result, layout] =
instance.GetDevice().createDescriptorSetLayoutUnique(desc_layout_ci);
ASSERT_MSG(layout_result == vk::Result::eSuccess,
"Failed to create graphics descriptor set layout: {}", vk::to_string(layout_result));
desc_layout = std::move(layout);
} }
void GraphicsPipeline::BindResources(const Liverpool::Regs& regs, void GraphicsPipeline::BindResources(const Liverpool::Regs& regs,

View file

@ -23,8 +23,20 @@ namespace Vulkan {
namespace { namespace {
std::vector<vk::PhysicalDevice> EnumeratePhysicalDevices(vk::UniqueInstance& instance) {
auto [devices_result, devices] = instance->enumeratePhysicalDevices();
ASSERT_MSG(devices_result == vk::Result::eSuccess, "Failed to enumerate physical devices: {}",
vk::to_string(devices_result));
return std::move(devices);
}
std::vector<std::string> GetSupportedExtensions(vk::PhysicalDevice physical) { std::vector<std::string> GetSupportedExtensions(vk::PhysicalDevice physical) {
const std::vector extensions = physical.enumerateDeviceExtensionProperties(); const auto [extensions_result, 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<std::string> supported_extensions; std::vector<std::string> supported_extensions;
supported_extensions.reserve(extensions.size()); supported_extensions.reserve(extensions.size());
for (const auto& extension : extensions) { for (const auto& extension : extensions) {
@ -82,13 +94,13 @@ std::string GetReadableVersion(u32 version) {
Instance::Instance(bool enable_validation, bool enable_crash_diagnostic) Instance::Instance(bool enable_validation, bool enable_crash_diagnostic)
: instance{CreateInstance(Frontend::WindowSystemType::Headless, enable_validation, : instance{CreateInstance(Frontend::WindowSystemType::Headless, enable_validation,
enable_crash_diagnostic)}, enable_crash_diagnostic)},
physical_devices{instance->enumeratePhysicalDevices()} {} physical_devices{EnumeratePhysicalDevices(instance)} {}
Instance::Instance(Frontend::WindowSDL& window, s32 physical_device_index, Instance::Instance(Frontend::WindowSDL& window, s32 physical_device_index,
bool enable_validation /*= false*/, bool enable_crash_diagnostic /*= false*/) bool enable_validation /*= false*/, bool enable_crash_diagnostic /*= false*/)
: instance{CreateInstance(window.getWindowInfo().type, enable_validation, : instance{CreateInstance(window.getWindowInfo().type, enable_validation,
enable_crash_diagnostic)}, enable_crash_diagnostic)},
physical_devices{instance->enumeratePhysicalDevices()} { physical_devices{EnumeratePhysicalDevices(instance)} {
if (enable_validation) { if (enable_validation) {
debug_callback = CreateDebugCallback(*instance); debug_callback = CreateDebugCallback(*instance);
} }
@ -421,15 +433,12 @@ bool Instance::CreateDevice() {
device_chain.unlink<vk::PhysicalDeviceVertexInputDynamicStateFeaturesEXT>(); device_chain.unlink<vk::PhysicalDeviceVertexInputDynamicStateFeaturesEXT>();
} }
try { auto [device_result, dev] = physical_device.createDeviceUnique(device_chain.get());
device = physical_device.createDeviceUnique(device_chain.get()); if (device_result != vk::Result::eSuccess) {
} catch (vk::ExtensionNotPresentError& err) { LOG_CRITICAL(Render_Vulkan, "Failed to create device: {}", vk::to_string(device_result));
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());
return false; return false;
} }
device = std::move(dev);
VULKAN_HPP_DEFAULT_DISPATCHER.init(*device); VULKAN_HPP_DEFAULT_DISPATCHER.init(*device);
@ -437,27 +446,33 @@ bool Instance::CreateDevice() {
present_queue = device->getQueue(queue_family_index, 0); present_queue = device->getQueue(queue_family_index, 0);
if (calibrated_timestamps) { if (calibrated_timestamps) {
const auto& time_domains = physical_device.getCalibrateableTimeDomainsEXT(); const auto [time_domains_result, time_domains] =
physical_device.getCalibrateableTimeDomainsEXT();
if (time_domains_result == vk::Result::eSuccess) {
#if _WIN64 #if _WIN64
const bool has_host_time_domain = const bool has_host_time_domain =
std::find(time_domains.cbegin(), time_domains.cend(), std::find(time_domains.cbegin(), time_domains.cend(),
vk::TimeDomainEXT::eQueryPerformanceCounter) != time_domains.cend(); vk::TimeDomainEXT::eQueryPerformanceCounter) != time_domains.cend();
#elif __linux__ #elif __linux__
const bool has_host_time_domain = const bool has_host_time_domain =
std::find(time_domains.cbegin(), time_domains.cend(), std::find(time_domains.cbegin(), time_domains.cend(),
vk::TimeDomainEXT::eClockMonotonicRaw) != time_domains.cend(); vk::TimeDomainEXT::eClockMonotonicRaw) != time_domains.cend();
#else #else
// Tracy limitation means only Windows and Linux can use host time domain. // Tracy limitation means only Windows and Linux can use host time domain.
// https://github.com/shadps4-emu/tracy/blob/c6d779d78508514102fbe1b8eb28bda10d95bb2a/public/tracy/TracyVulkan.hpp#L384-L389 // https://github.com/shadps4-emu/tracy/blob/c6d779d78508514102fbe1b8eb28bda10d95bb2a/public/tracy/TracyVulkan.hpp#L384-L389
const bool has_host_time_domain = false; const bool has_host_time_domain = false;
#endif #endif
if (has_host_time_domain) { if (has_host_time_domain) {
static constexpr std::string_view context_name{"vk_rasterizer"}; static constexpr std::string_view context_name{"vk_rasterizer"};
profiler_context = profiler_context = TracyVkContextHostCalibrated(
TracyVkContextHostCalibrated(*instance, physical_device, *device, *instance, physical_device, *device,
VULKAN_HPP_DEFAULT_DISPATCHER.vkGetInstanceProcAddr, VULKAN_HPP_DEFAULT_DISPATCHER.vkGetInstanceProcAddr,
VULKAN_HPP_DEFAULT_DISPATCHER.vkGetDeviceProcAddr); VULKAN_HPP_DEFAULT_DISPATCHER.vkGetDeviceProcAddr);
TracyVkContextName(profiler_context, context_name.data(), context_name.size()); TracyVkContextName(profiler_context, context_name.data(), context_name.size());
}
} else {
LOG_WARNING(Render_Vulkan, "Could not query calibrated time domains for profiling: {}",
vk::to_string(time_domains_result));
} }
} }
@ -513,7 +528,12 @@ void Instance::CollectToolingInfo() {
if (!tooling_info) { if (!tooling_info) {
return; return;
} }
const auto tools = physical_device.getToolPropertiesEXT(); const auto [tools_result, tools] = physical_device.getToolPropertiesEXT();
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) { for (const vk::PhysicalDeviceToolProperties& tool : tools) {
const std::string_view name = tool.name; const std::string_view name = tool.name;
LOG_INFO(Render_Vulkan, "Attached debugging tool: {}", name); LOG_INFO(Render_Vulkan, "Attached debugging tool: {}", name);

View file

@ -5,6 +5,8 @@
#include "video_core/renderer_vulkan/vk_instance.h" #include "video_core/renderer_vulkan/vk_instance.h"
#include "video_core/renderer_vulkan/vk_master_semaphore.h" #include "video_core/renderer_vulkan/vk_master_semaphore.h"
#include "common/assert.h"
namespace Vulkan { namespace Vulkan {
constexpr u64 WAIT_TIMEOUT = std::numeric_limits<u64>::max(); constexpr u64 WAIT_TIMEOUT = std::numeric_limits<u64>::max();
@ -17,7 +19,11 @@ MasterSemaphore::MasterSemaphore(const Instance& instance_) : instance{instance_
.initialValue = 0, .initialValue = 0,
}, },
}; };
semaphore = instance.GetDevice().createSemaphoreUnique(semaphore_chain.get()); auto [semaphore_result, sem] =
instance.GetDevice().createSemaphoreUnique(semaphore_chain.get());
ASSERT_MSG(semaphore_result == vk::Result::eSuccess, "Failed to create master semaphore: {}",
vk::to_string(semaphore_result));
semaphore = std::move(sem);
} }
MasterSemaphore::~MasterSemaphore() = default; MasterSemaphore::~MasterSemaphore() = default;
@ -27,7 +33,10 @@ void MasterSemaphore::Refresh() {
u64 counter{}; u64 counter{};
do { do {
this_tick = gpu_tick.load(std::memory_order_acquire); this_tick = gpu_tick.load(std::memory_order_acquire);
counter = instance.GetDevice().getSemaphoreCounterValue(*semaphore); auto [counter_result, cntr] = instance.GetDevice().getSemaphoreCounterValue(*semaphore);
ASSERT_MSG(counter_result == vk::Result::eSuccess,
"Failed to get master semaphore value: {}", vk::to_string(counter_result));
counter = cntr;
if (counter < this_tick) { if (counter < this_tick) {
return; return;
} }

View file

@ -136,7 +136,10 @@ PipelineCache::PipelineCache(const Instance& instance_, Scheduler& scheduler_,
.subgroup_size = instance.SubgroupSize(), .subgroup_size = instance.SubgroupSize(),
.support_explicit_workgroup_layout = true, .support_explicit_workgroup_layout = true,
}; };
pipeline_cache = instance.GetDevice().createPipelineCacheUnique({}); auto [cache_result, cache] = instance.GetDevice().createPipelineCacheUnique({});
ASSERT_MSG(cache_result == vk::Result::eSuccess, "Failed to create pipeline cache: {}",
vk::to_string(cache_result));
pipeline_cache = std::move(cache);
} }
PipelineCache::~PipelineCache() = default; PipelineCache::~PipelineCache() = default;

View file

@ -134,9 +134,10 @@ vk::SurfaceKHR CreateSurface(vk::Instance instance, const Frontend::WindowSDL& e
std::vector<const char*> GetInstanceExtensions(Frontend::WindowSystemType window_type, std::vector<const char*> GetInstanceExtensions(Frontend::WindowSystemType window_type,
bool enable_debug_utils) { bool enable_debug_utils) {
const auto properties = vk::enumerateInstanceExtensionProperties(); const auto [properties_result, properties] = vk::enumerateInstanceExtensionProperties();
if (properties.empty()) { if (properties_result != vk::Result::eSuccess || properties.empty()) {
LOG_ERROR(Render_Vulkan, "Failed to query extension properties"); LOG_ERROR(Render_Vulkan, "Failed to query extension properties: {}",
vk::to_string(properties_result));
return {}; return {};
} }
@ -207,10 +208,12 @@ vk::UniqueInstance CreateInstance(Frontend::WindowSystemType window_type, bool e
#endif #endif
VULKAN_HPP_DEFAULT_DISPATCHER.init(vkGetInstanceProcAddr); VULKAN_HPP_DEFAULT_DISPATCHER.init(vkGetInstanceProcAddr);
const u32 available_version = VULKAN_HPP_DEFAULT_DISPATCHER.vkEnumerateInstanceVersion const auto [available_version_result, available_version] =
? vk::enumerateInstanceVersion() VULKAN_HPP_DEFAULT_DISPATCHER.vkEnumerateInstanceVersion
: VK_API_VERSION_1_0; ? 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 >= TargetVulkanApiVersion, ASSERT_MSG(available_version >= TargetVulkanApiVersion,
"Vulkan {}.{} is required, but only {}.{} is supported by instance!", "Vulkan {}.{} is required, but only {}.{} is supported by instance!",
VK_VERSION_MAJOR(TargetVulkanApiVersion), VK_VERSION_MINOR(TargetVulkanApiVersion), VK_VERSION_MAJOR(TargetVulkanApiVersion), VK_VERSION_MINOR(TargetVulkanApiVersion),
@ -341,11 +344,13 @@ vk::UniqueInstance CreateInstance(Frontend::WindowSystemType window_type, bool e
}, },
}; };
auto instance = vk::createInstanceUnique(instance_ci_chain.get()); auto [instance_result, instance] = vk::createInstanceUnique(instance_ci_chain.get());
ASSERT_MSG(instance_result == vk::Result::eSuccess, "Failed to create instance: {}",
vk::to_string(instance_result));
VULKAN_HPP_DEFAULT_DISPATCHER.init(*instance); VULKAN_HPP_DEFAULT_DISPATCHER.init(*instance);
return instance; return std::move(instance);
} }
vk::UniqueDebugUtilsMessengerEXT CreateDebugCallback(vk::Instance instance) { vk::UniqueDebugUtilsMessengerEXT CreateDebugCallback(vk::Instance instance) {
@ -359,7 +364,10 @@ vk::UniqueDebugUtilsMessengerEXT CreateDebugCallback(vk::Instance instance) {
vk::DebugUtilsMessageTypeFlagBitsEXT::ePerformance, vk::DebugUtilsMessageTypeFlagBitsEXT::ePerformance,
.pfnUserCallback = DebugUtilsCallback, .pfnUserCallback = DebugUtilsCallback,
}; };
return instance.createDebugUtilsMessengerEXTUnique(msg_ci); auto [messenger_result, messenger] = instance.createDebugUtilsMessengerEXTUnique(msg_ci);
ASSERT_MSG(messenger_result == vk::Result::eSuccess, "Failed to create debug callback: {}",
vk::to_string(messenger_result));
return std::move(messenger);
} }
} // namespace Vulkan } // namespace Vulkan

View file

@ -7,6 +7,7 @@
#include <variant> #include <variant>
#include <fmt/format.h> #include <fmt/format.h>
#include "common/logging/log.h"
#include "common/types.h" #include "common/types.h"
#include "video_core/renderer_vulkan/vk_common.h" #include "video_core/renderer_vulkan/vk_common.h"
@ -36,7 +37,10 @@ void SetObjectName(vk::Device device, const HandleType& handle, std::string_view
.objectHandle = reinterpret_cast<u64>(static_cast<typename HandleType::NativeType>(handle)), .objectHandle = reinterpret_cast<u64>(static_cast<typename HandleType::NativeType>(handle)),
.pObjectName = debug_name.data(), .pObjectName = debug_name.data(),
}; };
device.setDebugUtilsObjectNameEXT(name_info); auto result = device.setDebugUtilsObjectNameEXT(name_info);
if (result != vk::Result::eSuccess) {
LOG_DEBUG(Render_Vulkan, "Could not set object debug name: {}", vk::to_string(result));
}
} }
template <VulkanHandleType HandleType, typename... Args> template <VulkanHandleType HandleType, typename... Args>

View file

@ -24,7 +24,6 @@ Rasterizer::Rasterizer(const Instance& instance_, Scheduler& scheduler_,
liverpool->BindRasterizer(this); liverpool->BindRasterizer(this);
} }
memory->SetRasterizer(this); memory->SetRasterizer(this);
wfi_event = instance.GetDevice().createEventUnique({});
} }
Rasterizer::~Rasterizer() = default; Rasterizer::~Rasterizer() = default;

View file

@ -67,7 +67,6 @@ private:
AmdGpu::Liverpool* liverpool; AmdGpu::Liverpool* liverpool;
Core::MemoryManager* memory; Core::MemoryManager* memory;
PipelineCache pipeline_cache; PipelineCache pipeline_cache;
vk::UniqueEvent wfi_event;
}; };
} // namespace Vulkan } // namespace Vulkan

View file

@ -69,7 +69,10 @@ CommandPool::CommandPool(const Instance& instance, MasterSemaphore* master_semap
.queueFamilyIndex = instance.GetGraphicsQueueFamilyIndex(), .queueFamilyIndex = instance.GetGraphicsQueueFamilyIndex(),
}; };
const vk::Device device = instance.GetDevice(); const vk::Device device = instance.GetDevice();
cmd_pool = device.createCommandPoolUnique(pool_create_info); auto [pool_result, pool] = device.createCommandPoolUnique(pool_create_info);
ASSERT_MSG(pool_result == vk::Result::eSuccess, "Failed to create command pool: {}",
vk::to_string(pool_result));
cmd_pool = std::move(pool);
if (instance.HasDebuggingToolAttached()) { if (instance.HasDebuggingToolAttached()) {
SetObjectName(device, *cmd_pool, "CommandPool"); SetObjectName(device, *cmd_pool, "CommandPool");
} }
@ -182,7 +185,10 @@ void DescriptorHeap::CreateDescriptorPool() {
.poolSizeCount = static_cast<u32>(pool_sizes.size()), .poolSizeCount = static_cast<u32>(pool_sizes.size()),
.pPoolSizes = pool_sizes.data(), .pPoolSizes = pool_sizes.data(),
}; };
curr_pool = device.createDescriptorPool(pool_info); auto [pool_result, pool] = device.createDescriptorPool(pool_info);
ASSERT_MSG(pool_result == vk::Result::eSuccess, "Failed to create descriptor pool: {}",
vk::to_string(pool_result));
curr_pool = pool;
} }
} // namespace Vulkan } // namespace Vulkan

View file

@ -89,7 +89,9 @@ void Scheduler::AllocateWorkerCommandBuffers() {
}; };
current_cmdbuf = command_pool.Commit(); current_cmdbuf = command_pool.Commit();
current_cmdbuf.begin(begin_info); auto begin_result = current_cmdbuf.begin(begin_info);
ASSERT_MSG(begin_result == vk::Result::eSuccess, "Failed to begin command buffer: {}",
vk::to_string(begin_result));
auto* profiler_ctx = instance.GetProfilerContext(); auto* profiler_ctx = instance.GetProfilerContext();
if (profiler_ctx) { if (profiler_ctx) {
@ -110,7 +112,9 @@ void Scheduler::SubmitExecution(SubmitInfo& info) {
} }
EndRendering(); EndRendering();
current_cmdbuf.end(); auto end_result = current_cmdbuf.end();
ASSERT_MSG(end_result == vk::Result::eSuccess, "Failed to end command buffer: {}",
vk::to_string(end_result));
const vk::Semaphore timeline = master_semaphore.Handle(); const vk::Semaphore timeline = master_semaphore.Handle();
info.AddSignal(timeline, signal_value); info.AddSignal(timeline, signal_value);
@ -138,12 +142,9 @@ void Scheduler::SubmitExecution(SubmitInfo& info) {
.pSignalSemaphores = info.signal_semas.data(), .pSignalSemaphores = info.signal_semas.data(),
}; };
try { ImGui::Core::TextureManager::Submit();
ImGui::Core::TextureManager::Submit(); auto submit_result = instance.GetGraphicsQueue().submit(submit_info, info.fence);
instance.GetGraphicsQueue().submit(submit_info, info.fence); ASSERT_MSG(submit_result != vk::Result::eErrorDeviceLost, "Device lost during submit");
} catch (vk::DeviceLostError& err) {
UNREACHABLE_MSG("Device lost during submit: {}", err.what());
}
master_semaphore.Refresh(); master_semaphore.Refresh();
AllocateWorkerCommandBuffers(); AllocateWorkerCommandBuffers();

View file

@ -218,13 +218,10 @@ vk::ShaderModule CompileSPV(std::span<const u32> code, vk::Device device) {
.pCode = code.data(), .pCode = code.data(),
}; };
try { auto [module_result, module] = device.createShaderModule(shader_info);
return device.createShaderModule(shader_info); ASSERT_MSG(module_result == vk::Result::eSuccess, "Failed to compile SPIR-V shader: {}",
} catch (vk::SystemError& err) { vk::to_string(module_result));
UNREACHABLE_MSG("{}", err.what()); return module;
}
return {};
} }
} // namespace Vulkan } // namespace Vulkan

View file

@ -37,8 +37,12 @@ void Swapchain::Create(u32 width_, u32 height_, vk::SurfaceKHR surface_) {
instance.GetPresentQueueFamilyIndex(), instance.GetPresentQueueFamilyIndex(),
}; };
const auto modes = instance.GetPhysicalDevice().getSurfacePresentModesKHR(surface); const auto [modes_result, modes] =
const auto find_mode = [&modes](vk::PresentModeKHR requested) { instance.GetPhysicalDevice().getSurfacePresentModesKHR(surface);
const auto find_mode = [&modes_result, &modes](vk::PresentModeKHR requested) {
if (modes_result != vk::Result::eSuccess) {
return false;
}
const auto it = const auto it =
std::find_if(modes.begin(), modes.end(), std::find_if(modes.begin(), modes.end(),
[&requested](vk::PresentModeKHR mode) { return mode == requested; }); [&requested](vk::PresentModeKHR mode) { return mode == requested; });
@ -70,12 +74,10 @@ void Swapchain::Create(u32 width_, u32 height_, vk::SurfaceKHR surface_) {
.oldSwapchain = nullptr, .oldSwapchain = nullptr,
}; };
try { auto [swapchain_result, chain] = instance.GetDevice().createSwapchainKHR(swapchain_info);
swapchain = instance.GetDevice().createSwapchainKHR(swapchain_info); ASSERT_MSG(swapchain_result == vk::Result::eSuccess, "Failed to create swapchain: {}",
} catch (vk::SystemError& err) { vk::to_string(swapchain_result));
LOG_CRITICAL(Render_Vulkan, "{}", err.what()); swapchain = chain;
UNREACHABLE();
}
SetupImages(); SetupImages();
RefreshSemaphores(); RefreshSemaphores();
@ -119,20 +121,22 @@ void Swapchain::Present() {
.pImageIndices = &image_index, .pImageIndices = &image_index,
}; };
try { auto result = instance.GetPresentQueue().presentKHR(present_info);
[[maybe_unused]] vk::Result result = instance.GetPresentQueue().presentKHR(present_info); if (result == vk::Result::eErrorOutOfDateKHR) {
} catch (vk::OutOfDateKHRError&) {
needs_recreation = true; needs_recreation = true;
} catch (const vk::SystemError& err) { } else {
LOG_CRITICAL(Render_Vulkan, "Swapchain presentation failed {}", err.what()); ASSERT_MSG(result == vk::Result::eSuccess, "Swapchain presentation failed: {}",
UNREACHABLE(); vk::to_string(result));
} }
frame_index = (frame_index + 1) % image_count; frame_index = (frame_index + 1) % image_count;
} }
void Swapchain::FindPresentFormat() { void Swapchain::FindPresentFormat() {
const auto formats = instance.GetPhysicalDevice().getSurfaceFormatsKHR(surface); const auto [formats_result, formats] =
instance.GetPhysicalDevice().getSurfaceFormatsKHR(surface);
ASSERT_MSG(formats_result == vk::Result::eSuccess, "Failed to query surface formats: {}",
vk::to_string(formats_result));
// If there is a single undefined surface format, the device doesn't care, so we'll just use // If there is a single undefined surface format, the device doesn't care, so we'll just use
// RGBA sRGB. // RGBA sRGB.
@ -158,8 +162,10 @@ void Swapchain::FindPresentFormat() {
} }
void Swapchain::SetSurfaceProperties() { void Swapchain::SetSurfaceProperties() {
const vk::SurfaceCapabilitiesKHR capabilities = const auto [capabilities_result, capabilities] =
instance.GetPhysicalDevice().getSurfaceCapabilitiesKHR(surface); instance.GetPhysicalDevice().getSurfaceCapabilitiesKHR(surface);
ASSERT_MSG(capabilities_result == vk::Result::eSuccess,
"Failed to query surface capabilities: {}", vk::to_string(capabilities_result));
extent = capabilities.currentExtent; extent = capabilities.currentExtent;
if (capabilities.currentExtent.width == std::numeric_limits<u32>::max()) { if (capabilities.currentExtent.width == std::numeric_limits<u32>::max()) {
@ -207,10 +213,17 @@ void Swapchain::RefreshSemaphores() {
present_ready.resize(image_count); present_ready.resize(image_count);
for (vk::Semaphore& semaphore : image_acquired) { for (vk::Semaphore& semaphore : image_acquired) {
semaphore = device.createSemaphore({}); auto [semaphore_result, sem] = device.createSemaphore({});
ASSERT_MSG(semaphore_result == vk::Result::eSuccess,
"Failed to create image acquired semaphore: {}",
vk::to_string(semaphore_result));
semaphore = sem;
} }
for (vk::Semaphore& semaphore : present_ready) { for (vk::Semaphore& semaphore : present_ready) {
semaphore = device.createSemaphore({}); auto [semaphore_result, sem] = device.createSemaphore({});
ASSERT_MSG(semaphore_result == vk::Result::eSuccess,
"Failed to create present ready semaphore: {}", vk::to_string(semaphore_result));
semaphore = sem;
} }
if (instance.HasDebuggingToolAttached()) { if (instance.HasDebuggingToolAttached()) {
@ -223,7 +236,10 @@ void Swapchain::RefreshSemaphores() {
void Swapchain::SetupImages() { void Swapchain::SetupImages() {
vk::Device device = instance.GetDevice(); vk::Device device = instance.GetDevice();
images = device.getSwapchainImagesKHR(swapchain); auto [images_result, imgs] = device.getSwapchainImagesKHR(swapchain);
ASSERT_MSG(images_result == vk::Result::eSuccess, "Failed to create swapchain images: {}",
vk::to_string(images_result));
images = std::move(imgs);
image_count = static_cast<u32>(images.size()); image_count = static_cast<u32>(images.size());
if (instance.HasDebuggingToolAttached()) { if (instance.HasDebuggingToolAttached()) {

View file

@ -1,7 +1,6 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
#define VULKAN_HPP_NO_EXCEPTIONS
#include <ranges> #include <ranges>
#include "common/assert.h" #include "common/assert.h"
#include "video_core/renderer_vulkan/liverpool_to_vk.h" #include "video_core/renderer_vulkan/liverpool_to_vk.h"

View file

@ -175,7 +175,10 @@ ImageView::ImageView(const Vulkan::Instance& instance, const ImageViewInfo& info
.layerCount = info.range.extent.layers, .layerCount = info.range.extent.layers,
}, },
}; };
image_view = instance.GetDevice().createImageViewUnique(image_view_ci); auto [view_result, view] = instance.GetDevice().createImageViewUnique(image_view_ci);
ASSERT_MSG(view_result == vk::Result::eSuccess, "Failed to create image view: {}",
vk::to_string(view_result));
image_view = std::move(view);
} }
ImageView::~ImageView() = default; ImageView::~ImageView() = default;

View file

@ -24,7 +24,10 @@ Sampler::Sampler(const Vulkan::Instance& instance, const AmdGpu::Sampler& sample
.borderColor = LiverpoolToVK::BorderColor(sampler.border_color_type), .borderColor = LiverpoolToVK::BorderColor(sampler.border_color_type),
.unnormalizedCoordinates = bool(sampler.force_unnormalized), .unnormalizedCoordinates = bool(sampler.force_unnormalized),
}; };
handle = instance.GetDevice().createSamplerUnique(sampler_ci); auto [sampler_result, smplr] = instance.GetDevice().createSamplerUnique(sampler_ci);
ASSERT_MSG(sampler_result == vk::Result::eSuccess, "Failed to create sampler: {}",
vk::to_string(sampler_result));
handle = std::move(smplr);
} }
Sampler::~Sampler() = default; Sampler::~Sampler() = default;

View file

@ -298,8 +298,10 @@ TileManager::TileManager(const Vulkan::Instance& instance, Vulkan::Scheduler& sc
.bindingCount = static_cast<u32>(bindings.size()), .bindingCount = static_cast<u32>(bindings.size()),
.pBindings = bindings.data(), .pBindings = bindings.data(),
}; };
static auto desc_layout = static auto [desc_layout_result, desc_layout] =
instance.GetDevice().createDescriptorSetLayoutUnique(desc_layout_ci); instance.GetDevice().createDescriptorSetLayoutUnique(desc_layout_ci);
ASSERT_MSG(desc_layout_result == vk::Result::eSuccess,
"Failed to create descriptor set layout: {}", vk::to_string(desc_layout_result));
const vk::PushConstantRange push_constants = { const vk::PushConstantRange push_constants = {
.stageFlags = vk::ShaderStageFlagBits::eCompute, .stageFlags = vk::ShaderStageFlagBits::eCompute,
@ -314,7 +316,10 @@ TileManager::TileManager(const Vulkan::Instance& instance, Vulkan::Scheduler& sc
.pushConstantRangeCount = 1, .pushConstantRangeCount = 1,
.pPushConstantRanges = &push_constants, .pPushConstantRanges = &push_constants,
}; };
ctx.pl_layout = instance.GetDevice().createPipelineLayoutUnique(layout_info); auto [layout_result, layout] = instance.GetDevice().createPipelineLayoutUnique(layout_info);
ASSERT_MSG(layout_result == vk::Result::eSuccess, "Failed to create pipeline layout: {}",
vk::to_string(layout_result));
ctx.pl_layout = std::move(layout);
const vk::ComputePipelineCreateInfo compute_pipeline_ci = { const vk::ComputePipelineCreateInfo compute_pipeline_ci = {
.stage = shader_ci, .stage = shader_ci,