diff --git a/intern/ghost/GHOST_C-api.h b/intern/ghost/GHOST_C-api.h index eb79788a069..63cf94df2ab 100644 --- a/intern/ghost/GHOST_C-api.h +++ b/intern/ghost/GHOST_C-api.h @@ -1285,32 +1285,10 @@ int GHOST_XrGetControllerModelData(GHOST_XrContextHandle xr_context, * * \param context: GHOST context handle of a vulkan context to * get the Vulkan handles from. - * \param r_instance: After calling this function the VkInstance - * referenced by this parameter will contain the VKInstance handle - * of the context associated with the `context` parameter. - * \param r_physical_device: After calling this function the VkPhysicalDevice - * referenced by this parameter will contain the VKPhysicalDevice handle - * of the context associated with the `context` parameter. - * \param r_device: After calling this function the VkDevice - * referenced by this parameter will contain the VKDevice handle - * of the context associated with the `context` parameter. - * \param r_graphic_queue_family: After calling this function the uint32_t - * referenced by this parameter will contain the graphic queue family id - * of the context associated with the `context` parameter. - * \param r_queue: After calling this function the VkQueue - * referenced by this parameter will contain the VKQueue handle - * of the context associated with the `context` parameter. - * \param r_queue_mutex: After calling this function the std::mutex referred - * by this parameter will contain the mutex of the context associated - * with the context parameter. + * \param r_handles: After calling this structure is filled with + * the vulkan handles of the context. */ -void GHOST_GetVulkanHandles(GHOST_ContextHandle context, - void *r_instance, - void *r_physical_device, - void *r_device, - uint32_t *r_graphic_queue_family, - void *r_queue, - void **r_queue_mutex); +void GHOST_GetVulkanHandles(GHOST_ContextHandle context, GHOST_VulkanHandles *r_handles); /** * Set the pre and post callbacks for vulkan swap chain in the given context. diff --git a/intern/ghost/GHOST_IContext.hh b/intern/ghost/GHOST_IContext.hh index e9b7aceccdd..20fb3564e75 100644 --- a/intern/ghost/GHOST_IContext.hh +++ b/intern/ghost/GHOST_IContext.hh @@ -53,33 +53,10 @@ class GHOST_IContext { * Other contexts will not return any handles and leave the * handles where the parameters are referring to unmodified. * - * \param context: GHOST context handle of a vulkan context to - * get the Vulkan handles from. - * \param r_instance: After calling this function the VkInstance - * referenced by this parameter will contain the VKInstance handle - * of the context associated with the `context` parameter. - * \param r_physical_device: After calling this function the VkPhysicalDevice - * referenced by this parameter will contain the VKPhysicalDevice handle - * of the context associated with the `context` parameter. - * \param r_device: After calling this function the VkDevice - * referenced by this parameter will contain the VKDevice handle - * of the context associated with the `context` parameter. - * \param r_graphic_queue_family: After calling this function the uint32_t - * referenced by this parameter will contain the graphic queue family id - * of the context associated with the `context` parameter. - * \param r_queue: After calling this function the VkQueue - * referenced by this parameter will contain the VKQueue handle - * of the context associated with the `context` parameter. - * \param r_queue_mutex: After calling this function the std::mutex referred - * by this parameter will contain the mutex of the context associated - * with the context parameter. + * \param r_handles: After calling this structure is filled with + * the vulkan handles of the context. */ - virtual GHOST_TSuccess getVulkanHandles(void *r_instance, - void *r_physical_device, - void *r_device, - uint32_t *r_graphic_queue_family, - void *r_queue, - void **r_queue_mutex) = 0; + virtual GHOST_TSuccess getVulkanHandles(GHOST_VulkanHandles &r_handles) = 0; /** * Acquire the current swap chain format. diff --git a/intern/ghost/GHOST_Types.h b/intern/ghost/GHOST_Types.h index c119bf9e9f4..80a0f370b0a 100644 --- a/intern/ghost/GHOST_Types.h +++ b/intern/ghost/GHOST_Types.h @@ -747,6 +747,16 @@ typedef struct { /** Resolution of the image. */ VkExtent2D extent; } GHOST_VulkanSwapChainData; + +typedef struct { + VkInstance instance; + VkPhysicalDevice physical_device; + VkDevice device; + uint32_t graphic_queue_family; + VkQueue queue; + void *queue_mutex; +} GHOST_VulkanHandles; + #endif typedef enum { diff --git a/intern/ghost/intern/GHOST_C-api.cc b/intern/ghost/intern/GHOST_C-api.cc index 535c57bebc9..c9e60dd32a0 100644 --- a/intern/ghost/intern/GHOST_C-api.cc +++ b/intern/ghost/intern/GHOST_C-api.cc @@ -1276,17 +1276,10 @@ int GHOST_XrGetControllerModelData(GHOST_XrContextHandle xr_contexthandle, #ifdef WITH_VULKAN_BACKEND -void GHOST_GetVulkanHandles(GHOST_ContextHandle contexthandle, - void *r_instance, - void *r_physical_device, - void *r_device, - uint32_t *r_graphic_queue_family, - void *r_queue, - void **r_queue_mutex) +void GHOST_GetVulkanHandles(GHOST_ContextHandle contexthandle, GHOST_VulkanHandles *r_handles) { GHOST_IContext *context = (GHOST_IContext *)contexthandle; - context->getVulkanHandles( - r_instance, r_physical_device, r_device, r_graphic_queue_family, r_queue, r_queue_mutex); + context->getVulkanHandles(*r_handles); } void GHOST_SetVulkanSwapBuffersCallbacks( diff --git a/intern/ghost/intern/GHOST_Context.hh b/intern/ghost/intern/GHOST_Context.hh index dbfa702da81..d509140c263 100644 --- a/intern/ghost/intern/GHOST_Context.hh +++ b/intern/ghost/intern/GHOST_Context.hh @@ -161,12 +161,7 @@ class GHOST_Context : public GHOST_IContext { * GHOST_kSuccess when the context is a Vulkan context and the * handles have been set. */ - virtual GHOST_TSuccess getVulkanHandles(void * /*r_instance*/, - void * /*r_physical_device*/, - void * /*r_device*/, - uint32_t * /*r_graphic_queue_family*/, - void * /*r_queue*/, - void ** /*r_queue_mutex*/) override + virtual GHOST_TSuccess getVulkanHandles(GHOST_VulkanHandles & /* r_handles */) override { return GHOST_kFailure; }; diff --git a/intern/ghost/intern/GHOST_ContextVK.cc b/intern/ghost/intern/GHOST_ContextVK.cc index d366ebeb558..a140a9ddf88 100644 --- a/intern/ghost/intern/GHOST_ContextVK.cc +++ b/intern/ghost/intern/GHOST_ContextVK.cc @@ -632,28 +632,28 @@ GHOST_TSuccess GHOST_ContextVK::getVulkanSwapChainFormat( return GHOST_kSuccess; } -GHOST_TSuccess GHOST_ContextVK::getVulkanHandles(void *r_instance, - void *r_physical_device, - void *r_device, - uint32_t *r_graphic_queue_family, - void *r_queue, - void **r_queue_mutex) +GHOST_TSuccess GHOST_ContextVK::getVulkanHandles(GHOST_VulkanHandles &r_handles) { - *((VkInstance *)r_instance) = VK_NULL_HANDLE; - *((VkPhysicalDevice *)r_physical_device) = VK_NULL_HANDLE; - *((VkDevice *)r_device) = VK_NULL_HANDLE; + r_handles = { + VK_NULL_HANDLE, /* instance */ + VK_NULL_HANDLE, /* physical_device */ + VK_NULL_HANDLE, /* device */ + 0, /* queue_family */ + VK_NULL_HANDLE, /* queue */ + nullptr, /* queue_mutex */ + }; if (vulkan_device.has_value()) { - *((VkInstance *)r_instance) = vulkan_device->instance; - *((VkPhysicalDevice *)r_physical_device) = vulkan_device->physical_device; - *((VkDevice *)r_device) = vulkan_device->device; - *r_graphic_queue_family = vulkan_device->generic_queue_family; - std::mutex **queue_mutex = (std::mutex **)r_queue_mutex; - *queue_mutex = &vulkan_device->queue_mutex; + r_handles = { + vulkan_device->instance, + vulkan_device->physical_device, + vulkan_device->device, + vulkan_device->generic_queue_family, + m_graphic_queue, + &vulkan_device->queue_mutex, + }; } - *((VkQueue *)r_queue) = m_graphic_queue; - return GHOST_kSuccess; } diff --git a/intern/ghost/intern/GHOST_ContextVK.hh b/intern/ghost/intern/GHOST_ContextVK.hh index 1b7b2b8eafa..e9d52ae2c92 100644 --- a/intern/ghost/intern/GHOST_ContextVK.hh +++ b/intern/ghost/intern/GHOST_ContextVK.hh @@ -124,12 +124,7 @@ class GHOST_ContextVK : public GHOST_Context { * Gets the Vulkan context related resource handles. * \return A boolean success indicator. */ - GHOST_TSuccess getVulkanHandles(void *r_instance, - void *r_physical_device, - void *r_device, - uint32_t *r_graphic_queue_family, - void *r_queue, - void **r_queue_mutex) override; + GHOST_TSuccess getVulkanHandles(GHOST_VulkanHandles &r_handles) override; GHOST_TSuccess getVulkanSwapChainFormat(GHOST_VulkanSwapChainData *r_swap_chain_data) override; diff --git a/source/blender/gpu/vulkan/vk_device.cc b/source/blender/gpu/vulkan/vk_device.cc index 5f609fa1b97..c5ee99d6ce8 100644 --- a/source/blender/gpu/vulkan/vk_device.cc +++ b/source/blender/gpu/vulkan/vk_device.cc @@ -85,14 +85,14 @@ void VKDevice::init(void *ghost_context) { BLI_assert(!is_initialized()); void *queue_mutex = nullptr; - GHOST_GetVulkanHandles((GHOST_ContextHandle)ghost_context, - &vk_instance_, - &vk_physical_device_, - &vk_device_, - &vk_queue_family_, - &vk_queue_, - &queue_mutex); - queue_mutex_ = static_cast(queue_mutex); + GHOST_VulkanHandles handles = {}; + GHOST_GetVulkanHandles((GHOST_ContextHandle)ghost_context, &handles); + vk_instance_ = handles.instance; + vk_physical_device_ = handles.physical_device; + vk_device_ = handles.device; + vk_queue_family_ = handles.graphic_queue_family; + vk_queue_ = handles.queue; + queue_mutex_ = static_cast(handles.queue_mutex); init_physical_device_properties(); init_physical_device_memory_properties();