summaryrefslogtreecommitdiffstats
path: root/src/yuzu_cmd/emu_window
diff options
context:
space:
mode:
Diffstat (limited to 'src/yuzu_cmd/emu_window')
-rw-r--r--src/yuzu_cmd/emu_window/emu_window_sdl2_gl.cpp6
-rw-r--r--src/yuzu_cmd/emu_window/emu_window_sdl2_gl.h4
-rw-r--r--src/yuzu_cmd/emu_window/emu_window_sdl2_vk.cpp159
-rw-r--r--src/yuzu_cmd/emu_window/emu_window_sdl2_vk.h18
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() {
SDL_GL_DeleteContext(window_context);
}
-void EmuWindow_SDL2_GL::RetrieveVulkanHandlers(void* get_instance_proc_addr, void* instance,
- void* surface) const {
- // Should not have been called from OpenGL
- UNREACHABLE();
-}
-
std::unique_ptr<Core::Frontend::GraphicsContext> EmuWindow_SDL2_GL::CreateSharedContext() const {
return std::make_unique<SDLGLContext>();
}
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:
void Present() override;
- /// Ignored in OpenGL
- void RetrieveVulkanHandlers(void* get_instance_proc_addr, void* instance,
- void* surface) const override;
-
std::unique_ptr<Core::Frontend::GraphicsContext> CreateSharedContext() const override;
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 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
-#include <algorithm>
+#include <cstdlib>
+#include <memory>
#include <string>
-#include <vector>
-#include <SDL.h>
-#include <SDL_vulkan.h>
+
#include <fmt/format.h>
-#include <vulkan/vulkan.h>
+
#include "common/assert.h"
#include "common/logging/log.h"
#include "common/scm_rev.h"
#include "core/settings.h"
+#include "video_core/renderer_vulkan/renderer_vulkan.h"
#include "yuzu_cmd/emu_window/emu_window_sdl2_vk.h"
+// Include these late to avoid polluting everything with Xlib macros
+#include <SDL.h>
+#include <SDL_syswm.h>
+
EmuWindow_SDL2_VK::EmuWindow_SDL2_VK(Core::System& system, bool fullscreen)
: EmuWindow_SDL2{system, fullscreen} {
- if (SDL_Vulkan_LoadLibrary(nullptr) != 0) {
- LOG_CRITICAL(Frontend, "SDL failed to load the Vulkan library: {}", SDL_GetError());
- exit(EXIT_FAILURE);
- }
-
- vkGetInstanceProcAddr =
- reinterpret_cast<PFN_vkGetInstanceProcAddr>(SDL_Vulkan_GetVkGetInstanceProcAddr());
- if (vkGetInstanceProcAddr == nullptr) {
- LOG_CRITICAL(Frontend, "Failed to retrieve Vulkan function pointer!");
- exit(EXIT_FAILURE);
- }
-
const std::string window_title = fmt::format("yuzu {} | {}-{} (Vulkan)", Common::g_build_name,
Common::g_scm_branch, Common::g_scm_desc);
render_window =
- SDL_CreateWindow(window_title.c_str(),
- SDL_WINDOWPOS_UNDEFINED, // x position
- SDL_WINDOWPOS_UNDEFINED, // y position
+ SDL_CreateWindow(window_title.c_str(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
Layout::ScreenUndocked::Width, Layout::ScreenUndocked::Height,
- SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_VULKAN);
-
- const bool use_standard_layers = UseStandardLayers(vkGetInstanceProcAddr);
-
- u32 extra_ext_count{};
- if (!SDL_Vulkan_GetInstanceExtensions(render_window, &extra_ext_count, NULL)) {
- LOG_CRITICAL(Frontend, "Failed to query Vulkan extensions count from SDL! {}",
- SDL_GetError());
- exit(1);
- }
-
- auto extra_ext_names = std::make_unique<const char* []>(extra_ext_count);
- if (!SDL_Vulkan_GetInstanceExtensions(render_window, &extra_ext_count, extra_ext_names.get())) {
- LOG_CRITICAL(Frontend, "Failed to query Vulkan extensions from SDL! {}", SDL_GetError());
- exit(1);
- }
- std::vector<const char*> enabled_extensions;
- enabled_extensions.insert(enabled_extensions.begin(), extra_ext_names.get(),
- extra_ext_names.get() + extra_ext_count);
-
- std::vector<const char*> enabled_layers;
- if (use_standard_layers) {
- enabled_extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
- enabled_layers.push_back("VK_LAYER_LUNARG_standard_validation");
- }
-
- VkApplicationInfo app_info{};
- app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
- app_info.apiVersion = VK_API_VERSION_1_1;
- app_info.applicationVersion = VK_MAKE_VERSION(0, 1, 0);
- app_info.pApplicationName = "yuzu-emu";
- app_info.engineVersion = VK_MAKE_VERSION(0, 1, 0);
- app_info.pEngineName = "yuzu-emu";
+ SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
- VkInstanceCreateInfo instance_ci{};
- instance_ci.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
- instance_ci.pApplicationInfo = &app_info;
- instance_ci.enabledExtensionCount = static_cast<u32>(enabled_extensions.size());
- instance_ci.ppEnabledExtensionNames = enabled_extensions.data();
- if (Settings::values.renderer_debug) {
- instance_ci.enabledLayerCount = static_cast<u32>(enabled_layers.size());
- instance_ci.ppEnabledLayerNames = enabled_layers.data();
+ SDL_SysWMinfo wm;
+ if (SDL_GetWindowWMInfo(render_window, &wm) == SDL_FALSE) {
+ LOG_CRITICAL(Frontend, "Failed to get information from the window manager");
+ std::exit(EXIT_FAILURE);
}
- const auto vkCreateInstance =
- reinterpret_cast<PFN_vkCreateInstance>(vkGetInstanceProcAddr(nullptr, "vkCreateInstance"));
- if (vkCreateInstance == nullptr ||
- vkCreateInstance(&instance_ci, nullptr, &vk_instance) != VK_SUCCESS) {
- LOG_CRITICAL(Frontend, "Failed to create Vulkan instance!");
- exit(EXIT_FAILURE);
- }
-
- vkDestroyInstance = reinterpret_cast<PFN_vkDestroyInstance>(
- vkGetInstanceProcAddr(vk_instance, "vkDestroyInstance"));
- if (vkDestroyInstance == nullptr) {
- LOG_CRITICAL(Frontend, "Failed to retrieve Vulkan function pointer!");
- exit(EXIT_FAILURE);
- }
-
- if (!SDL_Vulkan_CreateSurface(render_window, vk_instance, &vk_surface)) {
- LOG_CRITICAL(Frontend, "Failed to create Vulkan surface! {}", SDL_GetError());
- exit(EXIT_FAILURE);
+ switch (wm.subsystem) {
+#ifdef SDL_VIDEO_DRIVER_WINDOWS
+ case SDL_SYSWM_TYPE::SDL_SYSWM_WINDOWS:
+ window_info.type = Core::Frontend::WindowSystemType::Windows;
+ window_info.render_surface = reinterpret_cast<void*>(wm.info.win.window);
+ break;
+#endif
+#ifdef SDL_VIDEO_DRIVER_X11
+ case SDL_SYSWM_TYPE::SDL_SYSWM_X11:
+ window_info.type = Core::Frontend::WindowSystemType::X11;
+ window_info.display_connection = wm.info.x11.display;
+ window_info.render_surface = reinterpret_cast<void*>(wm.info.x11.window);
+ break;
+#endif
+#ifdef SDL_VIDEO_DRIVER_WAYLAND
+ case SDL_SYSWM_TYPE::SDL_SYSWM_WAYLAND:
+ window_info.type = Core::Frontend::WindowSystemType::Wayland;
+ window_info.display_connection = wm.info.wl.display;
+ window_info.render_surface = wm.info.wl.surface;
+ break;
+#endif
+ default:
+ LOG_CRITICAL(Frontend, "Window manager subsystem not implemented");
+ std::exit(EXIT_FAILURE);
}
OnResize();
@@ -107,51 +67,12 @@ EmuWindow_SDL2_VK::EmuWindow_SDL2_VK(Core::System& system, bool fullscreen)
Common::g_scm_branch, Common::g_scm_desc);
}
-EmuWindow_SDL2_VK::~EmuWindow_SDL2_VK() {
- vkDestroyInstance(vk_instance, nullptr);
-}
-
-void EmuWindow_SDL2_VK::RetrieveVulkanHandlers(void* get_instance_proc_addr, void* instance,
- void* surface) const {
- const auto instance_proc_addr = vkGetInstanceProcAddr;
- std::memcpy(get_instance_proc_addr, &instance_proc_addr, sizeof(instance_proc_addr));
- std::memcpy(instance, &vk_instance, sizeof(vk_instance));
- std::memcpy(surface, &vk_surface, sizeof(vk_surface));
-}
+EmuWindow_SDL2_VK::~EmuWindow_SDL2_VK() = default;
std::unique_ptr<Core::Frontend::GraphicsContext> EmuWindow_SDL2_VK::CreateSharedContext() const {
return nullptr;
}
-bool EmuWindow_SDL2_VK::UseStandardLayers(PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr) const {
- if (!Settings::values.renderer_debug) {
- return false;
- }
-
- const auto vkEnumerateInstanceLayerProperties =
- reinterpret_cast<PFN_vkEnumerateInstanceLayerProperties>(
- vkGetInstanceProcAddr(nullptr, "vkEnumerateInstanceLayerProperties"));
- if (vkEnumerateInstanceLayerProperties == nullptr) {
- LOG_CRITICAL(Frontend, "Failed to retrieve Vulkan function pointer!");
- return false;
- }
-
- u32 available_layers_count{};
- if (vkEnumerateInstanceLayerProperties(&available_layers_count, nullptr) != VK_SUCCESS) {
- LOG_CRITICAL(Frontend, "Failed to enumerate Vulkan validation layers!");
- return false;
- }
- std::vector<VkLayerProperties> layers(available_layers_count);
- if (vkEnumerateInstanceLayerProperties(&available_layers_count, layers.data()) != VK_SUCCESS) {
- LOG_CRITICAL(Frontend, "Failed to enumerate Vulkan validation layers!");
- return false;
- }
-
- return std::find_if(layers.begin(), layers.end(), [&](const auto& layer) {
- return layer.layerName == std::string("VK_LAYER_LUNARG_standard_validation");
- }) != layers.end();
-}
-
void EmuWindow_SDL2_VK::Present() {
// TODO (bunnei): ImplementMe
}
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 @@
#pragma once
-#include <vulkan/vulkan.h>
+#include <memory>
+
#include "core/frontend/emu_window.h"
#include "yuzu_cmd/emu_window/emu_window_sdl2.h"
+namespace Core {
+class System;
+}
+
class EmuWindow_SDL2_VK final : public EmuWindow_SDL2 {
public:
explicit EmuWindow_SDL2_VK(Core::System& system, bool fullscreen);
~EmuWindow_SDL2_VK();
void Present() override;
- void RetrieveVulkanHandlers(void* get_instance_proc_addr, void* instance,
- void* surface) const override;
std::unique_ptr<Core::Frontend::GraphicsContext> CreateSharedContext() const override;
-
-private:
- bool UseStandardLayers(PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr) const;
-
- VkInstance vk_instance{};
- VkSurfaceKHR vk_surface{};
-
- PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr{};
- PFN_vkDestroyInstance vkDestroyInstance{};
};