[PATCH v5 4/4] winevulkan: Implement VK_KHR_external_memory_win32 for images.

Georg Lehmann dadschoorse at gmail.com
Thu May 20 14:44:59 CDT 2021



On 20.05.21 20:31, Derek Lesho wrote:
> Signed-off-by: Derek Lesho <dlesho at codeweavers.com>
> ---
> v5:
>    - Use the helpers introduced in [PATCH 3/4 v5].
>    - Address other comments.
> ---
>   dlls/winevulkan/make_vulkan |  3 ++
>   dlls/winevulkan/vulkan.c    | 96 +++++++++++++++++++++++++++++--------
>   2 files changed, 80 insertions(+), 19 deletions(-)
> 
> diff --git a/dlls/winevulkan/make_vulkan b/dlls/winevulkan/make_vulkan
> index 33e3cdeaeac..c068cab1546 100755
> --- a/dlls/winevulkan/make_vulkan
> +++ b/dlls/winevulkan/make_vulkan
> @@ -193,6 +193,7 @@ FUNCTION_OVERRIDES = {
>       "vkAllocateMemory" : {"dispatch" : True, "driver" : False, "thunk" : ThunkType.NONE},
>       "vkCreateBuffer" : {"dispatch" : True, "driver" : False, "thunk" : ThunkType.NONE},
>       "vkCreateCommandPool" : {"dispatch": True, "driver" : False, "thunk" : ThunkType.NONE},
> +    "vkCreateImage" : {"dispatch" : True, "driver" : False, "thunk" : ThunkType.NONE},
>       "vkDestroyCommandPool" : {"dispatch": True, "driver" : False, "thunk" : ThunkType.NONE},
>       "vkDestroyDevice" : {"dispatch" : True, "driver" : False, "thunk" : ThunkType.NONE},
>       "vkFreeCommandBuffers" : {"dispatch" : True, "driver" : False, "thunk" : ThunkType.NONE},
> @@ -275,7 +276,9 @@ STRUCT_CHAIN_CONVERSIONS = {
>   
>       # Structs which require pNext chain modification
>       "VkBufferCreateInfo": [],
> +    "VkImageCreateInfo": [],
>       "VkMemoryAllocateInfo": ["VK_STRUCTURE_TYPE_EXPORT_MEMORY_WIN32_HANDLE_INFO_KHR", "VK_STRUCTURE_TYPE_IMPORT_MEMORY_WIN32_HANDLE_INFO_KHR"],
> +    "VkPhysicalDeviceImageFormatInfo2": [],
>   }
>   
>   
> diff --git a/dlls/winevulkan/vulkan.c b/dlls/winevulkan/vulkan.c
> index bf915b8145d..b8570fc826b 100644
> --- a/dlls/winevulkan/vulkan.c
> +++ b/dlls/winevulkan/vulkan.c
> @@ -1286,46 +1286,72 @@ void WINAPI wine_vkGetPhysicalDeviceExternalBufferPropertiesKHR(VkPhysicalDevice
>       wine_vk_get_physical_device_external_buffer_properties(phys_dev, phys_dev->instance->funcs.p_vkGetPhysicalDeviceExternalBufferPropertiesKHR, buffer_info, properties);
>   }
>   
> -VkResult WINAPI wine_vkGetPhysicalDeviceImageFormatProperties2(VkPhysicalDevice phys_dev,
> +static VkResult wine_vk_get_physical_device_image_format_properties_2(VkPhysicalDevice phys_dev,
> +        VkResult (*p_vkGetPhysicalDeviceImageFormatProperties2)(VkPhysicalDevice, const VkPhysicalDeviceImageFormatInfo2 *, VkImageFormatProperties2 *),
>           const VkPhysicalDeviceImageFormatInfo2 *format_info, VkImageFormatProperties2 *properties)
>   {
> +    VkPhysicalDeviceExternalImageFormatInfo *external_image_info_dup = NULL;
> +    const VkPhysicalDeviceExternalImageFormatInfo *external_image_info;
> +    VkPhysicalDeviceImageFormatInfo2 format_info_host = *format_info;
>       VkExternalImageFormatProperties *external_image_properties;
>       VkResult res;
>   
> -    TRACE("%p, %p, %p\n", phys_dev, format_info, properties);
> +    if ((external_image_info = wine_vk_find_struct(format_info, PHYSICAL_DEVICE_EXTERNAL_IMAGE_FORMAT_INFO)) && external_image_info->handleType)
> +    {
> +        if (external_image_info->handleType == VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT)
> +        {
> +            if ((res = convert_VkPhysicalDeviceImageFormatInfo2_struct_chain(format_info->pNext, &format_info_host)) < 0)
> +            {
> +                WARN("Failed to convert VkPhysicalDeviceImageFormatInfo2 pNext chain, res=%d.\n", res);
> +                return res;
> +            }
> +
> +            external_image_info_dup = wine_vk_find_struct(&format_info_host, PHYSICAL_DEVICE_EXTERNAL_IMAGE_FORMAT_INFO);
> +            external_image_info_dup->handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT;
> +        }
> +
> +        wine_vk_normalize_handle_types_host(&external_image_info_dup->handleType);
> +        if (!external_image_info_dup->handleType)
> +        {
> +            WARN("Unsupported handle type %#x.\n", external_image_info->handleType);
> +            return VK_ERROR_FORMAT_NOT_SUPPORTED;
> +        }

This still allows applications to query with FD_BIT.

> +    }
> +
> +    res = p_vkGetPhysicalDeviceImageFormatProperties2(phys_dev, &format_info_host, properties);
>   
> -    res = thunk_vkGetPhysicalDeviceImageFormatProperties2(phys_dev, format_info, properties);
> +    if (external_image_info_dup)
> +        free_VkPhysicalDeviceImageFormatInfo2_struct_chain(&format_info_host);
>   
>       if ((external_image_properties = wine_vk_find_struct(properties, EXTERNAL_IMAGE_FORMAT_PROPERTIES)))
>       {
>           VkExternalMemoryProperties *p = &external_image_properties->externalMemoryProperties;
> -        p->externalMemoryFeatures = 0;
> -        p->exportFromImportedHandleTypes = 0;
> -        p->compatibleHandleTypes = 0;
> +        if (p->exportFromImportedHandleTypes & VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT)
> +            p->exportFromImportedHandleTypes |= VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT;
> +        wine_vk_normalize_handle_types_win(&p->exportFromImportedHandleTypes);
> +
> +        if (p->compatibleHandleTypes & VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT)
> +            p->compatibleHandleTypes |= VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT;
> +        wine_vk_normalize_handle_types_win(&p->compatibleHandleTypes);
>       }
>   
>       return res;
>   }
>   
> -VkResult WINAPI wine_vkGetPhysicalDeviceImageFormatProperties2KHR(VkPhysicalDevice phys_dev,
> +VkResult WINAPI wine_vkGetPhysicalDeviceImageFormatProperties2(VkPhysicalDevice phys_dev,
>           const VkPhysicalDeviceImageFormatInfo2 *format_info, VkImageFormatProperties2 *properties)
>   {
> -    VkExternalImageFormatProperties *external_image_properties;
> -    VkResult res;
> -
>       TRACE("%p, %p, %p\n", phys_dev, format_info, properties);
>   
> -    res = thunk_vkGetPhysicalDeviceImageFormatProperties2KHR(phys_dev, format_info, properties);
> +    return wine_vk_get_physical_device_image_format_properties_2(phys_dev, thunk_vkGetPhysicalDeviceImageFormatProperties2, format_info, properties);
> +}
>   
> -    if ((external_image_properties = wine_vk_find_struct(properties, EXTERNAL_IMAGE_FORMAT_PROPERTIES)))
> -    {
> -        VkExternalMemoryProperties *p = &external_image_properties->externalMemoryProperties;
> -        p->externalMemoryFeatures = 0;
> -        p->exportFromImportedHandleTypes = 0;
> -        p->compatibleHandleTypes = 0;
> -    }
> +VkResult WINAPI wine_vkGetPhysicalDeviceImageFormatProperties2KHR(VkPhysicalDevice phys_dev,
> +        const VkPhysicalDeviceImageFormatInfo2 *format_info, VkImageFormatProperties2 *properties)
> +{
> +    TRACE("%p, %p, %p\n", phys_dev, format_info, properties);
>   
> -    return res;
> +    return wine_vk_get_physical_device_image_format_properties_2(phys_dev, thunk_vkGetPhysicalDeviceImageFormatProperties2KHR, format_info, properties);
>   }
>   
>   /* From ntdll/unix/sync.c */
> @@ -2058,3 +2084,35 @@ VkResult WINAPI wine_vkCreateBuffer(VkDevice device, const VkBufferCreateInfo *c
>   
>       return res;
>   }
> +
> +VkResult WINAPI wine_vkCreateImage(VkDevice device, const VkImageCreateInfo *create_info,
> +    const VkAllocationCallbacks *allocator, VkBuffer *image)
> +{
> +    VkExternalMemoryImageCreateInfo *external_memory_info;
> +    VkImageCreateInfo create_info_host = *create_info;
> +    VkResult res;
> +
> +    TRACE("%p %p %p %p\n", device, create_info, allocator, image);
> +
> +    if (allocator)
> +        FIXME("Support for allocation callbacks not implemented yet\n");
> +
> +    if ((res = convert_VkImageCreateInfo_struct_chain(create_info->pNext, &create_info_host)))
> +    {
> +        WARN("Failed to convert VkImageCreateInfo pNext chain, res=%d.\n", res);
> +        return res;
> +    }
> +
> +    if ((external_memory_info = wine_vk_find_struct(&create_info_host, EXTERNAL_MEMORY_IMAGE_CREATE_INFO)))
> +    {
> +        if (external_memory_info->handleTypes & VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT_KHR)
> +            external_memory_info->handleTypes |= VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR;
> +        wine_vk_normalize_handle_types_host(&external_memory_info->handleTypes);
> +    }
> +
> +    res = device->funcs.p_vkCreateImage(device->device, &create_info_host, NULL, image);
> +
> +    free_VkImageCreateInfo_struct_chain(&create_info_host);
> +
> +    return res;
> +}
> 



More information about the wine-devel mailing list