vulkan: Use structured bindings for result where possible.

This commit is contained in:
squidbus 2024-09-25 02:05:33 -07:00
commit 6cb1222b9a
15 changed files with 155 additions and 154 deletions

View file

@ -128,12 +128,12 @@ 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: {}", ASSERT_MSG(view_result == vk::Result::eSuccess, "Failed to create buffer view: {}",
vk::to_string(view.result)); vk::to_string(view_result));
scheduler->DeferOperation( scheduler->DeferOperation(
[view, device = instance->GetDevice()] { device.destroyBufferView(view.value); }); [view, device = instance->GetDevice()] { device.destroyBufferView(view); });
return view.value; return view;
} }
constexpr u64 WATCHES_INITIAL_RESERVE = 0x4000; constexpr u64 WATCHES_INITIAL_RESERVE = 0x4000;

View file

@ -82,10 +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];
auto fence_result = device.createFence({.flags = vk::FenceCreateFlagBits::eSignaled}); auto [fence_result, fence] =
ASSERT_MSG(fence_result.result == vk::Result::eSuccess, device.createFence({.flags = vk::FenceCreateFlagBits::eSignaled});
"Failed to create present done fence: {}", vk::to_string(fence_result.result)); ASSERT_MSG(fence_result == vk::Result::eSuccess, "Failed to create present done fence: {}",
frame.present_done = fence_result.value; vk::to_string(fence_result));
frame.present_done = fence;
free_queue.push(&frame); free_queue.push(&frame);
} }
@ -160,10 +161,10 @@ void RendererVulkan::RecreateFrame(Frame* frame, u32 width, u32 height) {
.layerCount = 1, .layerCount = 1,
}, },
}; };
auto view_result = device.createImageView(view_info); auto [view_result, view] = device.createImageView(view_info);
ASSERT_MSG(view_result.result == vk::Result::eSuccess, "Failed to create frame image view: {}", ASSERT_MSG(view_result == vk::Result::eSuccess, "Failed to create frame image view: {}",
vk::to_string(view_result.result)); vk::to_string(view_result));
frame->image_view = view_result.value; frame->image_view = view;
frame->width = width; frame->width = width;
frame->height = height; frame->height = height;
} }

View file

@ -15,6 +15,8 @@
#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 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,12 +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(),
}; };
auto descriptor_set_result = auto [descriptor_set_result, descriptor_set] =
instance.GetDevice().createDescriptorSetLayoutUnique(desc_layout_ci); instance.GetDevice().createDescriptorSetLayoutUnique(desc_layout_ci);
ASSERT_MSG(descriptor_set_result.result == vk::Result::eSuccess, ASSERT_MSG(descriptor_set_result == vk::Result::eSuccess,
"Failed to create compute descriptor set layout: {}", "Failed to create compute descriptor set layout: {}",
vk::to_string(descriptor_set_result.result)); vk::to_string(descriptor_set_result));
desc_layout = std::move(descriptor_set_result.value); 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 = {
@ -92,20 +92,20 @@ ComputePipeline::ComputePipeline(const Instance& instance_, Scheduler& scheduler
.pushConstantRangeCount = 1U, .pushConstantRangeCount = 1U,
.pPushConstantRanges = &push_constants, .pPushConstantRanges = &push_constants,
}; };
auto layout_result = instance.GetDevice().createPipelineLayoutUnique(layout_info); auto [layout_result, layout] = instance.GetDevice().createPipelineLayoutUnique(layout_info);
ASSERT_MSG(layout_result.result == vk::Result::eSuccess, ASSERT_MSG(layout_result == vk::Result::eSuccess,
"Failed to create compute pipeline layout: {}", vk::to_string(layout_result.result)); "Failed to create compute pipeline layout: {}", vk::to_string(layout_result));
pipeline_layout = std::move(layout_result.value); 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 pipeline_result = auto [pipeline_result, pipe] =
instance.GetDevice().createComputePipelineUnique(pipeline_cache, compute_pipeline_ci); instance.GetDevice().createComputePipelineUnique(pipeline_cache, compute_pipeline_ci);
ASSERT_MSG(pipeline_result.result == vk::Result::eSuccess, ASSERT_MSG(pipeline_result == vk::Result::eSuccess, "Failed to create compute pipeline: {}",
"Failed to create compute pipeline: {}", vk::to_string(pipeline_result.result)); vk::to_string(pipeline_result));
pipeline = std::move(pipeline_result.value); pipeline = std::move(pipe);
} }
ComputePipeline::~ComputePipeline() = default; ComputePipeline::~ComputePipeline() = default;

View file

@ -39,11 +39,10 @@ GraphicsPipeline::GraphicsPipeline(const Instance& instance_, Scheduler& schedul
.pushConstantRangeCount = 1, .pushConstantRangeCount = 1,
.pPushConstantRanges = &push_constants, .pPushConstantRanges = &push_constants,
}; };
auto layout_result = instance.GetDevice().createPipelineLayoutUnique(layout_info); auto [layout_result, layout] = instance.GetDevice().createPipelineLayoutUnique(layout_info);
ASSERT_MSG(layout_result.result == vk::Result::eSuccess, ASSERT_MSG(layout_result == vk::Result::eSuccess,
"Failed to create graphics pipeline layout: {}", "Failed to create graphics pipeline layout: {}", vk::to_string(layout_result));
vk::to_string(layout_result.result)); pipeline_layout = std::move(layout);
pipeline_layout = std::move(layout_result.value);
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;
@ -285,10 +284,11 @@ GraphicsPipeline::GraphicsPipeline(const Instance& instance_, Scheduler& schedul
.layout = *pipeline_layout, .layout = *pipeline_layout,
}; };
auto pipeline_result = device.createGraphicsPipelineUnique(pipeline_cache, pipeline_info); auto [pipeline_result, pipe] =
ASSERT_MSG(pipeline_result.result == vk::Result::eSuccess, device.createGraphicsPipelineUnique(pipeline_cache, pipeline_info);
"Failed to create graphics pipeline: {}", vk::to_string(pipeline_result.result)); ASSERT_MSG(pipeline_result == vk::Result::eSuccess, "Failed to create graphics pipeline: {}",
pipeline = std::move(pipeline_result.value); vk::to_string(pipeline_result));
pipeline = std::move(pipe);
} }
GraphicsPipeline::~GraphicsPipeline() = default; GraphicsPipeline::~GraphicsPipeline() = default;
@ -347,10 +347,11 @@ void GraphicsPipeline::BuildDescSetLayout() {
.bindingCount = static_cast<u32>(bindings.size()), .bindingCount = static_cast<u32>(bindings.size()),
.pBindings = bindings.data(), .pBindings = bindings.data(),
}; };
auto result = instance.GetDevice().createDescriptorSetLayoutUnique(desc_layout_ci); auto [layout_result, layout] =
ASSERT_MSG(result.result == vk::Result::eSuccess, instance.GetDevice().createDescriptorSetLayoutUnique(desc_layout_ci);
"Failed to create graphics descriptor set layout: {}", vk::to_string(result.result)); ASSERT_MSG(layout_result == vk::Result::eSuccess,
desc_layout = std::move(result.value); "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

@ -24,22 +24,22 @@ namespace Vulkan {
namespace { namespace {
std::vector<vk::PhysicalDevice> EnumeratePhysicalDevices(vk::UniqueInstance& instance) { std::vector<vk::PhysicalDevice> EnumeratePhysicalDevices(vk::UniqueInstance& instance) {
auto devices_result = instance->enumeratePhysicalDevices(); auto [devices_result, devices] = instance->enumeratePhysicalDevices();
ASSERT_MSG(devices_result.result == vk::Result::eSuccess, ASSERT_MSG(devices_result == vk::Result::eSuccess, "Failed to enumerate physical devices: {}",
"Failed to enumerate physical devices: {}", vk::to_string(devices_result.result)); vk::to_string(devices_result));
return std::move(devices_result.value); return std::move(devices);
} }
std::vector<std::string> GetSupportedExtensions(vk::PhysicalDevice physical) { std::vector<std::string> GetSupportedExtensions(vk::PhysicalDevice physical) {
const auto extensions = physical.enumerateDeviceExtensionProperties(); const auto [extensions_result, extensions] = physical.enumerateDeviceExtensionProperties();
if (extensions.result != vk::Result::eSuccess) { if (extensions_result != vk::Result::eSuccess) {
LOG_ERROR(Render_Vulkan, "Could not query supported extensions: {}", LOG_ERROR(Render_Vulkan, "Could not query supported extensions: {}",
vk::to_string(extensions.result)); vk::to_string(extensions_result));
return {}; return {};
} }
std::vector<std::string> supported_extensions; std::vector<std::string> supported_extensions;
supported_extensions.reserve(extensions.value.size()); supported_extensions.reserve(extensions.size());
for (const auto& extension : extensions.value) { for (const auto& extension : extensions) {
supported_extensions.emplace_back(extension.extensionName.data()); supported_extensions.emplace_back(extension.extensionName.data());
} }
return supported_extensions; return supported_extensions;
@ -433,13 +433,12 @@ bool Instance::CreateDevice() {
device_chain.unlink<vk::PhysicalDeviceVertexInputDynamicStateFeaturesEXT>(); device_chain.unlink<vk::PhysicalDeviceVertexInputDynamicStateFeaturesEXT>();
} }
auto device_result = physical_device.createDeviceUnique(device_chain.get()); auto [device_result, dev] = physical_device.createDeviceUnique(device_chain.get());
if (device_result.result != vk::Result::eSuccess) { if (device_result != vk::Result::eSuccess) {
LOG_CRITICAL(Render_Vulkan, "Failed to create device: {}", LOG_CRITICAL(Render_Vulkan, "Failed to create device: {}", vk::to_string(device_result));
vk::to_string(device_result.result));
return false; return false;
} }
device = std::move(device_result.value); device = std::move(dev);
VULKAN_HPP_DEFAULT_DISPATCHER.init(*device); VULKAN_HPP_DEFAULT_DISPATCHER.init(*device);
@ -447,9 +446,9 @@ 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_result = physical_device.getCalibrateableTimeDomainsEXT(); const auto [time_domains_result, time_domains] =
if (time_domains_result.result == vk::Result::eSuccess) { physical_device.getCalibrateableTimeDomainsEXT();
const auto& time_domains = time_domains_result.value; 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(),
@ -473,7 +472,7 @@ bool Instance::CreateDevice() {
} }
} else { } else {
LOG_WARNING(Render_Vulkan, "Could not query calibrated time domains for profiling: {}", LOG_WARNING(Render_Vulkan, "Could not query calibrated time domains for profiling: {}",
vk::to_string(time_domains_result.result)); vk::to_string(time_domains_result));
} }
} }
@ -529,13 +528,13 @@ 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) { if (tools_result != vk::Result::eSuccess) {
LOG_ERROR(Render_Vulkan, "Could not get Vulkan tool properties: {}", LOG_ERROR(Render_Vulkan, "Could not get Vulkan tool properties: {}",
vk::to_string(tools.result)); vk::to_string(tools_result));
return; return;
} }
for (const vk::PhysicalDeviceToolProperties& tool : tools.value) { 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);
has_renderdoc = has_renderdoc || name == "RenderDoc"; has_renderdoc = has_renderdoc || name == "RenderDoc";

View file

@ -19,10 +19,11 @@ MasterSemaphore::MasterSemaphore(const Instance& instance_) : instance{instance_
.initialValue = 0, .initialValue = 0,
}, },
}; };
auto result = instance.GetDevice().createSemaphoreUnique(semaphore_chain.get()); auto [semaphore_result, sem] =
ASSERT_MSG(result.result == vk::Result::eSuccess, "Failed to create master semaphore: {}", instance.GetDevice().createSemaphoreUnique(semaphore_chain.get());
vk::to_string(result.result)); ASSERT_MSG(semaphore_result == vk::Result::eSuccess, "Failed to create master semaphore: {}",
semaphore = std::move(result.value); vk::to_string(semaphore_result));
semaphore = std::move(sem);
} }
MasterSemaphore::~MasterSemaphore() = default; MasterSemaphore::~MasterSemaphore() = default;
@ -32,11 +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);
auto counter_result = instance.GetDevice().getSemaphoreCounterValue(*semaphore); auto [counter_result, cntr] = instance.GetDevice().getSemaphoreCounterValue(*semaphore);
ASSERT_MSG(counter_result.result == vk::Result::eSuccess, ASSERT_MSG(counter_result == vk::Result::eSuccess,
"Failed to get master semaphore value: {}", "Failed to get master semaphore value: {}", vk::to_string(counter_result));
vk::to_string(counter_result.result)); counter = cntr;
counter = counter_result.value;
if (counter < this_tick) { if (counter < this_tick) {
return; return;
} }

View file

@ -136,10 +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,
}; };
auto cache_result = instance.GetDevice().createPipelineCacheUnique({}); auto [cache_result, cache] = instance.GetDevice().createPipelineCacheUnique({});
ASSERT_MSG(cache_result.result == vk::Result::eSuccess, "Failed to create pipeline cache: {}", ASSERT_MSG(cache_result == vk::Result::eSuccess, "Failed to create pipeline cache: {}",
vk::to_string(cache_result.result)); vk::to_string(cache_result));
pipeline_cache = std::move(cache_result.value); pipeline_cache = std::move(cache);
} }
PipelineCache::~PipelineCache() = default; PipelineCache::~PipelineCache() = default;

View file

@ -134,13 +134,12 @@ 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_result = vk::enumerateInstanceExtensionProperties(); const auto [properties_result, properties] = vk::enumerateInstanceExtensionProperties();
if (properties_result.result != vk::Result::eSuccess || properties_result.value.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.result)); vk::to_string(properties_result));
return {}; return {};
} }
const auto& properties = properties_result.value;
// Add the windowing system specific extension // Add the windowing system specific extension
std::vector<const char*> extensions; std::vector<const char*> extensions;
@ -209,16 +208,16 @@ vk::UniqueInstance CreateInstance(Frontend::WindowSystemType window_type, bool e
#endif #endif
VULKAN_HPP_DEFAULT_DISPATCHER.init(vkGetInstanceProcAddr); VULKAN_HPP_DEFAULT_DISPATCHER.init(vkGetInstanceProcAddr);
const auto available_version = VULKAN_HPP_DEFAULT_DISPATCHER.vkEnumerateInstanceVersion const auto [available_version_result, available_version] =
? vk::enumerateInstanceVersion() VULKAN_HPP_DEFAULT_DISPATCHER.vkEnumerateInstanceVersion
: vk::ResultValue(vk::Result::eSuccess, VK_API_VERSION_1_0); ? vk::enumerateInstanceVersion()
ASSERT_MSG(available_version.result == vk::Result::eSuccess, : vk::ResultValue(vk::Result::eSuccess, VK_API_VERSION_1_0);
"Failed to query Vulkan API version: {}", vk::to_string(available_version.result)); ASSERT_MSG(available_version_result == vk::Result::eSuccess,
ASSERT_MSG(available_version.value >= TargetVulkanApiVersion, "Failed to query Vulkan API version: {}", vk::to_string(available_version_result));
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),
VK_VERSION_MAJOR(available_version.value), VK_VERSION_MAJOR(available_version), VK_VERSION_MINOR(available_version));
VK_VERSION_MINOR(available_version.value));
const auto extensions = GetInstanceExtensions(window_type, true); const auto extensions = GetInstanceExtensions(window_type, true);
@ -227,7 +226,7 @@ vk::UniqueInstance CreateInstance(Frontend::WindowSystemType window_type, bool e
.applicationVersion = VK_MAKE_VERSION(1, 0, 0), .applicationVersion = VK_MAKE_VERSION(1, 0, 0),
.pEngineName = "shadPS4 Vulkan", .pEngineName = "shadPS4 Vulkan",
.engineVersion = VK_MAKE_VERSION(1, 0, 0), .engineVersion = VK_MAKE_VERSION(1, 0, 0),
.apiVersion = available_version.value, .apiVersion = available_version,
}; };
u32 num_layers = 0; u32 num_layers = 0;
@ -345,13 +344,13 @@ vk::UniqueInstance CreateInstance(Frontend::WindowSystemType window_type, bool e
}, },
}; };
auto instance_result = vk::createInstanceUnique(instance_ci_chain.get()); auto [instance_result, instance] = vk::createInstanceUnique(instance_ci_chain.get());
ASSERT_MSG(instance_result.result == vk::Result::eSuccess, "Failed to create instance: {}", ASSERT_MSG(instance_result == vk::Result::eSuccess, "Failed to create instance: {}",
vk::to_string(instance_result.result)); vk::to_string(instance_result));
VULKAN_HPP_DEFAULT_DISPATCHER.init(*instance_result.value); VULKAN_HPP_DEFAULT_DISPATCHER.init(*instance);
return std::move(instance_result.value); return std::move(instance);
} }
vk::UniqueDebugUtilsMessengerEXT CreateDebugCallback(vk::Instance instance) { vk::UniqueDebugUtilsMessengerEXT CreateDebugCallback(vk::Instance instance) {
@ -365,10 +364,10 @@ vk::UniqueDebugUtilsMessengerEXT CreateDebugCallback(vk::Instance instance) {
vk::DebugUtilsMessageTypeFlagBitsEXT::ePerformance, vk::DebugUtilsMessageTypeFlagBitsEXT::ePerformance,
.pfnUserCallback = DebugUtilsCallback, .pfnUserCallback = DebugUtilsCallback,
}; };
auto result = instance.createDebugUtilsMessengerEXTUnique(msg_ci); auto [messenger_result, messenger] = instance.createDebugUtilsMessengerEXTUnique(msg_ci);
ASSERT_MSG(result.result == vk::Result::eSuccess, "Failed to create debug callback: {}", ASSERT_MSG(messenger_result == vk::Result::eSuccess, "Failed to create debug callback: {}",
vk::to_string(result.result)); vk::to_string(messenger_result));
return std::move(result.value); return std::move(messenger);
} }
} // namespace Vulkan } // namespace Vulkan

View file

@ -69,10 +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();
auto result = device.createCommandPoolUnique(pool_create_info); auto [pool_result, pool] = device.createCommandPoolUnique(pool_create_info);
ASSERT_MSG(result.result == vk::Result::eSuccess, "Failed to create command pool: {}", ASSERT_MSG(pool_result == vk::Result::eSuccess, "Failed to create command pool: {}",
vk::to_string(result.result)); vk::to_string(pool_result));
cmd_pool = std::move(result.value); cmd_pool = std::move(pool);
if (instance.HasDebuggingToolAttached()) { if (instance.HasDebuggingToolAttached()) {
SetObjectName(device, *cmd_pool, "CommandPool"); SetObjectName(device, *cmd_pool, "CommandPool");
} }
@ -185,10 +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(),
}; };
auto result = device.createDescriptorPool(pool_info); auto [pool_result, pool] = device.createDescriptorPool(pool_info);
ASSERT_MSG(result.result == vk::Result::eSuccess, "Failed to create descriptor pool: {}", ASSERT_MSG(pool_result == vk::Result::eSuccess, "Failed to create descriptor pool: {}",
vk::to_string(result.result)); vk::to_string(pool_result));
curr_pool = result.value; curr_pool = pool;
} }
} // namespace Vulkan } // namespace Vulkan

View file

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

View file

@ -37,16 +37,17 @@ 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);
if (modes.result != vk::Result::eSuccess) { const auto find_mode = [&modes_result, &modes](vk::PresentModeKHR requested) {
if (modes_result != vk::Result::eSuccess) {
return false; return false;
} }
const auto it = const auto it =
std::find_if(modes.value.begin(), modes.value.end(), std::find_if(modes.begin(), modes.end(),
[&requested](vk::PresentModeKHR mode) { return mode == requested; }); [&requested](vk::PresentModeKHR mode) { return mode == requested; });
return it != modes.value.end(); return it != modes.end();
}; };
const bool has_mailbox = find_mode(vk::PresentModeKHR::eMailbox); const bool has_mailbox = find_mode(vk::PresentModeKHR::eMailbox);
@ -73,10 +74,10 @@ void Swapchain::Create(u32 width_, u32 height_, vk::SurfaceKHR surface_) {
.oldSwapchain = nullptr, .oldSwapchain = nullptr,
}; };
auto swapchain_result = instance.GetDevice().createSwapchainKHR(swapchain_info); auto [swapchain_result, chain] = instance.GetDevice().createSwapchainKHR(swapchain_info);
ASSERT_MSG(swapchain_result.result == vk::Result::eSuccess, "Failed to create swapchain: {}", ASSERT_MSG(swapchain_result == vk::Result::eSuccess, "Failed to create swapchain: {}",
vk::to_string(swapchain_result.result)); vk::to_string(swapchain_result));
swapchain = std::move(swapchain_result.value); swapchain = chain;
SetupImages(); SetupImages();
RefreshSemaphores(); RefreshSemaphores();
@ -132,10 +133,10 @@ void Swapchain::Present() {
} }
void Swapchain::FindPresentFormat() { void Swapchain::FindPresentFormat() {
const auto formats_result = instance.GetPhysicalDevice().getSurfaceFormatsKHR(surface); const auto [formats_result, formats] =
ASSERT_MSG(formats_result.result == vk::Result::eSuccess, "Failed to query surface formats: {}", instance.GetPhysicalDevice().getSurfaceFormatsKHR(surface);
vk::to_string(formats_result.result)); ASSERT_MSG(formats_result == vk::Result::eSuccess, "Failed to query surface formats: {}",
const auto& formats = formats_result.value; 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.
@ -161,12 +162,10 @@ void Swapchain::FindPresentFormat() {
} }
void Swapchain::SetSurfaceProperties() { void Swapchain::SetSurfaceProperties() {
const auto capabilities_result = const auto [capabilities_result, capabilities] =
instance.GetPhysicalDevice().getSurfaceCapabilitiesKHR(surface); instance.GetPhysicalDevice().getSurfaceCapabilitiesKHR(surface);
ASSERT_MSG(capabilities_result.result == vk::Result::eSuccess, ASSERT_MSG(capabilities_result == vk::Result::eSuccess,
"Failed to query surface capabilities: {}", "Failed to query surface capabilities: {}", vk::to_string(capabilities_result));
vk::to_string(capabilities_result.result));
const auto& capabilities = capabilities_result.value;
extent = capabilities.currentExtent; extent = capabilities.currentExtent;
if (capabilities.currentExtent.width == std::numeric_limits<u32>::max()) { if (capabilities.currentExtent.width == std::numeric_limits<u32>::max()) {
@ -214,16 +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) {
auto result = device.createSemaphore({}); auto [semaphore_result, sem] = device.createSemaphore({});
ASSERT_MSG(result.result == vk::Result::eSuccess, ASSERT_MSG(semaphore_result == vk::Result::eSuccess,
"Failed to create image acquired semaphore: {}", vk::to_string(result.result)); "Failed to create image acquired semaphore: {}",
semaphore = result.value; vk::to_string(semaphore_result));
semaphore = sem;
} }
for (vk::Semaphore& semaphore : present_ready) { for (vk::Semaphore& semaphore : present_ready) {
auto result = device.createSemaphore({}); auto [semaphore_result, sem] = device.createSemaphore({});
ASSERT_MSG(result.result == vk::Result::eSuccess, ASSERT_MSG(semaphore_result == vk::Result::eSuccess,
"Failed to create present ready semaphore: {}", vk::to_string(result.result)); "Failed to create present ready semaphore: {}", vk::to_string(semaphore_result));
semaphore = result.value; semaphore = sem;
} }
if (instance.HasDebuggingToolAttached()) { if (instance.HasDebuggingToolAttached()) {
@ -236,10 +236,10 @@ void Swapchain::RefreshSemaphores() {
void Swapchain::SetupImages() { void Swapchain::SetupImages() {
vk::Device device = instance.GetDevice(); vk::Device device = instance.GetDevice();
auto images_result = device.getSwapchainImagesKHR(swapchain); auto [images_result, imgs] = device.getSwapchainImagesKHR(swapchain);
ASSERT_MSG(images_result.result == vk::Result::eSuccess, ASSERT_MSG(images_result == vk::Result::eSuccess, "Failed to create swapchain images: {}",
"Failed to create swapchain images: {}", vk::to_string(images_result.result)); vk::to_string(images_result));
images = std::move(images_result.value); 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

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

View file

@ -24,10 +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),
}; };
auto result = instance.GetDevice().createSamplerUnique(sampler_ci); auto [sampler_result, smplr] = instance.GetDevice().createSamplerUnique(sampler_ci);
ASSERT_MSG(result.result == vk::Result::eSuccess, "Failed to create sampler: {}", ASSERT_MSG(sampler_result == vk::Result::eSuccess, "Failed to create sampler: {}",
vk::to_string(result.result)); vk::to_string(sampler_result));
handle = std::move(result.value); handle = std::move(smplr);
} }
Sampler::~Sampler() = default; Sampler::~Sampler() = default;

View file

@ -298,11 +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_result = static auto [desc_layout_result, desc_layout] =
instance.GetDevice().createDescriptorSetLayoutUnique(desc_layout_ci); instance.GetDevice().createDescriptorSetLayoutUnique(desc_layout_ci);
ASSERT_MSG(desc_layout_result.result == vk::Result::eSuccess, ASSERT_MSG(desc_layout_result == vk::Result::eSuccess,
"Failed to create descriptor set layout: {}", "Failed to create descriptor set layout: {}", vk::to_string(desc_layout_result));
vk::to_string(desc_layout_result.result));
const vk::PushConstantRange push_constants = { const vk::PushConstantRange push_constants = {
.stageFlags = vk::ShaderStageFlagBits::eCompute, .stageFlags = vk::ShaderStageFlagBits::eCompute,
@ -310,17 +309,17 @@ TileManager::TileManager(const Vulkan::Instance& instance, Vulkan::Scheduler& sc
.size = sizeof(DetilerParams), .size = sizeof(DetilerParams),
}; };
const vk::DescriptorSetLayout set_layout = *desc_layout_result.value; const vk::DescriptorSetLayout set_layout = *desc_layout;
const vk::PipelineLayoutCreateInfo layout_info = { const vk::PipelineLayoutCreateInfo layout_info = {
.setLayoutCount = 1U, .setLayoutCount = 1U,
.pSetLayouts = &set_layout, .pSetLayouts = &set_layout,
.pushConstantRangeCount = 1, .pushConstantRangeCount = 1,
.pPushConstantRanges = &push_constants, .pPushConstantRanges = &push_constants,
}; };
auto layout_result = instance.GetDevice().createPipelineLayoutUnique(layout_info); auto [layout_result, layout] = instance.GetDevice().createPipelineLayoutUnique(layout_info);
ASSERT_MSG(layout_result.result == vk::Result::eSuccess, ASSERT_MSG(layout_result == vk::Result::eSuccess, "Failed to create pipeline layout: {}",
"Failed to create pipeline layout: {}", vk::to_string(layout_result.result)); vk::to_string(layout_result));
ctx.pl_layout = std::move(layout_result.value); ctx.pl_layout = std::move(layout);
const vk::ComputePipelineCreateInfo compute_pipeline_ci = { const vk::ComputePipelineCreateInfo compute_pipeline_ci = {
.stage = shader_ci, .stage = shader_ci,