[FFmpeg-devel] [PATCH] hwcontext_vulkan: fix recent lavapipe regression

Lynne dev at lynne.ee
Mon Jan 13 03:46:45 EET 2025


On 07/01/2025 13:58, Lynne wrote:
> lavapipe indicates it supports external_semaphore_fd, but actually,
> it does not support exporting such?
> 
> Ref: https://gitlab.freedesktop.org/mesa/mesa/-/issues/12422
> ---
>   libavutil/hwcontext_vulkan.c | 25 ++++++++++++++++++++++++-
>   libavutil/vulkan_functions.h |  1 +
>   2 files changed, 25 insertions(+), 1 deletion(-)
> 
> diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
> index c5f4de5684..f11243482b 100644
> --- a/libavutil/hwcontext_vulkan.c
> +++ b/libavutil/hwcontext_vulkan.c
> @@ -111,6 +111,7 @@ typedef struct VulkanDevicePriv {
>       VkPhysicalDeviceProperties2 props;
>       VkPhysicalDeviceMemoryProperties mprops;
>       VkPhysicalDeviceExternalMemoryHostPropertiesEXT hprops;
> +    VkExternalSemaphoreProperties ext_sem_props;
>   
>       /* Enabled features */
>       VulkanDeviceFeatures feats;
> @@ -1715,6 +1716,7 @@ static int vulkan_device_init(AVHWDeviceContext *ctx)
>       FFVulkanFunctions *vk = &p->vkctx.vkfn;
>       VkQueueFamilyProperties2 *qf;
>       VkQueueFamilyVideoPropertiesKHR *qf_vid;
> +    VkPhysicalDeviceExternalSemaphoreInfo ext_sem_props_info;
>       int graph_index, comp_index, tx_index, enc_index, dec_index;
>   
>       /* Set device extension flags */
> @@ -1760,6 +1762,23 @@ static int vulkan_device_init(AVHWDeviceContext *ctx)
>           return AVERROR_EXTERNAL;
>       }
>   
> +    ext_sem_props_info = (VkPhysicalDeviceExternalSemaphoreInfo) {
> +        .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_SEMAPHORE_INFO,
> +#ifdef _WIN32
> +        .handleType = IsWindows8OrGreater()
> +            ? VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_BIT
> +            : VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT,
> +#else
> +        .handleType = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT,
> +#endif
> +    };
> +
> +    p->ext_sem_props.sType = VK_STRUCTURE_TYPE_EXTERNAL_SEMAPHORE_PROPERTIES;
> +
> +    vk->GetPhysicalDeviceExternalSemaphoreProperties(hwctx->phys_dev,
> +                                                     &ext_sem_props_info,
> +                                                     &p->ext_sem_props);
> +
>       qf = av_malloc_array(qf_num, sizeof(VkQueueFamilyProperties2));
>       if (!qf)
>           return AVERROR(ENOMEM);
> @@ -2419,6 +2438,7 @@ static int create_frame(AVHWFramesContext *hwfc, AVVkFrame **frame,
>       VulkanDevicePriv *p = ctx->hwctx;
>       AVVulkanDeviceContext *hwctx = &p->p;
>       FFVulkanFunctions *vk = &p->vkctx.vkfn;
> +    AVVkFrame *f;
>   
>       VkExportSemaphoreCreateInfo ext_sem_info = {
>           .sType = VK_STRUCTURE_TYPE_EXPORT_SEMAPHORE_CREATE_INFO,
> @@ -2447,7 +2467,10 @@ static int create_frame(AVHWFramesContext *hwfc, AVVkFrame **frame,
>           .pNext = &sem_type_info,
>       };
>   
> -    AVVkFrame *f = av_vk_frame_alloc();
> +    if (!(p->ext_sem_props.externalSemaphoreFeatures & VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT))
> +        sem_type_info.pNext = NULL;
> +
> +    f = av_vk_frame_alloc();
>       if (!f) {
>           av_log(ctx, AV_LOG_ERROR, "Unable to allocate memory for AVVkFrame!\n");
>           return AVERROR(ENOMEM);
> diff --git a/libavutil/vulkan_functions.h b/libavutil/vulkan_functions.h
> index eb6f6b01c3..9c6f2d2641 100644
> --- a/libavutil/vulkan_functions.h
> +++ b/libavutil/vulkan_functions.h
> @@ -82,6 +82,7 @@ typedef uint64_t FFVulkanExtensions;
>       MACRO(1, 0, FF_VK_EXT_NO_FLAG,              CreateDevice)                            \
>       MACRO(1, 0, FF_VK_EXT_NO_FLAG,              GetPhysicalDeviceFeatures2)              \
>       MACRO(1, 0, FF_VK_EXT_NO_FLAG,              GetPhysicalDeviceProperties)             \
> +    MACRO(1, 0, FF_VK_EXT_NO_FLAG,              GetPhysicalDeviceExternalSemaphoreProperties)          \
>       MACRO(1, 0, FF_VK_EXT_VIDEO_QUEUE,          GetPhysicalDeviceVideoCapabilitiesKHR)     \
>       MACRO(1, 0, FF_VK_EXT_VIDEO_QUEUE,          GetPhysicalDeviceVideoFormatPropertiesKHR) \
>       MACRO(1, 0, FF_VK_EXT_NO_FLAG,              DeviceWaitIdle)                          \

Pushed with a better title.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_0xA2FEA5F03F034464.asc
Type: application/pgp-keys
Size: 624 bytes
Desc: OpenPGP public key
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20250113/3e8f59b0/attachment.key>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature.asc
Type: application/pgp-signature
Size: 236 bytes
Desc: OpenPGP digital signature
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20250113/3e8f59b0/attachment.sig>


More information about the ffmpeg-devel mailing list