diff options
Diffstat (limited to 'src')
21 files changed, 646 insertions, 348 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index fbebed715..eeceaa655 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt | |||
| @@ -106,6 +106,8 @@ add_library(common STATIC | |||
| 106 | common_funcs.h | 106 | common_funcs.h |
| 107 | common_paths.h | 107 | common_paths.h |
| 108 | common_types.h | 108 | common_types.h |
| 109 | dynamic_library.cpp | ||
| 110 | dynamic_library.h | ||
| 109 | file_util.cpp | 111 | file_util.cpp |
| 110 | file_util.h | 112 | file_util.h |
| 111 | hash.h | 113 | hash.h |
diff --git a/src/common/dynamic_library.cpp b/src/common/dynamic_library.cpp new file mode 100644 index 000000000..7ab54e9e4 --- /dev/null +++ b/src/common/dynamic_library.cpp | |||
| @@ -0,0 +1,106 @@ | |||
| 1 | // Copyright 2019 Dolphin Emulator Project | ||
| 2 | // Licensed under GPLv2+ | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <cstring> | ||
| 6 | #include <string> | ||
| 7 | #include <utility> | ||
| 8 | |||
| 9 | #include <fmt/format.h> | ||
| 10 | |||
| 11 | #include "common/dynamic_library.h" | ||
| 12 | |||
| 13 | #ifdef _WIN32 | ||
| 14 | #include <windows.h> | ||
| 15 | #else | ||
| 16 | #include <dlfcn.h> | ||
| 17 | #endif | ||
| 18 | |||
| 19 | namespace Common { | ||
| 20 | |||
| 21 | DynamicLibrary::DynamicLibrary() = default; | ||
| 22 | |||
| 23 | DynamicLibrary::DynamicLibrary(const char* filename) { | ||
| 24 | Open(filename); | ||
| 25 | } | ||
| 26 | |||
| 27 | DynamicLibrary::DynamicLibrary(DynamicLibrary&& rhs) noexcept | ||
| 28 | : handle{std::exchange(rhs.handle, nullptr)} {} | ||
| 29 | |||
| 30 | DynamicLibrary& DynamicLibrary::operator=(DynamicLibrary&& rhs) noexcept { | ||
| 31 | Close(); | ||
| 32 | handle = std::exchange(rhs.handle, nullptr); | ||
| 33 | return *this; | ||
| 34 | } | ||
| 35 | |||
| 36 | DynamicLibrary::~DynamicLibrary() { | ||
| 37 | Close(); | ||
| 38 | } | ||
| 39 | |||
| 40 | std::string DynamicLibrary::GetUnprefixedFilename(const char* filename) { | ||
| 41 | #if defined(_WIN32) | ||
| 42 | return std::string(filename) + ".dll"; | ||
| 43 | #elif defined(__APPLE__) | ||
| 44 | return std::string(filename) + ".dylib"; | ||
| 45 | #else | ||
| 46 | return std::string(filename) + ".so"; | ||
| 47 | #endif | ||
| 48 | } | ||
| 49 | |||
| 50 | std::string DynamicLibrary::GetVersionedFilename(const char* libname, int major, int minor) { | ||
| 51 | #if defined(_WIN32) | ||
| 52 | if (major >= 0 && minor >= 0) | ||
| 53 | return fmt::format("{}-{}-{}.dll", libname, major, minor); | ||
| 54 | else if (major >= 0) | ||
| 55 | return fmt::format("{}-{}.dll", libname, major); | ||
| 56 | else | ||
| 57 | return fmt::format("{}.dll", libname); | ||
| 58 | #elif defined(__APPLE__) | ||
| 59 | const char* prefix = std::strncmp(libname, "lib", 3) ? "lib" : ""; | ||
| 60 | if (major >= 0 && minor >= 0) | ||
| 61 | return fmt::format("{}{}.{}.{}.dylib", prefix, libname, major, minor); | ||
| 62 | else if (major >= 0) | ||
| 63 | return fmt::format("{}{}.{}.dylib", prefix, libname, major); | ||
| 64 | else | ||
| 65 | return fmt::format("{}{}.dylib", prefix, libname); | ||
| 66 | #else | ||
| 67 | const char* prefix = std::strncmp(libname, "lib", 3) ? "lib" : ""; | ||
| 68 | if (major >= 0 && minor >= 0) | ||
| 69 | return fmt::format("{}{}.so.{}.{}", prefix, libname, major, minor); | ||
| 70 | else if (major >= 0) | ||
| 71 | return fmt::format("{}{}.so.{}", prefix, libname, major); | ||
| 72 | else | ||
| 73 | return fmt::format("{}{}.so", prefix, libname); | ||
| 74 | #endif | ||
| 75 | } | ||
| 76 | |||
| 77 | bool DynamicLibrary::Open(const char* filename) { | ||
| 78 | #ifdef _WIN32 | ||
| 79 | handle = reinterpret_cast<void*>(LoadLibraryA(filename)); | ||
| 80 | #else | ||
| 81 | handle = dlopen(filename, RTLD_NOW); | ||
| 82 | #endif | ||
| 83 | return handle != nullptr; | ||
| 84 | } | ||
| 85 | |||
| 86 | void DynamicLibrary::Close() { | ||
| 87 | if (!IsOpen()) | ||
| 88 | return; | ||
| 89 | |||
| 90 | #ifdef _WIN32 | ||
| 91 | FreeLibrary(reinterpret_cast<HMODULE>(handle)); | ||
| 92 | #else | ||
| 93 | dlclose(handle); | ||
| 94 | #endif | ||
| 95 | handle = nullptr; | ||
| 96 | } | ||
| 97 | |||
| 98 | void* DynamicLibrary::GetSymbolAddress(const char* name) const { | ||
| 99 | #ifdef _WIN32 | ||
| 100 | return reinterpret_cast<void*>(GetProcAddress(reinterpret_cast<HMODULE>(handle), name)); | ||
| 101 | #else | ||
| 102 | return reinterpret_cast<void*>(dlsym(handle, name)); | ||
| 103 | #endif | ||
| 104 | } | ||
| 105 | |||
| 106 | } // namespace Common | ||
diff --git a/src/common/dynamic_library.h b/src/common/dynamic_library.h new file mode 100644 index 000000000..2a06372fd --- /dev/null +++ b/src/common/dynamic_library.h | |||
| @@ -0,0 +1,75 @@ | |||
| 1 | // Copyright 2019 Dolphin Emulator Project | ||
| 2 | // Licensed under GPLv2+ | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <string> | ||
| 8 | |||
| 9 | namespace Common { | ||
| 10 | |||
| 11 | /** | ||
| 12 | * Provides a platform-independent interface for loading a dynamic library and retrieving symbols. | ||
| 13 | * The interface maintains an internal reference count to allow one handle to be shared between | ||
| 14 | * multiple users. | ||
| 15 | */ | ||
| 16 | class DynamicLibrary final { | ||
| 17 | public: | ||
| 18 | /// Default constructor, does not load a library. | ||
| 19 | explicit DynamicLibrary(); | ||
| 20 | |||
| 21 | /// Automatically loads the specified library. Call IsOpen() to check validity before use. | ||
| 22 | explicit DynamicLibrary(const char* filename); | ||
| 23 | |||
| 24 | /// Moves the library. | ||
| 25 | DynamicLibrary(DynamicLibrary&&) noexcept; | ||
| 26 | DynamicLibrary& operator=(DynamicLibrary&&) noexcept; | ||
| 27 | |||
| 28 | /// Delete copies, we can't copy a dynamic library. | ||
| 29 | DynamicLibrary(const DynamicLibrary&) = delete; | ||
| 30 | DynamicLibrary& operator=(const DynamicLibrary&) = delete; | ||
| 31 | |||
| 32 | /// Closes the library. | ||
| 33 | ~DynamicLibrary(); | ||
| 34 | |||
| 35 | /// Returns the specified library name with the platform-specific suffix added. | ||
| 36 | static std::string GetUnprefixedFilename(const char* filename); | ||
| 37 | |||
| 38 | /// Returns the specified library name in platform-specific format. | ||
| 39 | /// Major/minor versions will not be included if set to -1. | ||
| 40 | /// If libname already contains the "lib" prefix, it will not be added again. | ||
| 41 | /// Windows: LIBNAME-MAJOR-MINOR.dll | ||
| 42 | /// Linux: libLIBNAME.so.MAJOR.MINOR | ||
| 43 | /// Mac: libLIBNAME.MAJOR.MINOR.dylib | ||
| 44 | static std::string GetVersionedFilename(const char* libname, int major = -1, int minor = -1); | ||
| 45 | |||
| 46 | /// Returns true if a module is loaded, otherwise false. | ||
| 47 | bool IsOpen() const { | ||
| 48 | return handle != nullptr; | ||
| 49 | } | ||
| 50 | |||
| 51 | /// Loads (or replaces) the handle with the specified library file name. | ||
| 52 | /// Returns true if the library was loaded and can be used. | ||
| 53 | bool Open(const char* filename); | ||
| 54 | |||
| 55 | /// Unloads the library, any function pointers from this library are no longer valid. | ||
| 56 | void Close(); | ||
| 57 | |||
| 58 | /// Returns the address of the specified symbol (function or variable) as an untyped pointer. | ||
| 59 | /// If the specified symbol does not exist in this library, nullptr is returned. | ||
| 60 | void* GetSymbolAddress(const char* name) const; | ||
| 61 | |||
| 62 | /// Obtains the address of the specified symbol, automatically casting to the correct type. | ||
| 63 | /// Returns true if the symbol was found and assigned, otherwise false. | ||
| 64 | template <typename T> | ||
| 65 | bool GetSymbol(const char* name, T* ptr) const { | ||
| 66 | *ptr = reinterpret_cast<T>(GetSymbolAddress(name)); | ||
| 67 | return *ptr != nullptr; | ||
| 68 | } | ||
| 69 | |||
| 70 | private: | ||
| 71 | /// Platform-dependent data type representing a dynamic library handle. | ||
| 72 | void* handle = nullptr; | ||
| 73 | }; | ||
| 74 | |||
| 75 | } // namespace Common | ||
diff --git a/src/core/frontend/emu_window.h b/src/core/frontend/emu_window.h index 72294d4d8..13aa14934 100644 --- a/src/core/frontend/emu_window.h +++ b/src/core/frontend/emu_window.h | |||
| @@ -12,6 +12,15 @@ | |||
| 12 | 12 | ||
| 13 | namespace Core::Frontend { | 13 | namespace Core::Frontend { |
| 14 | 14 | ||
| 15 | /// Information for the Graphics Backends signifying what type of screen pointer is in | ||
| 16 | /// WindowInformation | ||
| 17 | enum class WindowSystemType { | ||
| 18 | Headless, | ||
| 19 | Windows, | ||
| 20 | X11, | ||
| 21 | Wayland, | ||
| 22 | }; | ||
| 23 | |||
| 15 | /** | 24 | /** |
| 16 | * Represents a drawing context that supports graphics operations. | 25 | * Represents a drawing context that supports graphics operations. |
| 17 | */ | 26 | */ |
| @@ -76,6 +85,23 @@ public: | |||
| 76 | std::pair<unsigned, unsigned> min_client_area_size; | 85 | std::pair<unsigned, unsigned> min_client_area_size; |
| 77 | }; | 86 | }; |
| 78 | 87 | ||
| 88 | /// Data describing host window system information | ||
| 89 | struct WindowSystemInfo { | ||
| 90 | // Window system type. Determines which GL context or Vulkan WSI is used. | ||
| 91 | WindowSystemType type = WindowSystemType::Headless; | ||
| 92 | |||
| 93 | // Connection to a display server. This is used on X11 and Wayland platforms. | ||
| 94 | void* display_connection = nullptr; | ||
| 95 | |||
| 96 | // Render surface. This is a pointer to the native window handle, which depends | ||
| 97 | // on the platform. e.g. HWND for Windows, Window for X11. If the surface is | ||
| 98 | // set to nullptr, the video backend will run in headless mode. | ||
| 99 | void* render_surface = nullptr; | ||
| 100 | |||
| 101 | // Scale of the render surface. For hidpi systems, this will be >1. | ||
| 102 | float render_surface_scale = 1.0f; | ||
| 103 | }; | ||
| 104 | |||
| 79 | /// Polls window events | 105 | /// Polls window events |
| 80 | virtual void PollEvents() = 0; | 106 | virtual void PollEvents() = 0; |
| 81 | 107 | ||
| @@ -87,10 +113,6 @@ public: | |||
| 87 | /// Returns if window is shown (not minimized) | 113 | /// Returns if window is shown (not minimized) |
| 88 | virtual bool IsShown() const = 0; | 114 | virtual bool IsShown() const = 0; |
| 89 | 115 | ||
| 90 | /// Retrieves Vulkan specific handlers from the window | ||
| 91 | virtual void RetrieveVulkanHandlers(void* get_instance_proc_addr, void* instance, | ||
| 92 | void* surface) const = 0; | ||
| 93 | |||
| 94 | /** | 116 | /** |
| 95 | * Signal that a touch pressed event has occurred (e.g. mouse click pressed) | 117 | * Signal that a touch pressed event has occurred (e.g. mouse click pressed) |
| 96 | * @param framebuffer_x Framebuffer x-coordinate that was pressed | 118 | * @param framebuffer_x Framebuffer x-coordinate that was pressed |
| @@ -128,6 +150,13 @@ public: | |||
| 128 | } | 150 | } |
| 129 | 151 | ||
| 130 | /** | 152 | /** |
| 153 | * Returns system information about the drawing area. | ||
| 154 | */ | ||
| 155 | const WindowSystemInfo& GetWindowInfo() const { | ||
| 156 | return window_info; | ||
| 157 | } | ||
| 158 | |||
| 159 | /** | ||
| 131 | * Gets the framebuffer layout (width, height, and screen regions) | 160 | * Gets the framebuffer layout (width, height, and screen regions) |
| 132 | * @note This method is thread-safe | 161 | * @note This method is thread-safe |
| 133 | */ | 162 | */ |
| @@ -142,7 +171,7 @@ public: | |||
| 142 | void UpdateCurrentFramebufferLayout(unsigned width, unsigned height); | 171 | void UpdateCurrentFramebufferLayout(unsigned width, unsigned height); |
| 143 | 172 | ||
| 144 | protected: | 173 | protected: |
| 145 | EmuWindow(); | 174 | explicit EmuWindow(); |
| 146 | virtual ~EmuWindow(); | 175 | virtual ~EmuWindow(); |
| 147 | 176 | ||
| 148 | /** | 177 | /** |
| @@ -179,6 +208,8 @@ protected: | |||
| 179 | client_area_height = size.second; | 208 | client_area_height = size.second; |
| 180 | } | 209 | } |
| 181 | 210 | ||
| 211 | WindowSystemInfo window_info; | ||
| 212 | |||
| 182 | private: | 213 | private: |
| 183 | /** | 214 | /** |
| 184 | * Handler called when the minimal client area was requested to be changed via SetConfig. | 215 | * Handler called when the minimal client area was requested to be changed via SetConfig. |
diff --git a/src/video_core/renderer_vulkan/declarations.h b/src/video_core/renderer_vulkan/declarations.h index 323bf6b39..89a035ca4 100644 --- a/src/video_core/renderer_vulkan/declarations.h +++ b/src/video_core/renderer_vulkan/declarations.h | |||
| @@ -39,6 +39,7 @@ using UniqueFence = UniqueHandle<vk::Fence>; | |||
| 39 | using UniqueFramebuffer = UniqueHandle<vk::Framebuffer>; | 39 | using UniqueFramebuffer = UniqueHandle<vk::Framebuffer>; |
| 40 | using UniqueImage = UniqueHandle<vk::Image>; | 40 | using UniqueImage = UniqueHandle<vk::Image>; |
| 41 | using UniqueImageView = UniqueHandle<vk::ImageView>; | 41 | using UniqueImageView = UniqueHandle<vk::ImageView>; |
| 42 | using UniqueInstance = UniqueHandle<vk::Instance>; | ||
| 42 | using UniqueIndirectCommandsLayoutNVX = UniqueHandle<vk::IndirectCommandsLayoutNVX>; | 43 | using UniqueIndirectCommandsLayoutNVX = UniqueHandle<vk::IndirectCommandsLayoutNVX>; |
| 43 | using UniqueObjectTableNVX = UniqueHandle<vk::ObjectTableNVX>; | 44 | using UniqueObjectTableNVX = UniqueHandle<vk::ObjectTableNVX>; |
| 44 | using UniquePipeline = UniqueHandle<vk::Pipeline>; | 45 | using UniquePipeline = UniqueHandle<vk::Pipeline>; |
| @@ -50,6 +51,7 @@ using UniqueSampler = UniqueHandle<vk::Sampler>; | |||
| 50 | using UniqueSamplerYcbcrConversion = UniqueHandle<vk::SamplerYcbcrConversion>; | 51 | using UniqueSamplerYcbcrConversion = UniqueHandle<vk::SamplerYcbcrConversion>; |
| 51 | using UniqueSemaphore = UniqueHandle<vk::Semaphore>; | 52 | using UniqueSemaphore = UniqueHandle<vk::Semaphore>; |
| 52 | using UniqueShaderModule = UniqueHandle<vk::ShaderModule>; | 53 | using UniqueShaderModule = UniqueHandle<vk::ShaderModule>; |
| 54 | using UniqueSurfaceKHR = UniqueHandle<vk::SurfaceKHR>; | ||
| 53 | using UniqueSwapchainKHR = UniqueHandle<vk::SwapchainKHR>; | 55 | using UniqueSwapchainKHR = UniqueHandle<vk::SwapchainKHR>; |
| 54 | using UniqueValidationCacheEXT = UniqueHandle<vk::ValidationCacheEXT>; | 56 | using UniqueValidationCacheEXT = UniqueHandle<vk::ValidationCacheEXT>; |
| 55 | using UniqueDebugReportCallbackEXT = UniqueHandle<vk::DebugReportCallbackEXT>; | 57 | using UniqueDebugReportCallbackEXT = UniqueHandle<vk::DebugReportCallbackEXT>; |
diff --git a/src/video_core/renderer_vulkan/renderer_vulkan.cpp b/src/video_core/renderer_vulkan/renderer_vulkan.cpp index 6953aaafe..9cdb4b627 100644 --- a/src/video_core/renderer_vulkan/renderer_vulkan.cpp +++ b/src/video_core/renderer_vulkan/renderer_vulkan.cpp | |||
| @@ -2,13 +2,18 @@ | |||
| 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> | ||
| 6 | #include <array> | ||
| 7 | #include <cstring> | ||
| 5 | #include <memory> | 8 | #include <memory> |
| 6 | #include <optional> | 9 | #include <optional> |
| 10 | #include <string> | ||
| 7 | #include <vector> | 11 | #include <vector> |
| 8 | 12 | ||
| 9 | #include <fmt/format.h> | 13 | #include <fmt/format.h> |
| 10 | 14 | ||
| 11 | #include "common/assert.h" | 15 | #include "common/assert.h" |
| 16 | #include "common/dynamic_library.h" | ||
| 12 | #include "common/logging/log.h" | 17 | #include "common/logging/log.h" |
| 13 | #include "common/telemetry.h" | 18 | #include "common/telemetry.h" |
| 14 | #include "core/core.h" | 19 | #include "core/core.h" |
| @@ -30,15 +35,30 @@ | |||
| 30 | #include "video_core/renderer_vulkan/vk_state_tracker.h" | 35 | #include "video_core/renderer_vulkan/vk_state_tracker.h" |
| 31 | #include "video_core/renderer_vulkan/vk_swapchain.h" | 36 | #include "video_core/renderer_vulkan/vk_swapchain.h" |
| 32 | 37 | ||
| 38 | // Include these late to avoid changing Vulkan-Hpp's dynamic dispatcher size | ||
| 39 | #ifdef _WIN32 | ||
| 40 | #include <windows.h> | ||
| 41 | // ensure include order | ||
| 42 | #include <vulkan/vulkan_win32.h> | ||
| 43 | #endif | ||
| 44 | |||
| 45 | #ifdef __linux__ | ||
| 46 | #include <X11/Xlib.h> | ||
| 47 | #include <vulkan/vulkan_wayland.h> | ||
| 48 | #include <vulkan/vulkan_xlib.h> | ||
| 49 | #endif | ||
| 50 | |||
| 33 | namespace Vulkan { | 51 | namespace Vulkan { |
| 34 | 52 | ||
| 35 | namespace { | 53 | namespace { |
| 36 | 54 | ||
| 55 | using Core::Frontend::WindowSystemType; | ||
| 56 | |||
| 37 | VkBool32 DebugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT severity_, | 57 | VkBool32 DebugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT severity_, |
| 38 | VkDebugUtilsMessageTypeFlagsEXT type, | 58 | VkDebugUtilsMessageTypeFlagsEXT type, |
| 39 | const VkDebugUtilsMessengerCallbackDataEXT* data, | 59 | const VkDebugUtilsMessengerCallbackDataEXT* data, |
| 40 | [[maybe_unused]] void* user_data) { | 60 | [[maybe_unused]] void* user_data) { |
| 41 | const vk::DebugUtilsMessageSeverityFlagBitsEXT severity{severity_}; | 61 | const auto severity{static_cast<vk::DebugUtilsMessageSeverityFlagBitsEXT>(severity_)}; |
| 42 | const char* message{data->pMessage}; | 62 | const char* message{data->pMessage}; |
| 43 | 63 | ||
| 44 | if (severity & vk::DebugUtilsMessageSeverityFlagBitsEXT::eError) { | 64 | if (severity & vk::DebugUtilsMessageSeverityFlagBitsEXT::eError) { |
| @@ -53,6 +73,110 @@ VkBool32 DebugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT severity_, | |||
| 53 | return VK_FALSE; | 73 | return VK_FALSE; |
| 54 | } | 74 | } |
| 55 | 75 | ||
| 76 | Common::DynamicLibrary OpenVulkanLibrary() { | ||
| 77 | Common::DynamicLibrary library; | ||
| 78 | #ifdef __APPLE__ | ||
| 79 | // Check if a path to a specific Vulkan library has been specified. | ||
| 80 | char* libvulkan_env = getenv("LIBVULKAN_PATH"); | ||
| 81 | if (!libvulkan_env || !library.Open(libvulkan_env)) { | ||
| 82 | // Use the libvulkan.dylib from the application bundle. | ||
| 83 | std::string filename = File::GetBundleDirectory() + "/Contents/Frameworks/libvulkan.dylib"; | ||
| 84 | library.Open(filename.c_str()); | ||
| 85 | } | ||
| 86 | #else | ||
| 87 | std::string filename = Common::DynamicLibrary::GetVersionedFilename("vulkan", 1); | ||
| 88 | if (!library.Open(filename.c_str())) { | ||
| 89 | // Android devices may not have libvulkan.so.1, only libvulkan.so. | ||
| 90 | filename = Common::DynamicLibrary::GetVersionedFilename("vulkan"); | ||
| 91 | library.Open(filename.c_str()); | ||
| 92 | } | ||
| 93 | #endif | ||
| 94 | return library; | ||
| 95 | } | ||
| 96 | |||
| 97 | UniqueInstance CreateInstance(Common::DynamicLibrary& library, vk::DispatchLoaderDynamic& dld, | ||
| 98 | WindowSystemType window_type = WindowSystemType::Headless, | ||
| 99 | bool enable_layers = false) { | ||
| 100 | if (!library.IsOpen()) { | ||
| 101 | LOG_ERROR(Render_Vulkan, "Vulkan library not available"); | ||
| 102 | return UniqueInstance{}; | ||
| 103 | } | ||
| 104 | PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr; | ||
| 105 | if (!library.GetSymbol("vkGetInstanceProcAddr", &vkGetInstanceProcAddr)) { | ||
| 106 | LOG_ERROR(Render_Vulkan, "vkGetInstanceProcAddr not present in Vulkan"); | ||
| 107 | return UniqueInstance{}; | ||
| 108 | } | ||
| 109 | dld.init(vkGetInstanceProcAddr); | ||
| 110 | |||
| 111 | std::vector<const char*> extensions; | ||
| 112 | extensions.reserve(4); | ||
| 113 | switch (window_type) { | ||
| 114 | case Core::Frontend::WindowSystemType::Headless: | ||
| 115 | break; | ||
| 116 | #ifdef _WIN32 | ||
| 117 | case Core::Frontend::WindowSystemType::Windows: | ||
| 118 | extensions.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME); | ||
| 119 | break; | ||
| 120 | #endif | ||
| 121 | #ifdef __linux__ | ||
| 122 | case Core::Frontend::WindowSystemType::X11: | ||
| 123 | extensions.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME); | ||
| 124 | break; | ||
| 125 | case Core::Frontend::WindowSystemType::Wayland: | ||
| 126 | extensions.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME); | ||
| 127 | break; | ||
| 128 | #endif | ||
| 129 | default: | ||
| 130 | LOG_ERROR(Render_Vulkan, "Presentation not supported on this platform"); | ||
| 131 | break; | ||
| 132 | } | ||
| 133 | if (window_type != Core::Frontend::WindowSystemType::Headless) { | ||
| 134 | extensions.push_back(VK_KHR_SURFACE_EXTENSION_NAME); | ||
| 135 | } | ||
| 136 | if (enable_layers) { | ||
| 137 | extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); | ||
| 138 | } | ||
| 139 | |||
| 140 | u32 num_properties; | ||
| 141 | if (vk::enumerateInstanceExtensionProperties(nullptr, &num_properties, nullptr, dld) != | ||
| 142 | vk::Result::eSuccess) { | ||
| 143 | LOG_ERROR(Render_Vulkan, "Failed to query number of extension properties"); | ||
| 144 | return UniqueInstance{}; | ||
| 145 | } | ||
| 146 | std::vector<vk::ExtensionProperties> properties(num_properties); | ||
| 147 | if (vk::enumerateInstanceExtensionProperties(nullptr, &num_properties, properties.data(), | ||
| 148 | dld) != vk::Result::eSuccess) { | ||
| 149 | LOG_ERROR(Render_Vulkan, "Failed to query extension properties"); | ||
| 150 | return UniqueInstance{}; | ||
| 151 | } | ||
| 152 | |||
| 153 | for (const char* extension : extensions) { | ||
| 154 | const auto it = | ||
| 155 | std::find_if(properties.begin(), properties.end(), [extension](const auto& prop) { | ||
| 156 | return !std::strcmp(extension, prop.extensionName); | ||
| 157 | }); | ||
| 158 | if (it == properties.end()) { | ||
| 159 | LOG_ERROR(Render_Vulkan, "Required instance extension {} is not available", extension); | ||
| 160 | return UniqueInstance{}; | ||
| 161 | } | ||
| 162 | } | ||
| 163 | |||
| 164 | const vk::ApplicationInfo application_info("yuzu Emulator", VK_MAKE_VERSION(0, 1, 0), | ||
| 165 | "yuzu Emulator", VK_MAKE_VERSION(0, 1, 0), | ||
| 166 | VK_API_VERSION_1_1); | ||
| 167 | const std::array layers = {"VK_LAYER_LUNARG_standard_validation"}; | ||
| 168 | const vk::InstanceCreateInfo instance_ci( | ||
| 169 | {}, &application_info, enable_layers ? static_cast<u32>(layers.size()) : 0, layers.data(), | ||
| 170 | static_cast<u32>(extensions.size()), extensions.data()); | ||
| 171 | vk::Instance unsafe_instance; | ||
| 172 | if (vk::createInstance(&instance_ci, nullptr, &unsafe_instance, dld) != vk::Result::eSuccess) { | ||
| 173 | LOG_ERROR(Render_Vulkan, "Failed to create Vulkan instance"); | ||
| 174 | return UniqueInstance{}; | ||
| 175 | } | ||
| 176 | dld.init(unsafe_instance); | ||
| 177 | return UniqueInstance(unsafe_instance, {nullptr, dld}); | ||
| 178 | } | ||
| 179 | |||
| 56 | std::string GetReadableVersion(u32 version) { | 180 | std::string GetReadableVersion(u32 version) { |
| 57 | return fmt::format("{}.{}.{}", VK_VERSION_MAJOR(version), VK_VERSION_MINOR(version), | 181 | return fmt::format("{}.{}.{}", VK_VERSION_MAJOR(version), VK_VERSION_MINOR(version), |
| 58 | VK_VERSION_PATCH(version)); | 182 | VK_VERSION_PATCH(version)); |
| @@ -147,27 +271,12 @@ bool RendererVulkan::TryPresent(int /*timeout_ms*/) { | |||
| 147 | } | 271 | } |
| 148 | 272 | ||
| 149 | bool RendererVulkan::Init() { | 273 | bool RendererVulkan::Init() { |
| 150 | PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr{}; | 274 | library = OpenVulkanLibrary(); |
| 151 | render_window.RetrieveVulkanHandlers(&vkGetInstanceProcAddr, &instance, &surface); | 275 | instance = CreateInstance(library, dld, render_window.GetWindowInfo().type, |
| 152 | const vk::DispatchLoaderDynamic dldi(instance, vkGetInstanceProcAddr); | 276 | Settings::values.renderer_debug); |
| 153 | 277 | if (!instance || !CreateDebugCallback() || !CreateSurface() || !PickDevices()) { | |
| 154 | std::optional<vk::DebugUtilsMessengerEXT> callback; | ||
| 155 | if (Settings::values.renderer_debug && dldi.vkCreateDebugUtilsMessengerEXT) { | ||
| 156 | callback = CreateDebugCallback(dldi); | ||
| 157 | if (!callback) { | ||
| 158 | return false; | ||
| 159 | } | ||
| 160 | } | ||
| 161 | |||
| 162 | if (!PickDevices(dldi)) { | ||
| 163 | if (callback) { | ||
| 164 | instance.destroy(*callback, nullptr, dldi); | ||
| 165 | } | ||
| 166 | return false; | 278 | return false; |
| 167 | } | 279 | } |
| 168 | debug_callback = UniqueDebugUtilsMessengerEXT( | ||
| 169 | *callback, vk::ObjectDestroy<vk::Instance, vk::DispatchLoaderDynamic>( | ||
| 170 | instance, nullptr, device->GetDispatchLoader())); | ||
| 171 | 280 | ||
| 172 | Report(); | 281 | Report(); |
| 173 | 282 | ||
| @@ -176,7 +285,7 @@ bool RendererVulkan::Init() { | |||
| 176 | resource_manager = std::make_unique<VKResourceManager>(*device); | 285 | resource_manager = std::make_unique<VKResourceManager>(*device); |
| 177 | 286 | ||
| 178 | const auto& framebuffer = render_window.GetFramebufferLayout(); | 287 | const auto& framebuffer = render_window.GetFramebufferLayout(); |
| 179 | swapchain = std::make_unique<VKSwapchain>(surface, *device); | 288 | swapchain = std::make_unique<VKSwapchain>(*surface, *device); |
| 180 | swapchain->Create(framebuffer.width, framebuffer.height, false); | 289 | swapchain->Create(framebuffer.width, framebuffer.height, false); |
| 181 | 290 | ||
| 182 | state_tracker = std::make_unique<StateTracker>(system); | 291 | state_tracker = std::make_unique<StateTracker>(system); |
| @@ -213,8 +322,10 @@ void RendererVulkan::ShutDown() { | |||
| 213 | device.reset(); | 322 | device.reset(); |
| 214 | } | 323 | } |
| 215 | 324 | ||
| 216 | std::optional<vk::DebugUtilsMessengerEXT> RendererVulkan::CreateDebugCallback( | 325 | bool RendererVulkan::CreateDebugCallback() { |
| 217 | const vk::DispatchLoaderDynamic& dldi) { | 326 | if (!Settings::values.renderer_debug) { |
| 327 | return true; | ||
| 328 | } | ||
| 218 | const vk::DebugUtilsMessengerCreateInfoEXT callback_ci( | 329 | const vk::DebugUtilsMessengerCreateInfoEXT callback_ci( |
| 219 | {}, | 330 | {}, |
| 220 | vk::DebugUtilsMessageSeverityFlagBitsEXT::eError | | 331 | vk::DebugUtilsMessageSeverityFlagBitsEXT::eError | |
| @@ -225,32 +336,88 @@ std::optional<vk::DebugUtilsMessengerEXT> RendererVulkan::CreateDebugCallback( | |||
| 225 | vk::DebugUtilsMessageTypeFlagBitsEXT::eValidation | | 336 | vk::DebugUtilsMessageTypeFlagBitsEXT::eValidation | |
| 226 | vk::DebugUtilsMessageTypeFlagBitsEXT::ePerformance, | 337 | vk::DebugUtilsMessageTypeFlagBitsEXT::ePerformance, |
| 227 | &DebugCallback, nullptr); | 338 | &DebugCallback, nullptr); |
| 228 | vk::DebugUtilsMessengerEXT callback; | 339 | vk::DebugUtilsMessengerEXT unsafe_callback; |
| 229 | if (instance.createDebugUtilsMessengerEXT(&callback_ci, nullptr, &callback, dldi) != | 340 | if (instance->createDebugUtilsMessengerEXT(&callback_ci, nullptr, &unsafe_callback, dld) != |
| 230 | vk::Result::eSuccess) { | 341 | vk::Result::eSuccess) { |
| 231 | LOG_ERROR(Render_Vulkan, "Failed to create debug callback"); | 342 | LOG_ERROR(Render_Vulkan, "Failed to create debug callback"); |
| 232 | return {}; | 343 | return false; |
| 344 | } | ||
| 345 | debug_callback = UniqueDebugUtilsMessengerEXT(unsafe_callback, {*instance, nullptr, dld}); | ||
| 346 | return true; | ||
| 347 | } | ||
| 348 | |||
| 349 | bool RendererVulkan::CreateSurface() { | ||
| 350 | [[maybe_unused]] const auto& window_info = render_window.GetWindowInfo(); | ||
| 351 | VkSurfaceKHR unsafe_surface = nullptr; | ||
| 352 | |||
| 353 | #ifdef _WIN32 | ||
| 354 | if (window_info.type == Core::Frontend::WindowSystemType::Windows) { | ||
| 355 | const HWND hWnd = static_cast<HWND>(window_info.render_surface); | ||
| 356 | const VkWin32SurfaceCreateInfoKHR win32_ci{VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR, | ||
| 357 | nullptr, 0, nullptr, hWnd}; | ||
| 358 | const auto vkCreateWin32SurfaceKHR = reinterpret_cast<PFN_vkCreateWin32SurfaceKHR>( | ||
| 359 | dld.vkGetInstanceProcAddr(*instance, "vkCreateWin32SurfaceKHR")); | ||
| 360 | if (!vkCreateWin32SurfaceKHR || vkCreateWin32SurfaceKHR(instance.get(), &win32_ci, nullptr, | ||
| 361 | &unsafe_surface) != VK_SUCCESS) { | ||
| 362 | LOG_ERROR(Render_Vulkan, "Failed to initialize Win32 surface"); | ||
| 363 | return false; | ||
| 364 | } | ||
| 365 | } | ||
| 366 | #endif | ||
| 367 | #ifdef __linux__ | ||
| 368 | if (window_info.type == Core::Frontend::WindowSystemType::X11) { | ||
| 369 | const VkXlibSurfaceCreateInfoKHR xlib_ci{ | ||
| 370 | VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR, nullptr, 0, | ||
| 371 | static_cast<Display*>(window_info.display_connection), | ||
| 372 | reinterpret_cast<Window>(window_info.render_surface)}; | ||
| 373 | const auto vkCreateXlibSurfaceKHR = reinterpret_cast<PFN_vkCreateXlibSurfaceKHR>( | ||
| 374 | dld.vkGetInstanceProcAddr(*instance, "vkCreateXlibSurfaceKHR")); | ||
| 375 | if (!vkCreateXlibSurfaceKHR || vkCreateXlibSurfaceKHR(instance.get(), &xlib_ci, nullptr, | ||
| 376 | &unsafe_surface) != VK_SUCCESS) { | ||
| 377 | LOG_ERROR(Render_Vulkan, "Failed to initialize Xlib surface"); | ||
| 378 | return false; | ||
| 379 | } | ||
| 380 | } | ||
| 381 | if (window_info.type == Core::Frontend::WindowSystemType::Wayland) { | ||
| 382 | const VkWaylandSurfaceCreateInfoKHR wayland_ci{ | ||
| 383 | VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR, nullptr, 0, | ||
| 384 | static_cast<wl_display*>(window_info.display_connection), | ||
| 385 | static_cast<wl_surface*>(window_info.render_surface)}; | ||
| 386 | const auto vkCreateWaylandSurfaceKHR = reinterpret_cast<PFN_vkCreateWaylandSurfaceKHR>( | ||
| 387 | dld.vkGetInstanceProcAddr(*instance, "vkCreateWaylandSurfaceKHR")); | ||
| 388 | if (!vkCreateWaylandSurfaceKHR || | ||
| 389 | vkCreateWaylandSurfaceKHR(instance.get(), &wayland_ci, nullptr, &unsafe_surface) != | ||
| 390 | VK_SUCCESS) { | ||
| 391 | LOG_ERROR(Render_Vulkan, "Failed to initialize Wayland surface"); | ||
| 392 | return false; | ||
| 393 | } | ||
| 394 | } | ||
| 395 | #endif | ||
| 396 | if (!unsafe_surface) { | ||
| 397 | LOG_ERROR(Render_Vulkan, "Presentation not supported on this platform"); | ||
| 398 | return false; | ||
| 233 | } | 399 | } |
| 234 | return callback; | 400 | |
| 401 | surface = UniqueSurfaceKHR(unsafe_surface, {*instance, nullptr, dld}); | ||
| 402 | return true; | ||
| 235 | } | 403 | } |
| 236 | 404 | ||
| 237 | bool RendererVulkan::PickDevices(const vk::DispatchLoaderDynamic& dldi) { | 405 | bool RendererVulkan::PickDevices() { |
| 238 | const auto devices = instance.enumeratePhysicalDevices(dldi); | 406 | const auto devices = instance->enumeratePhysicalDevices(dld); |
| 239 | 407 | ||
| 240 | // TODO(Rodrigo): Choose device from config file | ||
| 241 | const s32 device_index = Settings::values.vulkan_device; | 408 | const s32 device_index = Settings::values.vulkan_device; |
| 242 | if (device_index < 0 || device_index >= static_cast<s32>(devices.size())) { | 409 | if (device_index < 0 || device_index >= static_cast<s32>(devices.size())) { |
| 243 | LOG_ERROR(Render_Vulkan, "Invalid device index {}!", device_index); | 410 | LOG_ERROR(Render_Vulkan, "Invalid device index {}!", device_index); |
| 244 | return false; | 411 | return false; |
| 245 | } | 412 | } |
| 246 | const vk::PhysicalDevice physical_device = devices[device_index]; | 413 | const vk::PhysicalDevice physical_device = devices[static_cast<std::size_t>(device_index)]; |
| 247 | 414 | ||
| 248 | if (!VKDevice::IsSuitable(dldi, physical_device, surface)) { | 415 | if (!VKDevice::IsSuitable(physical_device, *surface, dld)) { |
| 249 | return false; | 416 | return false; |
| 250 | } | 417 | } |
| 251 | 418 | ||
| 252 | device = std::make_unique<VKDevice>(dldi, physical_device, surface); | 419 | device = std::make_unique<VKDevice>(dld, physical_device, *surface); |
| 253 | return device->Create(dldi, instance); | 420 | return device->Create(*instance); |
| 254 | } | 421 | } |
| 255 | 422 | ||
| 256 | void RendererVulkan::Report() const { | 423 | void RendererVulkan::Report() const { |
| @@ -276,4 +443,33 @@ void RendererVulkan::Report() const { | |||
| 276 | telemetry_session.AddField(field, "GPU_Vulkan_Extensions", extensions); | 443 | telemetry_session.AddField(field, "GPU_Vulkan_Extensions", extensions); |
| 277 | } | 444 | } |
| 278 | 445 | ||
| 446 | std::vector<std::string> RendererVulkan::EnumerateDevices() { | ||
| 447 | // Avoid putting DispatchLoaderDynamic, it's too large | ||
| 448 | auto dld_memory = std::make_unique<vk::DispatchLoaderDynamic>(); | ||
| 449 | auto& dld = *dld_memory; | ||
| 450 | |||
| 451 | Common::DynamicLibrary library = OpenVulkanLibrary(); | ||
| 452 | UniqueInstance instance = CreateInstance(library, dld); | ||
| 453 | if (!instance) { | ||
| 454 | return {}; | ||
| 455 | } | ||
| 456 | |||
| 457 | u32 num_devices; | ||
| 458 | if (instance->enumeratePhysicalDevices(&num_devices, nullptr, dld) != vk::Result::eSuccess) { | ||
| 459 | return {}; | ||
| 460 | } | ||
| 461 | std::vector<vk::PhysicalDevice> devices(num_devices); | ||
| 462 | if (instance->enumeratePhysicalDevices(&num_devices, devices.data(), dld) != | ||
| 463 | vk::Result::eSuccess) { | ||
| 464 | return {}; | ||
| 465 | } | ||
| 466 | |||
| 467 | std::vector<std::string> names; | ||
| 468 | names.reserve(num_devices); | ||
| 469 | for (auto& device : devices) { | ||
| 470 | names.push_back(device.getProperties(dld).deviceName); | ||
| 471 | } | ||
| 472 | return names; | ||
| 473 | } | ||
| 474 | |||
| 279 | } // namespace Vulkan | 475 | } // namespace Vulkan |
diff --git a/src/video_core/renderer_vulkan/renderer_vulkan.h b/src/video_core/renderer_vulkan/renderer_vulkan.h index d14384e79..42e253de5 100644 --- a/src/video_core/renderer_vulkan/renderer_vulkan.h +++ b/src/video_core/renderer_vulkan/renderer_vulkan.h | |||
| @@ -6,8 +6,11 @@ | |||
| 6 | 6 | ||
| 7 | #include <memory> | 7 | #include <memory> |
| 8 | #include <optional> | 8 | #include <optional> |
| 9 | #include <string> | ||
| 9 | #include <vector> | 10 | #include <vector> |
| 10 | 11 | ||
| 12 | #include "common/dynamic_library.h" | ||
| 13 | |||
| 11 | #include "video_core/renderer_base.h" | 14 | #include "video_core/renderer_base.h" |
| 12 | #include "video_core/renderer_vulkan/declarations.h" | 15 | #include "video_core/renderer_vulkan/declarations.h" |
| 13 | 16 | ||
| @@ -44,18 +47,24 @@ public: | |||
| 44 | void SwapBuffers(const Tegra::FramebufferConfig* framebuffer) override; | 47 | void SwapBuffers(const Tegra::FramebufferConfig* framebuffer) override; |
| 45 | bool TryPresent(int timeout_ms) override; | 48 | bool TryPresent(int timeout_ms) override; |
| 46 | 49 | ||
| 50 | static std::vector<std::string> EnumerateDevices(); | ||
| 51 | |||
| 47 | private: | 52 | private: |
| 48 | std::optional<vk::DebugUtilsMessengerEXT> CreateDebugCallback( | 53 | bool CreateDebugCallback(); |
| 49 | const vk::DispatchLoaderDynamic& dldi); | ||
| 50 | 54 | ||
| 51 | bool PickDevices(const vk::DispatchLoaderDynamic& dldi); | 55 | bool CreateSurface(); |
| 56 | |||
| 57 | bool PickDevices(); | ||
| 52 | 58 | ||
| 53 | void Report() const; | 59 | void Report() const; |
| 54 | 60 | ||
| 55 | Core::System& system; | 61 | Core::System& system; |
| 56 | 62 | ||
| 57 | vk::Instance instance; | 63 | Common::DynamicLibrary library; |
| 58 | vk::SurfaceKHR surface; | 64 | vk::DispatchLoaderDynamic dld; |
| 65 | |||
| 66 | UniqueInstance instance; | ||
| 67 | UniqueSurfaceKHR surface; | ||
| 59 | 68 | ||
| 60 | VKScreenInfo screen_info; | 69 | VKScreenInfo screen_info; |
| 61 | 70 | ||
diff --git a/src/video_core/renderer_vulkan/vk_device.cpp b/src/video_core/renderer_vulkan/vk_device.cpp index 7aafb5e59..6f4ae9132 100644 --- a/src/video_core/renderer_vulkan/vk_device.cpp +++ b/src/video_core/renderer_vulkan/vk_device.cpp | |||
| @@ -10,6 +10,7 @@ | |||
| 10 | #include <string_view> | 10 | #include <string_view> |
| 11 | #include <thread> | 11 | #include <thread> |
| 12 | #include <vector> | 12 | #include <vector> |
| 13 | |||
| 13 | #include "common/assert.h" | 14 | #include "common/assert.h" |
| 14 | #include "core/settings.h" | 15 | #include "core/settings.h" |
| 15 | #include "video_core/renderer_vulkan/declarations.h" | 16 | #include "video_core/renderer_vulkan/declarations.h" |
| @@ -35,20 +36,20 @@ void SetNext(void**& next, T& data) { | |||
| 35 | } | 36 | } |
| 36 | 37 | ||
| 37 | template <typename T> | 38 | template <typename T> |
| 38 | T GetFeatures(vk::PhysicalDevice physical, const vk::DispatchLoaderDynamic& dldi) { | 39 | T GetFeatures(vk::PhysicalDevice physical, const vk::DispatchLoaderDynamic& dld) { |
| 39 | vk::PhysicalDeviceFeatures2 features; | 40 | vk::PhysicalDeviceFeatures2 features; |
| 40 | T extension_features; | 41 | T extension_features; |
| 41 | features.pNext = &extension_features; | 42 | features.pNext = &extension_features; |
| 42 | physical.getFeatures2(&features, dldi); | 43 | physical.getFeatures2(&features, dld); |
| 43 | return extension_features; | 44 | return extension_features; |
| 44 | } | 45 | } |
| 45 | 46 | ||
| 46 | template <typename T> | 47 | template <typename T> |
| 47 | T GetProperties(vk::PhysicalDevice physical, const vk::DispatchLoaderDynamic& dldi) { | 48 | T GetProperties(vk::PhysicalDevice physical, const vk::DispatchLoaderDynamic& dld) { |
| 48 | vk::PhysicalDeviceProperties2 properties; | 49 | vk::PhysicalDeviceProperties2 properties; |
| 49 | T extension_properties; | 50 | T extension_properties; |
| 50 | properties.pNext = &extension_properties; | 51 | properties.pNext = &extension_properties; |
| 51 | physical.getProperties2(&properties, dldi); | 52 | physical.getProperties2(&properties, dld); |
| 52 | return extension_properties; | 53 | return extension_properties; |
| 53 | } | 54 | } |
| 54 | 55 | ||
| @@ -78,19 +79,19 @@ vk::FormatFeatureFlags GetFormatFeatures(vk::FormatProperties properties, Format | |||
| 78 | 79 | ||
| 79 | } // Anonymous namespace | 80 | } // Anonymous namespace |
| 80 | 81 | ||
| 81 | VKDevice::VKDevice(const vk::DispatchLoaderDynamic& dldi, vk::PhysicalDevice physical, | 82 | VKDevice::VKDevice(const vk::DispatchLoaderDynamic& dld, vk::PhysicalDevice physical, |
| 82 | vk::SurfaceKHR surface) | 83 | vk::SurfaceKHR surface) |
| 83 | : physical{physical}, properties{physical.getProperties(dldi)}, | 84 | : dld{dld}, physical{physical}, properties{physical.getProperties(dld)}, |
| 84 | format_properties{GetFormatProperties(dldi, physical)} { | 85 | format_properties{GetFormatProperties(dld, physical)} { |
| 85 | SetupFamilies(dldi, surface); | 86 | SetupFamilies(surface); |
| 86 | SetupFeatures(dldi); | 87 | SetupFeatures(); |
| 87 | } | 88 | } |
| 88 | 89 | ||
| 89 | VKDevice::~VKDevice() = default; | 90 | VKDevice::~VKDevice() = default; |
| 90 | 91 | ||
| 91 | bool VKDevice::Create(const vk::DispatchLoaderDynamic& dldi, vk::Instance instance) { | 92 | bool VKDevice::Create(vk::Instance instance) { |
| 92 | const auto queue_cis = GetDeviceQueueCreateInfos(); | 93 | const auto queue_cis = GetDeviceQueueCreateInfos(); |
| 93 | const std::vector extensions = LoadExtensions(dldi); | 94 | const std::vector extensions = LoadExtensions(); |
| 94 | 95 | ||
| 95 | vk::PhysicalDeviceFeatures2 features2; | 96 | vk::PhysicalDeviceFeatures2 features2; |
| 96 | void** next = &features2.pNext; | 97 | void** next = &features2.pNext; |
| @@ -165,15 +166,13 @@ bool VKDevice::Create(const vk::DispatchLoaderDynamic& dldi, vk::Instance instan | |||
| 165 | nullptr); | 166 | nullptr); |
| 166 | device_ci.pNext = &features2; | 167 | device_ci.pNext = &features2; |
| 167 | 168 | ||
| 168 | vk::Device dummy_logical; | 169 | vk::Device unsafe_logical; |
| 169 | if (physical.createDevice(&device_ci, nullptr, &dummy_logical, dldi) != vk::Result::eSuccess) { | 170 | if (physical.createDevice(&device_ci, nullptr, &unsafe_logical, dld) != vk::Result::eSuccess) { |
| 170 | LOG_CRITICAL(Render_Vulkan, "Logical device failed to be created!"); | 171 | LOG_CRITICAL(Render_Vulkan, "Logical device failed to be created!"); |
| 171 | return false; | 172 | return false; |
| 172 | } | 173 | } |
| 173 | 174 | dld.init(instance, dld.vkGetInstanceProcAddr, unsafe_logical); | |
| 174 | dld.init(instance, dldi.vkGetInstanceProcAddr, dummy_logical, dldi.vkGetDeviceProcAddr); | 175 | logical = UniqueDevice(unsafe_logical, {nullptr, dld}); |
| 175 | logical = UniqueDevice( | ||
| 176 | dummy_logical, vk::ObjectDestroy<vk::NoParent, vk::DispatchLoaderDynamic>(nullptr, dld)); | ||
| 177 | 176 | ||
| 178 | CollectTelemetryParameters(); | 177 | CollectTelemetryParameters(); |
| 179 | 178 | ||
| @@ -235,8 +234,8 @@ void VKDevice::ReportLoss() const { | |||
| 235 | // *(VKGraphicsPipeline*)data[0] | 234 | // *(VKGraphicsPipeline*)data[0] |
| 236 | } | 235 | } |
| 237 | 236 | ||
| 238 | bool VKDevice::IsOptimalAstcSupported(const vk::PhysicalDeviceFeatures& features, | 237 | bool VKDevice::IsOptimalAstcSupported(const vk::PhysicalDeviceFeatures& features) const { |
| 239 | const vk::DispatchLoaderDynamic& dldi) const { | 238 | // Disable for now to avoid converting ASTC twice. |
| 240 | static constexpr std::array astc_formats = { | 239 | static constexpr std::array astc_formats = { |
| 241 | vk::Format::eAstc4x4UnormBlock, vk::Format::eAstc4x4SrgbBlock, | 240 | vk::Format::eAstc4x4UnormBlock, vk::Format::eAstc4x4SrgbBlock, |
| 242 | vk::Format::eAstc5x4UnormBlock, vk::Format::eAstc5x4SrgbBlock, | 241 | vk::Format::eAstc5x4UnormBlock, vk::Format::eAstc5x4SrgbBlock, |
| @@ -260,7 +259,7 @@ bool VKDevice::IsOptimalAstcSupported(const vk::PhysicalDeviceFeatures& features | |||
| 260 | vk::FormatFeatureFlagBits::eBlitDst | vk::FormatFeatureFlagBits::eTransferSrc | | 259 | vk::FormatFeatureFlagBits::eBlitDst | vk::FormatFeatureFlagBits::eTransferSrc | |
| 261 | vk::FormatFeatureFlagBits::eTransferDst}; | 260 | vk::FormatFeatureFlagBits::eTransferDst}; |
| 262 | for (const auto format : astc_formats) { | 261 | for (const auto format : astc_formats) { |
| 263 | const auto format_properties{physical.getFormatProperties(format, dldi)}; | 262 | const auto format_properties{physical.getFormatProperties(format, dld)}; |
| 264 | if (!(format_properties.optimalTilingFeatures & format_feature_usage)) { | 263 | if (!(format_properties.optimalTilingFeatures & format_feature_usage)) { |
| 265 | return false; | 264 | return false; |
| 266 | } | 265 | } |
| @@ -279,11 +278,9 @@ bool VKDevice::IsFormatSupported(vk::Format wanted_format, vk::FormatFeatureFlag | |||
| 279 | return (supported_usage & wanted_usage) == wanted_usage; | 278 | return (supported_usage & wanted_usage) == wanted_usage; |
| 280 | } | 279 | } |
| 281 | 280 | ||
| 282 | bool VKDevice::IsSuitable(const vk::DispatchLoaderDynamic& dldi, vk::PhysicalDevice physical, | 281 | bool VKDevice::IsSuitable(vk::PhysicalDevice physical, vk::SurfaceKHR surface, |
| 283 | vk::SurfaceKHR surface) { | 282 | const vk::DispatchLoaderDynamic& dld) { |
| 284 | bool is_suitable = true; | 283 | static constexpr std::array required_extensions = { |
| 285 | |||
| 286 | constexpr std::array required_extensions = { | ||
| 287 | VK_KHR_SWAPCHAIN_EXTENSION_NAME, | 284 | VK_KHR_SWAPCHAIN_EXTENSION_NAME, |
| 288 | VK_KHR_16BIT_STORAGE_EXTENSION_NAME, | 285 | VK_KHR_16BIT_STORAGE_EXTENSION_NAME, |
| 289 | VK_KHR_8BIT_STORAGE_EXTENSION_NAME, | 286 | VK_KHR_8BIT_STORAGE_EXTENSION_NAME, |
| @@ -293,9 +290,10 @@ bool VKDevice::IsSuitable(const vk::DispatchLoaderDynamic& dldi, vk::PhysicalDev | |||
| 293 | VK_EXT_SHADER_SUBGROUP_VOTE_EXTENSION_NAME, | 290 | VK_EXT_SHADER_SUBGROUP_VOTE_EXTENSION_NAME, |
| 294 | VK_EXT_HOST_QUERY_RESET_EXTENSION_NAME, | 291 | VK_EXT_HOST_QUERY_RESET_EXTENSION_NAME, |
| 295 | }; | 292 | }; |
| 293 | bool is_suitable = true; | ||
| 296 | std::bitset<required_extensions.size()> available_extensions{}; | 294 | std::bitset<required_extensions.size()> available_extensions{}; |
| 297 | 295 | ||
| 298 | for (const auto& prop : physical.enumerateDeviceExtensionProperties(nullptr, dldi)) { | 296 | for (const auto& prop : physical.enumerateDeviceExtensionProperties(nullptr, dld)) { |
| 299 | for (std::size_t i = 0; i < required_extensions.size(); ++i) { | 297 | for (std::size_t i = 0; i < required_extensions.size(); ++i) { |
| 300 | if (available_extensions[i]) { | 298 | if (available_extensions[i]) { |
| 301 | continue; | 299 | continue; |
| @@ -315,7 +313,7 @@ bool VKDevice::IsSuitable(const vk::DispatchLoaderDynamic& dldi, vk::PhysicalDev | |||
| 315 | } | 313 | } |
| 316 | 314 | ||
| 317 | bool has_graphics{}, has_present{}; | 315 | bool has_graphics{}, has_present{}; |
| 318 | const auto queue_family_properties = physical.getQueueFamilyProperties(dldi); | 316 | const auto queue_family_properties = physical.getQueueFamilyProperties(dld); |
| 319 | for (u32 i = 0; i < static_cast<u32>(queue_family_properties.size()); ++i) { | 317 | for (u32 i = 0; i < static_cast<u32>(queue_family_properties.size()); ++i) { |
| 320 | const auto& family = queue_family_properties[i]; | 318 | const auto& family = queue_family_properties[i]; |
| 321 | if (family.queueCount == 0) { | 319 | if (family.queueCount == 0) { |
| @@ -323,7 +321,7 @@ bool VKDevice::IsSuitable(const vk::DispatchLoaderDynamic& dldi, vk::PhysicalDev | |||
| 323 | } | 321 | } |
| 324 | has_graphics |= | 322 | has_graphics |= |
| 325 | (family.queueFlags & vk::QueueFlagBits::eGraphics) != static_cast<vk::QueueFlagBits>(0); | 323 | (family.queueFlags & vk::QueueFlagBits::eGraphics) != static_cast<vk::QueueFlagBits>(0); |
| 326 | has_present |= physical.getSurfaceSupportKHR(i, surface, dldi) != 0; | 324 | has_present |= physical.getSurfaceSupportKHR(i, surface, dld) != 0; |
| 327 | } | 325 | } |
| 328 | if (!has_graphics || !has_present) { | 326 | if (!has_graphics || !has_present) { |
| 329 | LOG_ERROR(Render_Vulkan, "Device lacks a graphics and present queue"); | 327 | LOG_ERROR(Render_Vulkan, "Device lacks a graphics and present queue"); |
| @@ -331,7 +329,7 @@ bool VKDevice::IsSuitable(const vk::DispatchLoaderDynamic& dldi, vk::PhysicalDev | |||
| 331 | } | 329 | } |
| 332 | 330 | ||
| 333 | // TODO(Rodrigo): Check if the device matches all requeriments. | 331 | // TODO(Rodrigo): Check if the device matches all requeriments. |
| 334 | const auto properties{physical.getProperties(dldi)}; | 332 | const auto properties{physical.getProperties(dld)}; |
| 335 | const auto& limits{properties.limits}; | 333 | const auto& limits{properties.limits}; |
| 336 | 334 | ||
| 337 | constexpr u32 required_ubo_size = 65536; | 335 | constexpr u32 required_ubo_size = 65536; |
| @@ -348,7 +346,7 @@ bool VKDevice::IsSuitable(const vk::DispatchLoaderDynamic& dldi, vk::PhysicalDev | |||
| 348 | is_suitable = false; | 346 | is_suitable = false; |
| 349 | } | 347 | } |
| 350 | 348 | ||
| 351 | const auto features{physical.getFeatures(dldi)}; | 349 | const auto features{physical.getFeatures(dld)}; |
| 352 | const std::array feature_report = { | 350 | const std::array feature_report = { |
| 353 | std::make_pair(features.vertexPipelineStoresAndAtomics, "vertexPipelineStoresAndAtomics"), | 351 | std::make_pair(features.vertexPipelineStoresAndAtomics, "vertexPipelineStoresAndAtomics"), |
| 354 | std::make_pair(features.independentBlend, "independentBlend"), | 352 | std::make_pair(features.independentBlend, "independentBlend"), |
| @@ -380,7 +378,7 @@ bool VKDevice::IsSuitable(const vk::DispatchLoaderDynamic& dldi, vk::PhysicalDev | |||
| 380 | return is_suitable; | 378 | return is_suitable; |
| 381 | } | 379 | } |
| 382 | 380 | ||
| 383 | std::vector<const char*> VKDevice::LoadExtensions(const vk::DispatchLoaderDynamic& dldi) { | 381 | std::vector<const char*> VKDevice::LoadExtensions() { |
| 384 | std::vector<const char*> extensions; | 382 | std::vector<const char*> extensions; |
| 385 | const auto Test = [&](const vk::ExtensionProperties& extension, | 383 | const auto Test = [&](const vk::ExtensionProperties& extension, |
| 386 | std::optional<std::reference_wrapper<bool>> status, const char* name, | 384 | std::optional<std::reference_wrapper<bool>> status, const char* name, |
| @@ -411,7 +409,7 @@ std::vector<const char*> VKDevice::LoadExtensions(const vk::DispatchLoaderDynami | |||
| 411 | bool has_khr_shader_float16_int8{}; | 409 | bool has_khr_shader_float16_int8{}; |
| 412 | bool has_ext_subgroup_size_control{}; | 410 | bool has_ext_subgroup_size_control{}; |
| 413 | bool has_ext_transform_feedback{}; | 411 | bool has_ext_transform_feedback{}; |
| 414 | for (const auto& extension : physical.enumerateDeviceExtensionProperties(nullptr, dldi)) { | 412 | for (const auto& extension : physical.enumerateDeviceExtensionProperties(nullptr, dld)) { |
| 415 | Test(extension, khr_uniform_buffer_standard_layout, | 413 | Test(extension, khr_uniform_buffer_standard_layout, |
| 416 | VK_KHR_UNIFORM_BUFFER_STANDARD_LAYOUT_EXTENSION_NAME, true); | 414 | VK_KHR_UNIFORM_BUFFER_STANDARD_LAYOUT_EXTENSION_NAME, true); |
| 417 | Test(extension, has_khr_shader_float16_int8, VK_KHR_SHADER_FLOAT16_INT8_EXTENSION_NAME, | 415 | Test(extension, has_khr_shader_float16_int8, VK_KHR_SHADER_FLOAT16_INT8_EXTENSION_NAME, |
| @@ -433,15 +431,15 @@ std::vector<const char*> VKDevice::LoadExtensions(const vk::DispatchLoaderDynami | |||
| 433 | 431 | ||
| 434 | if (has_khr_shader_float16_int8) { | 432 | if (has_khr_shader_float16_int8) { |
| 435 | is_float16_supported = | 433 | is_float16_supported = |
| 436 | GetFeatures<vk::PhysicalDeviceFloat16Int8FeaturesKHR>(physical, dldi).shaderFloat16; | 434 | GetFeatures<vk::PhysicalDeviceFloat16Int8FeaturesKHR>(physical, dld).shaderFloat16; |
| 437 | extensions.push_back(VK_KHR_SHADER_FLOAT16_INT8_EXTENSION_NAME); | 435 | extensions.push_back(VK_KHR_SHADER_FLOAT16_INT8_EXTENSION_NAME); |
| 438 | } | 436 | } |
| 439 | 437 | ||
| 440 | if (has_ext_subgroup_size_control) { | 438 | if (has_ext_subgroup_size_control) { |
| 441 | const auto features = | 439 | const auto features = |
| 442 | GetFeatures<vk::PhysicalDeviceSubgroupSizeControlFeaturesEXT>(physical, dldi); | 440 | GetFeatures<vk::PhysicalDeviceSubgroupSizeControlFeaturesEXT>(physical, dld); |
| 443 | const auto properties = | 441 | const auto properties = |
| 444 | GetProperties<vk::PhysicalDeviceSubgroupSizeControlPropertiesEXT>(physical, dldi); | 442 | GetProperties<vk::PhysicalDeviceSubgroupSizeControlPropertiesEXT>(physical, dld); |
| 445 | 443 | ||
| 446 | is_warp_potentially_bigger = properties.maxSubgroupSize > GuestWarpSize; | 444 | is_warp_potentially_bigger = properties.maxSubgroupSize > GuestWarpSize; |
| 447 | 445 | ||
| @@ -456,9 +454,9 @@ std::vector<const char*> VKDevice::LoadExtensions(const vk::DispatchLoaderDynami | |||
| 456 | 454 | ||
| 457 | if (has_ext_transform_feedback) { | 455 | if (has_ext_transform_feedback) { |
| 458 | const auto features = | 456 | const auto features = |
| 459 | GetFeatures<vk::PhysicalDeviceTransformFeedbackFeaturesEXT>(physical, dldi); | 457 | GetFeatures<vk::PhysicalDeviceTransformFeedbackFeaturesEXT>(physical, dld); |
| 460 | const auto properties = | 458 | const auto properties = |
| 461 | GetProperties<vk::PhysicalDeviceTransformFeedbackPropertiesEXT>(physical, dldi); | 459 | GetProperties<vk::PhysicalDeviceTransformFeedbackPropertiesEXT>(physical, dld); |
| 462 | 460 | ||
| 463 | if (features.transformFeedback && features.geometryStreams && | 461 | if (features.transformFeedback && features.geometryStreams && |
| 464 | properties.maxTransformFeedbackStreams >= 4 && properties.maxTransformFeedbackBuffers && | 462 | properties.maxTransformFeedbackStreams >= 4 && properties.maxTransformFeedbackBuffers && |
| @@ -471,10 +469,10 @@ std::vector<const char*> VKDevice::LoadExtensions(const vk::DispatchLoaderDynami | |||
| 471 | return extensions; | 469 | return extensions; |
| 472 | } | 470 | } |
| 473 | 471 | ||
| 474 | void VKDevice::SetupFamilies(const vk::DispatchLoaderDynamic& dldi, vk::SurfaceKHR surface) { | 472 | void VKDevice::SetupFamilies(vk::SurfaceKHR surface) { |
| 475 | std::optional<u32> graphics_family_, present_family_; | 473 | std::optional<u32> graphics_family_, present_family_; |
| 476 | 474 | ||
| 477 | const auto queue_family_properties = physical.getQueueFamilyProperties(dldi); | 475 | const auto queue_family_properties = physical.getQueueFamilyProperties(dld); |
| 478 | for (u32 i = 0; i < static_cast<u32>(queue_family_properties.size()); ++i) { | 476 | for (u32 i = 0; i < static_cast<u32>(queue_family_properties.size()); ++i) { |
| 479 | if (graphics_family_ && present_family_) | 477 | if (graphics_family_ && present_family_) |
| 480 | break; | 478 | break; |
| @@ -483,10 +481,12 @@ void VKDevice::SetupFamilies(const vk::DispatchLoaderDynamic& dldi, vk::SurfaceK | |||
| 483 | if (queue_family.queueCount == 0) | 481 | if (queue_family.queueCount == 0) |
| 484 | continue; | 482 | continue; |
| 485 | 483 | ||
| 486 | if (queue_family.queueFlags & vk::QueueFlagBits::eGraphics) | 484 | if (queue_family.queueFlags & vk::QueueFlagBits::eGraphics) { |
| 487 | graphics_family_ = i; | 485 | graphics_family_ = i; |
| 488 | if (physical.getSurfaceSupportKHR(i, surface, dldi)) | 486 | } |
| 487 | if (physical.getSurfaceSupportKHR(i, surface, dld)) { | ||
| 489 | present_family_ = i; | 488 | present_family_ = i; |
| 489 | } | ||
| 490 | } | 490 | } |
| 491 | ASSERT(graphics_family_ && present_family_); | 491 | ASSERT(graphics_family_ && present_family_); |
| 492 | 492 | ||
| @@ -494,10 +494,10 @@ void VKDevice::SetupFamilies(const vk::DispatchLoaderDynamic& dldi, vk::SurfaceK | |||
| 494 | present_family = *present_family_; | 494 | present_family = *present_family_; |
| 495 | } | 495 | } |
| 496 | 496 | ||
| 497 | void VKDevice::SetupFeatures(const vk::DispatchLoaderDynamic& dldi) { | 497 | void VKDevice::SetupFeatures() { |
| 498 | const auto supported_features{physical.getFeatures(dldi)}; | 498 | const auto supported_features{physical.getFeatures(dld)}; |
| 499 | is_formatless_image_load_supported = supported_features.shaderStorageImageReadWithoutFormat; | 499 | is_formatless_image_load_supported = supported_features.shaderStorageImageReadWithoutFormat; |
| 500 | is_optimal_astc_supported = IsOptimalAstcSupported(supported_features, dldi); | 500 | is_optimal_astc_supported = IsOptimalAstcSupported(supported_features); |
| 501 | } | 501 | } |
| 502 | 502 | ||
| 503 | void VKDevice::CollectTelemetryParameters() { | 503 | void VKDevice::CollectTelemetryParameters() { |
| @@ -525,7 +525,7 @@ std::vector<vk::DeviceQueueCreateInfo> VKDevice::GetDeviceQueueCreateInfos() con | |||
| 525 | } | 525 | } |
| 526 | 526 | ||
| 527 | std::unordered_map<vk::Format, vk::FormatProperties> VKDevice::GetFormatProperties( | 527 | std::unordered_map<vk::Format, vk::FormatProperties> VKDevice::GetFormatProperties( |
| 528 | const vk::DispatchLoaderDynamic& dldi, vk::PhysicalDevice physical) { | 528 | const vk::DispatchLoaderDynamic& dld, vk::PhysicalDevice physical) { |
| 529 | static constexpr std::array formats{vk::Format::eA8B8G8R8UnormPack32, | 529 | static constexpr std::array formats{vk::Format::eA8B8G8R8UnormPack32, |
| 530 | vk::Format::eA8B8G8R8UintPack32, | 530 | vk::Format::eA8B8G8R8UintPack32, |
| 531 | vk::Format::eA8B8G8R8SnormPack32, | 531 | vk::Format::eA8B8G8R8SnormPack32, |
| @@ -606,7 +606,7 @@ std::unordered_map<vk::Format, vk::FormatProperties> VKDevice::GetFormatProperti | |||
| 606 | vk::Format::eE5B9G9R9UfloatPack32}; | 606 | vk::Format::eE5B9G9R9UfloatPack32}; |
| 607 | std::unordered_map<vk::Format, vk::FormatProperties> format_properties; | 607 | std::unordered_map<vk::Format, vk::FormatProperties> format_properties; |
| 608 | for (const auto format : formats) { | 608 | for (const auto format : formats) { |
| 609 | format_properties.emplace(format, physical.getFormatProperties(format, dldi)); | 609 | format_properties.emplace(format, physical.getFormatProperties(format, dld)); |
| 610 | } | 610 | } |
| 611 | return format_properties; | 611 | return format_properties; |
| 612 | } | 612 | } |
diff --git a/src/video_core/renderer_vulkan/vk_device.h b/src/video_core/renderer_vulkan/vk_device.h index 6e656517f..d9d809852 100644 --- a/src/video_core/renderer_vulkan/vk_device.h +++ b/src/video_core/renderer_vulkan/vk_device.h | |||
| @@ -22,12 +22,12 @@ const u32 GuestWarpSize = 32; | |||
| 22 | /// Handles data specific to a physical device. | 22 | /// Handles data specific to a physical device. |
| 23 | class VKDevice final { | 23 | class VKDevice final { |
| 24 | public: | 24 | public: |
| 25 | explicit VKDevice(const vk::DispatchLoaderDynamic& dldi, vk::PhysicalDevice physical, | 25 | explicit VKDevice(const vk::DispatchLoaderDynamic& dld, vk::PhysicalDevice physical, |
| 26 | vk::SurfaceKHR surface); | 26 | vk::SurfaceKHR surface); |
| 27 | ~VKDevice(); | 27 | ~VKDevice(); |
| 28 | 28 | ||
| 29 | /// Initializes the device. Returns true on success. | 29 | /// Initializes the device. Returns true on success. |
| 30 | bool Create(const vk::DispatchLoaderDynamic& dldi, vk::Instance instance); | 30 | bool Create(vk::Instance instance); |
| 31 | 31 | ||
| 32 | /** | 32 | /** |
| 33 | * Returns a format supported by the device for the passed requeriments. | 33 | * Returns a format supported by the device for the passed requeriments. |
| @@ -188,18 +188,18 @@ public: | |||
| 188 | } | 188 | } |
| 189 | 189 | ||
| 190 | /// Checks if the physical device is suitable. | 190 | /// Checks if the physical device is suitable. |
| 191 | static bool IsSuitable(const vk::DispatchLoaderDynamic& dldi, vk::PhysicalDevice physical, | 191 | static bool IsSuitable(vk::PhysicalDevice physical, vk::SurfaceKHR surface, |
| 192 | vk::SurfaceKHR surface); | 192 | const vk::DispatchLoaderDynamic& dld); |
| 193 | 193 | ||
| 194 | private: | 194 | private: |
| 195 | /// Loads extensions into a vector and stores available ones in this object. | 195 | /// Loads extensions into a vector and stores available ones in this object. |
| 196 | std::vector<const char*> LoadExtensions(const vk::DispatchLoaderDynamic& dldi); | 196 | std::vector<const char*> LoadExtensions(); |
| 197 | 197 | ||
| 198 | /// Sets up queue families. | 198 | /// Sets up queue families. |
| 199 | void SetupFamilies(const vk::DispatchLoaderDynamic& dldi, vk::SurfaceKHR surface); | 199 | void SetupFamilies(vk::SurfaceKHR surface); |
| 200 | 200 | ||
| 201 | /// Sets up device features. | 201 | /// Sets up device features. |
| 202 | void SetupFeatures(const vk::DispatchLoaderDynamic& dldi); | 202 | void SetupFeatures(); |
| 203 | 203 | ||
| 204 | /// Collects telemetry information from the device. | 204 | /// Collects telemetry information from the device. |
| 205 | void CollectTelemetryParameters(); | 205 | void CollectTelemetryParameters(); |
| @@ -208,8 +208,7 @@ private: | |||
| 208 | std::vector<vk::DeviceQueueCreateInfo> GetDeviceQueueCreateInfos() const; | 208 | std::vector<vk::DeviceQueueCreateInfo> GetDeviceQueueCreateInfos() const; |
| 209 | 209 | ||
| 210 | /// Returns true if ASTC textures are natively supported. | 210 | /// Returns true if ASTC textures are natively supported. |
| 211 | bool IsOptimalAstcSupported(const vk::PhysicalDeviceFeatures& features, | 211 | bool IsOptimalAstcSupported(const vk::PhysicalDeviceFeatures& features) const; |
| 212 | const vk::DispatchLoaderDynamic& dldi) const; | ||
| 213 | 212 | ||
| 214 | /// Returns true if a format is supported. | 213 | /// Returns true if a format is supported. |
| 215 | bool IsFormatSupported(vk::Format wanted_format, vk::FormatFeatureFlags wanted_usage, | 214 | bool IsFormatSupported(vk::Format wanted_format, vk::FormatFeatureFlags wanted_usage, |
| @@ -217,10 +216,10 @@ private: | |||
| 217 | 216 | ||
| 218 | /// Returns the device properties for Vulkan formats. | 217 | /// Returns the device properties for Vulkan formats. |
| 219 | static std::unordered_map<vk::Format, vk::FormatProperties> GetFormatProperties( | 218 | static std::unordered_map<vk::Format, vk::FormatProperties> GetFormatProperties( |
| 220 | const vk::DispatchLoaderDynamic& dldi, vk::PhysicalDevice physical); | 219 | const vk::DispatchLoaderDynamic& dld, vk::PhysicalDevice physical); |
| 221 | 220 | ||
| 222 | const vk::PhysicalDevice physical; ///< Physical device. | ||
| 223 | vk::DispatchLoaderDynamic dld; ///< Device function pointers. | 221 | vk::DispatchLoaderDynamic dld; ///< Device function pointers. |
| 222 | vk::PhysicalDevice physical; ///< Physical device. | ||
| 224 | vk::PhysicalDeviceProperties properties; ///< Device properties. | 223 | vk::PhysicalDeviceProperties properties; ///< Device properties. |
| 225 | UniqueDevice logical; ///< Logical device. | 224 | UniqueDevice logical; ///< Logical device. |
| 226 | vk::Queue graphics_queue; ///< Main graphics queue. | 225 | vk::Queue graphics_queue; ///< Main graphics queue. |
diff --git a/src/yuzu/CMakeLists.txt b/src/yuzu/CMakeLists.txt index d34b47b3f..8b9404718 100644 --- a/src/yuzu/CMakeLists.txt +++ b/src/yuzu/CMakeLists.txt | |||
| @@ -150,6 +150,10 @@ target_link_libraries(yuzu PRIVATE common core input_common video_core) | |||
| 150 | target_link_libraries(yuzu PRIVATE Boost::boost glad Qt5::OpenGL Qt5::Widgets) | 150 | target_link_libraries(yuzu PRIVATE Boost::boost glad Qt5::OpenGL Qt5::Widgets) |
| 151 | target_link_libraries(yuzu PRIVATE ${PLATFORM_LIBRARIES} Threads::Threads) | 151 | target_link_libraries(yuzu PRIVATE ${PLATFORM_LIBRARIES} Threads::Threads) |
| 152 | 152 | ||
| 153 | if (ENABLE_VULKAN AND NOT WIN32) | ||
| 154 | target_include_directories(yuzu PRIVATE ${Qt5Gui_PRIVATE_INCLUDE_DIRS}) | ||
| 155 | endif() | ||
| 156 | |||
| 153 | target_compile_definitions(yuzu PRIVATE | 157 | target_compile_definitions(yuzu PRIVATE |
| 154 | # Use QStringBuilder for string concatenation to reduce | 158 | # Use QStringBuilder for string concatenation to reduce |
| 155 | # the overall number of temporary strings created. | 159 | # the overall number of temporary strings created. |
diff --git a/src/yuzu/bootmanager.cpp b/src/yuzu/bootmanager.cpp index 7b211bd32..1cac2f942 100644 --- a/src/yuzu/bootmanager.cpp +++ b/src/yuzu/bootmanager.cpp | |||
| @@ -14,8 +14,9 @@ | |||
| 14 | #include <QScreen> | 14 | #include <QScreen> |
| 15 | #include <QStringList> | 15 | #include <QStringList> |
| 16 | #include <QWindow> | 16 | #include <QWindow> |
| 17 | #ifdef HAS_VULKAN | 17 | |
| 18 | #include <QVulkanWindow> | 18 | #if !defined(WIN32) && HAS_VULKAN |
| 19 | #include <qpa/qplatformnativeinterface.h> | ||
| 19 | #endif | 20 | #endif |
| 20 | 21 | ||
| 21 | #include <fmt/format.h> | 22 | #include <fmt/format.h> |
| @@ -237,16 +238,50 @@ private: | |||
| 237 | #ifdef HAS_VULKAN | 238 | #ifdef HAS_VULKAN |
| 238 | class VulkanRenderWidget : public RenderWidget { | 239 | class VulkanRenderWidget : public RenderWidget { |
| 239 | public: | 240 | public: |
| 240 | explicit VulkanRenderWidget(GRenderWindow* parent, QVulkanInstance* instance) | 241 | explicit VulkanRenderWidget(GRenderWindow* parent) : RenderWidget(parent) { |
| 241 | : RenderWidget(parent) { | ||
| 242 | windowHandle()->setSurfaceType(QWindow::VulkanSurface); | 242 | windowHandle()->setSurfaceType(QWindow::VulkanSurface); |
| 243 | windowHandle()->setVulkanInstance(instance); | ||
| 244 | } | 243 | } |
| 245 | }; | 244 | }; |
| 246 | #endif | 245 | #endif |
| 247 | 246 | ||
| 248 | GRenderWindow::GRenderWindow(GMainWindow* parent_, EmuThread* emu_thread) | 247 | static Core::Frontend::WindowSystemType GetWindowSystemType() { |
| 249 | : QWidget(parent_), emu_thread(emu_thread) { | 248 | // Determine WSI type based on Qt platform. |
| 249 | QString platform_name = QGuiApplication::platformName(); | ||
| 250 | if (platform_name == QStringLiteral("windows")) | ||
| 251 | return Core::Frontend::WindowSystemType::Windows; | ||
| 252 | else if (platform_name == QStringLiteral("xcb")) | ||
| 253 | return Core::Frontend::WindowSystemType::X11; | ||
| 254 | else if (platform_name == QStringLiteral("wayland")) | ||
| 255 | return Core::Frontend::WindowSystemType::Wayland; | ||
| 256 | |||
| 257 | LOG_CRITICAL(Frontend, "Unknown Qt platform!"); | ||
| 258 | return Core::Frontend::WindowSystemType::Windows; | ||
| 259 | } | ||
| 260 | |||
| 261 | static Core::Frontend::EmuWindow::WindowSystemInfo GetWindowSystemInfo(QWindow* window) { | ||
| 262 | Core::Frontend::EmuWindow::WindowSystemInfo wsi; | ||
| 263 | wsi.type = GetWindowSystemType(); | ||
| 264 | |||
| 265 | #ifdef HAS_VULKAN | ||
| 266 | // Our Win32 Qt external doesn't have the private API. | ||
| 267 | #if defined(WIN32) || defined(__APPLE__) | ||
| 268 | wsi.render_surface = window ? reinterpret_cast<void*>(window->winId()) : nullptr; | ||
| 269 | #else | ||
| 270 | QPlatformNativeInterface* pni = QGuiApplication::platformNativeInterface(); | ||
| 271 | wsi.display_connection = pni->nativeResourceForWindow("display", window); | ||
| 272 | if (wsi.type == Core::Frontend::WindowSystemType::Wayland) | ||
| 273 | wsi.render_surface = window ? pni->nativeResourceForWindow("surface", window) : nullptr; | ||
| 274 | else | ||
| 275 | wsi.render_surface = window ? reinterpret_cast<void*>(window->winId()) : nullptr; | ||
| 276 | #endif | ||
| 277 | wsi.render_surface_scale = window ? static_cast<float>(window->devicePixelRatio()) : 1.0f; | ||
| 278 | #endif | ||
| 279 | |||
| 280 | return wsi; | ||
| 281 | } | ||
| 282 | |||
| 283 | GRenderWindow::GRenderWindow(GMainWindow* parent_, EmuThread* emu_thread_) | ||
| 284 | : QWidget(parent_), emu_thread(emu_thread_) { | ||
| 250 | setWindowTitle(QStringLiteral("yuzu %1 | %2-%3") | 285 | setWindowTitle(QStringLiteral("yuzu %1 | %2-%3") |
| 251 | .arg(QString::fromUtf8(Common::g_build_name), | 286 | .arg(QString::fromUtf8(Common::g_build_name), |
| 252 | QString::fromUtf8(Common::g_scm_branch), | 287 | QString::fromUtf8(Common::g_scm_branch), |
| @@ -459,6 +494,9 @@ bool GRenderWindow::InitRenderTarget() { | |||
| 459 | break; | 494 | break; |
| 460 | } | 495 | } |
| 461 | 496 | ||
| 497 | // Update the Window System information with the new render target | ||
| 498 | window_info = GetWindowSystemInfo(child_widget->windowHandle()); | ||
| 499 | |||
| 462 | child_widget->resize(Layout::ScreenUndocked::Width, Layout::ScreenUndocked::Height); | 500 | child_widget->resize(Layout::ScreenUndocked::Width, Layout::ScreenUndocked::Height); |
| 463 | layout()->addWidget(child_widget); | 501 | layout()->addWidget(child_widget); |
| 464 | // Reset minimum required size to avoid resizing issues on the main window after restarting. | 502 | // Reset minimum required size to avoid resizing issues on the main window after restarting. |
| @@ -530,30 +568,7 @@ bool GRenderWindow::InitializeOpenGL() { | |||
| 530 | 568 | ||
| 531 | bool GRenderWindow::InitializeVulkan() { | 569 | bool GRenderWindow::InitializeVulkan() { |
| 532 | #ifdef HAS_VULKAN | 570 | #ifdef HAS_VULKAN |
| 533 | vk_instance = std::make_unique<QVulkanInstance>(); | 571 | auto child = new VulkanRenderWidget(this); |
| 534 | vk_instance->setApiVersion(QVersionNumber(1, 1, 0)); | ||
| 535 | vk_instance->setFlags(QVulkanInstance::Flag::NoDebugOutputRedirect); | ||
| 536 | if (Settings::values.renderer_debug) { | ||
| 537 | const auto supported_layers{vk_instance->supportedLayers()}; | ||
| 538 | const bool found = | ||
| 539 | std::find_if(supported_layers.begin(), supported_layers.end(), [](const auto& layer) { | ||
| 540 | constexpr const char searched_layer[] = "VK_LAYER_LUNARG_standard_validation"; | ||
| 541 | return layer.name == searched_layer; | ||
| 542 | }); | ||
| 543 | if (found) { | ||
| 544 | vk_instance->setLayers(QByteArrayList() << "VK_LAYER_LUNARG_standard_validation"); | ||
| 545 | vk_instance->setExtensions(QByteArrayList() << VK_EXT_DEBUG_UTILS_EXTENSION_NAME); | ||
| 546 | } | ||
| 547 | } | ||
| 548 | if (!vk_instance->create()) { | ||
| 549 | QMessageBox::critical( | ||
| 550 | this, tr("Error while initializing Vulkan 1.1!"), | ||
| 551 | tr("Your OS doesn't seem to support Vulkan 1.1 instances, or you do not have the " | ||
| 552 | "latest graphics drivers.")); | ||
| 553 | return false; | ||
| 554 | } | ||
| 555 | |||
| 556 | auto child = new VulkanRenderWidget(this, vk_instance.get()); | ||
| 557 | child_widget = child; | 572 | child_widget = child; |
| 558 | child_widget->windowHandle()->create(); | 573 | child_widget->windowHandle()->create(); |
| 559 | main_context = std::make_unique<DummyContext>(); | 574 | main_context = std::make_unique<DummyContext>(); |
| @@ -566,21 +581,6 @@ bool GRenderWindow::InitializeVulkan() { | |||
| 566 | #endif | 581 | #endif |
| 567 | } | 582 | } |
| 568 | 583 | ||
| 569 | void GRenderWindow::RetrieveVulkanHandlers(void* get_instance_proc_addr, void* instance, | ||
| 570 | void* surface) const { | ||
| 571 | #ifdef HAS_VULKAN | ||
| 572 | const auto instance_proc_addr = vk_instance->getInstanceProcAddr("vkGetInstanceProcAddr"); | ||
| 573 | const VkInstance instance_copy = vk_instance->vkInstance(); | ||
| 574 | const VkSurfaceKHR surface_copy = vk_instance->surfaceForWindow(child_widget->windowHandle()); | ||
| 575 | |||
| 576 | std::memcpy(get_instance_proc_addr, &instance_proc_addr, sizeof(instance_proc_addr)); | ||
| 577 | std::memcpy(instance, &instance_copy, sizeof(instance_copy)); | ||
| 578 | std::memcpy(surface, &surface_copy, sizeof(surface_copy)); | ||
| 579 | #else | ||
| 580 | UNREACHABLE_MSG("Executing Vulkan code without compiling Vulkan"); | ||
| 581 | #endif | ||
| 582 | } | ||
| 583 | |||
| 584 | bool GRenderWindow::LoadOpenGL() { | 584 | bool GRenderWindow::LoadOpenGL() { |
| 585 | auto context = CreateSharedContext(); | 585 | auto context = CreateSharedContext(); |
| 586 | auto scope = context->Acquire(); | 586 | auto scope = context->Acquire(); |
diff --git a/src/yuzu/bootmanager.h b/src/yuzu/bootmanager.h index d69078df1..3626604ca 100644 --- a/src/yuzu/bootmanager.h +++ b/src/yuzu/bootmanager.h | |||
| @@ -22,9 +22,6 @@ class GMainWindow; | |||
| 22 | class QKeyEvent; | 22 | class QKeyEvent; |
| 23 | class QTouchEvent; | 23 | class QTouchEvent; |
| 24 | class QStringList; | 24 | class QStringList; |
| 25 | #ifdef HAS_VULKAN | ||
| 26 | class QVulkanInstance; | ||
| 27 | #endif | ||
| 28 | 25 | ||
| 29 | namespace VideoCore { | 26 | namespace VideoCore { |
| 30 | enum class LoadCallbackStage; | 27 | enum class LoadCallbackStage; |
| @@ -122,8 +119,6 @@ public: | |||
| 122 | // EmuWindow implementation. | 119 | // EmuWindow implementation. |
| 123 | void PollEvents() override; | 120 | void PollEvents() override; |
| 124 | bool IsShown() const override; | 121 | bool IsShown() const override; |
| 125 | void RetrieveVulkanHandlers(void* get_instance_proc_addr, void* instance, | ||
| 126 | void* surface) const override; | ||
| 127 | std::unique_ptr<Core::Frontend::GraphicsContext> CreateSharedContext() const override; | 122 | std::unique_ptr<Core::Frontend::GraphicsContext> CreateSharedContext() const override; |
| 128 | 123 | ||
| 129 | void BackupGeometry(); | 124 | void BackupGeometry(); |
| @@ -186,10 +181,6 @@ private: | |||
| 186 | // should instead be shared from | 181 | // should instead be shared from |
| 187 | std::shared_ptr<Core::Frontend::GraphicsContext> main_context; | 182 | std::shared_ptr<Core::Frontend::GraphicsContext> main_context; |
| 188 | 183 | ||
| 189 | #ifdef HAS_VULKAN | ||
| 190 | std::unique_ptr<QVulkanInstance> vk_instance; | ||
| 191 | #endif | ||
| 192 | |||
| 193 | /// Temporary storage of the screenshot taken | 184 | /// Temporary storage of the screenshot taken |
| 194 | QImage screenshot_image; | 185 | QImage screenshot_image; |
| 195 | 186 | ||
diff --git a/src/yuzu/configuration/configure_graphics.cpp b/src/yuzu/configuration/configure_graphics.cpp index a821c7b3c..ea667caef 100644 --- a/src/yuzu/configuration/configure_graphics.cpp +++ b/src/yuzu/configuration/configure_graphics.cpp | |||
| @@ -15,6 +15,10 @@ | |||
| 15 | #include "ui_configure_graphics.h" | 15 | #include "ui_configure_graphics.h" |
| 16 | #include "yuzu/configuration/configure_graphics.h" | 16 | #include "yuzu/configuration/configure_graphics.h" |
| 17 | 17 | ||
| 18 | #ifdef HAS_VULKAN | ||
| 19 | #include "video_core/renderer_vulkan/renderer_vulkan.h" | ||
| 20 | #endif | ||
| 21 | |||
| 18 | namespace { | 22 | namespace { |
| 19 | enum class Resolution : int { | 23 | enum class Resolution : int { |
| 20 | Auto, | 24 | Auto, |
| @@ -165,41 +169,9 @@ void ConfigureGraphics::UpdateDeviceComboBox() { | |||
| 165 | 169 | ||
| 166 | void ConfigureGraphics::RetrieveVulkanDevices() { | 170 | void ConfigureGraphics::RetrieveVulkanDevices() { |
| 167 | #ifdef HAS_VULKAN | 171 | #ifdef HAS_VULKAN |
| 168 | QVulkanInstance instance; | 172 | vulkan_devices.clear(); |
| 169 | instance.setApiVersion(QVersionNumber(1, 1, 0)); | 173 | for (auto& name : Vulkan::RendererVulkan::EnumerateDevices()) { |
| 170 | if (!instance.create()) { | 174 | vulkan_devices.push_back(QString::fromStdString(name)); |
| 171 | LOG_INFO(Frontend, "Vulkan 1.1 not available"); | ||
| 172 | return; | ||
| 173 | } | ||
| 174 | const auto vkEnumeratePhysicalDevices{reinterpret_cast<PFN_vkEnumeratePhysicalDevices>( | ||
| 175 | instance.getInstanceProcAddr("vkEnumeratePhysicalDevices"))}; | ||
| 176 | if (vkEnumeratePhysicalDevices == nullptr) { | ||
| 177 | LOG_INFO(Frontend, "Failed to get pointer to vkEnumeratePhysicalDevices"); | ||
| 178 | return; | ||
| 179 | } | ||
| 180 | u32 physical_device_count; | ||
| 181 | if (vkEnumeratePhysicalDevices(instance.vkInstance(), &physical_device_count, nullptr) != | ||
| 182 | VK_SUCCESS) { | ||
| 183 | LOG_INFO(Frontend, "Failed to get physical devices count"); | ||
| 184 | return; | ||
| 185 | } | ||
| 186 | std::vector<VkPhysicalDevice> physical_devices(physical_device_count); | ||
| 187 | if (vkEnumeratePhysicalDevices(instance.vkInstance(), &physical_device_count, | ||
| 188 | physical_devices.data()) != VK_SUCCESS) { | ||
| 189 | LOG_INFO(Frontend, "Failed to get physical devices"); | ||
| 190 | return; | ||
| 191 | } | ||
| 192 | |||
| 193 | const auto vkGetPhysicalDeviceProperties{reinterpret_cast<PFN_vkGetPhysicalDeviceProperties>( | ||
| 194 | instance.getInstanceProcAddr("vkGetPhysicalDeviceProperties"))}; | ||
| 195 | if (vkGetPhysicalDeviceProperties == nullptr) { | ||
| 196 | LOG_INFO(Frontend, "Failed to get pointer to vkGetPhysicalDeviceProperties"); | ||
| 197 | return; | ||
| 198 | } | ||
| 199 | for (const auto physical_device : physical_devices) { | ||
| 200 | VkPhysicalDeviceProperties properties; | ||
| 201 | vkGetPhysicalDeviceProperties(physical_device, &properties); | ||
| 202 | vulkan_devices.push_back(QString::fromUtf8(properties.deviceName)); | ||
| 203 | } | 175 | } |
| 204 | #endif | 176 | #endif |
| 205 | } | 177 | } |
diff --git a/src/yuzu/game_list.cpp b/src/yuzu/game_list.cpp index a2b88c787..dccbabcbf 100644 --- a/src/yuzu/game_list.cpp +++ b/src/yuzu/game_list.cpp | |||
| @@ -315,7 +315,7 @@ GameList::GameList(FileSys::VirtualFilesystem vfs, FileSys::ManualContentProvide | |||
| 315 | item_model->setHeaderData(COLUMN_FILE_TYPE - 1, Qt::Horizontal, tr("File type")); | 315 | item_model->setHeaderData(COLUMN_FILE_TYPE - 1, Qt::Horizontal, tr("File type")); |
| 316 | item_model->setHeaderData(COLUMN_SIZE - 1, Qt::Horizontal, tr("Size")); | 316 | item_model->setHeaderData(COLUMN_SIZE - 1, Qt::Horizontal, tr("Size")); |
| 317 | } | 317 | } |
| 318 | item_model->setSortRole(GameListItemPath::TitleRole); | 318 | item_model->setSortRole(GameListItemPath::SortRole); |
| 319 | 319 | ||
| 320 | connect(main_window, &GMainWindow::UpdateThemedIcons, this, &GameList::onUpdateThemedIcons); | 320 | connect(main_window, &GMainWindow::UpdateThemedIcons, this, &GameList::onUpdateThemedIcons); |
| 321 | connect(tree_view, &QTreeView::activated, this, &GameList::ValidateEntry); | 321 | connect(tree_view, &QTreeView::activated, this, &GameList::ValidateEntry); |
| @@ -441,6 +441,8 @@ void GameList::DonePopulating(QStringList watch_list) { | |||
| 441 | if (children_total > 0) { | 441 | if (children_total > 0) { |
| 442 | search_field->setFocus(); | 442 | search_field->setFocus(); |
| 443 | } | 443 | } |
| 444 | item_model->sort(tree_view->header()->sortIndicatorSection(), | ||
| 445 | tree_view->header()->sortIndicatorOrder()); | ||
| 444 | } | 446 | } |
| 445 | 447 | ||
| 446 | void GameList::PopupContextMenu(const QPoint& menu_location) { | 448 | void GameList::PopupContextMenu(const QPoint& menu_location) { |
| @@ -666,8 +668,6 @@ void GameList::LoadInterfaceLayout() { | |||
| 666 | // so make it as large as possible as default. | 668 | // so make it as large as possible as default. |
| 667 | header->resizeSection(COLUMN_NAME, header->width()); | 669 | header->resizeSection(COLUMN_NAME, header->width()); |
| 668 | } | 670 | } |
| 669 | |||
| 670 | item_model->sort(header->sortIndicatorSection(), header->sortIndicatorOrder()); | ||
| 671 | } | 671 | } |
| 672 | 672 | ||
| 673 | const QStringList GameList::supported_file_extensions = { | 673 | const QStringList GameList::supported_file_extensions = { |
diff --git a/src/yuzu/game_list_p.h b/src/yuzu/game_list_p.h index 7cde72d1b..3e6d5a7cd 100644 --- a/src/yuzu/game_list_p.h +++ b/src/yuzu/game_list_p.h | |||
| @@ -65,10 +65,10 @@ public: | |||
| 65 | */ | 65 | */ |
| 66 | class GameListItemPath : public GameListItem { | 66 | class GameListItemPath : public GameListItem { |
| 67 | public: | 67 | public: |
| 68 | static const int TitleRole = SortRole; | 68 | static const int TitleRole = SortRole + 1; |
| 69 | static const int FullPathRole = SortRole + 1; | 69 | static const int FullPathRole = SortRole + 2; |
| 70 | static const int ProgramIdRole = SortRole + 2; | 70 | static const int ProgramIdRole = SortRole + 3; |
| 71 | static const int FileTypeRole = SortRole + 3; | 71 | static const int FileTypeRole = SortRole + 4; |
| 72 | 72 | ||
| 73 | GameListItemPath() = default; | 73 | GameListItemPath() = default; |
| 74 | GameListItemPath(const QString& game_path, const std::vector<u8>& picture_data, | 74 | GameListItemPath(const QString& game_path, const std::vector<u8>& picture_data, |
| @@ -95,7 +95,7 @@ public: | |||
| 95 | } | 95 | } |
| 96 | 96 | ||
| 97 | QVariant data(int role) const override { | 97 | QVariant data(int role) const override { |
| 98 | if (role == Qt::DisplayRole) { | 98 | if (role == Qt::DisplayRole || role == SortRole) { |
| 99 | std::string filename; | 99 | std::string filename; |
| 100 | Common::SplitPath(data(FullPathRole).toString().toStdString(), nullptr, &filename, | 100 | Common::SplitPath(data(FullPathRole).toString().toStdString(), nullptr, &filename, |
| 101 | nullptr); | 101 | nullptr); |
| @@ -110,6 +110,9 @@ public: | |||
| 110 | const auto& row1 = row_data.at(UISettings::values.row_1_text_id); | 110 | const auto& row1 = row_data.at(UISettings::values.row_1_text_id); |
| 111 | const int row2_id = UISettings::values.row_2_text_id; | 111 | const int row2_id = UISettings::values.row_2_text_id; |
| 112 | 112 | ||
| 113 | if (role == SortRole) | ||
| 114 | return row1.toLower(); | ||
| 115 | |||
| 113 | if (row2_id == 4) // None | 116 | if (row2_id == 4) // None |
| 114 | return row1; | 117 | return row1; |
| 115 | 118 | ||
| @@ -123,6 +126,13 @@ public: | |||
| 123 | 126 | ||
| 124 | return GameListItem::data(role); | 127 | return GameListItem::data(role); |
| 125 | } | 128 | } |
| 129 | |||
| 130 | /** | ||
| 131 | * Override to prevent automatic sorting. | ||
| 132 | */ | ||
| 133 | bool operator<(const QStandardItem& other) const override { | ||
| 134 | return false; | ||
| 135 | } | ||
| 126 | }; | 136 | }; |
| 127 | 137 | ||
| 128 | class GameListItemCompat : public GameListItem { | 138 | class GameListItemCompat : public GameListItem { |
| @@ -289,6 +299,10 @@ public: | |||
| 289 | int type() const override { | 299 | int type() const override { |
| 290 | return static_cast<int>(GameListItemType::AddDir); | 300 | return static_cast<int>(GameListItemType::AddDir); |
| 291 | } | 301 | } |
| 302 | |||
| 303 | bool operator<(const QStandardItem& other) const override { | ||
| 304 | return false; | ||
| 305 | } | ||
| 292 | }; | 306 | }; |
| 293 | 307 | ||
| 294 | class GameList; | 308 | class GameList; |
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 | }; |
diff --git a/src/yuzu_tester/emu_window/emu_window_sdl2_hide.cpp b/src/yuzu_tester/emu_window/emu_window_sdl2_hide.cpp index a837430cc..8584f6671 100644 --- a/src/yuzu_tester/emu_window/emu_window_sdl2_hide.cpp +++ b/src/yuzu_tester/emu_window/emu_window_sdl2_hide.cpp | |||
| @@ -116,10 +116,6 @@ bool EmuWindow_SDL2_Hide::IsShown() const { | |||
| 116 | return false; | 116 | return false; |
| 117 | } | 117 | } |
| 118 | 118 | ||
| 119 | void EmuWindow_SDL2_Hide::RetrieveVulkanHandlers(void*, void*, void*) const { | ||
| 120 | UNREACHABLE(); | ||
| 121 | } | ||
| 122 | |||
| 123 | class SDLGLContext : public Core::Frontend::GraphicsContext { | 119 | class SDLGLContext : public Core::Frontend::GraphicsContext { |
| 124 | public: | 120 | public: |
| 125 | explicit SDLGLContext() { | 121 | explicit SDLGLContext() { |
diff --git a/src/yuzu_tester/emu_window/emu_window_sdl2_hide.h b/src/yuzu_tester/emu_window/emu_window_sdl2_hide.h index 9f5d04fca..c13a82df2 100644 --- a/src/yuzu_tester/emu_window/emu_window_sdl2_hide.h +++ b/src/yuzu_tester/emu_window/emu_window_sdl2_hide.h | |||
| @@ -19,10 +19,6 @@ public: | |||
| 19 | /// Whether the screen is being shown or not. | 19 | /// Whether the screen is being shown or not. |
| 20 | bool IsShown() const override; | 20 | bool IsShown() const override; |
| 21 | 21 | ||
| 22 | /// Retrieves Vulkan specific handlers from the window | ||
| 23 | void RetrieveVulkanHandlers(void* get_instance_proc_addr, void* instance, | ||
| 24 | void* surface) const override; | ||
| 25 | |||
| 26 | std::unique_ptr<Core::Frontend::GraphicsContext> CreateSharedContext() const override; | 22 | std::unique_ptr<Core::Frontend::GraphicsContext> CreateSharedContext() const override; |
| 27 | 23 | ||
| 28 | private: | 24 | private: |