[Bf-blender-cvs] [8e437578342] tmp-vulkan: GHOST: Vulkan Backend.

Jeroen Bakker noreply at git.blender.org
Tue Nov 23 14:01:16 CET 2021


Commit: 8e437578342193832d8f66f9d8c81d6be723e927
Author: Jeroen Bakker
Date:   Tue Nov 9 12:31:34 2021 +0100
Branches: tmp-vulkan
https://developer.blender.org/rB8e437578342193832d8f66f9d8c81d6be723e927

GHOST: Vulkan Backend.

This adds a vulkan backend to GHOST. Still WIP, we should decide what
would be the minimum requirement to land in master.

Differential Revision: https://developer.blender.org/D13155

===================================================================

M	CMakeLists.txt
M	build_files/cmake/platform/platform_unix.cmake
M	build_files/cmake/platform/platform_win32.cmake
M	intern/ghost/CMakeLists.txt
M	intern/ghost/GHOST_C-api.h
M	intern/ghost/GHOST_IContext.h
M	intern/ghost/GHOST_ISystem.h
M	intern/ghost/GHOST_IWindow.h
M	intern/ghost/GHOST_Types.h
M	intern/ghost/intern/GHOST_C-api.cpp
M	intern/ghost/intern/GHOST_Context.h
A	intern/ghost/intern/GHOST_ContextVK.cpp
A	intern/ghost/intern/GHOST_ContextVK.h
M	intern/ghost/intern/GHOST_System.h
M	intern/ghost/intern/GHOST_SystemCocoa.h
M	intern/ghost/intern/GHOST_SystemCocoa.mm
M	intern/ghost/intern/GHOST_SystemNULL.h
M	intern/ghost/intern/GHOST_SystemSDL.cpp
M	intern/ghost/intern/GHOST_SystemSDL.h
M	intern/ghost/intern/GHOST_SystemWayland.cpp
M	intern/ghost/intern/GHOST_SystemWayland.h
M	intern/ghost/intern/GHOST_SystemWin32.cpp
M	intern/ghost/intern/GHOST_SystemWin32.h
M	intern/ghost/intern/GHOST_SystemX11.cpp
M	intern/ghost/intern/GHOST_SystemX11.h
M	intern/ghost/intern/GHOST_Window.h
M	intern/ghost/intern/GHOST_WindowCocoa.mm
M	intern/ghost/intern/GHOST_WindowWayland.cpp
M	intern/ghost/intern/GHOST_WindowWin32.cpp
M	intern/ghost/intern/GHOST_WindowX11.cpp
M	intern/ghost/intern/GHOST_WindowX11.h
M	intern/ghost/test/multitest/MultiTest.c
M	source/blender/windowmanager/intern/wm_window.c

===================================================================

diff --git a/CMakeLists.txt b/CMakeLists.txt
index d2e2d02dcde..6527c82c0fc 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -513,9 +513,12 @@ if(UNIX AND NOT APPLE)
 endif()
 
 
+# Vulkan
+option(WITH_VULKAN              "Enable Vulkan GHOST backend (for development purposes)" OFF)
+
 # OpenGL
 
-option(WITH_OPENGL              "When off limits visibility of the opengl headers to just bf_gpu and gawain (temporary option for development purposes)" ON)
+option(WITH_OPENGL              "When off limits visibility of the opengl headers to just bf_gpu (temporary option for development purposes)" ON)
 option(WITH_GLEW_ES             "Switches to experimental copy of GLEW that has support for OpenGL ES. (temporary option for development purposes)" OFF)
 option(WITH_GL_EGL              "Use the EGL OpenGL system library instead of the platform specific OpenGL system library (CGL, glX, or WGL)"       OFF)
 option(WITH_GL_PROFILE_ES20     "Support using OpenGL ES 2.0. (through either EGL or the AGL/WGL/XGL 'es20' profile)"                               OFF)
@@ -525,6 +528,7 @@ mark_as_advanced(
   WITH_GLEW_ES
   WITH_GL_EGL
   WITH_GL_PROFILE_ES20
+  WITH_VULKAN
 )
 
 if(WIN32)
@@ -1125,6 +1129,15 @@ if(WITH_OPENVDB)
   list(APPEND OPENVDB_LIBRARIES ${BOOST_LIBRARIES} ${TBB_LIBRARIES})
 endif()
 
+#-----------------------------------------------------------------------------
+# Configure Vulkan.
+
+if(WITH_VULKAN)
+  list(APPEND BLENDER_GL_LIBRARIES ${Vulkan_LIBRARY})
+
+  add_definitions(-DWITH_VULKAN)
+endif()
+
 #-----------------------------------------------------------------------------
 # Configure OpenGL.
 
diff --git a/build_files/cmake/platform/platform_unix.cmake b/build_files/cmake/platform/platform_unix.cmake
index fc0c37e4c8b..7f0e53b141d 100644
--- a/build_files/cmake/platform/platform_unix.cmake
+++ b/build_files/cmake/platform/platform_unix.cmake
@@ -102,6 +102,10 @@ find_package_wrapper(ZLIB REQUIRED)
 find_package_wrapper(Zstd REQUIRED)
 find_package_wrapper(Freetype REQUIRED)
 
+if(WITH_VULKAN)
+  find_package_wrapper(Vulkan REQUIRED)
+endif()
+
 if(WITH_PYTHON)
   # No way to set py35, remove for now.
   # find_package(PythonLibs)
diff --git a/build_files/cmake/platform/platform_win32.cmake b/build_files/cmake/platform/platform_win32.cmake
index e83eba74fc0..e837f14433e 100644
--- a/build_files/cmake/platform/platform_win32.cmake
+++ b/build_files/cmake/platform/platform_win32.cmake
@@ -874,5 +874,19 @@ if(WITH_HARU)
   endif()
 endif()
 
+if(WITH_VULKAN)
+  if(EXISTS ${LIBDIR}/vulkan)
+    set(Vulkan_FOUND On)
+    set(Vulkan_ROOT_DIR ${LIBDIR}/vulkan)
+    set(Vulkan_INCLUDE_DIR ${Vulkan_ROOT_DIR}/include)
+    set(Vulkan_INCLUDE_DIRS ${Vulkan_INCLUDE_DIR})
+    set(Vulkan_LIBRARY ${Vulkan_ROOT_DIR}/lib/vulkan-1.lib)
+    set(Vulkan_LIBRARIES ${Vulkan_LIBRARY})
+  else()
+    message(WARNING "vulkan was not found, disabling WITH_VULKAN")
+    set(WITH_VULKAN OFF)
+  endif()
+endif()
+
 set(ZSTD_INCLUDE_DIRS ${LIBDIR}/zstd/include)
 set(ZSTD_LIBRARIES ${LIBDIR}/zstd/lib/zstd_static.lib)
diff --git a/intern/ghost/CMakeLists.txt b/intern/ghost/CMakeLists.txt
index 41642311185..1404b3489ec 100644
--- a/intern/ghost/CMakeLists.txt
+++ b/intern/ghost/CMakeLists.txt
@@ -89,6 +89,18 @@ set(LIB
   ${GLEW_LIBRARY}
 )
 
+if(WITH_VULKAN)
+  list(APPEND SRC
+    intern/GHOST_ContextVK.cpp
+
+    intern/GHOST_ContextVK.h
+  )
+
+  list(APPEND INC_SYS
+    ${Vulkan_INCLUDE_DIRS}
+  )
+endif()
+
 if(WITH_GHOST_DEBUG)
   list(APPEND SRC
     intern/GHOST_EventPrinter.cpp
diff --git a/intern/ghost/GHOST_C-api.h b/intern/ghost/GHOST_C-api.h
index 784febe8581..48f104776d1 100644
--- a/intern/ghost/GHOST_C-api.h
+++ b/intern/ghost/GHOST_C-api.h
@@ -195,6 +195,7 @@ extern GHOST_WindowHandle GHOST_CreateWindow(GHOST_SystemHandle systemhandle,
  * \return A handle to the new context ( == NULL if creation failed).
  */
 extern GHOST_ContextHandle GHOST_CreateOpenGLContext(GHOST_SystemHandle systemhandle,
+                                                     GHOST_TDrawingContextType type,
                                                      GHOST_GLSettings glSettings);
 
 /**
@@ -542,6 +543,13 @@ extern int GHOST_GetValid(GHOST_WindowHandle windowhandle);
  */
 extern GHOST_TDrawingContextType GHOST_GetDrawingContextType(GHOST_WindowHandle windowhandle);
 
+/**
+ * Returns the drawing context used in this window.
+ * \param windowhandle: The handle to the window.
+ * \return The window drawing context.
+ */
+extern GHOST_ContextHandle GHOST_GetDrawingContext(GHOST_WindowHandle windowhandle);
+
 /**
  * Tries to install a rendering context in this window.
  * \param windowhandle: The handle to the window.
@@ -1166,6 +1174,30 @@ int GHOST_XrGetControllerModelData(GHOST_XrContextHandle xr_context,
 
 #endif /* WITH_XR_OPENXR */
 
+#ifdef WITH_VULKAN
+
+/**
+ * Return vulkan handles for the given context.
+ */
+void GHOST_GetVulkanHandles(GHOST_ContextHandle context,
+                            void *r_instance,
+                            void *r_physical_device,
+                            void *r_device,
+                            uint32_t *r_graphic_queue_familly);
+
+/**
+ * Return vulkan backbuffer resources handles for the given window.
+ */
+void GHOST_GetVulkanBackbuffer(GHOST_WindowHandle windowhandle,
+                               void *image,
+                               void *framebuffer,
+                               void *command_buffer,
+                               void *render_pass,
+                               void *extent,
+                               uint32_t *fb_id);
+
+#endif
+
 #ifdef __cplusplus
 }
 
diff --git a/intern/ghost/GHOST_IContext.h b/intern/ghost/GHOST_IContext.h
index 1b5f996cb54..4b8e6c0e567 100644
--- a/intern/ghost/GHOST_IContext.h
+++ b/intern/ghost/GHOST_IContext.h
@@ -56,6 +56,11 @@ class GHOST_IContext {
 
   virtual unsigned int getDefaultFramebuffer() = 0;
 
+  virtual GHOST_TSuccess getVulkanHandles(void *, void *, void *, uint32_t *) = 0;
+
+  virtual GHOST_TSuccess getVulkanBackbuffer(
+      void *, void *, void *, void *, void *, uint32_t *) = 0;
+
   virtual GHOST_TSuccess swapBuffers() = 0;
 
 #ifdef WITH_CXX_GUARDEDALLOC
diff --git a/intern/ghost/GHOST_ISystem.h b/intern/ghost/GHOST_ISystem.h
index 05c6c9d907f..0e95971795b 100644
--- a/intern/ghost/GHOST_ISystem.h
+++ b/intern/ghost/GHOST_ISystem.h
@@ -265,7 +265,8 @@ class GHOST_ISystem {
    * Never explicitly delete the context, use #disposeContext() instead.
    * \return The new context (or 0 if creation failed).
    */
-  virtual GHOST_IContext *createOffscreenContext(GHOST_GLSettings glSettings) = 0;
+  virtual GHOST_IContext *createOffscreenContext(GHOST_TDrawingContextType type,
+                                                 GHOST_GLSettings glSettings) = 0;
 
   /**
    * Dispose of a context.
diff --git a/intern/ghost/GHOST_IWindow.h b/intern/ghost/GHOST_IWindow.h
index 91f576ca304..4642241845e 100644
--- a/intern/ghost/GHOST_IWindow.h
+++ b/intern/ghost/GHOST_IWindow.h
@@ -30,6 +30,8 @@
 #include <stdlib.h>
 #include <string>
 
+class GHOST_IContext;
+
 /**
  * Interface for GHOST windows.
  *
@@ -71,6 +73,12 @@ class GHOST_IWindow {
    */
   virtual GHOST_TDrawingContextType getDrawingContextType() = 0;
 
+  /**
+   * Returns the type of drawing context used in this window.
+   * \return The current type of drawing context.
+   */
+  virtual GHOST_IContext *getDrawingContext() = 0;
+
   /**
    * Tries to install a rendering context in this window.
    * \param type: The type of rendering context installed.
@@ -218,6 +226,18 @@ class GHOST_IWindow {
    */
   virtual unsigned int getDefaultFramebuffer() = 0;
 
+  /**
+   * Gets the Vulkan framebuffer related resource handles associated with the Vulkan context.
+   * Needs to be called after each swap events as the framebuffer will change.
+   * \return  A boolean success indicator.
+   */
+  virtual GHOST_TSuccess getVulkanBackbuffer(void * /*image*/,
+                                             void * /*framebuffer*/,
+                                             void * /*command_buffer*/,
+                                             void * /*render_pass*/,
+                                             void * /*extent*/,
+                                             uint32_t * /*fb_id*/) = 0;
+
   /**
    * Invalidates the contents of this window.
    * \return Indication of success.
diff --git a/intern/ghost/GHOST_Types.h b/intern/ghost/GHOST_Types.h
index 2c8014a08cc..ef222e4e70a 100644
--- a/intern/ghost/GHOST_Types.h
+++ b/intern/ghost/GHOST_Types.h
@@ -145,6 +145,9 @@ typedef enum { GHOST_kWindowOrderTop = 0, GHOST_kWindowOrderBottom } GHOST_TWind
 typedef enum {
   GHOST_kDrawingContextTypeNone = 0,
   GHOST_kDrawingContextTypeOpenGL,
+#ifdef WITH_VULKAN
+  GHOST_kDrawingContextTypeVulkan,
+#endif
 #ifdef WIN32
   GHOST_kDrawingContextTypeD3D,
 #endif
diff --git a/intern/ghost/intern/GHOST_C-api.cpp b/intern/ghost/intern/GHOST_C-api.cpp
index a21c3a90c06..5a19123f044 100644
--- a/intern/ghost/intern/GHOST_C-api.cpp
+++ b/intern/ghost/intern/GHOST_C-api.cpp
@@ -137,11 +137,12 @@ void GHOST_GetAllDisplayDimensions(GHOST_SystemHandle systemhandle,
 }
 
 GHOST_ContextHandle GHOST_CreateOpenGLContext(GHOST_SystemHandle systemhandle,
+                                              GHOST_TDrawingContextType type,
                                               GHOST_GLSettings glSettings)
 {
   GHOST_ISystem *system = (GHOST_ISystem *)systemhandle;
 
-  return (GHOST_ContextHandle)system->createOffscreenContext(glSettings);
+  return (GHOST_ContextHandle)system->createOffscreenContext(type, glSettings);
 }
 
 GHOST_TSuccess GHOST_DisposeOpenGLContext(GHOST_SystemHandle systemhandle,
@@ -493,6 +494,13 @@ GHOST_TDrawingContextType GHOST_GetDrawingContextType(GHOST_WindowHandle windowh
   return window->getDrawingContextType();
 }
 
+GHOST_ContextHandle GHOST_GetDrawingContext(GHOST_WindowHandle windowhandle)
+{
+  GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
+
+  return (GHOST_ContextHandle)window->getDrawingContext();
+}
+
 GHOST_TSuccess GHOST_SetDrawingContextType(GHOST_WindowHandle windowhandle,
                                            GHOST_TDrawin

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list