plugins: use linear storage if not the same device
authorJulien Isorce <j.isorce@samsung.com>
Wed, 19 Oct 2016 14:47:41 +0000 (15:47 +0100)
committerVíctor Manuel Jáquez Leal <victorx.jaquez@intel.com>
Thu, 9 Feb 2017 10:24:08 +0000 (11:24 +0100)
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

index 85a5e0f..7509efa 100644 (file)
@@ -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;