[Bf-blender-cvs] [be9dc493a46] tmp-vulkan: GHOST: Add barebone vulkan context for X11
Clément Foucault
noreply at git.blender.org
Thu Jul 23 16:21:40 CEST 2020
Commit: be9dc493a466e89127cbcd1733c4ac52be75df76
Author: Clément Foucault
Date: Sun Jul 19 01:47:27 2020 +0200
Branches: tmp-vulkan
https://developer.blender.org/rBbe9dc493a466e89127cbcd1733c4ac52be75df76
GHOST: Add barebone vulkan context for X11
The context does nothing. For now it always fail and will always
fallback to opengl.
===================================================================
M intern/ghost/CMakeLists.txt
A intern/ghost/intern/GHOST_ContextVK.cpp
A intern/ghost/intern/GHOST_ContextVK.h
M intern/ghost/intern/GHOST_SystemX11.cpp
M intern/ghost/intern/GHOST_WindowX11.cpp
===================================================================
diff --git a/intern/ghost/CMakeLists.txt b/intern/ghost/CMakeLists.txt
index 77e777db872..2573460530e 100644
--- a/intern/ghost/CMakeLists.txt
+++ b/intern/ghost/CMakeLists.txt
@@ -204,6 +204,18 @@ elseif(WITH_GHOST_X11 OR WITH_GHOST_WAYLAND)
)
endif()
+ if(WITH_VULKAN)
+ list(APPEND SRC
+ intern/GHOST_ContextVK.cpp
+
+ intern/GHOST_ContextVK.h
+ )
+
+ list(APPEND INC_SYS
+ ${Vulkan_INCLUDE_DIR}
+ )
+ endif()
+
if(WITH_GHOST_XDND)
add_definitions(-DWITH_XDND)
diff --git a/intern/ghost/intern/GHOST_ContextVK.cpp b/intern/ghost/intern/GHOST_ContextVK.cpp
new file mode 100644
index 00000000000..45d8651044d
--- /dev/null
+++ b/intern/ghost/intern/GHOST_ContextVK.cpp
@@ -0,0 +1,86 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2014 Blender Foundation.
+ * All rights reserved.
+ */
+
+/** \file
+ * \ingroup GHOST
+ *
+ * Definition of GHOST_ContextVK class.
+ */
+
+#include "GHOST_ContextVK.h"
+#include "GHOST_SystemX11.h"
+
+#include <vulkan/vulkan.h>
+
+#include <vector>
+
+#include <cassert>
+#include <cstdio>
+#include <cstring>
+
+GHOST_ContextVK::GHOST_ContextVK(bool stereoVisual) : GHOST_Context(stereoVisual)
+{
+ assert(m_display != NULL);
+}
+
+GHOST_ContextVK::~GHOST_ContextVK()
+{
+}
+
+GHOST_TSuccess GHOST_ContextVK::swapBuffers()
+{
+ return GHOST_kSuccess;
+}
+
+GHOST_TSuccess GHOST_ContextVK::activateDrawingContext()
+{
+ return GHOST_kSuccess;
+}
+
+GHOST_TSuccess GHOST_ContextVK::releaseDrawingContext()
+{
+ return GHOST_kSuccess;
+}
+
+GHOST_TSuccess GHOST_ContextVK::initializeDrawingContext()
+{
+ uint32_t extensionCount = 0;
+ vkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, nullptr);
+
+ printf("Vulkan extensions supported : %u\n", extensionCount);
+
+ return GHOST_kFailure;
+}
+
+GHOST_TSuccess GHOST_ContextVK::releaseNativeHandles()
+{
+ return GHOST_kSuccess;
+}
+
+GHOST_TSuccess GHOST_ContextVK::setSwapInterval(int interval)
+{
+ (void)interval;
+ return GHOST_kSuccess;
+}
+
+GHOST_TSuccess GHOST_ContextVK::getSwapInterval(int &intervalOut)
+{
+ (void)intervalOut;
+ return GHOST_kSuccess;
+}
diff --git a/intern/ghost/intern/GHOST_ContextVK.h b/intern/ghost/intern/GHOST_ContextVK.h
new file mode 100644
index 00000000000..1110a8bd702
--- /dev/null
+++ b/intern/ghost/intern/GHOST_ContextVK.h
@@ -0,0 +1,101 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2014 Blender Foundation.
+ * All rights reserved.
+ */
+
+/** \file
+ * \ingroup GHOST
+ */
+
+#ifndef __GHOST_CONTEXTVK_H__
+#define __GHOST_CONTEXTVK_H__
+
+#include "GHOST_Context.h"
+
+#ifndef GHOST_OPENGL_VK_CONTEXT_FLAGS
+/* leave as convenience define for the future */
+# define GHOST_OPENGL_VK_CONTEXT_FLAGS 0
+#endif
+
+#ifndef GHOST_OPENGL_VK_RESET_NOTIFICATION_STRATEGY
+# define GHOST_OPENGL_VK_RESET_NOTIFICATION_STRATEGY 0
+#endif
+
+class GHOST_ContextVK : public GHOST_Context {
+ /* XR code needs low level graphics data to send to OpenXR. */
+ // friend class GHOST_XrGraphicsBindingOpenGL;
+
+ public:
+ /**
+ * Constructor.
+ */
+ GHOST_ContextVK(bool stereoVisual);
+
+ /**
+ * Destructor.
+ */
+ ~GHOST_ContextVK();
+
+ /**
+ * Swaps front and back buffers of a window.
+ * \return A boolean success indicator.
+ */
+ GHOST_TSuccess swapBuffers();
+
+ /**
+ * Activates the drawing context of this window.
+ * \return A boolean success indicator.
+ */
+ GHOST_TSuccess activateDrawingContext();
+
+ /**
+ * Release the drawing context of the calling thread.
+ * \return A boolean success indicator.
+ */
+ GHOST_TSuccess releaseDrawingContext();
+
+ /**
+ * Call immediately after new to initialize. If this fails then immediately delete the object.
+ * \return Indication as to whether initialization has succeeded.
+ */
+ GHOST_TSuccess initializeDrawingContext();
+
+ /**
+ * Removes references to native handles from this context and then returns
+ * \return GHOST_kSuccess if it is OK for the parent to release the handles and
+ * GHOST_kFailure if releasing the handles will interfere with sharing
+ */
+ GHOST_TSuccess releaseNativeHandles();
+
+ /**
+ * Sets the swap interval for swapBuffers.
+ * \param interval The swap interval to use.
+ * \return A boolean success indicator.
+ */
+ GHOST_TSuccess setSwapInterval(int interval);
+
+ /**
+ * Gets the current swap interval for swapBuffers.
+ * \param intervalOut Variable to store the swap interval if it can be read.
+ * \return Whether the swap interval can be read.
+ */
+ GHOST_TSuccess getSwapInterval(int &intervalOut);
+
+ private:
+};
+
+#endif // __GHOST_CONTEXTVK_H__
diff --git a/intern/ghost/intern/GHOST_SystemX11.cpp b/intern/ghost/intern/GHOST_SystemX11.cpp
index 96073c21e79..1f25ca3c1b9 100644
--- a/intern/ghost/intern/GHOST_SystemX11.cpp
+++ b/intern/ghost/intern/GHOST_SystemX11.cpp
@@ -48,6 +48,10 @@
#include "GHOST_Debug.h"
+#if defined(WITH_VULKAN)
+# include "GHOST_ContextVK.h"
+#endif
+
#if defined(WITH_GL_EGL)
# include "GHOST_ContextEGL.h"
# include <EGL/eglext.h>
@@ -437,6 +441,17 @@ GHOST_IContext *GHOST_SystemX11::createOffscreenContext()
GHOST_Context *context;
+#if defined(WITH_VULKAN)
+ {
+ context = new GHOST_ContextVK(false);
+
+ if (context->initializeDrawingContext())
+ return context;
+ else
+ delete context;
+ }
+#endif
+
for (int minor = 5; minor >= 0; --minor) {
#if defined(WITH_GL_EGL)
context = new GHOST_ContextEGL(false,
diff --git a/intern/ghost/intern/GHOST_WindowX11.cpp b/intern/ghost/intern/GHOST_WindowX11.cpp
index 691f1790a2d..3b642a77b6c 100644
--- a/intern/ghost/intern/GHOST_WindowX11.cpp
+++ b/intern/ghost/intern/GHOST_WindowX11.cpp
@@ -38,6 +38,10 @@
# include "GHOST_DropTargetX11.h"
#endif
+#if defined(WITH_VULKAN)
+# include "GHOST_ContextVK.h"
+#endif
+
#ifdef WITH_GL_EGL
# include "GHOST_ContextEGL.h"
# include <EGL/eglext.h>
@@ -1318,12 +1322,7 @@ GHOST_Context *GHOST_WindowX11::newDrawingContext(GHOST_TDrawingContextType type
{
if (type == GHOST_kDrawingContextTypeOpenGL) {
- // During development:
- // try 4.x compatibility profile
- // try 3.3 compatibility profile
- // fall back to 3.0 if needed
- //
- // Final Blender 2.8:
+ // Blender 2.8:
// try 4.x core profile
// try 3.3 core profile
// no fallbacks
@@ -1359,6 +1358,18 @@ GHOST_Context *GHOST_WindowX11::newDrawingContext(GHOST_TDrawingContextType type
GHOST_Context *context;
+ // Vulkan port
+ // try vulkan
+ // fallback to OGL
+#if defined(WITH_VULKAN)
+ context = new GHOST_ContextVK(m_wantStereoVisual);
+
+ if (context->initializeDrawingContext())
+ return context;
+ else
+ delete context;
+#endif
+
for (int minor = 5; minor >= 0; --minor) {
#ifdef WITH_GL_EGL
context = new GHOST_ContextEGL(
More information about the Bf-blender-cvs
mailing list