summaryrefslogtreecommitdiff
path: root/Source/Core/VideoBackends/Vulkan/SwapChain.cpp
diff options
context:
space:
mode:
authorConnor McLaughlin <stenzek@gmail.com>2019-02-16 14:15:00 +1000
committerGitHub <noreply@github.com>2019-02-16 14:15:00 +1000
commitb5c3881fe703287c4f883ca42a3b931bb6594854 (patch)
tree29daf45582fa2860c76127271457675184341900 /Source/Core/VideoBackends/Vulkan/SwapChain.cpp
parentc41f32bcf8fe0c04d54d3541df210a604b2399d1 (diff)
parenteabde77892faf4408481f685f2fbf1b348232d5f (diff)
Merge pull request #7512 from stenzek/runtime-headless
DolphinNoGUI: Runtime selection of platform
Diffstat (limited to 'Source/Core/VideoBackends/Vulkan/SwapChain.cpp')
-rw-r--r--Source/Core/VideoBackends/Vulkan/SwapChain.cpp172
1 files changed, 79 insertions, 93 deletions
diff --git a/Source/Core/VideoBackends/Vulkan/SwapChain.cpp b/Source/Core/VideoBackends/Vulkan/SwapChain.cpp
index 2759a59283..94cd0ade67 100644
--- a/Source/Core/VideoBackends/Vulkan/SwapChain.cpp
+++ b/Source/Core/VideoBackends/Vulkan/SwapChain.cpp
@@ -18,16 +18,12 @@
#if defined(VK_USE_PLATFORM_XLIB_KHR)
#include <X11/Xlib.h>
-#elif defined(VK_USE_PLATFORM_XCB_KHR)
-#include <X11/Xlib-xcb.h>
-#include <X11/Xlib.h>
#endif
namespace Vulkan
{
-SwapChain::SwapChain(void* display_handle, void* native_handle, VkSurfaceKHR surface, bool vsync)
- : m_display_handle(display_handle), m_native_handle(native_handle), m_surface(surface),
- m_vsync_enabled(vsync)
+SwapChain::SwapChain(const WindowSystemInfo& wsi, VkSurfaceKHR surface, bool vsync)
+ : m_wsi(wsi), m_surface(surface), m_vsync_enabled(vsync)
{
}
@@ -39,110 +35,101 @@ SwapChain::~SwapChain()
DestroySemaphores();
}
-VkSurfaceKHR SwapChain::CreateVulkanSurface(VkInstance instance, void* display_handle, void* hwnd)
+VkSurfaceKHR SwapChain::CreateVulkanSurface(VkInstance instance, const WindowSystemInfo& wsi)
{
#if defined(VK_USE_PLATFORM_WIN32_KHR)
- VkWin32SurfaceCreateInfoKHR surface_create_info = {
- VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR, // VkStructureType sType
- nullptr, // const void* pNext
- 0, // VkWin32SurfaceCreateFlagsKHR flags
- nullptr, // HINSTANCE hinstance
- reinterpret_cast<HWND>(hwnd) // HWND hwnd
- };
-
- VkSurfaceKHR surface;
- VkResult res = vkCreateWin32SurfaceKHR(instance, &surface_create_info, nullptr, &surface);
- if (res != VK_SUCCESS)
+ if (wsi.type == WindowSystemType::Windows)
{
- LOG_VULKAN_ERROR(res, "vkCreateWin32SurfaceKHR failed: ");
- return VK_NULL_HANDLE;
- }
-
- return surface;
-
-#elif defined(VK_USE_PLATFORM_XLIB_KHR)
- VkXlibSurfaceCreateInfoKHR surface_create_info = {
- VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR, // VkStructureType sType
- nullptr, // const void* pNext
- 0, // VkXlibSurfaceCreateFlagsKHR flags
- static_cast<Display*>(display_handle), // Display* dpy
- reinterpret_cast<Window>(hwnd) // Window window
- };
+ VkWin32SurfaceCreateInfoKHR surface_create_info = {
+ VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR, // VkStructureType sType
+ nullptr, // const void* pNext
+ 0, // VkWin32SurfaceCreateFlagsKHR flags
+ nullptr, // HINSTANCE hinstance
+ reinterpret_cast<HWND>(wsi.render_surface) // HWND hwnd
+ };
+
+ VkSurfaceKHR surface;
+ VkResult res = vkCreateWin32SurfaceKHR(instance, &surface_create_info, nullptr, &surface);
+ if (res != VK_SUCCESS)
+ {
+ LOG_VULKAN_ERROR(res, "vkCreateWin32SurfaceKHR failed: ");
+ return VK_NULL_HANDLE;
+ }
- VkSurfaceKHR surface;
- VkResult res = vkCreateXlibSurfaceKHR(instance, &surface_create_info, nullptr, &surface);
- if (res != VK_SUCCESS)
- {
- LOG_VULKAN_ERROR(res, "vkCreateXlibSurfaceKHR failed: ");
- return VK_NULL_HANDLE;
+ return surface;
}
+#endif
- return surface;
-
-#elif defined(VK_USE_PLATFORM_XCB_KHR)
- // If we ever switch to using xcb, we should pass the display handle as well.
- xcb_connection_t* connection = XGetXCBConnection(display_handle);
-
- VkXcbSurfaceCreateInfoKHR surface_create_info = {
- VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR, // VkStructureType sType
- nullptr, // const void* pNext
- 0, // VkXcbSurfaceCreateFlagsKHR flags
- connection, // xcb_connection_t* connection
- static_cast<xcb_window_t>(reinterpret_cast<uintptr_t>(hwnd)) // xcb_window_t window
- };
-
- VkSurfaceKHR surface;
- VkResult res = vkCreateXcbSurfaceKHR(instance, &surface_create_info, nullptr, &surface);
- if (res != VK_SUCCESS)
+#if defined(VK_USE_PLATFORM_XLIB_KHR)
+ if (wsi.type == WindowSystemType::X11)
{
- LOG_VULKAN_ERROR(res, "vkCreateXcbSurfaceKHR failed: ");
- return VK_NULL_HANDLE;
- }
-
- return surface;
+ VkXlibSurfaceCreateInfoKHR surface_create_info = {
+ VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR, // VkStructureType sType
+ nullptr, // const void* pNext
+ 0, // VkXlibSurfaceCreateFlagsKHR flags
+ static_cast<Display*>(wsi.display_connection), // Display* dpy
+ reinterpret_cast<Window>(wsi.render_surface) // Window window
+ };
+
+ VkSurfaceKHR surface;
+ VkResult res = vkCreateXlibSurfaceKHR(instance, &surface_create_info, nullptr, &surface);
+ if (res != VK_SUCCESS)
+ {
+ LOG_VULKAN_ERROR(res, "vkCreateXlibSurfaceKHR failed: ");
+ return VK_NULL_HANDLE;
+ }
-#elif defined(VK_USE_PLATFORM_ANDROID_KHR)
- VkAndroidSurfaceCreateInfoKHR surface_create_info = {
- VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR, // VkStructureType sType
- nullptr, // const void* pNext
- 0, // VkAndroidSurfaceCreateFlagsKHR flags
- reinterpret_cast<ANativeWindow*>(hwnd) // ANativeWindow* window
- };
+ return surface;
+ }
+#endif
- VkSurfaceKHR surface;
- VkResult res = vkCreateAndroidSurfaceKHR(instance, &surface_create_info, nullptr, &surface);
- if (res != VK_SUCCESS)
+#if defined(VK_USE_PLATFORM_ANDROID_KHR)
+ if (wsi.type == WindowSystemType::Android)
{
- LOG_VULKAN_ERROR(res, "vkCreateAndroidSurfaceKHR failed: ");
- return VK_NULL_HANDLE;
+ VkAndroidSurfaceCreateInfoKHR surface_create_info = {
+ VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR, // VkStructureType sType
+ nullptr, // const void* pNext
+ 0, // VkAndroidSurfaceCreateFlagsKHR flags
+ reinterpret_cast<ANativeWindow*>(wsi.render_surface) // ANativeWindow* window
+ };
+
+ VkSurfaceKHR surface;
+ VkResult res = vkCreateAndroidSurfaceKHR(instance, &surface_create_info, nullptr, &surface);
+ if (res != VK_SUCCESS)
+ {
+ LOG_VULKAN_ERROR(res, "vkCreateAndroidSurfaceKHR failed: ");
+ return VK_NULL_HANDLE;
+ }
+
+ return surface;
}
+#endif
- return surface;
+#if defined(VK_USE_PLATFORM_MACOS_MVK)
+ if (wsi.type == WindowSystemType::MacOS)
+ {
+ VkMacOSSurfaceCreateInfoMVK surface_create_info = {
+ VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK, nullptr, 0, wsi.render_surface};
-#elif defined(VK_USE_PLATFORM_MACOS_MVK)
- VkMacOSSurfaceCreateInfoMVK surface_create_info = {
- VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK, nullptr, 0, hwnd};
+ VkSurfaceKHR surface;
+ VkResult res = vkCreateMacOSSurfaceMVK(instance, &surface_create_info, nullptr, &surface);
+ if (res != VK_SUCCESS)
+ {
+ LOG_VULKAN_ERROR(res, "vkCreateMacOSSurfaceMVK failed: ");
+ return VK_NULL_HANDLE;
+ }
- VkSurfaceKHR surface;
- VkResult res = vkCreateMacOSSurfaceMVK(instance, &surface_create_info, nullptr, &surface);
- if (res != VK_SUCCESS)
- {
- LOG_VULKAN_ERROR(res, "vkCreateMacOSSurfaceMVK failed: ");
- return VK_NULL_HANDLE;
+ return surface;
}
+#endif
- return surface;
-#else
return VK_NULL_HANDLE;
-#endif
}
-std::unique_ptr<SwapChain> SwapChain::Create(void* display_handle, void* native_handle,
- VkSurfaceKHR surface, bool vsync)
+std::unique_ptr<SwapChain> SwapChain::Create(const WindowSystemInfo& wsi, VkSurfaceKHR surface,
+ bool vsync)
{
- std::unique_ptr<SwapChain> swap_chain =
- std::make_unique<SwapChain>(display_handle, native_handle, surface, vsync);
-
+ std::unique_ptr<SwapChain> swap_chain = std::make_unique<SwapChain>(wsi, surface, vsync);
if (!swap_chain->CreateSemaphores() || !swap_chain->CreateSwapChain() ||
!swap_chain->SetupSwapChainImages())
{
@@ -531,9 +518,8 @@ bool SwapChain::RecreateSurface(void* native_handle)
DestroySurface();
// Re-create the surface with the new native handle
- m_native_handle = native_handle;
- m_surface =
- CreateVulkanSurface(g_vulkan_context->GetVulkanInstance(), m_display_handle, native_handle);
+ m_wsi.render_surface = native_handle;
+ m_surface = CreateVulkanSurface(g_vulkan_context->GetVulkanInstance(), m_wsi);
if (m_surface == VK_NULL_HANDLE)
return false;