st/va: ensure linear memory for dmabuf
authorJulien Isorce <j.isorce@samsung.com>
Tue, 14 Jun 2016 07:40:33 +0000 (08:40 +0100)
committerJulien Isorce <j.isorce@samsung.com>
Tue, 14 Jun 2016 07:40:33 +0000 (08:40 +0100)
In order to do zero-copy between two different devices
the memory should not be tiled.

Tested with GStreamer on a laptop that has 2 GPUs:
1- gstvaapidecode:
   HW decoding and dmabuf export with nouveau driver on Nvidia GPU.
2- glimagesink:
   EGLImage imports dmabuf on Intel GPU.

TEST: DRI_PRIME=1 gst-launch vaapidecodebin ! glimagesink

Signed-off-by: Julien Isorce <j.isorce@samsung.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
src/gallium/auxiliary/vl/vl_video_buffer.c
src/gallium/include/pipe/p_video_codec.h
src/gallium/state_trackers/va/surface.c

index 4a68ac1337f38878178f546cd18adb956dd077d6..fdc9598f8ac8858a422bae9f8802ddd8e9d4d35e 100644 (file)
@@ -250,7 +250,7 @@ vl_video_buffer_template(struct pipe_resource *templ,
    templ->height0 = tmpl->height;
    templ->depth0 = depth;
    templ->array_size = array_size;
-   templ->bind = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET;
+   templ->bind = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET | tmpl->bind;
    templ->usage = usage;
 
    vl_video_buffer_adjust_size(&templ->width0, &templ->height0, plane,
index b5575ab9afab01244856ddc0c422b1eb10d4fc96..b4b2b9c96776d27b8a24943ee14bbda39a10ff8f 100644 (file)
@@ -126,6 +126,7 @@ struct pipe_video_buffer
    unsigned width;
    unsigned height;
    bool interlaced;
+   unsigned bind;
 
    /**
     * destroy this video buffer
index 8a6a397528aa0a0274ab4ef62e464d84ca7acf05..5efb8934c5cbda2b2a664baf7e7075c7cbeb7372 100644 (file)
@@ -621,6 +621,14 @@ vlVaCreateSurfaces2(VADriverContextP ctx, unsigned int format,
 
       switch (memory_type) {
       case VA_SURFACE_ATTRIB_MEM_TYPE_VA:
+         /* The application will clear the TILING flag when the surface is
+          * intended to be exported as dmabuf. Adding shared flag because not
+          * null memory_attibute means VASurfaceAttribExternalBuffers is used.
+          */
+         if (memory_attibute &&
+             !(memory_attibute->flags & VA_SURFACE_EXTBUF_DESC_ENABLE_TILING))
+            templat.bind = PIPE_BIND_LINEAR | PIPE_BIND_SHARED;
+
          surf->buffer = drv->pipe->create_video_buffer(drv->pipe, &templat);
          if (!surf->buffer) {
             FREE(surf);