[vlc-commits] [Git][videolan/vlc][master] 3 commits: opengl: interop_vaapi: create images before binding them

Steve Lhomme (@robUx4) gitlab at videolan.org
Wed Sep 16 05:59:15 UTC 2026



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
26e52988 by Alexandre Janniaux at 2026-09-16T05:40:27+00:00
opengl: interop_vaapi: create images before binding them

In case of error, the images for the previous plane were already bound.
Proceed with the allocation first, and then do the binding only when it
cannot fail the allocation anymore.

- - - - -
e7e6e5bf by Alexandre Janniaux at 2026-09-16T05:40:27+00:00
opengl: interop_vaapi: drop libva < 1.1 code

The interop had different import part between <1.1 and above, but the
code in the fallback was not even compiling and the core now requires
a higher version or more header guards for the chromas.

libva 1.0 is already pretty old.

- - - - -
778ec071 by Alexandre Janniaux at 2026-09-16T05:40:27+00:00
opengl: interop_vaapi: cleanup after <1.1 drop

release_buffer_info is now always true.

- - - - -


1 changed file:

- modules/video_output/opengl/interop_vaapi.c


Changes:

=====================================
modules/video_output/opengl/interop_vaapi.c
=====================================
@@ -81,14 +81,9 @@ struct priv
 
     struct {
         picture_t *                 pic;
-#if VA_CHECK_VERSION(1, 1, 0)
         /* VADRMPRIMESurfaceDescriptor carries modifier information
          * (GPU tiling, compression, etc...) */
         VADRMPRIMESurfaceDescriptor va_surface_descriptor;
-#else
-        VAImage                     va_image;
-        VABufferInfo                va_buffer_info;
-#endif
         unsigned                    num_planes;
         void *                      egl_images[3];
     } last;
@@ -129,13 +124,8 @@ vaegl_release_last_pic(const struct vlc_gl_interop *interop, struct priv *priv)
     for (unsigned i = 0; i < priv->last.num_planes; ++i)
         vaegl_image_destroy(interop, priv->last.egl_images[i]);
 
-#if VA_CHECK_VERSION(1, 1, 0)
     for (unsigned i = 0; i < priv->last.va_surface_descriptor.num_objects; ++i)
         close(priv->last.va_surface_descriptor.objects[i].fd);
-#else
-    vlc_vaapi_ReleaseBufferHandle(o, priv->vadpy, priv->last.va_image.buf);
-    vlc_vaapi_DestroyImage(o, priv->vadpy, priv->last.va_image.image_id);
-#endif
 
     picture_Release(priv->last.pic);
 }
@@ -180,11 +170,7 @@ tc_vaegl_update(const struct vlc_gl_interop *interop, uint32_t textures[],
 
     if (pic == priv->last.pic)
     {
-#if VA_CHECK_VERSION(1, 1, 0)
         for (unsigned i = 0; i < priv->last.va_surface_descriptor.num_layers; ++i)
-#else
-        for (unsigned i = 0; i < priv->last.va_image.num_planes; ++i)
-#endif
         {
             priv->gl.BindTexture(interop->tex_target, textures[i]);
             priv->glEGLImageTargetTexture2DOES(interop->tex_target, priv->last.egl_images[i]);
@@ -192,17 +178,11 @@ tc_vaegl_update(const struct vlc_gl_interop *interop, uint32_t textures[],
         return VLC_SUCCESS;
     }
 
-#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;
+    bool release_image = false;
     unsigned num_planes = 0;
 
-#if VA_CHECK_VERSION(1, 1, 0)
     {
         VAStatus s = vaSyncSurface(priv->vadpy, vlc_vaapi_PicGetSurface(pic));
         if (s != VA_STATUS_SUCCESS) // non-fatal. ex: VA_STATUS_ERROR_DECODING_ERROR
@@ -214,24 +194,7 @@ tc_vaegl_update(const struct vlc_gl_interop *interop, uint32_t textures[],
                                       &va_surface_descriptor))
         goto error;
     release_image = true;
-#else
-    if (vlc_vaapi_DeriveImage(o, priv->vadpy, vlc_vaapi_PicGetSurface(pic),
-                              &va_image))
-        goto error;
-    release_image = true;
-
-    assert(va_image.format.fourcc == priv->fourcc);
 
-    va_buffer_info = (VABufferInfo) {
-        .mem_type = VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME
-    };
-    if (vlc_vaapi_AcquireBufferHandle(o, priv->vadpy, va_image.buf,
-                                      &va_buffer_info))
-        goto error;
-#endif
-    release_buffer_info = true;
-
-#if VA_CHECK_VERSION(1, 1, 0)
     num_planes = va_surface_descriptor.num_layers;
     for (unsigned i = 0; i < num_planes; ++i)
     {
@@ -246,38 +209,19 @@ tc_vaegl_update(const struct vlc_gl_interop *interop, uint32_t textures[],
                                va_surface_descriptor.objects[obj_idx].drm_format_modifier);
         if (egl_images[i] == NULL)
             goto error;
-
-        priv->gl.BindTexture(interop->tex_target, textures[i]);
-
-        priv->glEGLImageTargetTexture2DOES(interop->tex_target, egl_images[i]);
     }
-#else
-    num_planes = va_image.num_planes;
-    for (unsigned i = 0; i < num_planes; ++i)
-    {
-        egl_images[i] =
-            vaegl_image_create(interop, tex_width[i], tex_height[i],
-                               priv->drm_fourccs[i], va_buffer_info.handle,
-                               va_image.offsets[i], va_image.pitches[i],
-                               DRM_FORMAT_MOD_INVALID);
-        if (egl_images[i] == NULL)
-            goto error;
 
+    for (size_t i = 0; i < num_planes; ++i)
+    {
         priv->gl.BindTexture(interop->tex_target, textures[i]);
-
         priv->glEGLImageTargetTexture2DOES(interop->tex_target, egl_images[i]);
     }
-#endif
 
     if (priv->last.pic != NULL)
         vaegl_release_last_pic(interop, priv);
     priv->last.pic = picture_Hold(pic);
-#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 < num_planes; ++i)
@@ -288,22 +232,11 @@ tc_vaegl_update(const struct vlc_gl_interop *interop, uint32_t textures[],
 error:
     if (release_image)
     {
-        if (release_buffer_info)
-        {
-#if VA_CHECK_VERSION(1, 1, 0)
-            for (unsigned i = 0; i < va_surface_descriptor.num_objects; ++i)
-                close(va_surface_descriptor.objects[i].fd);
-#else
-            vlc_vaapi_ReleaseBufferHandle(o, priv->vadpy, va_image.buf);
-#endif
-        }
+        for (unsigned i = 0; i < va_surface_descriptor.num_objects; ++i)
+            close(va_surface_descriptor.objects[i].fd);
 
         for (unsigned i = 0; i < 3 && egl_images[i] != NULL; ++i)
             vaegl_image_destroy(interop, egl_images[i]);
-
-#if !VA_CHECK_VERSION(1, 1, 0)
-        vlc_vaapi_DestroyImage(o, priv->vadpy, va_image.image_id);
-#endif
     }
     return VLC_EGENERIC;
 }
@@ -366,16 +299,13 @@ tc_va_check_derive_image(const struct vlc_gl_interop *interop)
     if (!pool)
         return VLC_EGENERIC;
 
-    int ret;
-
-#if VA_CHECK_VERSION(1, 1, 0)
     VADRMPRIMESurfaceDescriptor desc;
 
-    ret = vlc_vaapi_ExportSurfaceHandle(o, priv->vadpy, va_surface_ids[0],
-                                        VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2,
-                                        VA_EXPORT_SURFACE_READ_ONLY |
-                                        VA_EXPORT_SURFACE_SEPARATE_LAYERS,
-                                        &desc);
+    int ret = vlc_vaapi_ExportSurfaceHandle(o, priv->vadpy, va_surface_ids[0],
+                                            VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2,
+                                            VA_EXPORT_SURFACE_READ_ONLY |
+                                            VA_EXPORT_SURFACE_SEPARATE_LAYERS,
+                                            &desc);
     if (ret != VLC_SUCCESS)
         goto done;
 
@@ -410,50 +340,6 @@ tc_va_check_derive_image(const struct vlc_gl_interop *interop)
 done_desc:
     for (unsigned i = 0; i < desc.num_objects; ++i)
         close(desc.objects[i].fd);
-    goto done;
-#else
-    VAImage va_image = { .image_id = VA_INVALID_ID };
-    ret = vlc_vaapi_DeriveImage(o, priv->vadpy, va_surface_ids[0],
-                                &va_image);
-    if (ret != VLC_SUCCESS)
-        goto done;
-    assert(va_image.format.fourcc == priv->fourcc);
-
-    VABufferInfo va_buffer_info = (VABufferInfo) {
-        .mem_type = VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME
-    };
-    ret = vlc_vaapi_AcquireBufferHandle(o, priv->vadpy, va_image.buf,
-                                        &va_buffer_info);
-    if (ret != VLC_SUCCESS)
-        goto done_derive;
-
-    for (unsigned i = 0; i < interop->tex_count; ++i)
-    {
-        EGLint w = (va_image.width * interop->texs[i].w.num) / interop->texs[i].w.den;
-        EGLint h = (va_image.height * interop->texs[i].h.num) / interop->texs[i].h.den;
-        EGLImageKHR egl_image =
-            vaegl_image_create(interop, w, h, priv->drm_fourccs[i], va_buffer_info.handle,
-                               va_image.offsets[i], va_image.pitches[i],
-                               DRM_FORMAT_MOD_INVALID);
-        if (egl_image == NULL)
-        {
-            msg_Warn(o, "Can't create Image KHR: kernel too old ?");
-            ret = VLC_EGENERIC;
-            goto done_derive;
-        }
-        vaegl_image_destroy(interop, egl_image);
-    }
-
-    ret = VLC_SUCCESS;
-
-done_derive:
-    if (va_image.image_id != VA_INVALID_ID)
-    {
-        if (va_image.buf != VA_INVALID_ID)
-            vlc_vaapi_ReleaseBufferHandle(o, priv->vadpy, va_image.buf);
-        vlc_vaapi_DestroyImage(o, priv->vadpy, va_image.image_id);
-    }
-#endif
 
 done:
     picture_pool_Release(pool);



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/72446ca8113c84f37bcadf6eaf25f60bafebbc74...778ec071ff216602f2a6e4ddd522dfdb6b791472

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/72446ca8113c84f37bcadf6eaf25f60bafebbc74...778ec071ff216602f2a6e4ddd522dfdb6b791472
You're receiving this email because of your account on code.videolan.org. Manage all notifications: https://code.videolan.org/-/profile/notifications | Help: https://code.videolan.org/help




More information about the vlc-commits mailing list