diff options
Diffstat (limited to 'src/yuzu_cmd')
| -rw-r--r-- | src/yuzu_cmd/emu_window/emu_window_sdl2_gl.cpp | 24 | ||||
| -rw-r--r-- | src/yuzu_cmd/emu_window/emu_window_sdl2_gl.h | 6 | ||||
| -rw-r--r-- | src/yuzu_cmd/emu_window/emu_window_sdl2_vk.cpp | 167 | ||||
| -rw-r--r-- | src/yuzu_cmd/emu_window/emu_window_sdl2_vk.h | 20 | ||||
| -rw-r--r-- | src/yuzu_cmd/yuzu.cpp | 13 |
5 files changed, 58 insertions, 172 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 c0d373477..411e7e647 100644 --- a/src/yuzu_cmd/emu_window/emu_window_sdl2_gl.cpp +++ b/src/yuzu_cmd/emu_window/emu_window_sdl2_gl.cpp | |||
| @@ -37,16 +37,24 @@ public: | |||
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | void MakeCurrent() override { | 39 | void MakeCurrent() override { |
| 40 | SDL_GL_MakeCurrent(window, context); | 40 | if (is_current) { |
| 41 | return; | ||
| 42 | } | ||
| 43 | is_current = SDL_GL_MakeCurrent(window, context) == 0; | ||
| 41 | } | 44 | } |
| 42 | 45 | ||
| 43 | void DoneCurrent() override { | 46 | void DoneCurrent() override { |
| 47 | if (!is_current) { | ||
| 48 | return; | ||
| 49 | } | ||
| 44 | SDL_GL_MakeCurrent(window, nullptr); | 50 | SDL_GL_MakeCurrent(window, nullptr); |
| 51 | is_current = false; | ||
| 45 | } | 52 | } |
| 46 | 53 | ||
| 47 | private: | 54 | private: |
| 48 | SDL_Window* window; | 55 | SDL_Window* window; |
| 49 | SDL_GLContext context; | 56 | SDL_GLContext context; |
| 57 | bool is_current = false; | ||
| 50 | }; | 58 | }; |
| 51 | 59 | ||
| 52 | bool EmuWindow_SDL2_GL::SupportsRequiredGLExtensions() { | 60 | bool EmuWindow_SDL2_GL::SupportsRequiredGLExtensions() { |
| @@ -148,20 +156,6 @@ EmuWindow_SDL2_GL::~EmuWindow_SDL2_GL() { | |||
| 148 | SDL_GL_DeleteContext(window_context); | 156 | SDL_GL_DeleteContext(window_context); |
| 149 | } | 157 | } |
| 150 | 158 | ||
| 151 | void EmuWindow_SDL2_GL::MakeCurrent() { | ||
| 152 | core_context->MakeCurrent(); | ||
| 153 | } | ||
| 154 | |||
| 155 | void EmuWindow_SDL2_GL::DoneCurrent() { | ||
| 156 | core_context->DoneCurrent(); | ||
| 157 | } | ||
| 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 b80669ff0..48bb41683 100644 --- a/src/yuzu_cmd/emu_window/emu_window_sdl2_gl.h +++ b/src/yuzu_cmd/emu_window/emu_window_sdl2_gl.h | |||
| @@ -13,14 +13,8 @@ public: | |||
| 13 | explicit EmuWindow_SDL2_GL(Core::System& system, bool fullscreen); | 13 | explicit EmuWindow_SDL2_GL(Core::System& system, bool fullscreen); |
| 14 | ~EmuWindow_SDL2_GL(); | 14 | ~EmuWindow_SDL2_GL(); |
| 15 | 15 | ||
| 16 | void MakeCurrent() override; | ||
| 17 | void DoneCurrent() override; | ||
| 18 | void Present() override; | 16 | void Present() override; |
| 19 | 17 | ||
| 20 | /// Ignored in OpenGL | ||
| 21 | void RetrieveVulkanHandlers(void* get_instance_proc_addr, void* instance, | ||
| 22 | void* surface) const override; | ||
| 23 | |||
| 24 | std::unique_ptr<Core::Frontend::GraphicsContext> CreateSharedContext() const override; | 18 | std::unique_ptr<Core::Frontend::GraphicsContext> CreateSharedContext() const override; |
| 25 | 19 | ||
| 26 | 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 abcc58165..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 | |||
| 73 | VkInstanceCreateInfo instance_ci{}; | ||
| 74 | instance_ci.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; | ||
| 75 | instance_ci.pApplicationInfo = &app_info; | ||
| 76 | instance_ci.enabledExtensionCount = static_cast<u32>(enabled_extensions.size()); | ||
| 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 | } | ||
| 82 | 30 | ||
| 83 | const auto vkCreateInstance = | 31 | SDL_SysWMinfo wm; |
| 84 | reinterpret_cast<PFN_vkCreateInstance>(vkGetInstanceProcAddr(nullptr, "vkCreateInstance")); | 32 | if (SDL_GetWindowWMInfo(render_window, &wm) == SDL_FALSE) { |
| 85 | if (vkCreateInstance == nullptr || | 33 | LOG_CRITICAL(Frontend, "Failed to get information from the window manager"); |
| 86 | vkCreateInstance(&instance_ci, nullptr, &vk_instance) != VK_SUCCESS) { | 34 | std::exit(EXIT_FAILURE); |
| 87 | LOG_CRITICAL(Frontend, "Failed to create Vulkan instance!"); | ||
| 88 | exit(EXIT_FAILURE); | ||
| 89 | } | 35 | } |
| 90 | 36 | ||
| 91 | vkDestroyInstance = reinterpret_cast<PFN_vkDestroyInstance>( | 37 | switch (wm.subsystem) { |
| 92 | vkGetInstanceProcAddr(vk_instance, "vkDestroyInstance")); | 38 | #ifdef SDL_VIDEO_DRIVER_WINDOWS |
| 93 | if (vkDestroyInstance == nullptr) { | 39 | case SDL_SYSWM_TYPE::SDL_SYSWM_WINDOWS: |
| 94 | LOG_CRITICAL(Frontend, "Failed to retrieve Vulkan function pointer!"); | 40 | window_info.type = Core::Frontend::WindowSystemType::Windows; |
| 95 | exit(EXIT_FAILURE); | 41 | window_info.render_surface = reinterpret_cast<void*>(wm.info.win.window); |
| 96 | } | 42 | break; |
| 97 | 43 | #endif | |
| 98 | if (!SDL_Vulkan_CreateSurface(render_window, vk_instance, &vk_surface)) { | 44 | #ifdef SDL_VIDEO_DRIVER_X11 |
| 99 | LOG_CRITICAL(Frontend, "Failed to create Vulkan surface! {}", SDL_GetError()); | 45 | case SDL_SYSWM_TYPE::SDL_SYSWM_X11: |
| 100 | exit(EXIT_FAILURE); | 46 | window_info.type = Core::Frontend::WindowSystemType::X11; |
| 47 | window_info.display_connection = wm.info.x11.display; | ||
| 48 | window_info.render_surface = reinterpret_cast<void*>(wm.info.x11.window); | ||
| 49 | break; | ||
| 50 | #endif | ||
| 51 | #ifdef SDL_VIDEO_DRIVER_WAYLAND | ||
| 52 | case SDL_SYSWM_TYPE::SDL_SYSWM_WAYLAND: | ||
| 53 | window_info.type = Core::Frontend::WindowSystemType::Wayland; | ||
| 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,59 +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::MakeCurrent() { | ||
| 115 | // Unused on Vulkan | ||
| 116 | } | ||
| 117 | |||
| 118 | void EmuWindow_SDL2_VK::DoneCurrent() { | ||
| 119 | // Unused on Vulkan | ||
| 120 | } | ||
| 121 | |||
| 122 | void EmuWindow_SDL2_VK::RetrieveVulkanHandlers(void* get_instance_proc_addr, void* instance, | ||
| 123 | void* surface) const { | ||
| 124 | const auto instance_proc_addr = vkGetInstanceProcAddr; | ||
| 125 | std::memcpy(get_instance_proc_addr, &instance_proc_addr, sizeof(instance_proc_addr)); | ||
| 126 | std::memcpy(instance, &vk_instance, sizeof(vk_instance)); | ||
| 127 | std::memcpy(surface, &vk_surface, sizeof(vk_surface)); | ||
| 128 | } | ||
| 129 | 71 | ||
| 130 | std::unique_ptr<Core::Frontend::GraphicsContext> EmuWindow_SDL2_VK::CreateSharedContext() const { | 72 | std::unique_ptr<Core::Frontend::GraphicsContext> EmuWindow_SDL2_VK::CreateSharedContext() const { |
| 131 | return nullptr; | 73 | return nullptr; |
| 132 | } | 74 | } |
| 133 | 75 | ||
| 134 | bool EmuWindow_SDL2_VK::UseStandardLayers(PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr) const { | ||
| 135 | if (!Settings::values.renderer_debug) { | ||
| 136 | return false; | ||
| 137 | } | ||
| 138 | |||
| 139 | const auto vkEnumerateInstanceLayerProperties = | ||
| 140 | reinterpret_cast<PFN_vkEnumerateInstanceLayerProperties>( | ||
| 141 | vkGetInstanceProcAddr(nullptr, "vkEnumerateInstanceLayerProperties")); | ||
| 142 | if (vkEnumerateInstanceLayerProperties == nullptr) { | ||
| 143 | LOG_CRITICAL(Frontend, "Failed to retrieve Vulkan function pointer!"); | ||
| 144 | return false; | ||
| 145 | } | ||
| 146 | |||
| 147 | u32 available_layers_count{}; | ||
| 148 | if (vkEnumerateInstanceLayerProperties(&available_layers_count, nullptr) != VK_SUCCESS) { | ||
| 149 | LOG_CRITICAL(Frontend, "Failed to enumerate Vulkan validation layers!"); | ||
| 150 | return false; | ||
| 151 | } | ||
| 152 | std::vector<VkLayerProperties> layers(available_layers_count); | ||
| 153 | if (vkEnumerateInstanceLayerProperties(&available_layers_count, layers.data()) != VK_SUCCESS) { | ||
| 154 | LOG_CRITICAL(Frontend, "Failed to enumerate Vulkan validation layers!"); | ||
| 155 | return false; | ||
| 156 | } | ||
| 157 | |||
| 158 | return std::find_if(layers.begin(), layers.end(), [&](const auto& layer) { | ||
| 159 | return layer.layerName == std::string("VK_LAYER_LUNARG_standard_validation"); | ||
| 160 | }) != layers.end(); | ||
| 161 | } | ||
| 162 | |||
| 163 | void EmuWindow_SDL2_VK::Present() { | 76 | void EmuWindow_SDL2_VK::Present() { |
| 164 | // TODO (bunnei): ImplementMe | 77 | // TODO (bunnei): ImplementMe |
| 165 | } | 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 1eb8c0868..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,29 +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 MakeCurrent() override; | ||
| 17 | void DoneCurrent() override; | ||
| 18 | void Present() override; | 21 | void Present() override; |
| 19 | void RetrieveVulkanHandlers(void* get_instance_proc_addr, void* instance, | ||
| 20 | void* surface) const override; | ||
| 21 | 22 | ||
| 22 | std::unique_ptr<Core::Frontend::GraphicsContext> CreateSharedContext() const override; | 23 | std::unique_ptr<Core::Frontend::GraphicsContext> CreateSharedContext() const override; |
| 23 | |||
| 24 | private: | ||
| 25 | bool UseStandardLayers(PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr) const; | ||
| 26 | |||
| 27 | VkInstance vk_instance{}; | ||
| 28 | VkSurfaceKHR vk_surface{}; | ||
| 29 | |||
| 30 | PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr{}; | ||
| 31 | PFN_vkDestroyInstance vkDestroyInstance{}; | ||
| 32 | }; | 24 | }; |
diff --git a/src/yuzu_cmd/yuzu.cpp b/src/yuzu_cmd/yuzu.cpp index babf4c3a4..4d2ea7e9e 100644 --- a/src/yuzu_cmd/yuzu.cpp +++ b/src/yuzu_cmd/yuzu.cpp | |||
| @@ -230,17 +230,10 @@ int main(int argc, char** argv) { | |||
| 230 | 230 | ||
| 231 | system.TelemetrySession().AddField(Telemetry::FieldType::App, "Frontend", "SDL"); | 231 | system.TelemetrySession().AddField(Telemetry::FieldType::App, "Frontend", "SDL"); |
| 232 | 232 | ||
| 233 | system.Renderer().Rasterizer().LoadDiskResources(); | 233 | // Core is loaded, start the GPU (makes the GPU contexts current to this thread) |
| 234 | system.GPU().Start(); | ||
| 234 | 235 | ||
| 235 | // Acquire render context for duration of the thread if this is the rendering thread | 236 | system.Renderer().Rasterizer().LoadDiskResources(); |
| 236 | if (!Settings::values.use_asynchronous_gpu_emulation) { | ||
| 237 | emu_window->MakeCurrent(); | ||
| 238 | } | ||
| 239 | SCOPE_EXIT({ | ||
| 240 | if (!Settings::values.use_asynchronous_gpu_emulation) { | ||
| 241 | emu_window->DoneCurrent(); | ||
| 242 | } | ||
| 243 | }); | ||
| 244 | 237 | ||
| 245 | std::thread render_thread([&emu_window] { emu_window->Present(); }); | 238 | std::thread render_thread([&emu_window] { emu_window->Present(); }); |
| 246 | while (emu_window->IsOpen()) { | 239 | while (emu_window->IsOpen()) { |