diff options
| author | 2020-12-24 21:24:34 -0300 | |
|---|---|---|
| committer | 2020-12-31 02:02:48 -0300 | |
| commit | d93742142243dea1355012b9f0ce7f5ac8a2dc02 (patch) | |
| tree | 67538ec18461b8d0f2e125fb7b797b89b8189db8 /src | |
| parent | Merge pull request #5263 from lioncash/uninit (diff) | |
| download | yuzu-d93742142243dea1355012b9f0ce7f5ac8a2dc02.tar.gz yuzu-d93742142243dea1355012b9f0ce7f5ac8a2dc02.tar.xz yuzu-d93742142243dea1355012b9f0ce7f5ac8a2dc02.zip | |
vulkan_common: Move dynamic library load to a separate file
Allows us to initialize a Vulkan dynamic library from different backends
without duplicating code.
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/video_core/renderer_vulkan/renderer_vulkan.cpp | 39 | ||||
| -rw-r--r-- | src/video_core/vulkan_common/vulkan_library.cpp | 36 | ||||
| -rw-r--r-- | src/video_core/vulkan_common/vulkan_library.h | 13 |
4 files changed, 59 insertions, 31 deletions
diff --git a/src/video_core/CMakeLists.txt b/src/video_core/CMakeLists.txt index 948e167c3..d967fe07b 100644 --- a/src/video_core/CMakeLists.txt +++ b/src/video_core/CMakeLists.txt | |||
| @@ -260,6 +260,8 @@ add_library(video_core STATIC | |||
| 260 | textures/texture.h | 260 | textures/texture.h |
| 261 | video_core.cpp | 261 | video_core.cpp |
| 262 | video_core.h | 262 | video_core.h |
| 263 | vulkan_common/vulkan_library.cpp | ||
| 264 | vulkan_common/vulkan_library.h | ||
| 263 | ) | 265 | ) |
| 264 | 266 | ||
| 265 | create_target_directory_groups(video_core) | 267 | create_target_directory_groups(video_core) |
diff --git a/src/video_core/renderer_vulkan/renderer_vulkan.cpp b/src/video_core/renderer_vulkan/renderer_vulkan.cpp index 7f521cb9b..7a34c95ab 100644 --- a/src/video_core/renderer_vulkan/renderer_vulkan.cpp +++ b/src/video_core/renderer_vulkan/renderer_vulkan.cpp | |||
| @@ -12,8 +12,6 @@ | |||
| 12 | 12 | ||
| 13 | #include <fmt/format.h> | 13 | #include <fmt/format.h> |
| 14 | 14 | ||
| 15 | #include "common/dynamic_library.h" | ||
| 16 | #include "common/file_util.h" | ||
| 17 | #include "common/logging/log.h" | 15 | #include "common/logging/log.h" |
| 18 | #include "common/telemetry.h" | 16 | #include "common/telemetry.h" |
| 19 | #include "core/core.h" | 17 | #include "core/core.h" |
| @@ -32,6 +30,7 @@ | |||
| 32 | #include "video_core/renderer_vulkan/vk_state_tracker.h" | 30 | #include "video_core/renderer_vulkan/vk_state_tracker.h" |
| 33 | #include "video_core/renderer_vulkan/vk_swapchain.h" | 31 | #include "video_core/renderer_vulkan/vk_swapchain.h" |
| 34 | #include "video_core/renderer_vulkan/wrapper.h" | 32 | #include "video_core/renderer_vulkan/wrapper.h" |
| 33 | #include "video_core/vulkan_common/vulkan_library.h" | ||
| 35 | 34 | ||
| 36 | // Include these late to avoid polluting previous headers | 35 | // Include these late to avoid polluting previous headers |
| 37 | #ifdef _WIN32 | 36 | #ifdef _WIN32 |
| @@ -70,31 +69,10 @@ VkBool32 DebugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT severity, | |||
| 70 | return VK_FALSE; | 69 | return VK_FALSE; |
| 71 | } | 70 | } |
| 72 | 71 | ||
| 73 | Common::DynamicLibrary OpenVulkanLibrary() { | 72 | std::pair<vk::Instance, u32> CreateInstance( |
| 74 | Common::DynamicLibrary library; | 73 | Common::DynamicLibrary& library, vk::InstanceDispatch& dld, |
| 75 | #ifdef __APPLE__ | 74 | WindowSystemType window_type = WindowSystemType::Headless, bool enable_debug_utils = false, |
| 76 | // Check if a path to a specific Vulkan library has been specified. | 75 | bool enable_layers = false) { |
| 77 | char* libvulkan_env = getenv("LIBVULKAN_PATH"); | ||
| 78 | if (!libvulkan_env || !library.Open(libvulkan_env)) { | ||
| 79 | // Use the libvulkan.dylib from the application bundle. | ||
| 80 | const std::string filename = | ||
| 81 | Common::FS::GetBundleDirectory() + "/Contents/Frameworks/libvulkan.dylib"; | ||
| 82 | library.Open(filename.c_str()); | ||
| 83 | } | ||
| 84 | #else | ||
| 85 | std::string filename = Common::DynamicLibrary::GetVersionedFilename("vulkan", 1); | ||
| 86 | if (!library.Open(filename.c_str())) { | ||
| 87 | // Android devices may not have libvulkan.so.1, only libvulkan.so. | ||
| 88 | filename = Common::DynamicLibrary::GetVersionedFilename("vulkan"); | ||
| 89 | (void)library.Open(filename.c_str()); | ||
| 90 | } | ||
| 91 | #endif | ||
| 92 | return library; | ||
| 93 | } | ||
| 94 | |||
| 95 | std::pair<vk::Instance, u32> CreateInstance(Common::DynamicLibrary& library, | ||
| 96 | vk::InstanceDispatch& dld, WindowSystemType window_type, | ||
| 97 | bool enable_debug_utils, bool enable_layers) { | ||
| 98 | if (!library.IsOpen()) { | 76 | if (!library.IsOpen()) { |
| 99 | LOG_ERROR(Render_Vulkan, "Vulkan library not available"); | 77 | LOG_ERROR(Render_Vulkan, "Vulkan library not available"); |
| 100 | return {}; | 78 | return {}; |
| @@ -285,7 +263,7 @@ void RendererVulkan::SwapBuffers(const Tegra::FramebufferConfig* framebuffer) { | |||
| 285 | } | 263 | } |
| 286 | 264 | ||
| 287 | bool RendererVulkan::Init() { | 265 | bool RendererVulkan::Init() { |
| 288 | library = OpenVulkanLibrary(); | 266 | library = OpenLibrary(); |
| 289 | std::tie(instance, instance_version) = CreateInstance( | 267 | std::tie(instance, instance_version) = CreateInstance( |
| 290 | library, dld, render_window.GetWindowInfo().type, true, Settings::values.renderer_debug); | 268 | library, dld, render_window.GetWindowInfo().type, true, Settings::values.renderer_debug); |
| 291 | if (!instance || !CreateDebugCallback() || !CreateSurface() || !PickDevices()) { | 269 | if (!instance || !CreateDebugCallback() || !CreateSurface() || !PickDevices()) { |
| @@ -446,9 +424,8 @@ void RendererVulkan::Report() const { | |||
| 446 | 424 | ||
| 447 | std::vector<std::string> RendererVulkan::EnumerateDevices() { | 425 | std::vector<std::string> RendererVulkan::EnumerateDevices() { |
| 448 | vk::InstanceDispatch dld; | 426 | vk::InstanceDispatch dld; |
| 449 | Common::DynamicLibrary library = OpenVulkanLibrary(); | 427 | Common::DynamicLibrary library = OpenLibrary(); |
| 450 | vk::Instance instance = | 428 | vk::Instance instance = CreateInstance(library, dld).first; |
| 451 | CreateInstance(library, dld, WindowSystemType::Headless, false, false).first; | ||
| 452 | if (!instance) { | 429 | if (!instance) { |
| 453 | return {}; | 430 | return {}; |
| 454 | } | 431 | } |
diff --git a/src/video_core/vulkan_common/vulkan_library.cpp b/src/video_core/vulkan_common/vulkan_library.cpp new file mode 100644 index 000000000..27c958221 --- /dev/null +++ b/src/video_core/vulkan_common/vulkan_library.cpp | |||
| @@ -0,0 +1,36 @@ | |||
| 1 | // Copyright 2020 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <cstdlib> | ||
| 6 | #include <string> | ||
| 7 | |||
| 8 | #include "common/dynamic_library.h" | ||
| 9 | #include "common/file_util.h" | ||
| 10 | #include "video_core/vulkan_common/vulkan_library.h" | ||
| 11 | |||
| 12 | namespace Vulkan { | ||
| 13 | |||
| 14 | Common::DynamicLibrary OpenLibrary() { | ||
| 15 | Common::DynamicLibrary library; | ||
| 16 | #ifdef __APPLE__ | ||
| 17 | // Check if a path to a specific Vulkan library has been specified. | ||
| 18 | char* const libvulkan_env = std::getenv("LIBVULKAN_PATH"); | ||
| 19 | if (!libvulkan_env || !library.Open(libvulkan_env)) { | ||
| 20 | // Use the libvulkan.dylib from the application bundle. | ||
| 21 | const std::string filename = | ||
| 22 | Common::FS::GetBundleDirectory() + "/Contents/Frameworks/libvulkan.dylib"; | ||
| 23 | library.Open(filename.c_str()); | ||
| 24 | } | ||
| 25 | #else | ||
| 26 | std::string filename = Common::DynamicLibrary::GetVersionedFilename("vulkan", 1); | ||
| 27 | if (!library.Open(filename.c_str())) { | ||
| 28 | // Android devices may not have libvulkan.so.1, only libvulkan.so. | ||
| 29 | filename = Common::DynamicLibrary::GetVersionedFilename("vulkan"); | ||
| 30 | void(library.Open(filename.c_str())); | ||
| 31 | } | ||
| 32 | #endif | ||
| 33 | return library; | ||
| 34 | } | ||
| 35 | |||
| 36 | } // namespace Vulkan | ||
diff --git a/src/video_core/vulkan_common/vulkan_library.h b/src/video_core/vulkan_common/vulkan_library.h new file mode 100644 index 000000000..8b28b0e17 --- /dev/null +++ b/src/video_core/vulkan_common/vulkan_library.h | |||
| @@ -0,0 +1,13 @@ | |||
| 1 | // Copyright 2020 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include "common/dynamic_library.h" | ||
| 8 | |||
| 9 | namespace Vulkan { | ||
| 10 | |||
| 11 | Common::DynamicLibrary OpenLibrary(); | ||
| 12 | |||
| 13 | } // namespace Vulkan | ||