diff options
Diffstat (limited to 'src/video_core')
| -rw-r--r-- | src/video_core/renderer_vulkan/declarations.h | 1 | ||||
| -rw-r--r-- | src/video_core/renderer_vulkan/renderer_vulkan.cpp | 213 | ||||
| -rw-r--r-- | src/video_core/renderer_vulkan/renderer_vulkan.h | 16 | ||||
| -rw-r--r-- | src/video_core/renderer_vulkan/vk_device.cpp | 92 | ||||
| -rw-r--r-- | src/video_core/renderer_vulkan/vk_device.h | 21 |
5 files changed, 238 insertions, 105 deletions
diff --git a/src/video_core/renderer_vulkan/declarations.h b/src/video_core/renderer_vulkan/declarations.h index d2a1140c1..89a035ca4 100644 --- a/src/video_core/renderer_vulkan/declarations.h +++ b/src/video_core/renderer_vulkan/declarations.h | |||
| @@ -51,6 +51,7 @@ using UniqueSampler = UniqueHandle<vk::Sampler>; | |||
| 51 | using UniqueSamplerYcbcrConversion = UniqueHandle<vk::SamplerYcbcrConversion>; | 51 | using UniqueSamplerYcbcrConversion = UniqueHandle<vk::SamplerYcbcrConversion>; |
| 52 | using UniqueSemaphore = UniqueHandle<vk::Semaphore>; | 52 | using UniqueSemaphore = UniqueHandle<vk::Semaphore>; |
| 53 | using UniqueShaderModule = UniqueHandle<vk::ShaderModule>; | 53 | using UniqueShaderModule = UniqueHandle<vk::ShaderModule>; |
| 54 | using UniqueSurfaceKHR = UniqueHandle<vk::SurfaceKHR>; | ||
| 54 | using UniqueSwapchainKHR = UniqueHandle<vk::SwapchainKHR>; | 55 | using UniqueSwapchainKHR = UniqueHandle<vk::SwapchainKHR>; |
| 55 | using UniqueValidationCacheEXT = UniqueHandle<vk::ValidationCacheEXT>; | 56 | using UniqueValidationCacheEXT = UniqueHandle<vk::ValidationCacheEXT>; |
| 56 | 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 9c323a1aa..9cdb4b627 100644 --- a/src/video_core/renderer_vulkan/renderer_vulkan.cpp +++ b/src/video_core/renderer_vulkan/renderer_vulkan.cpp | |||
| @@ -2,8 +2,12 @@ | |||
| 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> |
| @@ -31,15 +35,30 @@ | |||
| 31 | #include "video_core/renderer_vulkan/vk_state_tracker.h" | 35 | #include "video_core/renderer_vulkan/vk_state_tracker.h" |
| 32 | #include "video_core/renderer_vulkan/vk_swapchain.h" | 36 | #include "video_core/renderer_vulkan/vk_swapchain.h" |
| 33 | 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 | |||
| 34 | namespace Vulkan { | 51 | namespace Vulkan { |
| 35 | 52 | ||
| 36 | namespace { | 53 | namespace { |
| 37 | 54 | ||
| 55 | using Core::Frontend::WindowSystemType; | ||
| 56 | |||
| 38 | VkBool32 DebugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT severity_, | 57 | VkBool32 DebugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT severity_, |
| 39 | VkDebugUtilsMessageTypeFlagsEXT type, | 58 | VkDebugUtilsMessageTypeFlagsEXT type, |
| 40 | const VkDebugUtilsMessengerCallbackDataEXT* data, | 59 | const VkDebugUtilsMessengerCallbackDataEXT* data, |
| 41 | [[maybe_unused]] void* user_data) { | 60 | [[maybe_unused]] void* user_data) { |
| 42 | const vk::DebugUtilsMessageSeverityFlagBitsEXT severity{severity_}; | 61 | const auto severity{static_cast<vk::DebugUtilsMessageSeverityFlagBitsEXT>(severity_)}; |
| 43 | const char* message{data->pMessage}; | 62 | const char* message{data->pMessage}; |
| 44 | 63 | ||
| 45 | if (severity & vk::DebugUtilsMessageSeverityFlagBitsEXT::eError) { | 64 | if (severity & vk::DebugUtilsMessageSeverityFlagBitsEXT::eError) { |
| @@ -75,21 +94,86 @@ Common::DynamicLibrary OpenVulkanLibrary() { | |||
| 75 | return library; | 94 | return library; |
| 76 | } | 95 | } |
| 77 | 96 | ||
| 78 | UniqueInstance CreateInstance(Common::DynamicLibrary& library, vk::DispatchLoaderDynamic& dld) { | 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 | } | ||
| 79 | PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr; | 104 | PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr; |
| 80 | if (!library.GetSymbol("vkGetInstanceProcAddr", &vkGetInstanceProcAddr)) { | 105 | if (!library.GetSymbol("vkGetInstanceProcAddr", &vkGetInstanceProcAddr)) { |
| 106 | LOG_ERROR(Render_Vulkan, "vkGetInstanceProcAddr not present in Vulkan"); | ||
| 81 | return UniqueInstance{}; | 107 | return UniqueInstance{}; |
| 82 | } | 108 | } |
| 83 | dld.init(vkGetInstanceProcAddr); | 109 | dld.init(vkGetInstanceProcAddr); |
| 84 | 110 | ||
| 85 | const vk::ApplicationInfo application_info("yuzu", VK_MAKE_VERSION(0, 1, 0), "yuzu", | 111 | std::vector<const char*> extensions; |
| 86 | VK_MAKE_VERSION(0, 1, 0), VK_API_VERSION_1_1); | 112 | extensions.reserve(4); |
| 87 | const vk::InstanceCreateInfo instance_ci({}, &application_info, 0, nullptr, 0, nullptr); | 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()); | ||
| 88 | vk::Instance unsafe_instance; | 171 | vk::Instance unsafe_instance; |
| 89 | if (vk::createInstance(&instance_ci, nullptr, &unsafe_instance, dld) != vk::Result::eSuccess) { | 172 | if (vk::createInstance(&instance_ci, nullptr, &unsafe_instance, dld) != vk::Result::eSuccess) { |
| 173 | LOG_ERROR(Render_Vulkan, "Failed to create Vulkan instance"); | ||
| 90 | return UniqueInstance{}; | 174 | return UniqueInstance{}; |
| 91 | } | 175 | } |
| 92 | dld.init(unsafe_instance, vkGetInstanceProcAddr); | 176 | dld.init(unsafe_instance); |
| 93 | return UniqueInstance(unsafe_instance, {nullptr, dld}); | 177 | return UniqueInstance(unsafe_instance, {nullptr, dld}); |
| 94 | } | 178 | } |
| 95 | 179 | ||
| @@ -187,27 +271,12 @@ bool RendererVulkan::TryPresent(int /*timeout_ms*/) { | |||
| 187 | } | 271 | } |
| 188 | 272 | ||
| 189 | bool RendererVulkan::Init() { | 273 | bool RendererVulkan::Init() { |
| 190 | PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr{}; | 274 | library = OpenVulkanLibrary(); |
| 191 | render_window.RetrieveVulkanHandlers(&vkGetInstanceProcAddr, &instance, &surface); | 275 | instance = CreateInstance(library, dld, render_window.GetWindowInfo().type, |
| 192 | const vk::DispatchLoaderDynamic dldi(instance, vkGetInstanceProcAddr); | 276 | Settings::values.renderer_debug); |
| 193 | 277 | if (!instance || !CreateDebugCallback() || !CreateSurface() || !PickDevices()) { | |
| 194 | std::optional<vk::DebugUtilsMessengerEXT> callback; | ||
| 195 | if (Settings::values.renderer_debug && dldi.vkCreateDebugUtilsMessengerEXT) { | ||
| 196 | callback = CreateDebugCallback(dldi); | ||
| 197 | if (!callback) { | ||
| 198 | return false; | ||
| 199 | } | ||
| 200 | } | ||
| 201 | |||
| 202 | if (!PickDevices(dldi)) { | ||
| 203 | if (callback) { | ||
| 204 | instance.destroy(*callback, nullptr, dldi); | ||
| 205 | } | ||
| 206 | return false; | 278 | return false; |
| 207 | } | 279 | } |
| 208 | debug_callback = UniqueDebugUtilsMessengerEXT( | ||
| 209 | *callback, vk::ObjectDestroy<vk::Instance, vk::DispatchLoaderDynamic>( | ||
| 210 | instance, nullptr, device->GetDispatchLoader())); | ||
| 211 | 280 | ||
| 212 | Report(); | 281 | Report(); |
| 213 | 282 | ||
| @@ -216,7 +285,7 @@ bool RendererVulkan::Init() { | |||
| 216 | resource_manager = std::make_unique<VKResourceManager>(*device); | 285 | resource_manager = std::make_unique<VKResourceManager>(*device); |
| 217 | 286 | ||
| 218 | const auto& framebuffer = render_window.GetFramebufferLayout(); | 287 | const auto& framebuffer = render_window.GetFramebufferLayout(); |
| 219 | swapchain = std::make_unique<VKSwapchain>(surface, *device); | 288 | swapchain = std::make_unique<VKSwapchain>(*surface, *device); |
| 220 | swapchain->Create(framebuffer.width, framebuffer.height, false); | 289 | swapchain->Create(framebuffer.width, framebuffer.height, false); |
| 221 | 290 | ||
| 222 | state_tracker = std::make_unique<StateTracker>(system); | 291 | state_tracker = std::make_unique<StateTracker>(system); |
| @@ -253,8 +322,10 @@ void RendererVulkan::ShutDown() { | |||
| 253 | device.reset(); | 322 | device.reset(); |
| 254 | } | 323 | } |
| 255 | 324 | ||
| 256 | std::optional<vk::DebugUtilsMessengerEXT> RendererVulkan::CreateDebugCallback( | 325 | bool RendererVulkan::CreateDebugCallback() { |
| 257 | const vk::DispatchLoaderDynamic& dldi) { | 326 | if (!Settings::values.renderer_debug) { |
| 327 | return true; | ||
| 328 | } | ||
| 258 | const vk::DebugUtilsMessengerCreateInfoEXT callback_ci( | 329 | const vk::DebugUtilsMessengerCreateInfoEXT callback_ci( |
| 259 | {}, | 330 | {}, |
| 260 | vk::DebugUtilsMessageSeverityFlagBitsEXT::eError | | 331 | vk::DebugUtilsMessageSeverityFlagBitsEXT::eError | |
| @@ -265,32 +336,88 @@ std::optional<vk::DebugUtilsMessengerEXT> RendererVulkan::CreateDebugCallback( | |||
| 265 | vk::DebugUtilsMessageTypeFlagBitsEXT::eValidation | | 336 | vk::DebugUtilsMessageTypeFlagBitsEXT::eValidation | |
| 266 | vk::DebugUtilsMessageTypeFlagBitsEXT::ePerformance, | 337 | vk::DebugUtilsMessageTypeFlagBitsEXT::ePerformance, |
| 267 | &DebugCallback, nullptr); | 338 | &DebugCallback, nullptr); |
| 268 | vk::DebugUtilsMessengerEXT callback; | 339 | vk::DebugUtilsMessengerEXT unsafe_callback; |
| 269 | if (instance.createDebugUtilsMessengerEXT(&callback_ci, nullptr, &callback, dldi) != | 340 | if (instance->createDebugUtilsMessengerEXT(&callback_ci, nullptr, &unsafe_callback, dld) != |
| 270 | vk::Result::eSuccess) { | 341 | vk::Result::eSuccess) { |
| 271 | LOG_ERROR(Render_Vulkan, "Failed to create debug callback"); | 342 | LOG_ERROR(Render_Vulkan, "Failed to create debug callback"); |
| 272 | 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; | ||
| 273 | } | 399 | } |
| 274 | return callback; | 400 | |
| 401 | surface = UniqueSurfaceKHR(unsafe_surface, {*instance, nullptr, dld}); | ||
| 402 | return true; | ||
| 275 | } | 403 | } |
| 276 | 404 | ||
| 277 | bool RendererVulkan::PickDevices(const vk::DispatchLoaderDynamic& dldi) { | 405 | bool RendererVulkan::PickDevices() { |
| 278 | const auto devices = instance.enumeratePhysicalDevices(dldi); | 406 | const auto devices = instance->enumeratePhysicalDevices(dld); |
| 279 | 407 | ||
| 280 | // TODO(Rodrigo): Choose device from config file | ||
| 281 | const s32 device_index = Settings::values.vulkan_device; | 408 | const s32 device_index = Settings::values.vulkan_device; |
| 282 | if (device_index < 0 || device_index >= static_cast<s32>(devices.size())) { | 409 | if (device_index < 0 || device_index >= static_cast<s32>(devices.size())) { |
| 283 | LOG_ERROR(Render_Vulkan, "Invalid device index {}!", device_index); | 410 | LOG_ERROR(Render_Vulkan, "Invalid device index {}!", device_index); |
| 284 | return false; | 411 | return false; |
| 285 | } | 412 | } |
| 286 | const vk::PhysicalDevice physical_device = devices[device_index]; | 413 | const vk::PhysicalDevice physical_device = devices[static_cast<std::size_t>(device_index)]; |
| 287 | 414 | ||
| 288 | if (!VKDevice::IsSuitable(dldi, physical_device, surface)) { | 415 | if (!VKDevice::IsSuitable(physical_device, *surface, dld)) { |
| 289 | return false; | 416 | return false; |
| 290 | } | 417 | } |
| 291 | 418 | ||
| 292 | device = std::make_unique<VKDevice>(dldi, physical_device, surface); | 419 | device = std::make_unique<VKDevice>(dld, physical_device, *surface); |
| 293 | return device->Create(dldi, instance); | 420 | return device->Create(*instance); |
| 294 | } | 421 | } |
| 295 | 422 | ||
| 296 | void RendererVulkan::Report() const { | 423 | void RendererVulkan::Report() const { |
| @@ -317,11 +444,11 @@ void RendererVulkan::Report() const { | |||
| 317 | } | 444 | } |
| 318 | 445 | ||
| 319 | std::vector<std::string> RendererVulkan::EnumerateDevices() { | 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 | |||
| 320 | Common::DynamicLibrary library = OpenVulkanLibrary(); | 451 | Common::DynamicLibrary library = OpenVulkanLibrary(); |
| 321 | if (!library.IsOpen()) { | ||
| 322 | return {}; | ||
| 323 | } | ||
| 324 | vk::DispatchLoaderDynamic dld; | ||
| 325 | UniqueInstance instance = CreateInstance(library, dld); | 452 | UniqueInstance instance = CreateInstance(library, dld); |
| 326 | if (!instance) { | 453 | if (!instance) { |
| 327 | return {}; | 454 | return {}; |
diff --git a/src/video_core/renderer_vulkan/renderer_vulkan.h b/src/video_core/renderer_vulkan/renderer_vulkan.h index 7a17c546d..42e253de5 100644 --- a/src/video_core/renderer_vulkan/renderer_vulkan.h +++ b/src/video_core/renderer_vulkan/renderer_vulkan.h | |||
| @@ -9,6 +9,8 @@ | |||
| 9 | #include <string> | 9 | #include <string> |
| 10 | #include <vector> | 10 | #include <vector> |
| 11 | 11 | ||
| 12 | #include "common/dynamic_library.h" | ||
| 13 | |||
| 12 | #include "video_core/renderer_base.h" | 14 | #include "video_core/renderer_base.h" |
| 13 | #include "video_core/renderer_vulkan/declarations.h" | 15 | #include "video_core/renderer_vulkan/declarations.h" |
| 14 | 16 | ||
| @@ -48,17 +50,21 @@ public: | |||
| 48 | static std::vector<std::string> EnumerateDevices(); | 50 | static std::vector<std::string> EnumerateDevices(); |
| 49 | 51 | ||
| 50 | private: | 52 | private: |
| 51 | std::optional<vk::DebugUtilsMessengerEXT> CreateDebugCallback( | 53 | bool CreateDebugCallback(); |
| 52 | const vk::DispatchLoaderDynamic& dldi); | 54 | |
| 55 | bool CreateSurface(); | ||
| 53 | 56 | ||
| 54 | bool PickDevices(const vk::DispatchLoaderDynamic& dldi); | 57 | bool PickDevices(); |
| 55 | 58 | ||
| 56 | void Report() const; | 59 | void Report() const; |
| 57 | 60 | ||
| 58 | Core::System& system; | 61 | Core::System& system; |
| 59 | 62 | ||
| 60 | vk::Instance instance; | 63 | Common::DynamicLibrary library; |
| 61 | vk::SurfaceKHR surface; | 64 | vk::DispatchLoaderDynamic dld; |
| 65 | |||
| 66 | UniqueInstance instance; | ||
| 67 | UniqueSurfaceKHR surface; | ||
| 62 | 68 | ||
| 63 | VKScreenInfo screen_info; | 69 | VKScreenInfo screen_info; |
| 64 | 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. |