diff options
| -rw-r--r-- | src/video_core/renderer_vulkan/renderer_vulkan.cpp | 35 | ||||
| -rw-r--r-- | src/video_core/vulkan_common/vulkan_instance.cpp | 2 | ||||
| -rw-r--r-- | src/video_core/vulkan_common/vulkan_instance.h | 2 | ||||
| -rw-r--r-- | src/video_core/vulkan_common/vulkan_wrapper.cpp | 12 | ||||
| -rw-r--r-- | src/video_core/vulkan_common/vulkan_wrapper.h | 3 |
5 files changed, 21 insertions, 33 deletions
diff --git a/src/video_core/renderer_vulkan/renderer_vulkan.cpp b/src/video_core/renderer_vulkan/renderer_vulkan.cpp index 831c204c2..f64318f25 100644 --- a/src/video_core/renderer_vulkan/renderer_vulkan.cpp +++ b/src/video_core/renderer_vulkan/renderer_vulkan.cpp | |||
| @@ -170,7 +170,6 @@ void RendererVulkan::ShutDown() { | |||
| 170 | if (const auto& dev = device->GetLogical()) { | 170 | if (const auto& dev = device->GetLogical()) { |
| 171 | dev.WaitIdle(); | 171 | dev.WaitIdle(); |
| 172 | } | 172 | } |
| 173 | |||
| 174 | rasterizer.reset(); | 173 | rasterizer.reset(); |
| 175 | blit_screen.reset(); | 174 | blit_screen.reset(); |
| 176 | scheduler.reset(); | 175 | scheduler.reset(); |
| @@ -180,19 +179,13 @@ void RendererVulkan::ShutDown() { | |||
| 180 | } | 179 | } |
| 181 | 180 | ||
| 182 | bool RendererVulkan::PickDevices() { | 181 | bool RendererVulkan::PickDevices() { |
| 183 | const auto devices = instance.EnumeratePhysicalDevices(); | 182 | const std::vector<VkPhysicalDevice> devices = instance.EnumeratePhysicalDevices(); |
| 184 | if (!devices) { | ||
| 185 | LOG_ERROR(Render_Vulkan, "Failed to enumerate physical devices"); | ||
| 186 | return false; | ||
| 187 | } | ||
| 188 | |||
| 189 | const s32 device_index = Settings::values.vulkan_device.GetValue(); | 183 | const s32 device_index = Settings::values.vulkan_device.GetValue(); |
| 190 | if (device_index < 0 || device_index >= static_cast<s32>(devices->size())) { | 184 | if (device_index < 0 || device_index >= static_cast<s32>(devices.size())) { |
| 191 | LOG_ERROR(Render_Vulkan, "Invalid device index {}!", device_index); | 185 | LOG_ERROR(Render_Vulkan, "Invalid device index {}!", device_index); |
| 192 | return false; | 186 | return false; |
| 193 | } | 187 | } |
| 194 | const vk::PhysicalDevice physical_device((*devices)[static_cast<std::size_t>(device_index)], | 188 | const vk::PhysicalDevice physical_device(devices[static_cast<std::size_t>(device_index)], dld); |
| 195 | dld); | ||
| 196 | if (!VKDevice::IsSuitable(physical_device, *surface)) { | 189 | if (!VKDevice::IsSuitable(physical_device, *surface)) { |
| 197 | return false; | 190 | return false; |
| 198 | } | 191 | } |
| @@ -224,23 +217,21 @@ void RendererVulkan::Report() const { | |||
| 224 | telemetry_session.AddField(field, "GPU_Vulkan_Extensions", extensions); | 217 | telemetry_session.AddField(field, "GPU_Vulkan_Extensions", extensions); |
| 225 | } | 218 | } |
| 226 | 219 | ||
| 227 | std::vector<std::string> RendererVulkan::EnumerateDevices() { | 220 | std::vector<std::string> RendererVulkan::EnumerateDevices() try { |
| 228 | vk::InstanceDispatch dld; | 221 | vk::InstanceDispatch dld; |
| 229 | Common::DynamicLibrary library = OpenLibrary(); | 222 | const Common::DynamicLibrary library = OpenLibrary(); |
| 230 | vk::Instance instance = CreateInstance(library, dld).first; | 223 | const vk::Instance instance = CreateInstance(library, dld).first; |
| 231 | if (!instance) { | 224 | const std::vector<VkPhysicalDevice> physical_devices = instance.EnumeratePhysicalDevices(); |
| 232 | return {}; | ||
| 233 | } | ||
| 234 | const std::optional physical_devices = instance.EnumeratePhysicalDevices(); | ||
| 235 | if (!physical_devices) { | ||
| 236 | return {}; | ||
| 237 | } | ||
| 238 | std::vector<std::string> names; | 225 | std::vector<std::string> names; |
| 239 | names.reserve(physical_devices->size()); | 226 | names.reserve(physical_devices.size()); |
| 240 | for (const auto& device : *physical_devices) { | 227 | for (const VkPhysicalDevice device : physical_devices) { |
| 241 | names.push_back(vk::PhysicalDevice(device, dld).GetProperties().deviceName); | 228 | names.push_back(vk::PhysicalDevice(device, dld).GetProperties().deviceName); |
| 242 | } | 229 | } |
| 243 | return names; | 230 | return names; |
| 231 | |||
| 232 | } catch (const vk::Exception& exception) { | ||
| 233 | LOG_ERROR(Render_Vulkan, "Failed to enumerate devices with error: {}", exception.what()); | ||
| 234 | return {}; | ||
| 244 | } | 235 | } |
| 245 | 236 | ||
| 246 | } // namespace Vulkan | 237 | } // namespace Vulkan |
diff --git a/src/video_core/vulkan_common/vulkan_instance.cpp b/src/video_core/vulkan_common/vulkan_instance.cpp index d3d8630e5..ee46fc6cc 100644 --- a/src/video_core/vulkan_common/vulkan_instance.cpp +++ b/src/video_core/vulkan_common/vulkan_instance.cpp | |||
| @@ -111,7 +111,7 @@ void RemoveUnavailableLayers(const vk::InstanceDispatch& dld, std::vector<const | |||
| 111 | } | 111 | } |
| 112 | } // Anonymous namespace | 112 | } // Anonymous namespace |
| 113 | 113 | ||
| 114 | std::pair<vk::Instance, u32> CreateInstance(Common::DynamicLibrary& library, | 114 | std::pair<vk::Instance, u32> CreateInstance(const Common::DynamicLibrary& library, |
| 115 | vk::InstanceDispatch& dld, | 115 | vk::InstanceDispatch& dld, |
| 116 | Core::Frontend::WindowSystemType window_type, | 116 | Core::Frontend::WindowSystemType window_type, |
| 117 | bool enable_debug_utils, bool enable_layers) { | 117 | bool enable_debug_utils, bool enable_layers) { |
diff --git a/src/video_core/vulkan_common/vulkan_instance.h b/src/video_core/vulkan_common/vulkan_instance.h index ff2be0a48..5acca9756 100644 --- a/src/video_core/vulkan_common/vulkan_instance.h +++ b/src/video_core/vulkan_common/vulkan_instance.h | |||
| @@ -14,7 +14,7 @@ | |||
| 14 | namespace Vulkan { | 14 | namespace Vulkan { |
| 15 | 15 | ||
| 16 | [[nodiscard]] std::pair<vk::Instance, u32> CreateInstance( | 16 | [[nodiscard]] std::pair<vk::Instance, u32> CreateInstance( |
| 17 | Common::DynamicLibrary& library, vk::InstanceDispatch& dld, | 17 | const Common::DynamicLibrary& library, vk::InstanceDispatch& dld, |
| 18 | Core::Frontend::WindowSystemType window_type = Core::Frontend::WindowSystemType::Headless, | 18 | Core::Frontend::WindowSystemType window_type = Core::Frontend::WindowSystemType::Headless, |
| 19 | bool enable_debug_utils = false, bool enable_layers = false); | 19 | bool enable_debug_utils = false, bool enable_layers = false); |
| 20 | 20 | ||
diff --git a/src/video_core/vulkan_common/vulkan_wrapper.cpp b/src/video_core/vulkan_common/vulkan_wrapper.cpp index f4177537b..8698c3f92 100644 --- a/src/video_core/vulkan_common/vulkan_wrapper.cpp +++ b/src/video_core/vulkan_common/vulkan_wrapper.cpp | |||
| @@ -465,17 +465,13 @@ Instance Instance::Create(u32 version, Span<const char*> layers, Span<const char | |||
| 465 | return Instance(instance, dispatch); | 465 | return Instance(instance, dispatch); |
| 466 | } | 466 | } |
| 467 | 467 | ||
| 468 | std::optional<std::vector<VkPhysicalDevice>> Instance::EnumeratePhysicalDevices() const { | 468 | std::vector<VkPhysicalDevice> Instance::EnumeratePhysicalDevices() const { |
| 469 | u32 num; | 469 | u32 num; |
| 470 | if (dld->vkEnumeratePhysicalDevices(handle, &num, nullptr) != VK_SUCCESS) { | 470 | Check(dld->vkEnumeratePhysicalDevices(handle, &num, nullptr)); |
| 471 | return std::nullopt; | ||
| 472 | } | ||
| 473 | std::vector<VkPhysicalDevice> physical_devices(num); | 471 | std::vector<VkPhysicalDevice> physical_devices(num); |
| 474 | if (dld->vkEnumeratePhysicalDevices(handle, &num, physical_devices.data()) != VK_SUCCESS) { | 472 | Check(dld->vkEnumeratePhysicalDevices(handle, &num, physical_devices.data())); |
| 475 | return std::nullopt; | ||
| 476 | } | ||
| 477 | SortPhysicalDevices(physical_devices, *dld); | 473 | SortPhysicalDevices(physical_devices, *dld); |
| 478 | return std::make_optional(std::move(physical_devices)); | 474 | return physical_devices; |
| 479 | } | 475 | } |
| 480 | 476 | ||
| 481 | DebugUtilsMessenger Instance::CreateDebugUtilsMessenger( | 477 | DebugUtilsMessenger Instance::CreateDebugUtilsMessenger( |
diff --git a/src/video_core/vulkan_common/vulkan_wrapper.h b/src/video_core/vulkan_common/vulkan_wrapper.h index 012982a3f..af3083c84 100644 --- a/src/video_core/vulkan_common/vulkan_wrapper.h +++ b/src/video_core/vulkan_common/vulkan_wrapper.h | |||
| @@ -580,7 +580,8 @@ public: | |||
| 580 | 580 | ||
| 581 | /// Enumerates physical devices. | 581 | /// Enumerates physical devices. |
| 582 | /// @return Physical devices and an empty handle on failure. | 582 | /// @return Physical devices and an empty handle on failure. |
| 583 | std::optional<std::vector<VkPhysicalDevice>> EnumeratePhysicalDevices() const; | 583 | /// @throw Exception on Vulkan error. |
| 584 | std::vector<VkPhysicalDevice> EnumeratePhysicalDevices() const; | ||
| 584 | 585 | ||
| 585 | /// Creates a debug callback messenger. | 586 | /// Creates a debug callback messenger. |
| 586 | /// @throw Exception on creation failure. | 587 | /// @throw Exception on creation failure. |