[Bf-blender-cvs] [b40787115bf] tmp-vulkan: GHOST: Device discovery API.

Jeroen Bakker noreply at git.blender.org
Tue Nov 23 15:29:42 CET 2021


Commit: b40787115bf1e2c3e9d5155a5859e250dfc593a1
Author: Jeroen Bakker
Date:   Tue Nov 23 15:29:11 2021 +0100
Branches: tmp-vulkan
https://developer.blender.org/rBb40787115bf1e2c3e9d5155a5859e250dfc593a1

GHOST: Device discovery API.

Still wip.

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

M	intern/ghost/GHOST_C-api.h
M	intern/ghost/GHOST_Types.h
M	intern/ghost/intern/GHOST_C-api.cpp
M	intern/ghost/intern/GHOST_ContextVK.cpp
M	intern/ghost/intern/GHOST_ContextVK.h

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

diff --git a/intern/ghost/GHOST_C-api.h b/intern/ghost/GHOST_C-api.h
index 6d47153fa5a..1e2200af21c 100644
--- a/intern/ghost/GHOST_C-api.h
+++ b/intern/ghost/GHOST_C-api.h
@@ -1188,7 +1188,27 @@ void GHOST_GetVulkanBackbuffer(GHOST_WindowHandle windowhandle,
                                void *render_pass,
                                void *extent,
                                uint32_t *fb_id);
+/**
+ * \brief Query vulkan devices.
+ *
+ * \returns a device list handle or NULL when there is no vulkan available.
+ */
+GHOST_VulkanDeviceListHandle GHOST_QueryVulkanDevices(GHOST_ContextHandle system);
 
+/**
+ * \brief Destroy the given device list.
+ */
+GHOST_TSuccess GHOST_DestroyVulkanDeviceList(GHOST_VulkanDeviceListHandle device_list_handle);
+
+/**
+ * \brief Get an item from the given device list.
+ *
+ * \returns GHOST_kSuccess when device is loaded. GHOST_kFailure when the given device_list_handle
+ * is incorrect or the given index is out of range.
+ */
+GHOST_TSuccess GHOST_GetVulkanDeviceListItem(GHOST_VulkanDeviceListHandle device_list_handle,
+                                             int64_t index,
+                                             GHOST_VulkanPhysicalDevice *r_device);
 #endif
 
 #ifdef __cplusplus
diff --git a/intern/ghost/GHOST_Types.h b/intern/ghost/GHOST_Types.h
index 4a3830ad608..60a3286a2eb 100644
--- a/intern/ghost/GHOST_Types.h
+++ b/intern/ghost/GHOST_Types.h
@@ -29,6 +29,10 @@
 #  include "MEM_guardedalloc.h"
 #endif
 
+#ifdef WITH_VULKAN
+#  include "vulkan/vulkan.h"
+#endif
+
 #if defined(WITH_CXX_GUARDEDALLOC) && defined(__cplusplus)
 #  define GHOST_DECLARE_HANDLE(name) \
     typedef struct name##__ { \
@@ -785,3 +789,20 @@ typedef struct GHOST_XrControllerModelData {
 } GHOST_XrControllerModelData;
 
 #endif /* WITH_XR_OPENXR */
+
+#ifdef WITH_VULKAN
+
+GHOST_DECLARE_HANDLE(GHOST_VulkanDeviceListHandle);
+
+typedef struct GHOST_VulkanPhysicalDeviceID {
+  uint32_t vendor_id;
+  uint32_t device_id;
+  int32_t index;
+} GHOST_VulkanPhysicalDeviceID;
+
+typedef struct GHOST_VulkanPhysicalDevice {
+  GHOST_VulkanPhysicalDeviceID device_id;
+  VkPhysicalDeviceProperties device_properties;
+} GHOST_VulkanPhysicalDevice;
+
+#endif
\ No newline at end of file
diff --git a/intern/ghost/intern/GHOST_C-api.cpp b/intern/ghost/intern/GHOST_C-api.cpp
index 5a19123f044..8e79b61c27c 100644
--- a/intern/ghost/intern/GHOST_C-api.cpp
+++ b/intern/ghost/intern/GHOST_C-api.cpp
@@ -35,6 +35,9 @@
 #  include "GHOST_IXrContext.h"
 #  include "intern/GHOST_XrSession.h"
 #endif
+#ifdef WITH_VULKAN
+#  include "intern/GHOST_ContextVK.h"
+#endif
 #include "intern/GHOST_CallbackEventConsumer.h"
 #include "intern/GHOST_XrException.h"
 
@@ -1146,4 +1149,41 @@ void GHOST_GetVulkanBackbuffer(GHOST_WindowHandle windowhandle,
   window->getVulkanBackbuffer(image, framebuffer, command_buffer, render_pass, extent, fb_id);
 }
 
+/**
+ * \brief Query vulkan devices.
+ *
+ * \returns a device list handle or NULL when there is no vulkan available.
+ */
+GHOST_VulkanDeviceListHandle GHOST_QueryVulkanDevices(GHOST_ContextHandle contexthandle)
+{
+  GHOST_ContextVK *context = (GHOST_ContextVK *)contexthandle;
+  return (GHOST_VulkanDeviceListHandle)context->queryDevices();
+}
+
+/**
+ * \brief Destroy the given device list.
+ */
+GHOST_TSuccess GHOST_DestroyVulkanDeviceList(GHOST_VulkanDeviceListHandle device_list_handle)
+{
+  if (device_list_handle == nullptr) {
+    return GHOST_kFailure;
+  }
+
+  GHOST_ContextVK::destroyDeviceList((GHOST_VulkanDeviceList *)device_list_handle);
+  return GHOST_kSuccess;
+}
+
+/**
+ * \brief Get an item from the given device list.
+ *
+ * \returns GHOST_kSuccess when device is loaded. GHOST_kFailure when the given device_list_handle
+ * is incorrect or the given index is out of range.
+ */
+GHOST_TSuccess GHOST_GetVulkanDeviceListItem(GHOST_VulkanDeviceListHandle device_list_handle,
+                                             int64_t index,
+                                             GHOST_VulkanPhysicalDevice *r_device)
+{
+  return GHOST_kFailure;
+}
+
 #endif /* WITH_VULKAN */
diff --git a/intern/ghost/intern/GHOST_ContextVK.cpp b/intern/ghost/intern/GHOST_ContextVK.cpp
index 58d7db961a6..b5695714853 100644
--- a/intern/ghost/intern/GHOST_ContextVK.cpp
+++ b/intern/ghost/intern/GHOST_ContextVK.cpp
@@ -1028,3 +1028,17 @@ GHOST_TSuccess GHOST_ContextVK::releaseNativeHandles()
 {
   return GHOST_kSuccess;
 }
+
+GHOST_VulkanDeviceList *GHOST_ContextVK::queryDevices()
+{
+  if (m_instance == nullptr) {
+    // TODO(jbakker): initializeVkInstance();
+  }
+  GHOST_VulkanDeviceList *device_list = new GHOST_VulkanDeviceList();
+  return device_list;
+}
+
+void GHOST_ContextVK::destroyDeviceList(GHOST_VulkanDeviceList *device_list)
+{
+  delete device_list;
+}
\ No newline at end of file
diff --git a/intern/ghost/intern/GHOST_ContextVK.h b/intern/ghost/intern/GHOST_ContextVK.h
index 5048e0308f5..440b106a109 100644
--- a/intern/ghost/intern/GHOST_ContextVK.h
+++ b/intern/ghost/intern/GHOST_ContextVK.h
@@ -64,6 +64,10 @@ typedef enum {
 #endif
 } GHOST_TVulkanPlatformType;
 
+struct GHOST_VulkanDeviceList {
+  std::vector<GHOST_VulkanPhysicalDevice> m_devices;
+};
+
 class GHOST_ContextVK : public GHOST_Context {
   /* XR code needs low level graphics data to send to OpenXR. */
   // friend class GHOST_XrGraphicsBindingOpenGL;
@@ -167,6 +171,9 @@ class GHOST_ContextVK : public GHOST_Context {
     return GHOST_kFailure;
   };
 
+  GHOST_VulkanDeviceList *queryDevices();
+  static void destroyDeviceList(GHOST_VulkanDeviceList *device_list);
+
  private:
 #ifdef _WIN32
   HWND m_hwnd;



More information about the Bf-blender-cvs mailing list