[Bf-blender-cvs] [8bf8db8ca2d] tmp-vulkan: Vulkan: Add support for wayland.
Jeroen Bakker
noreply at git.blender.org
Tue Jul 6 10:43:29 CEST 2021
Commit: 8bf8db8ca2dd534ce4aaa32a0921b599f36098c4
Author: Jeroen Bakker
Date: Tue Jul 6 10:42:45 2021 +0200
Branches: tmp-vulkan
https://developer.blender.org/rB8bf8db8ca2dd534ce4aaa32a0921b599f36098c4
Vulkan: Add support for wayland.
===================================================================
M intern/ghost/intern/GHOST_ContextVK.cpp
M intern/ghost/intern/GHOST_ContextVK.h
M intern/ghost/intern/GHOST_SystemWayland.cpp
M intern/ghost/intern/GHOST_SystemX11.cpp
M intern/ghost/intern/GHOST_WindowWayland.cpp
M intern/ghost/intern/GHOST_WindowX11.cpp
===================================================================
diff --git a/intern/ghost/intern/GHOST_ContextVK.cpp b/intern/ghost/intern/GHOST_ContextVK.cpp
index dd93b09d4d9..86568f495ea 100644
--- a/intern/ghost/intern/GHOST_ContextVK.cpp
+++ b/intern/ghost/intern/GHOST_ContextVK.cpp
@@ -31,6 +31,9 @@
# include <MoltenVK/vk_mvk_moltenvk.h>
#else /* X11 */
# include <vulkan/vulkan_xlib.h>
+# ifdef WITH_GHOST_WAYLAND
+# include <vulkan/vulkan_wayland.h>
+# endif
#endif
#include <vector>
@@ -124,9 +127,14 @@ GHOST_ContextVK::GHOST_ContextVK(bool stereoVisual,
HWND hwnd,
#elif defined(__APPLE__)
CAMetalLayer *metal_layer,
-#else /* X11 */
+#else
+ GHOST_TVulkanPlatformType platform,
+ /* X11 */
Window window,
Display *display,
+ /* Wayland */
+ wl_surface *wayland_surface,
+ wl_display *wayland_display,
#endif
int contextMajorVersion,
int contextMinorVersion,
@@ -136,9 +144,14 @@ GHOST_ContextVK::GHOST_ContextVK(bool stereoVisual,
m_hwnd(hwnd),
#elif defined(__APPLE__)
m_metal_layer(metal_layer),
-#else /* X11 */
+#else
+ m_platform(platform),
+ /* X11 */
m_display(display),
m_window(window),
+ /* Wayland */
+ m_wayland_surface(wayland_surface),
+ m_wayland_display(wayland_display),
#endif
m_context_major_version(contextMajorVersion),
m_context_minor_version(contextMinorVersion),
@@ -822,14 +835,45 @@ GHOST_TSuccess GHOST_ContextVK::createSwapchain(void)
return GHOST_kSuccess;
}
+const char *GHOST_ContextVK::getPlatformSpecificSurfaceExtension() const
+{
+#ifdef _WIN32
+ return VK_KHR_WIN32_SURFACE_EXTENSION_NAME;
+#elif defined(__APPLE__)
+ return VK_EXT_METAL_SURFACE_EXTENSION_NAME;
+#else /* UNIX/Linux */
+ switch (m_platform) {
+ case GHOST_kVulkanPlatformX11:
+ return VK_KHR_XLIB_SURFACE_EXTENSION_NAME;
+ break;
+# ifdef WITH_GHOST_WAYLAND
+ case GHOST_kVulkanPlatformWayland:
+ return VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME;
+ break;
+# endif
+ }
+#endif
+ return NULL;
+}
+
GHOST_TSuccess GHOST_ContextVK::initializeDrawingContext()
{
#ifdef _WIN32
const bool use_window_surface = (m_hwnd != NULL);
#elif defined(__APPLE__)
const bool use_window_surface = (m_metal_layer != NULL);
-#else /* X11 */
- const bool use_window_surface = (m_display != NULL) && (m_window != (Window)NULL);
+#else /* UNIX/Linux */
+ bool use_window_surface = false;
+ switch (m_platform) {
+ case GHOST_kVulkanPlatformX11:
+ use_window_surface = (m_display != NULL) && (m_window != (Window)NULL);
+ break;
+# ifdef WITH_GHOST_WAYLAND
+ case GHOST_kVulkanPlatformWayland:
+ use_window_surface = (m_wayland_display != NULL) && (m_wayland_surface != NULL);
+ break;
+# endif
+ }
#endif
auto layers_available = getLayersAvailable();
@@ -844,13 +888,8 @@ GHOST_TSuccess GHOST_ContextVK::initializeDrawingContext()
vector<const char *> extensions_enabled;
if (use_window_surface) {
-#ifdef _WIN32
- const char *native_surface_extension_name = VK_KHR_WIN32_SURFACE_EXTENSION_NAME;
-#elif defined(__APPLE__)
- const char *native_surface_extension_name = VK_EXT_METAL_SURFACE_EXTENSION_NAME;
-#else /* X11 */
- const char *native_surface_extension_name = VK_KHR_XLIB_SURFACE_EXTENSION_NAME;
-#endif
+ const char *native_surface_extension_name = getPlatformSpecificSurfaceExtension();
+
requireExtension(extensions_available, extensions_enabled, "VK_KHR_surface");
requireExtension(extensions_available, extensions_enabled, native_surface_extension_name);
@@ -890,11 +929,27 @@ GHOST_TSuccess GHOST_ContextVK::initializeDrawingContext()
info.pLayer = m_metal_layer;
VK_CHECK(vkCreateMetalSurfaceEXT(m_instance, &info, nullptr, &m_surface));
#else
- VkXlibSurfaceCreateInfoKHR surface_create_info = {};
- surface_create_info.sType = VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR;
- surface_create_info.dpy = m_display;
- surface_create_info.window = m_window;
- VK_CHECK(vkCreateXlibSurfaceKHR(m_instance, &surface_create_info, NULL, &m_surface));
+ switch (m_platform) {
+ case GHOST_kVulkanPlatformX11: {
+ VkXlibSurfaceCreateInfoKHR surface_create_info = {};
+ surface_create_info.sType = VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR;
+ surface_create_info.dpy = m_display;
+ surface_create_info.window = m_window;
+ VK_CHECK(vkCreateXlibSurfaceKHR(m_instance, &surface_create_info, NULL, &m_surface));
+ break;
+ }
+# ifdef WITH_GHOST_WAYLAND
+ case GHOST_kVulkanPlatformWayland: {
+ VkWaylandSurfaceCreateInfoKHR surface_create_info = {};
+ surface_create_info.sType = VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR;
+ surface_create_info.display = m_wayland_display;
+ surface_create_info.surface = m_wayland_surface;
+ VK_CHECK(vkCreateWaylandSurfaceKHR(m_instance, &surface_create_info, NULL, &m_surface));
+ break;
+ }
+# endif
+ }
+
#endif
}
diff --git a/intern/ghost/intern/GHOST_ContextVK.h b/intern/ghost/intern/GHOST_ContextVK.h
index a4a5a3f75e2..ba19cc68214 100644
--- a/intern/ghost/intern/GHOST_ContextVK.h
+++ b/intern/ghost/intern/GHOST_ContextVK.h
@@ -32,6 +32,12 @@
# include "GHOST_SystemCocoa.h"
#else
# include "GHOST_SystemX11.h"
+# ifdef WITH_GHOST_WAYLAND
+# include "GHOST_SystemWayland.h"
+# else
+# define wl_surface void
+# define wl_display void
+# endif
#endif
#include <vector>
@@ -51,6 +57,13 @@
# define GHOST_OPENGL_VK_RESET_NOTIFICATION_STRATEGY 0
#endif
+typedef enum {
+ GHOST_kVulkanPlatformX11 = 0,
+#ifdef WITH_GHOST_WAYLAND
+ GHOST_kVulkanPlatformWayland,
+#endif
+} GHOST_TVulkanPlatformType;
+
class GHOST_ContextVK : public GHOST_Context {
/* XR code needs low level graphics data to send to OpenXR. */
// friend class GHOST_XrGraphicsBindingOpenGL;
@@ -65,9 +78,14 @@ class GHOST_ContextVK : public GHOST_Context {
#elif defined(__APPLE__)
/* FIXME CAMetalLayer but have issue with linking. */
void *metal_layer,
-#else /* X11 */
+#else
+ GHOST_TVulkanPlatformType platform,
+ /* X11 */
Window window,
Display *display,
+ /* Wayland */
+ wl_surface *wayland_surface,
+ wl_display *wayland_display,
#endif
int contextMajorVersion,
int contextMinorVersion,
@@ -155,9 +173,14 @@ class GHOST_ContextVK : public GHOST_Context {
#elif defined(__APPLE__)
/* FIXME CAMetalLayer but have issue with linking. */
void *m_metal_layer;
-#else /* X11 */
+#else /* Linux */
+ GHOST_TVulkanPlatformType m_platform;
+ /* X11 */
Display *m_display;
Window m_window;
+ /* Wayland */
+ wl_surface *m_wayland_surface;
+ wl_display *m_wayland_display;
#endif
const int m_context_major_version;
@@ -195,6 +218,7 @@ class GHOST_ContextVK : public GHOST_Context {
/** Used to unique framebuffer ids to return when swapchain is recreated. */
uint32_t m_swapchain_id = 0;
+ const char *getPlatformSpecificSurfaceExtension()const ;
GHOST_TSuccess pickPhysicalDevice(std::vector<const char *> required_exts);
GHOST_TSuccess createSwapchain(void);
GHOST_TSuccess destroySwapchain(void);
diff --git a/intern/ghost/intern/GHOST_SystemWayland.cpp b/intern/ghost/intern/GHOST_SystemWayland.cpp
index c7d7b3edbef..8062d7d67ae 100644
--- a/intern/ghost/intern/GHOST_SystemWayland.cpp
+++ b/intern/ghost/intern/GHOST_SystemWayland.cpp
@@ -30,6 +30,10 @@
#include "GHOST_ContextEGL.h"
+#if defined(WITH_VULKAN)
+# include "GHOST_ContextVK.h"
+#endif
+
#include <EGL/egl.h>
#include <wayland-egl.h>
@@ -1581,56 +1585,75 @@ void GHOST_SystemWayland::getAllDisplayDimensions(GHOST_TUns32 &width, GHOST_TUn
getMainDisplayDimensions(width, height);
}
-GHOST_IContext *GHOST_SystemWayland::createOffscreenContext(GHOST_TDrawingContextType /* type */,
+GHOST_IContext *GHOST_SystemWayland::createOffscreenContext(GHOST_TDrawingContextType type,
GHOST_GLSettings glSettings)
{
- /* Create new off-screen window. */
- wl_surface *os_surface = wl_compositor_create_surface(compositor());
- wl_egl_window *os_egl_window = wl_egl_window_create(os_surface, int(1), int(1));
+#if defined(WITH_VULKAN)
+ const bool debug_context = (glSettings.flags & GHOST_glDebugContext) != 0;
- d->os_surfaces.push_back(os_surface);
- d->os_egl_windows.push_back(os_egl_window);
+ if (type == GHOST_kDrawingContextTypeVulkan) {
+ GHOST_Context *context = new GHOST_ContextVK(
+ false, GHOST_kVulkanPlatformWayland, 0, NULL, NULL, d->display, 1, 0, debug_context);
- GHOST_Context *context;
+ if (context->initializeDrawingContext()) {
+ return context;
+ }
+ else {
+ delete context;
+ }
+ }
+#else
+ (void)glSettings;
+#endif
+
+ if (type == GHOST_kDrawingContextTypeOpenGL) {
+ /* Create new off-screen window. */
+ wl_surface *os_surface = wl_compositor_create_surface(compositor());
+ wl_egl_window *os_egl_window = wl_egl_window_create(os_surface, int(1), int(1));
+
+ d->os_surfaces.push_back(os_surface);
+ d->os_egl_windows.push_back(os_egl_window);
+
+ GHOST_Context *context;
+
+ for (int minor = 6; minor >= 0; --minor) {
+ context = new GHOST_ContextEGL(this,
+ false,
+ EGLNativeWindowType(os_egl_window),
+ EGLNativeDisplayType(d->display),
+ EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT,
+ 4,
+ minor,
+ GHOST_OPENGL_EGL_CONTEXT_FLAGS,
+ GHOST_OPENGL_EGL_RESET_NOTIFICATION_STRATE
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list