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)                
          \
-- 
2.45.2
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Reply via email to