From 5d579fc8461ea0bc32ab09da690c5cdf99018219 Mon Sep 17 00:00:00 2001 From: Doug Johnson Date: Sat, 8 Jul 2017 03:19:32 -0600 Subject: [PATCH] Add Linux vulkan init routines using xcb lib --- src/xenia/ui/vulkan/vulkan_context.cc | 30 +++++++++++++++++++++++++- src/xenia/ui/vulkan/vulkan_instance.cc | 30 +++++++++++++++++++++++++- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/src/xenia/ui/vulkan/vulkan_context.cc b/src/xenia/ui/vulkan/vulkan_context.cc index 381fb0ab7..cef115278 100644 --- a/src/xenia/ui/vulkan/vulkan_context.cc +++ b/src/xenia/ui/vulkan/vulkan_context.cc @@ -2,7 +2,7 @@ ****************************************************************************** * Xenia : Xbox 360 Emulator Research Project * ****************************************************************************** - * Copyright 2016 Ben Vanik. All rights reserved. * + * Copyright 2017 Ben Vanik. All rights reserved. * * Released under the BSD license - see LICENSE in the root for more details. * ****************************************************************************** */ @@ -25,6 +25,10 @@ #include "xenia/ui/vulkan/vulkan_util.h" #include "xenia/ui/window.h" +#if XE_PLATFORM_LINUX +#include "xenia/ui/window_gtk.h" +#endif + namespace xe { namespace ui { namespace vulkan { @@ -61,6 +65,30 @@ bool VulkanContext::Initialize() { auto err = vkCreateWin32SurfaceKHR(*provider->instance(), &create_info, nullptr, &surface); CheckResult(err, "vkCreateWin32SurfaceKHR"); +#elif XE_PLATFORM_LINUX +#ifdef GDK_WINDOWING_X11 + GtkWidget* window_handle = + static_cast(target_window_->native_handle()); + GdkDisplay* gdk_display = gtk_widget_get_display(window_handle); + assert(GDK_IS_X11_DISPLAY(gdk_display)); + xcb_connection_t* connection = + XGetXCBConnection(gdk_x11_display_get_xdisplay(gdk_display)); + xcb_window_t window = gdk_x11_window_get_xid( + gtk_widget_get_window(window_handle)); + VkXcbSurfaceCreateInfoKHR create_info; + create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR; + create_info.pNext = nullptr; + create_info.flags = 0; + create_info.connection = static_cast + (target_window_->native_platform_handle()); + create_info.window = + static_cast(window); + auto err = vkCreateXcbSurfaceKHR(*provider->instance(), &create_info, + nullptr, &surface); + CheckResult(err, "vkCreateXcbSurfaceKHR"); +#else +#error Unsupported GDK Backend on Linux. +#endif // GDK_WINDOWING_X11 #else #error Platform not yet implemented. #endif // XE_PLATFORM_WIN32 diff --git a/src/xenia/ui/vulkan/vulkan_instance.cc b/src/xenia/ui/vulkan/vulkan_instance.cc index cb7a3ee91..6aaa8c41c 100644 --- a/src/xenia/ui/vulkan/vulkan_instance.cc +++ b/src/xenia/ui/vulkan/vulkan_instance.cc @@ -2,7 +2,7 @@ ****************************************************************************** * Xenia : Xbox 360 Emulator Research Project * ****************************************************************************** - * Copyright 2016 Ben Vanik. All rights reserved. * + * Copyright 2017 Ben Vanik. All rights reserved. * * Released under the BSD license - see LICENSE in the root for more details. * ****************************************************************************** */ @@ -26,6 +26,10 @@ #include "xenia/ui/vulkan/vulkan_util.h" #include "xenia/ui/window.h" +#if XE_PLATFORM_LINUX +#include "xenia/ui/window_gtk.h" +#endif + #define VK_API_VERSION VK_API_VERSION_1_0 namespace xe { @@ -385,6 +389,30 @@ bool VulkanInstance::QueryDevices(Window* any_target_window) { create_info.hwnd = static_cast(any_target_window->native_handle()); err = vkCreateWin32SurfaceKHR(handle, &create_info, nullptr, &any_surface); CheckResult(err, "vkCreateWin32SurfaceKHR"); +#elif XE_PLATFORM_LINUX +#ifdef GDK_WINDOWING_X11 + GtkWidget* window_handle = + static_cast(any_target_window->native_handle()); + GdkDisplay* gdk_display = gtk_widget_get_display(window_handle); + assert(GDK_IS_X11_DISPLAY(gdk_display)); + xcb_connection_t* connection = + XGetXCBConnection(gdk_x11_display_get_xdisplay(gdk_display)); + xcb_window_t window = gdk_x11_window_get_xid( + gtk_widget_get_window(window_handle)); + VkXcbSurfaceCreateInfoKHR create_info; + create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR; + create_info.pNext = nullptr; + create_info.flags = 0; + create_info.connection = static_cast + (any_target_window->native_platform_handle()); + create_info.window = + static_cast(window); + auto err = vkCreateXcbSurfaceKHR(handle, &create_info, + nullptr, &any_surface); + CheckResult(err, "vkCreateXcbSurfaceKHR"); +#else +#error Unsupported GDK Backend on Linux. +#endif // GDK_WINDOWING_X11 #else #error Platform not yet implemented. #endif // XE_PLATFORM_WIN32