[vlc-commits] [Git][videolan/vlc][3.0.x] 2 commits: converter_vaapi: Don't use DeriveImage with ExportSurfaceHandle

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Sun Apr 28 14:44:57 UTC 2024



Jean-Baptiste Kempf pushed to branch 3.0.x at VideoLAN / VLC


Commits:
ea946360 by David Rosca at 2024-04-28T14:01:49+00:00
converter_vaapi: Don't use DeriveImage with ExportSurfaceHandle

DeriveImage is only needed when AcquireBufferHandle is used with old libva.

(cherry picked from commit b1e5a91d616190d931b999f223c8206bc94bc6c5)

- - - - -
374ce3b5 by David Rosca at 2024-04-28T14:01:49+00:00
vaapi: chroma: Implement vaPutImage upload fallback

(cherry picked from commit ac178ac8e3132b40330c1344fe3700b38ad0b552)

- - - - -


2 changed files:

- modules/hw/vaapi/chroma.c
- modules/video_output/opengl/converter_vaapi.c


Changes:

=====================================
modules/hw/vaapi/chroma.c
=====================================
@@ -252,18 +252,40 @@ UploadSurface(filter_t *filter, picture_t *src)
     vlc_vaapi_PicAttachContext(dest_pic);
     picture_CopyProperties(dest_pic, src);
 
-    if (vlc_vaapi_DeriveImage(VLC_OBJECT(filter), va_dpy,
-                              vlc_vaapi_PicGetSurface(dest_pic), &dest_img)
-        || vlc_vaapi_MapBuffer(VLC_OBJECT(filter), va_dpy,
-                               dest_img.buf, &dest_buf))
+    if (filter->p_sys->derive_failed ||
+        vlc_vaapi_DeriveImage(VLC_OBJECT(filter), va_dpy,
+                              vlc_vaapi_PicGetSurface(dest_pic), &dest_img))
+    {
+        if (filter->p_sys->image_fallback_failed)
+            goto error;
+
+        filter->p_sys->derive_failed = true;
+
+        if (CreateFallbackImage(filter, dest_pic, va_dpy, &dest_img))
+        {
+            filter->p_sys->image_fallback_failed = true;
+            goto error;
+        }
+    }
+
+    if (vlc_vaapi_MapBuffer(VLC_OBJECT(filter), va_dpy,
+                            dest_img.buf, &dest_buf))
         goto error;
 
     FillVAImageFromPicture(&dest_img, dest_buf, dest_pic,
                            src, &filter->p_sys->cache);
 
-    if (vlc_vaapi_UnmapBuffer(VLC_OBJECT(filter), va_dpy, dest_img.buf)
-        || vlc_vaapi_DestroyImage(VLC_OBJECT(filter),
-                                  va_dpy, dest_img.image_id))
+    if (vlc_vaapi_UnmapBuffer(VLC_OBJECT(filter), va_dpy, dest_img.buf))
+        goto error;
+
+    if (filter->p_sys->derive_failed &&
+        vaPutImage(va_dpy, vlc_vaapi_PicGetSurface(dest_pic), dest_img.image_id,
+                   0, 0, dest_pic->format.i_width, dest_pic->format.i_height,
+                   0, 0, dest_pic->format.i_width, dest_pic->format.i_height))
+        goto error;
+
+    if (vlc_vaapi_DestroyImage(VLC_OBJECT(filter),
+                               va_dpy, dest_img.image_id))
         goto error;
 
 ret:


=====================================
modules/video_output/opengl/converter_vaapi.c
=====================================
@@ -72,9 +72,10 @@ struct priv
          * (GPU tiling, compression, etc...) */
         VADRMPRIMESurfaceDescriptor va_surface_descriptor;
 #else
+        VAImage                     va_image;
         VABufferInfo                va_buffer_info;
 #endif
-        VAImage                     va_image;
+        unsigned                    num_planes;
         void *                      egl_images[3];
     } last;
 };
@@ -111,7 +112,7 @@ vaegl_release_last_pic(const opengl_tex_converter_t *tc, struct priv *priv)
 {
     vlc_object_t *o = VLC_OBJECT(tc->gl);
 
-    for (unsigned i = 0; i < priv->last.va_image.num_planes; ++i)
+    for (unsigned i = 0; i < priv->last.num_planes; ++i)
         vaegl_image_destroy(tc, priv->last.egl_images[i]);
 
 #if VA_CHECK_VERSION(1, 1, 0)
@@ -119,9 +120,9 @@ vaegl_release_last_pic(const opengl_tex_converter_t *tc, struct priv *priv)
         close(priv->last.va_surface_descriptor.objects[i].fd);
 #else
     vlc_vaapi_ReleaseBufferHandle(o, priv->vadpy, priv->last.va_image.buf);
-#endif
 
     vlc_vaapi_DestroyImage(o, priv->vadpy, priv->last.va_image.image_id);
+#endif
 
     picture_Release(priv->last.pic);
 }
@@ -182,26 +183,35 @@ tc_vaegl_update(const opengl_tex_converter_t *tc, GLuint *textures,
     (void) plane_offset;
     struct priv *priv = tc->priv;
     vlc_object_t *o = VLC_OBJECT(tc->gl);
-    VAImage va_image;
 #if VA_CHECK_VERSION(1, 1, 0)
     VADRMPRIMESurfaceDescriptor va_surface_descriptor;
 #else
+    VAImage va_image;
     VABufferInfo va_buffer_info;
 #endif
     EGLImageKHR egl_images[3] = { };
     bool release_image = false, release_buffer_info = false;
+    unsigned num_planes = 0;
 
     if (pic == priv->last.pic)
     {
-        va_image = priv->last.va_image;
 #if VA_CHECK_VERSION(1, 1, 0)
         va_surface_descriptor = priv->last.va_surface_descriptor;
+#else
+        va_image = priv->last.va_image;
 #endif
-        for (unsigned i = 0; i < priv->last.va_image.num_planes; ++i)
+        for (unsigned i = 0; i < priv->last.num_planes; ++i)
             egl_images[i] = priv->last.egl_images[i];
     }
     else
     {
+#if VA_CHECK_VERSION(1, 1, 0)
+        if (vlc_vaapi_ExportSurfaceHandle(o, priv->vadpy, vlc_vaapi_PicGetSurface(pic),
+                                          VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2, 0,
+                                          &va_surface_descriptor))
+            goto error;
+        release_image = true;
+#else
         if (vlc_vaapi_DeriveImage(o, priv->vadpy, vlc_vaapi_PicGetSurface(pic),
                                   &va_image))
             goto error;
@@ -209,12 +219,6 @@ tc_vaegl_update(const opengl_tex_converter_t *tc, GLuint *textures,
 
         assert(va_image.format.fourcc == priv->fourcc);
 
-#if VA_CHECK_VERSION(1, 1, 0)
-        if (vlc_vaapi_ExportSurfaceHandle(o, priv->vadpy, vlc_vaapi_PicGetSurface(pic),
-                                          VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2, 0,
-                                          &va_surface_descriptor))
-            goto error;
-#else
         va_buffer_info = (VABufferInfo) {
             .mem_type = VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME
         };
@@ -226,7 +230,8 @@ tc_vaegl_update(const opengl_tex_converter_t *tc, GLuint *textures,
     }
 
 #if VA_CHECK_VERSION(1, 1, 0)
-    for (unsigned i = 0; i < va_surface_descriptor.num_layers; ++i)
+    num_planes = va_surface_descriptor.num_layers;
+    for (unsigned i = 0; i < num_planes; ++i)
     {
         unsigned obj_idx = va_surface_descriptor.layers[i].object_index[0];
 
@@ -251,7 +256,8 @@ tc_vaegl_update(const opengl_tex_converter_t *tc, GLuint *textures,
         priv->glEGLImageTargetTexture2DOES(tc->tex_target, egl_images[i]);
     }
 #else
-    for (unsigned i = 0; i < va_image.num_planes; ++i)
+    num_planes = va_image.num_planes;
+    for (unsigned i = 0; i < num_planes; ++i)
     {
         egl_images[i] =
             vaegl_image_create(tc, tex_width[i], tex_height[i],
@@ -272,14 +278,15 @@ tc_vaegl_update(const opengl_tex_converter_t *tc, GLuint *textures,
         if (priv->last.pic != NULL)
             vaegl_release_last_pic(tc, priv);
         priv->last.pic = picture_Hold(pic);
-        priv->last.va_image = va_image;
 #if VA_CHECK_VERSION(1, 1, 0)
         priv->last.va_surface_descriptor = va_surface_descriptor;
 #else
+        priv->last.va_image = va_image;
         priv->last.va_buffer_info = va_buffer_info;
 #endif
+        priv->last.num_planes = num_planes;
 
-        for (unsigned i = 0; i < va_image.num_planes; ++i)
+        for (unsigned i = 0; i < num_planes; ++i)
             priv->last.egl_images[i] = egl_images[i];
     }
 
@@ -301,7 +308,9 @@ error:
         for (unsigned i = 0; i < 3 && egl_images[i] != NULL; ++i)
             vaegl_image_destroy(tc, egl_images[i]);
 
+#if !VA_CHECK_VERSION(1, 1, 0)
         vlc_vaapi_DestroyImage(o, priv->vadpy, va_image.image_id);
+#endif
     }
     return VLC_EGENERIC;
 }



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/5b557e89a2354c2018f16868e814e1dd2ff9af18...374ce3b5e1cdbdc94a2a8ea9714e9dfdbc1d2f9f

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/5b557e89a2354c2018f16868e814e1dd2ff9af18...374ce3b5e1cdbdc94a2a8ea9714e9dfdbc1d2f9f
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list