diff options
| author | 2020-12-24 21:24:34 -0300 | |
|---|---|---|
| committer | 2020-12-31 02:02:48 -0300 | |
| commit | d93742142243dea1355012b9f0ce7f5ac8a2dc02 (patch) | |
| tree | 67538ec18461b8d0f2e125fb7b797b89b8189db8 /src/video_core/renderer_vulkan | |
| 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/video_core/renderer_vulkan')
| -rw-r--r-- | src/video_core/renderer_vulkan/renderer_vulkan.cpp | 39 |
1 files changed, 8 insertions, 31 deletions
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 | } |