summaryrefslogtreecommitdiffstats
path: root/src/yuzu_cmd
diff options
context:
space:
mode:
Diffstat (limited to 'src/yuzu_cmd')
-rw-r--r--src/yuzu_cmd/CMakeLists.txt11
-rw-r--r--src/yuzu_cmd/config.cpp6
-rw-r--r--src/yuzu_cmd/default_ini.h11
-rw-r--r--src/yuzu_cmd/emu_window/emu_window_sdl2.cpp4
-rw-r--r--src/yuzu_cmd/emu_window/emu_window_sdl2.h3
-rw-r--r--src/yuzu_cmd/emu_window/emu_window_sdl2_gl.cpp7
-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.cpp162
-rw-r--r--src/yuzu_cmd/emu_window/emu_window_sdl2_vk.h39
-rw-r--r--src/yuzu_cmd/yuzu.cpp18
10 files changed, 264 insertions, 1 deletions
diff --git a/src/yuzu_cmd/CMakeLists.txt b/src/yuzu_cmd/CMakeLists.txt
index b5f06ab9e..a15719a0f 100644
--- a/src/yuzu_cmd/CMakeLists.txt
+++ b/src/yuzu_cmd/CMakeLists.txt
@@ -8,11 +8,22 @@ add_executable(yuzu-cmd
emu_window/emu_window_sdl2_gl.h
emu_window/emu_window_sdl2.cpp
emu_window/emu_window_sdl2.h
+ emu_window/emu_window_sdl2_gl.cpp
+ emu_window/emu_window_sdl2_gl.h
resource.h
yuzu.cpp
yuzu.rc
)
+if (ENABLE_VULKAN)
+ target_sources(yuzu-cmd PRIVATE
+ emu_window/emu_window_sdl2_vk.cpp
+ emu_window/emu_window_sdl2_vk.h)
+
+ target_include_directories(yuzu-cmd PRIVATE ../../externals/Vulkan-Headers/include)
+ target_compile_definitions(yuzu-cmd PRIVATE HAS_VULKAN)
+endif()
+
create_target_directory_groups(yuzu-cmd)
target_link_libraries(yuzu-cmd PRIVATE common core input_common)
diff --git a/src/yuzu_cmd/config.cpp b/src/yuzu_cmd/config.cpp
index 161583b54..b01a36023 100644
--- a/src/yuzu_cmd/config.cpp
+++ b/src/yuzu_cmd/config.cpp
@@ -371,6 +371,12 @@ void Config::ReadValues() {
Settings::values.use_multi_core = sdl2_config->GetBoolean("Core", "use_multi_core", false);
// Renderer
+ const int renderer_backend = sdl2_config->GetInteger(
+ "Renderer", "backend", static_cast<int>(Settings::RendererBackend::OpenGL));
+ Settings::values.renderer_backend = static_cast<Settings::RendererBackend>(renderer_backend);
+ Settings::values.renderer_debug = sdl2_config->GetBoolean("Renderer", "debug", false);
+ Settings::values.vulkan_device = sdl2_config->GetInteger("Renderer", "vulkan_device", 0);
+
Settings::values.resolution_factor =
static_cast<float>(sdl2_config->GetReal("Renderer", "resolution_factor", 1.0));
Settings::values.use_frame_limit = sdl2_config->GetBoolean("Renderer", "use_frame_limit", true);
diff --git a/src/yuzu_cmd/default_ini.h b/src/yuzu_cmd/default_ini.h
index e829f8695..00fd88279 100644
--- a/src/yuzu_cmd/default_ini.h
+++ b/src/yuzu_cmd/default_ini.h
@@ -98,6 +98,17 @@ udp_pad_index=
use_multi_core=
[Renderer]
+# Which backend API to use.
+# 0 (default): OpenGL, 1: Vulkan
+backend =
+
+# Enable graphics API debugging mode.
+# 0 (default): Disabled, 1: Enabled
+debug =
+
+# Which Vulkan physical device to use (defaults to 0)
+vulkan_device =
+
# Whether to use software or hardware rendering.
# 0: Software, 1 (default): Hardware
use_hw_renderer =
diff --git a/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp b/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp
index b1c512db1..e96139885 100644
--- a/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp
+++ b/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp
@@ -89,6 +89,10 @@ bool EmuWindow_SDL2::IsOpen() const {
return is_open;
}
+bool EmuWindow_SDL2::IsShown() const {
+ return is_shown;
+}
+
void EmuWindow_SDL2::OnResize() {
int width, height;
SDL_GetWindowSize(render_window, &width, &height);
diff --git a/src/yuzu_cmd/emu_window/emu_window_sdl2.h b/src/yuzu_cmd/emu_window/emu_window_sdl2.h
index eaa971f77..b38f56661 100644
--- a/src/yuzu_cmd/emu_window/emu_window_sdl2.h
+++ b/src/yuzu_cmd/emu_window/emu_window_sdl2.h
@@ -21,6 +21,9 @@ public:
/// Whether the window is still open, and a close request hasn't yet been sent
bool IsOpen() const;
+ /// Returns if window is shown (not minimized)
+ bool IsShown() const override;
+
protected:
/// Called by PollEvents when a key is pressed or released.
void OnKeyEvent(int key, u8 state);
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 6fde694a2..7ffa0ac09 100644
--- a/src/yuzu_cmd/emu_window/emu_window_sdl2_gl.cpp
+++ b/src/yuzu_cmd/emu_window/emu_window_sdl2_gl.cpp
@@ -9,6 +9,7 @@
#include <SDL.h>
#include <fmt/format.h>
#include <glad/glad.h>
+#include "common/assert.h"
#include "common/logging/log.h"
#include "common/scm_rev.h"
#include "common/string_util.h"
@@ -151,6 +152,12 @@ void EmuWindow_SDL2_GL::DoneCurrent() {
SDL_GL_MakeCurrent(render_window, nullptr);
}
+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 630deba93..c753085a8 100644
--- a/src/yuzu_cmd/emu_window/emu_window_sdl2_gl.h
+++ b/src/yuzu_cmd/emu_window/emu_window_sdl2_gl.h
@@ -22,6 +22,10 @@ public:
/// Releases the GL context from the caller thread
void DoneCurrent() 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
new file mode 100644
index 000000000..a203f0da9
--- /dev/null
+++ b/src/yuzu_cmd/emu_window/emu_window_sdl2_vk.cpp
@@ -0,0 +1,162 @@
+// Copyright 2018 yuzu Emulator Project
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#include <algorithm>
+#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 "yuzu_cmd/emu_window/emu_window_sdl2_vk.h"
+
+EmuWindow_SDL2_VK::EmuWindow_SDL2_VK(bool fullscreen) : EmuWindow_SDL2(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
+ 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";
+
+ 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();
+ }
+
+ 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);
+ }
+
+ OnResize();
+ OnMinimalClientAreaChangeRequest(GetActiveConfig().min_client_area_size);
+ SDL_PumpEvents();
+ LOG_INFO(Frontend, "yuzu Version: {} | {}-{} (Vulkan)", Common::g_build_name,
+ Common::g_scm_branch, Common::g_scm_desc);
+}
+
+EmuWindow_SDL2_VK::~EmuWindow_SDL2_VK() {
+ vkDestroyInstance(vk_instance, nullptr);
+}
+
+void EmuWindow_SDL2_VK::SwapBuffers() {}
+
+void EmuWindow_SDL2_VK::MakeCurrent() {
+ // Unused on Vulkan
+}
+
+void EmuWindow_SDL2_VK::DoneCurrent() {
+ // Unused on Vulkan
+}
+
+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));
+}
+
+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();
+}
diff --git a/src/yuzu_cmd/emu_window/emu_window_sdl2_vk.h b/src/yuzu_cmd/emu_window/emu_window_sdl2_vk.h
new file mode 100644
index 000000000..2a7c06a24
--- /dev/null
+++ b/src/yuzu_cmd/emu_window/emu_window_sdl2_vk.h
@@ -0,0 +1,39 @@
+// Copyright 2018 yuzu Emulator Project
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include <vulkan/vulkan.h>
+#include "core/frontend/emu_window.h"
+#include "yuzu_cmd/emu_window/emu_window_sdl2.h"
+
+class EmuWindow_SDL2_VK final : public EmuWindow_SDL2 {
+public:
+ explicit EmuWindow_SDL2_VK(bool fullscreen);
+ ~EmuWindow_SDL2_VK();
+
+ /// Swap buffers to display the next frame
+ void SwapBuffers() override;
+
+ /// Makes the graphics context current for the caller thread
+ void MakeCurrent() override;
+
+ /// Releases the GL context from the caller thread
+ void DoneCurrent() override;
+
+ /// Retrieves Vulkan specific handlers from the window
+ 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{};
+};
diff --git a/src/yuzu_cmd/yuzu.cpp b/src/yuzu_cmd/yuzu.cpp
index 3ee088a91..325795321 100644
--- a/src/yuzu_cmd/yuzu.cpp
+++ b/src/yuzu_cmd/yuzu.cpp
@@ -32,6 +32,9 @@
#include "yuzu_cmd/config.h"
#include "yuzu_cmd/emu_window/emu_window_sdl2.h"
#include "yuzu_cmd/emu_window/emu_window_sdl2_gl.h"
+#ifdef HAS_VULKAN
+#include "yuzu_cmd/emu_window/emu_window_sdl2_vk.h"
+#endif
#include "core/file_sys/registered_cache.h"
@@ -174,7 +177,20 @@ int main(int argc, char** argv) {
Settings::values.use_gdbstub = use_gdbstub;
Settings::Apply();
- std::unique_ptr<EmuWindow_SDL2> emu_window{std::make_unique<EmuWindow_SDL2_GL>(fullscreen)};
+ std::unique_ptr<EmuWindow_SDL2> emu_window;
+ switch (Settings::values.renderer_backend) {
+ case Settings::RendererBackend::OpenGL:
+ emu_window = std::make_unique<EmuWindow_SDL2_GL>(fullscreen);
+ break;
+ case Settings::RendererBackend::Vulkan:
+#ifdef HAS_VULKAN
+ emu_window = std::make_unique<EmuWindow_SDL2_VK>(fullscreen);
+ break;
+#else
+ LOG_CRITICAL(Frontend, "Vulkan backend has not been compiled!");
+ return 1;
+#endif
+ }
if (!Settings::values.use_multi_core) {
// Single core mode must acquire OpenGL context for entire emulation session