[Bf-blender-cvs] [18ba57ddb62] temp-ghost-vulkan: Copied from tmp-vulkan branch.

Jeroen Bakker noreply at git.blender.org
Tue Nov 1 08:43:08 CET 2022


Commit: 18ba57ddb62b8f97c6abe8125d74fc279ce2b08d
Author: Jeroen Bakker
Date:   Fri Oct 21 09:06:08 2022 +0200
Branches: temp-ghost-vulkan
https://developer.blender.org/rB18ba57ddb62b8f97c6abe8125d74fc279ce2b08d

Copied from tmp-vulkan branch.

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

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_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_Window.cpp
M	intern/ghost/intern/GHOST_Window.h

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

diff --git a/build_files/cmake/platform/platform_win32.cmake b/build_files/cmake/platform/platform_win32.cmake
index e321f9120c5..d439c7de5de 100644
--- a/build_files/cmake/platform/platform_win32.cmake
+++ b/build_files/cmake/platform/platform_win32.cmake
@@ -925,8 +925,8 @@ if(WITH_VULKAN_BACKEND)
     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)
+    message(WARNING "vulkan was not found, disabling WITH_VULKAN_BACKEND")
+    set(WITH_VULKAN_BACKEND OFF)
   endif()
 endif()
 
diff --git a/intern/ghost/CMakeLists.txt b/intern/ghost/CMakeLists.txt
index ea21d831b0c..37c5fa74f2d 100644
--- a/intern/ghost/CMakeLists.txt
+++ b/intern/ghost/CMakeLists.txt
@@ -76,6 +76,18 @@ set(LIB
   ${Epoxy_LIBRARIES}
 )
 
+if(WITH_VULKAN_BACKEND)
+  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 62984c762c1..a8dae232d8b 100644
--- a/intern/ghost/GHOST_C-api.h
+++ b/intern/ghost/GHOST_C-api.h
@@ -1185,6 +1185,30 @@ int GHOST_XrGetControllerModelData(GHOST_XrContextHandle xr_context,
 
 #endif /* WITH_XR_OPENXR */
 
+#ifdef WITH_VULKAN_BACKEND
+
+/**
+ * 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 3d4a034f7f3..52863e8c061 100644
--- a/intern/ghost/GHOST_IContext.h
+++ b/intern/ghost/GHOST_IContext.h
@@ -40,6 +40,20 @@ class GHOST_IContext {
 
   virtual unsigned int getDefaultFramebuffer() = 0;
 
+  virtual GHOST_TSuccess getVulkanHandles(void *, void *, void *, uint32_t *) = 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;
+
   virtual GHOST_TSuccess swapBuffers() = 0;
 
 #ifdef WITH_CXX_GUARDEDALLOC
diff --git a/intern/ghost/GHOST_IWindow.h b/intern/ghost/GHOST_IWindow.h
index f712d9bd9f0..9a8a97ed43f 100644
--- a/intern/ghost/GHOST_IWindow.h
+++ b/intern/ghost/GHOST_IWindow.h
@@ -14,6 +14,8 @@
 #include <stdlib.h>
 #include <string>
 
+class GHOST_IContext;
+
 /**
  * Interface for GHOST windows.
  *
@@ -62,6 +64,12 @@ class GHOST_IWindow {
    */
   virtual GHOST_TSuccess setDrawingContextType(GHOST_TDrawingContextType type) = 0;
 
+  /**
+   * Returns the drawing context used in this window.
+   * \return The current drawing context.
+   */
+  virtual GHOST_IContext *getDrawingContext() = 0;
+
   /**
    * Sets the title displayed in the title bar.
    * \param title: The title to display in the title bar.
@@ -202,6 +210,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 db4eeff3122..3932bc76af0 100644
--- a/intern/ghost/GHOST_Types.h
+++ b/intern/ghost/GHOST_Types.h
@@ -156,6 +156,9 @@ typedef enum {
 #ifdef __APPLE__
   GHOST_kDrawingContextTypeMetal,
 #endif
+#ifdef WITH_VULKAN_BACKEND
+  GHOST_kDrawingContextTypeVulkan,
+#endif
 } GHOST_TDrawingContextType;
 
 typedef enum {
diff --git a/intern/ghost/intern/GHOST_C-api.cpp b/intern/ghost/intern/GHOST_C-api.cpp
index 0c595b27148..0430dc8602c 100644
--- a/intern/ghost/intern/GHOST_C-api.cpp
+++ b/intern/ghost/intern/GHOST_C-api.cpp
@@ -565,6 +565,12 @@ GHOST_TSuccess GHOST_SetDrawingContextType(GHOST_WindowHandle windowhandle,
   return window->setDrawingContextType(type);
 }
 
+GHOST_ContextHandle GHOST_GetDrawingContext(GHOST_WindowHandle windowhandle)
+{
+  GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
+  return (GHOST_ContextHandle)window->getDrawingContext();
+}
+
 void GHOST_SetTitle(GHOST_WindowHandle windowhandle, const char *title)
 {
   GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
@@ -1190,3 +1196,35 @@ int GHOST_XrGetControllerModelData(GHOST_XrContextHandle xr_contexthandle,
 }
 
 #endif /* WITH_XR_OPENXR */
+
+#ifdef WITH_VULKAN_BACKEND
+
+/**
+ * Return vulkan handles for the given context.
+ */
+void GHOST_GetVulkanHandles(GHOST_ContextHandle contexthandle,
+                            void *r_instance,
+                            void *r_physical_device,
+                            void *r_device,
+                            uint32_t *r_graphic_queue_familly)
+{
+  GHOST_IContext *context = (GHOST_IContext *)contexthandle;
+  context->getVulkanHandles(r_instance, r_physical_device, r_device, 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)
+{
+  GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
+  window->getVulkanBackbuffer(image, framebuffer, command_buffer, render_pass, extent, fb_id);
+}
+
+#endif /* WITH_VULKAN */
\ No newline at end of file
diff --git a/intern/ghost/intern/GHOST_Context.h b/intern/ghost/intern/GHOST_Context.h
index 04d445e7f85..366781f8134 100644
--- a/intern/ghost/intern/GHOST_Context.h
+++ b/intern/ghost/intern/GHOST_Context.h
@@ -135,6 +135,33 @@ class GHOST_Context : public GHOST_IContext {
     return 0;
   }
 
+  /**
+   * Gets the Vulkan context related resource handles.
+   * \return  A boolean success indicator.
+   */
+  virtual GHOST_TSuccess getVulkanHandles(void * /*r_instance*/,
+                                          void * /*r_physical_device*/,
+                                          void * /*r_device*/,
+                                          uint32_t * /*r_graphic_queue_familly*/) override
+  {
+    return GHOST_kFailure;
+  };
+
+  /**
+   * 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*/) override
+  {
+    return GHOST_kFailure;
+  }
+
  protected:
   bool m_stereoVisual;
 
diff --git a/intern/ghost/intern/GHOST_ContextVK.cpp b/intern/ghost/intern/GHOST_ContextVK.cpp
new file mode 100644
index 00000000000..fb91505fdc7
--- /dev/null
+++ b/intern/ghost/intern/GHOST_ContextVK.cpp
@@ -0,0 +1,1011 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+/** \file
+ * \ingroup GHOST
+ */
+
+#include "GHOST_ContextVK.h"
+
+#ifdef _WIN32
+#  include <vulkan/vulkan_win32.h>
+#elif defined(__APPLE__)
+#  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>
+
+#include <cassert>
+#include <cstdio>
+#include <cstring>
+#include <iostream>
+
+/* Set to 0 to allow devices that do not have the required features.
+ * This allows development on OSX until we really needs these features. */
+#define STRICT_REQUIREMENTS 1
+
+using namespace std;
+
+static const char *vulkan_error_as_string(VkResult result)
+{
+#define FORMAT_ERROR(X) \
+  case X: { \
+    return "" #X; \
+  }
+
+  switch (result) {
+    FORMAT_ERROR(VK_NOT_READY);
+    FORMAT_ERROR(VK_TIMEOUT);
+    FORMAT_ERROR(VK_EVENT_SET);
+    FORMAT_ERROR(VK_EVENT_RESET);
+    FORMAT_ERROR(VK_INCOMPLETE);
+    FORMAT_ERROR(VK_ERROR_OUT_OF_HOST_MEMORY);
+    FORMAT_ERROR(VK_ERROR_OUT_OF_DEVICE_MEMORY);
+    FORMAT_ERROR(VK_ERROR_INITIALIZATION_FAILED);
+    FORMAT_ERROR(VK_ERROR_DEVICE_LOST);
+    FORMAT_ERROR(VK_ERROR_MEMORY_MAP_FAILED);
+    FOR

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list