diff options
| author | 2020-04-02 02:32:58 -0300 | |
|---|---|---|
| committer | 2020-04-07 16:32:19 -0300 | |
| commit | bf1d66b7c074c02aa8148f2edbdc959082c229e1 (patch) | |
| tree | 744ff7c8db629f73181da21c44ec76ee70cd4e52 /src/yuzu_cmd | |
| parent | renderer_vulkan: Query device names from the backend (diff) | |
| download | yuzu-bf1d66b7c074c02aa8148f2edbdc959082c229e1.tar.gz yuzu-bf1d66b7c074c02aa8148f2edbdc959082c229e1.tar.xz yuzu-bf1d66b7c074c02aa8148f2edbdc959082c229e1.zip | |
yuzu: Drop SDL2 and Qt frontend Vulkan requirements
Create Vulkan instances and surfaces from the Vulkan backend.
Diffstat (limited to 'src/yuzu_cmd')
| -rw-r--r-- | src/yuzu_cmd/emu_window/emu_window_sdl2_gl.cpp | 6 | ||||
| -rw-r--r-- | src/yuzu_cmd/emu_window/emu_window_sdl2_gl.h | 4 | ||||
| -rw-r--r-- | src/yuzu_cmd/emu_window/emu_window_sdl2_vk.cpp | 159 | ||||
| -rw-r--r-- | src/yuzu_cmd/emu_window/emu_window_sdl2_vk.h | 18 |
4 files changed, 46 insertions, 141 deletions
diff --git a/src/yuzu_cmd/emu_window/emu_window_sdl2_gl.cpp b/src/yuzu_cmd/emu_window/emu_window_sdl2_gl.cpp index 3522dcf6d..411e7e647 100644 --- a/src/yuzu_cmd/emu_window/emu_window_sdl2_gl.cpp +++ b/src/yuzu_cmd/emu_window/emu_window_sdl2_gl.cpp | |||
| @@ -156,12 +156,6 @@ EmuWindow_SDL2_GL::~EmuWindow_SDL2_GL() { | |||
| 156 | SDL_GL_DeleteContext(window_context); | 156 | SDL_GL_DeleteContext(window_context); |
| 157 | } | 157 | } |
| 158 | 158 | ||
| 159 | void EmuWindow_SDL2_GL::RetrieveVulkanHandlers(void* get_instance_proc_addr, void* instance, | ||
| 160 | void* surface) const { | ||
| 161 | // Should not have been called from OpenGL | ||
| 162 | UNREACHABLE(); | ||
| 163 | } | ||
| 164 | |||
| 165 | std::unique_ptr<Core::Frontend::GraphicsContext> EmuWindow_SDL2_GL::CreateSharedContext() const { | 159 | std::unique_ptr<Core::Frontend::GraphicsContext> EmuWindow_SDL2_GL::CreateSharedContext() const { |
| 166 | return std::make_unique<SDLGLContext>(); | 160 | return std::make_unique<SDLGLContext>(); |
| 167 | } | 161 | } |
diff --git a/src/yuzu_cmd/emu_window/emu_window_sdl2_gl.h b/src/yuzu_cmd/emu_window/emu_window_sdl2_gl.h index e092021d7..48bb41683 100644 --- a/src/yuzu_cmd/emu_window/emu_window_sdl2_gl.h +++ b/src/yuzu_cmd/emu_window/emu_window_sdl2_gl.h | |||
| @@ -15,10 +15,6 @@ public: | |||
| 15 | 15 | ||
| 16 | void Present() override; | 16 | void Present() override; |
| 17 | 17 | ||
| 18 | /// Ignored in OpenGL | ||
| 19 | void RetrieveVulkanHandlers(void* get_instance_proc_addr, void* instance, | ||
| 20 | void* surface) const override; | ||
| 21 | |||
| 22 | std::unique_ptr<Core::Frontend::GraphicsContext> CreateSharedContext() const override; | 18 | std::unique_ptr<Core::Frontend::GraphicsContext> CreateSharedContext() const override; |
| 23 | 19 | ||
| 24 | private: | 20 | private: |
diff --git a/src/yuzu_cmd/emu_window/emu_window_sdl2_vk.cpp b/src/yuzu_cmd/emu_window/emu_window_sdl2_vk.cpp index 46d053f04..f2990910e 100644 --- a/src/yuzu_cmd/emu_window/emu_window_sdl2_vk.cpp +++ b/src/yuzu_cmd/emu_window/emu_window_sdl2_vk.cpp | |||
| @@ -2,102 +2,62 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <algorithm> | 5 | #include <cstdlib> |
| 6 | #include <memory> | ||
| 6 | #include <string> | 7 | #include <string> |
| 7 | #include <vector> | 8 | |
| 8 | #include <SDL.h> | ||
| 9 | #include <SDL_vulkan.h> | ||
| 10 | #include <fmt/format.h> | 9 | #include <fmt/format.h> |
| 11 | #include <vulkan/vulkan.h> | 10 | |
| 12 | #include "common/assert.h" | 11 | #include "common/assert.h" |
| 13 | #include "common/logging/log.h" | 12 | #include "common/logging/log.h" |
| 14 | #include "common/scm_rev.h" | 13 | #include "common/scm_rev.h" |
| 15 | #include "core/settings.h" | 14 | #include "core/settings.h" |
| 15 | #include "video_core/renderer_vulkan/renderer_vulkan.h" | ||
| 16 | #include "yuzu_cmd/emu_window/emu_window_sdl2_vk.h" | 16 | #include "yuzu_cmd/emu_window/emu_window_sdl2_vk.h" |
| 17 | 17 | ||
| 18 | // Include these late to avoid polluting everything with Xlib macros | ||
| 19 | #include <SDL.h> | ||
| 20 | #include <SDL_syswm.h> | ||
| 21 | |||
| 18 | EmuWindow_SDL2_VK::EmuWindow_SDL2_VK(Core::System& system, bool fullscreen) | 22 | EmuWindow_SDL2_VK::EmuWindow_SDL2_VK(Core::System& system, bool fullscreen) |
| 19 | : EmuWindow_SDL2{system, fullscreen} { | 23 | : EmuWindow_SDL2{system, fullscreen} { |
| 20 | if (SDL_Vulkan_LoadLibrary(nullptr) != 0) { | ||
| 21 | LOG_CRITICAL(Frontend, "SDL failed to load the Vulkan library: {}", SDL_GetError()); | ||
| 22 | exit(EXIT_FAILURE); | ||
| 23 | } | ||
| 24 | |||
| 25 | vkGetInstanceProcAddr = | ||
| 26 | reinterpret_cast<PFN_vkGetInstanceProcAddr>(SDL_Vulkan_GetVkGetInstanceProcAddr()); | ||
| 27 | if (vkGetInstanceProcAddr == nullptr) { | ||
| 28 | LOG_CRITICAL(Frontend, "Failed to retrieve Vulkan function pointer!"); | ||
| 29 | exit(EXIT_FAILURE); | ||
| 30 | } | ||
| 31 | |||
| 32 | const std::string window_title = fmt::format("yuzu {} | {}-{} (Vulkan)", Common::g_build_name, | 24 | const std::string window_title = fmt::format("yuzu {} | {}-{} (Vulkan)", Common::g_build_name, |
| 33 | Common::g_scm_branch, Common::g_scm_desc); | 25 | Common::g_scm_branch, Common::g_scm_desc); |
| 34 | render_window = | 26 | render_window = |
| 35 | SDL_CreateWindow(window_title.c_str(), | 27 | SDL_CreateWindow(window_title.c_str(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, |
| 36 | SDL_WINDOWPOS_UNDEFINED, // x position | ||
| 37 | SDL_WINDOWPOS_UNDEFINED, // y position | ||
| 38 | Layout::ScreenUndocked::Width, Layout::ScreenUndocked::Height, | 28 | Layout::ScreenUndocked::Width, Layout::ScreenUndocked::Height, |
| 39 | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_VULKAN); | 29 | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI); |
| 40 | |||
| 41 | const bool use_standard_layers = UseStandardLayers(vkGetInstanceProcAddr); | ||
| 42 | |||
| 43 | u32 extra_ext_count{}; | ||
| 44 | if (!SDL_Vulkan_GetInstanceExtensions(render_window, &extra_ext_count, NULL)) { | ||
| 45 | LOG_CRITICAL(Frontend, "Failed to query Vulkan extensions count from SDL! {}", | ||
| 46 | SDL_GetError()); | ||
| 47 | exit(1); | ||
| 48 | } | ||
| 49 | |||
| 50 | auto extra_ext_names = std::make_unique<const char* []>(extra_ext_count); | ||
| 51 | if (!SDL_Vulkan_GetInstanceExtensions(render_window, &extra_ext_count, extra_ext_names.get())) { | ||
| 52 | LOG_CRITICAL(Frontend, "Failed to query Vulkan extensions from SDL! {}", SDL_GetError()); | ||
| 53 | exit(1); | ||
| 54 | } | ||
| 55 | std::vector<const char*> enabled_extensions; | ||
| 56 | enabled_extensions.insert(enabled_extensions.begin(), extra_ext_names.get(), | ||
| 57 | extra_ext_names.get() + extra_ext_count); | ||
| 58 | |||
| 59 | std::vector<const char*> enabled_layers; | ||
| 60 | if (use_standard_layers) { | ||
| 61 | enabled_extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); | ||
| 62 | enabled_layers.push_back("VK_LAYER_LUNARG_standard_validation"); | ||
| 63 | } | ||
| 64 | |||
| 65 | VkApplicationInfo app_info{}; | ||
| 66 | app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; | ||
| 67 | app_info.apiVersion = VK_API_VERSION_1_1; | ||
| 68 | app_info.applicationVersion = VK_MAKE_VERSION(0, 1, 0); | ||
| 69 | app_info.pApplicationName = "yuzu-emu"; | ||
| 70 | app_info.engineVersion = VK_MAKE_VERSION(0, 1, 0); | ||
| 71 | app_info.pEngineName = "yuzu-emu"; | ||
| 72 | 30 | ||
| 73 | VkInstanceCreateInfo instance_ci{}; | 31 | SDL_SysWMinfo wm; |
| 74 | instance_ci.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; | 32 | if (SDL_GetWindowWMInfo(render_window, &wm) == SDL_FALSE) { |
| 75 | instance_ci.pApplicationInfo = &app_info; | 33 | LOG_CRITICAL(Frontend, "Failed to get information from the window manager"); |
| 76 | instance_ci.enabledExtensionCount = static_cast<u32>(enabled_extensions.size()); | 34 | std::exit(EXIT_FAILURE); |
| 77 | instance_ci.ppEnabledExtensionNames = enabled_extensions.data(); | ||
| 78 | if (Settings::values.renderer_debug) { | ||
| 79 | instance_ci.enabledLayerCount = static_cast<u32>(enabled_layers.size()); | ||
| 80 | instance_ci.ppEnabledLayerNames = enabled_layers.data(); | ||
| 81 | } | 35 | } |
| 82 | 36 | ||
| 83 | const auto vkCreateInstance = | 37 | switch (wm.subsystem) { |
| 84 | reinterpret_cast<PFN_vkCreateInstance>(vkGetInstanceProcAddr(nullptr, "vkCreateInstance")); | 38 | #ifdef SDL_VIDEO_DRIVER_WINDOWS |
| 85 | if (vkCreateInstance == nullptr || | 39 | case SDL_SYSWM_TYPE::SDL_SYSWM_WINDOWS: |
| 86 | vkCreateInstance(&instance_ci, nullptr, &vk_instance) != VK_SUCCESS) { | 40 | window_info.type = Core::Frontend::WindowSystemType::Windows; |
| 87 | LOG_CRITICAL(Frontend, "Failed to create Vulkan instance!"); | 41 | window_info.render_surface = reinterpret_cast<void*>(wm.info.win.window); |
| 88 | exit(EXIT_FAILURE); | 42 | break; |
| 89 | } | 43 | #endif |
| 90 | 44 | #ifdef SDL_VIDEO_DRIVER_X11 | |
| 91 | vkDestroyInstance = reinterpret_cast<PFN_vkDestroyInstance>( | 45 | case SDL_SYSWM_TYPE::SDL_SYSWM_X11: |
| 92 | vkGetInstanceProcAddr(vk_instance, "vkDestroyInstance")); | 46 | window_info.type = Core::Frontend::WindowSystemType::X11; |
| 93 | if (vkDestroyInstance == nullptr) { | 47 | window_info.display_connection = wm.info.x11.display; |
| 94 | LOG_CRITICAL(Frontend, "Failed to retrieve Vulkan function pointer!"); | 48 | window_info.render_surface = reinterpret_cast<void*>(wm.info.x11.window); |
| 95 | exit(EXIT_FAILURE); | 49 | break; |
| 96 | } | 50 | #endif |
| 97 | 51 | #ifdef SDL_VIDEO_DRIVER_WAYLAND | |
| 98 | if (!SDL_Vulkan_CreateSurface(render_window, vk_instance, &vk_surface)) { | 52 | case SDL_SYSWM_TYPE::SDL_SYSWM_WAYLAND: |
| 99 | LOG_CRITICAL(Frontend, "Failed to create Vulkan surface! {}", SDL_GetError()); | 53 | window_info.type = Core::Frontend::WindowSystemType::Wayland; |
| 100 | exit(EXIT_FAILURE); | 54 | window_info.display_connection = wm.info.wl.display; |
| 55 | window_info.render_surface = wm.info.wl.surface; | ||
| 56 | break; | ||
| 57 | #endif | ||
| 58 | default: | ||
| 59 | LOG_CRITICAL(Frontend, "Window manager subsystem not implemented"); | ||
| 60 | std::exit(EXIT_FAILURE); | ||
| 101 | } | 61 | } |
| 102 | 62 | ||
| 103 | OnResize(); | 63 | OnResize(); |
| @@ -107,51 +67,12 @@ EmuWindow_SDL2_VK::EmuWindow_SDL2_VK(Core::System& system, bool fullscreen) | |||
| 107 | Common::g_scm_branch, Common::g_scm_desc); | 67 | Common::g_scm_branch, Common::g_scm_desc); |
| 108 | } | 68 | } |
| 109 | 69 | ||
| 110 | EmuWindow_SDL2_VK::~EmuWindow_SDL2_VK() { | 70 | EmuWindow_SDL2_VK::~EmuWindow_SDL2_VK() = default; |
| 111 | vkDestroyInstance(vk_instance, nullptr); | ||
| 112 | } | ||
| 113 | |||
| 114 | void EmuWindow_SDL2_VK::RetrieveVulkanHandlers(void* get_instance_proc_addr, void* instance, | ||
| 115 | void* surface) const { | ||
| 116 | const auto instance_proc_addr = vkGetInstanceProcAddr; | ||
| 117 | std::memcpy(get_instance_proc_addr, &instance_proc_addr, sizeof(instance_proc_addr)); | ||
| 118 | std::memcpy(instance, &vk_instance, sizeof(vk_instance)); | ||
| 119 | std::memcpy(surface, &vk_surface, sizeof(vk_surface)); | ||
| 120 | } | ||
| 121 | 71 | ||
| 122 | std::unique_ptr<Core::Frontend::GraphicsContext> EmuWindow_SDL2_VK::CreateSharedContext() const { | 72 | std::unique_ptr<Core::Frontend::GraphicsContext> EmuWindow_SDL2_VK::CreateSharedContext() const { |
| 123 | return nullptr; | 73 | return nullptr; |
| 124 | } | 74 | } |
| 125 | 75 | ||
| 126 | bool EmuWindow_SDL2_VK::UseStandardLayers(PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr) const { | ||
| 127 | if (!Settings::values.renderer_debug) { | ||
| 128 | return false; | ||
| 129 | } | ||
| 130 | |||
| 131 | const auto vkEnumerateInstanceLayerProperties = | ||
| 132 | reinterpret_cast<PFN_vkEnumerateInstanceLayerProperties>( | ||
| 133 | vkGetInstanceProcAddr(nullptr, "vkEnumerateInstanceLayerProperties")); | ||
| 134 | if (vkEnumerateInstanceLayerProperties == nullptr) { | ||
| 135 | LOG_CRITICAL(Frontend, "Failed to retrieve Vulkan function pointer!"); | ||
| 136 | return false; | ||
| 137 | } | ||
| 138 | |||
| 139 | u32 available_layers_count{}; | ||
| 140 | if (vkEnumerateInstanceLayerProperties(&available_layers_count, nullptr) != VK_SUCCESS) { | ||
| 141 | LOG_CRITICAL(Frontend, "Failed to enumerate Vulkan validation layers!"); | ||
| 142 | return false; | ||
| 143 | } | ||
| 144 | std::vector<VkLayerProperties> layers(available_layers_count); | ||
| 145 | if (vkEnumerateInstanceLayerProperties(&available_layers_count, layers.data()) != VK_SUCCESS) { | ||
| 146 | LOG_CRITICAL(Frontend, "Failed to enumerate Vulkan validation layers!"); | ||
| 147 | return false; | ||
| 148 | } | ||
| 149 | |||
| 150 | return std::find_if(layers.begin(), layers.end(), [&](const auto& layer) { | ||
| 151 | return layer.layerName == std::string("VK_LAYER_LUNARG_standard_validation"); | ||
| 152 | }) != layers.end(); | ||
| 153 | } | ||
| 154 | |||
| 155 | void EmuWindow_SDL2_VK::Present() { | 76 | void EmuWindow_SDL2_VK::Present() { |
| 156 | // TODO (bunnei): ImplementMe | 77 | // TODO (bunnei): ImplementMe |
| 157 | } | 78 | } |
diff --git a/src/yuzu_cmd/emu_window/emu_window_sdl2_vk.h b/src/yuzu_cmd/emu_window/emu_window_sdl2_vk.h index 3dd1f3f61..b8021ebea 100644 --- a/src/yuzu_cmd/emu_window/emu_window_sdl2_vk.h +++ b/src/yuzu_cmd/emu_window/emu_window_sdl2_vk.h | |||
| @@ -4,27 +4,21 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <vulkan/vulkan.h> | 7 | #include <memory> |
| 8 | |||
| 8 | #include "core/frontend/emu_window.h" | 9 | #include "core/frontend/emu_window.h" |
| 9 | #include "yuzu_cmd/emu_window/emu_window_sdl2.h" | 10 | #include "yuzu_cmd/emu_window/emu_window_sdl2.h" |
| 10 | 11 | ||
| 12 | namespace Core { | ||
| 13 | class System; | ||
| 14 | } | ||
| 15 | |||
| 11 | class EmuWindow_SDL2_VK final : public EmuWindow_SDL2 { | 16 | class EmuWindow_SDL2_VK final : public EmuWindow_SDL2 { |
| 12 | public: | 17 | public: |
| 13 | explicit EmuWindow_SDL2_VK(Core::System& system, bool fullscreen); | 18 | explicit EmuWindow_SDL2_VK(Core::System& system, bool fullscreen); |
| 14 | ~EmuWindow_SDL2_VK(); | 19 | ~EmuWindow_SDL2_VK(); |
| 15 | 20 | ||
| 16 | void Present() override; | 21 | void Present() override; |
| 17 | void RetrieveVulkanHandlers(void* get_instance_proc_addr, void* instance, | ||
| 18 | void* surface) const override; | ||
| 19 | 22 | ||
| 20 | std::unique_ptr<Core::Frontend::GraphicsContext> CreateSharedContext() const override; | 23 | std::unique_ptr<Core::Frontend::GraphicsContext> CreateSharedContext() const override; |
| 21 | |||
| 22 | private: | ||
| 23 | bool UseStandardLayers(PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr) const; | ||
| 24 | |||
| 25 | VkInstance vk_instance{}; | ||
| 26 | VkSurfaceKHR vk_surface{}; | ||
| 27 | |||
| 28 | PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr{}; | ||
| 29 | PFN_vkDestroyInstance vkDestroyInstance{}; | ||
| 30 | }; | 24 | }; |