From a8e482f93f7d78144dbd5aaf919dcfe8d7efb64c Mon Sep 17 00:00:00 2001 From: Julien Isorce Date: Wed, 19 Oct 2016 15:47:41 +0100 Subject: [PATCH] plugins: use linear storage if not the same device When dmabuf is negotiated downstream and decoding and rendering are not done on the same device, the layout has to be linear in order for the memory to be shared accross devices, since each device has its own way to do tiling. Right now this code is rather just a to-do comment, since we are not fetching the device ids. https://bugzilla.gnome.org/show_bug.cgi?id=755072 --- gst/vaapi/gstvaapipluginbase.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/gst/vaapi/gstvaapipluginbase.c b/gst/vaapi/gstvaapipluginbase.c index 85a5e0f005..7509efa24c 100644 --- a/gst/vaapi/gstvaapipluginbase.c +++ b/gst/vaapi/gstvaapipluginbase.c @@ -539,6 +539,26 @@ error_create_allocator: } } +static inline guint +get_dmabuf_surface_allocation_flags () +{ + /* @FIXME: fetch the real devices ids */ + /* Pair vendor/device identifies an unique physical device. */ + guint va_vendor_id = 0x00; + guint va_device_id = 0x00; + guint gl_vendor_id = 0x00; + guint gl_device_id = 0x00; + + /* Requires linear memory only if fd export is done on a different + * device than the device where the fd is imported. */ + gboolean same_physical_device = va_vendor_id == gl_vendor_id + && va_device_id == gl_device_id; + + if (same_physical_device) + return 0; + return GST_VAAPI_SURFACE_ALLOC_FLAG_LINEAR_STORAGE; +} + static gboolean ensure_srcpad_allocator (GstVaapiPluginBase * plugin, GstVideoInfo * vinfo, GstCaps * caps) @@ -565,14 +585,12 @@ ensure_srcpad_allocator (GstVaapiPluginBase * plugin, GstVideoInfo * vinfo, return TRUE; plugin->srcpad_allocator = NULL; - - /* enable direct rendering if downstream requests raw video */ if (caps && gst_caps_is_video_raw (caps)) { if (plugin->srcpad_can_dmabuf) { if (GST_IS_VIDEO_DECODER (plugin) || GST_IS_BASE_TRANSFORM (plugin)) { plugin->srcpad_allocator = - gst_vaapi_dmabuf_allocator_new (plugin->display, vinfo, 0, - GST_PAD_SRC); + gst_vaapi_dmabuf_allocator_new (plugin->display, vinfo, + get_dmabuf_surface_allocation_flags (), GST_PAD_SRC); } } else { usage_flag = GST_VAAPI_IMAGE_USAGE_FLAG_DIRECT_RENDER;