Mesa (main): gallium/dri: let the driver know if the imported image is DRI_PRIME buffer

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Oct 18 15:59:44 UTC 2021


Module: Mesa
Branch: main
Commit: e9c3dbd046137aebcc18e1d7a1040dc669a0c140
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=e9c3dbd046137aebcc18e1d7a1040dc669a0c140

Author: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer at amd.com>
Date:   Thu Oct 14 15:12:12 2021 +0200

gallium/dri: let the driver know if the imported image is DRI_PRIME buffer

Use createImageFromFds2 together with __DRI_IMAGE_PRIME_LINEAR_BUFFER, so
the driver's resource_from_handle hook will be aware that this specific
image is the linear buffer.

Reviewed-by: Marek Olšák <marek.olsak at amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13362>

---

 include/GL/internal/dri_interface.h  |  1 +
 src/gallium/frontends/dri/dri2.c     |  2 ++
 src/gallium/include/pipe/p_defines.h |  1 +
 src/loader/loader_dri3_helper.c      | 30 +++++++++++++++++++++---------
 4 files changed, 25 insertions(+), 9 deletions(-)

diff --git a/include/GL/internal/dri_interface.h b/include/GL/internal/dri_interface.h
index cd30046fde2..5e06912ffb5 100644
--- a/include/GL/internal/dri_interface.h
+++ b/include/GL/internal/dri_interface.h
@@ -1411,6 +1411,7 @@ enum __DRIChromaSiting {
  * Flags for createImageFromDmaBufs3 and createImageFromFds2
  */
 #define __DRI_IMAGE_PROTECTED_CONTENT_FLAG 0x00000001
+#define __DRI_IMAGE_PRIME_LINEAR_BUFFER    0x00000002
 
 /**
  * queryDmaBufFormatModifierAttribs attributes
diff --git a/src/gallium/frontends/dri/dri2.c b/src/gallium/frontends/dri/dri2.c
index 8c8630586eb..0bf82bbe72a 100644
--- a/src/gallium/frontends/dri/dri2.c
+++ b/src/gallium/frontends/dri/dri2.c
@@ -1526,6 +1526,8 @@ dri2_from_fds2(__DRIscreen *screen, int width, int height, int fourcc,
    unsigned bind = 0;
    if (flags & __DRI_IMAGE_PROTECTED_CONTENT_FLAG)
       bind |= PIPE_BIND_PROTECTED;
+   if (flags & __DRI_IMAGE_PRIME_LINEAR_BUFFER)
+      bind |= PIPE_BIND_DRI_PRIME;
 
    return dri2_create_image_from_fd(screen, width, height, fourcc,
                                    DRM_FORMAT_MOD_INVALID, fds, num_fds,
diff --git a/src/gallium/include/pipe/p_defines.h b/src/gallium/include/pipe/p_defines.h
index 608667b1468..c88aee3936f 100644
--- a/src/gallium/include/pipe/p_defines.h
+++ b/src/gallium/include/pipe/p_defines.h
@@ -514,6 +514,7 @@ enum pipe_flush_flags
 #define PIPE_BIND_LINEAR      (1 << 21)
 #define PIPE_BIND_PROTECTED   (1 << 22) /* Resource will be protected/encrypted */
 #define PIPE_BIND_SAMPLER_REDUCTION_MINMAX (1 << 23) /* PIPE_CAP_SAMPLER_REDUCTION_MINMAX */
+#define PIPE_BIND_DRI_PRIME   (1 << 24)
 
 
 /**
diff --git a/src/loader/loader_dri3_helper.c b/src/loader/loader_dri3_helper.c
index fc043bd0533..b9019b6cd25 100644
--- a/src/loader/loader_dri3_helper.c
+++ b/src/loader/loader_dri3_helper.c
@@ -1545,15 +1545,27 @@ dri3_alloc_render_buffer(struct loader_dri3_drawable *draw, unsigned int format,
       /* The linear buffer was created in the display GPU's vram, so we
        * need to make it visible to render GPU
        */
-      buffer->linear_buffer =
-         draw->ext->image->createImageFromFds(draw->dri_screen,
-                                              width,
-                                              height,
-                                              image_format_to_fourcc(format),
-                                              &buffer_fds[0], num_planes,
-                                              &buffer->strides[0],
-                                              &buffer->offsets[0],
-                                              buffer);
+      if (draw->ext->image->base.version >= 20)
+         buffer->linear_buffer =
+            draw->ext->image->createImageFromFds2(draw->dri_screen,
+                                                  width,
+                                                  height,
+                                                  image_format_to_fourcc(format),
+                                                  &buffer_fds[0], num_planes,
+                                                  __DRI_IMAGE_PRIME_LINEAR_BUFFER,
+                                                  &buffer->strides[0],
+                                                  &buffer->offsets[0],
+                                                  buffer);
+      else
+         buffer->linear_buffer =
+            draw->ext->image->createImageFromFds(draw->dri_screen,
+                                                 width,
+                                                 height,
+                                                 image_format_to_fourcc(format),
+                                                 &buffer_fds[0], num_planes,
+                                                 &buffer->strides[0],
+                                                 &buffer->offsets[0],
+                                                 buffer);
       if (!buffer->linear_buffer)
          goto no_buffer_attrib;
 



More information about the mesa-commit mailing list