From aa6809e2a8f8264f6c5ed359a0fc458c66368856 Mon Sep 17 00:00:00 2001 From: Steveice10 <1269164+Steveice10@users.noreply.github.com> Date: Thu, 15 Feb 2024 19:38:32 -0800 Subject: [PATCH] renderer_vulkan: Use no more than target supported version. (#7439) --- src/video_core/renderer_vulkan/vk_instance.cpp | 9 ++++++++- src/video_core/renderer_vulkan/vk_platform.cpp | 18 ++++++++++-------- src/video_core/renderer_vulkan/vk_platform.h | 2 ++ 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/video_core/renderer_vulkan/vk_instance.cpp b/src/video_core/renderer_vulkan/vk_instance.cpp index b9b5aa6ac..c0e14e4a2 100644 --- a/src/video_core/renderer_vulkan/vk_instance.cpp +++ b/src/video_core/renderer_vulkan/vk_instance.cpp @@ -4,6 +4,7 @@ #include #include +#include #include "common/assert.h" #include "common/settings.h" @@ -153,6 +154,12 @@ Instance::Instance(Core::TelemetrySession& telemetry, Frontend::EmuWindow& windo physical_device = physical_devices[physical_device_index]; available_extensions = GetSupportedExtensions(physical_device); properties = physical_device.getProperties(); + if (properties.apiVersion < TargetVulkanApiVersion) { + throw std::runtime_error(fmt::format( + "Vulkan {}.{} is required, but only {}.{} is supported by device!", + VK_VERSION_MAJOR(TargetVulkanApiVersion), VK_VERSION_MINOR(TargetVulkanApiVersion), + VK_VERSION_MAJOR(properties.apiVersion), VK_VERSION_MINOR(properties.apiVersion))); + } CollectTelemetryParameters(telemetry); CreateDevice(); @@ -629,7 +636,7 @@ void Instance::CreateAllocator() { .device = *device, .pVulkanFunctions = &functions, .instance = *instance, - .vulkanApiVersion = properties.apiVersion, + .vulkanApiVersion = TargetVulkanApiVersion, }; const VkResult result = vmaCreateAllocator(&allocator_info, &allocator); diff --git a/src/video_core/renderer_vulkan/vk_platform.cpp b/src/video_core/renderer_vulkan/vk_platform.cpp index 2b415354f..94ce93ec9 100644 --- a/src/video_core/renderer_vulkan/vk_platform.cpp +++ b/src/video_core/renderer_vulkan/vk_platform.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include "common/assert.h" #include "common/logging/log.h" @@ -290,13 +291,14 @@ vk::UniqueInstance CreateInstance(const Common::DynamicLibrary& library, } VULKAN_HPP_DEFAULT_DISPATCHER.init(vkGetInstanceProcAddr); - if (!VULKAN_HPP_DEFAULT_DISPATCHER.vkEnumerateInstanceVersion) { - throw std::runtime_error("Vulkan 1.0 is not supported, 1.1 is required!"); - } - - const u32 available_version = vk::enumerateInstanceVersion(); - if (available_version < VK_API_VERSION_1_1) { - throw std::runtime_error("Vulkan 1.0 is not supported, 1.1 is required!"); + const u32 available_version = VULKAN_HPP_DEFAULT_DISPATCHER.vkEnumerateInstanceVersion + ? vk::enumerateInstanceVersion() + : VK_API_VERSION_1_0; + if (available_version < TargetVulkanApiVersion) { + throw std::runtime_error(fmt::format( + "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))); } const auto extensions = GetInstanceExtensions(window_type, enable_validation); @@ -306,7 +308,7 @@ vk::UniqueInstance CreateInstance(const Common::DynamicLibrary& library, .applicationVersion = VK_MAKE_VERSION(1, 0, 0), .pEngineName = "Citra Vulkan", .engineVersion = VK_MAKE_VERSION(1, 0, 0), - .apiVersion = VK_API_VERSION_1_3, + .apiVersion = TargetVulkanApiVersion, }; boost::container::static_vector layers; diff --git a/src/video_core/renderer_vulkan/vk_platform.h b/src/video_core/renderer_vulkan/vk_platform.h index 20e9ebb0d..68f6457e0 100644 --- a/src/video_core/renderer_vulkan/vk_platform.h +++ b/src/video_core/renderer_vulkan/vk_platform.h @@ -19,6 +19,8 @@ enum class WindowSystemType : u8; namespace Vulkan { +constexpr u32 TargetVulkanApiVersion = VK_API_VERSION_1_1; + using DebugCallback = std::variant;