[Mesa-dev] [PATCH 3/5] gallium: add offset to winsys_handle

Rob Clark robdclark at gmail.com
Sun Sep 21 10:46:28 PDT 2014


From: Rob Clark <robclark at freedesktop.org>

Push offset down to driver when importing dmabuf.  This is needed to
more fully support EGL_EXT_image_dma_buf_import (ie. when a non-zero
offset is specified).

Still requires driver support, but the per-driver support for this
should be relatively straightforward.

Signed-off-by: Rob Clark <robclark at freedesktop.org>
---
Not compile tested on r300, radeonsi because of lack of llvm, and vc4
due to not buildable on x86 if ilo enabled.

 src/gallium/drivers/freedreno/freedreno_resource.c  | 5 +++++
 src/gallium/drivers/i915/i915_resource.c            | 4 ++++
 src/gallium/drivers/ilo/ilo_resource.c              | 4 ++++
 src/gallium/drivers/llvmpipe/lp_texture.c           | 3 +++
 src/gallium/drivers/nouveau/nv30/nv30_resource.c    | 4 ++++
 src/gallium/drivers/nouveau/nv50/nv50_resource.c    | 4 ++++
 src/gallium/drivers/nouveau/nvc0/nvc0_resource.c    | 3 +++
 src/gallium/drivers/r300/r300_texture.c             | 5 +++++
 src/gallium/drivers/radeon/r600_texture.c           | 4 ++++
 src/gallium/drivers/softpipe/sp_texture.c           | 5 +++++
 src/gallium/drivers/svga/svga_resource.c            | 4 ++++
 src/gallium/drivers/vc4/vc4_resource.c              | 5 +++++
 src/gallium/include/state_tracker/drm_driver.h      | 5 +++++
 src/gallium/state_trackers/dri/dri2.c               | 3 ++-
 src/gallium/state_trackers/egl/wayland/native_drm.c | 1 +
 15 files changed, 58 insertions(+), 1 deletion(-)

diff --git a/src/gallium/drivers/freedreno/freedreno_resource.c b/src/gallium/drivers/freedreno/freedreno_resource.c
index 1b39c33..9fe9cc5 100644
--- a/src/gallium/drivers/freedreno/freedreno_resource.c
+++ b/src/gallium/drivers/freedreno/freedreno_resource.c
@@ -32,6 +32,8 @@
 #include "util/u_string.h"
 #include "util/u_surface.h"
 
+#include "state_tracker/drm_driver.h"
+
 #include "freedreno_resource.h"
 #include "freedreno_screen.h"
 #include "freedreno_surface.h"
@@ -321,6 +323,9 @@ fd_resource_from_handle(struct pipe_screen *pscreen,
 	if (!rsc)
 		return NULL;
 
+	if (handle->offset != 0)
+		return NULL;
+
 	*prsc = *tmpl;
 
 	pipe_reference_init(&prsc->reference, 1);
diff --git a/src/gallium/drivers/i915/i915_resource.c b/src/gallium/drivers/i915/i915_resource.c
index 627ed2b..452347b 100644
--- a/src/gallium/drivers/i915/i915_resource.c
+++ b/src/gallium/drivers/i915/i915_resource.c
@@ -1,5 +1,7 @@
 #include "util/u_debug.h"
 
+#include "state_tracker/drm_driver.h"
+
 #include "i915_resource.h"
 #include "i915_context.h"
 #include "i915_screen.h"
@@ -25,6 +27,8 @@ i915_resource_from_handle(struct pipe_screen * screen,
 			 const struct pipe_resource *template,
 			 struct winsys_handle *whandle)
 {
+   if (whandle->offset != 0)
+      return NULL;
    if (template->target == PIPE_BUFFER)
       return NULL;
    else
diff --git a/src/gallium/drivers/ilo/ilo_resource.c b/src/gallium/drivers/ilo/ilo_resource.c
index c6eadc3..6801715 100644
--- a/src/gallium/drivers/ilo/ilo_resource.c
+++ b/src/gallium/drivers/ilo/ilo_resource.c
@@ -25,6 +25,8 @@
  *    Chia-I Wu <olv at lunarg.com>
  */
 
+#include "state_tracker/drm_driver.h"
+
 #include "ilo_layout.h"
 #include "ilo_screen.h"
 #include "ilo_resource.h"
@@ -456,6 +458,8 @@ ilo_resource_from_handle(struct pipe_screen *screen,
                          const struct pipe_resource *templ,
                          struct winsys_handle *handle)
 {
+   if (handle->offset != 0)
+      return NULL;
    if (templ->target == PIPE_BUFFER)
       return NULL;
    else
diff --git a/src/gallium/drivers/llvmpipe/lp_texture.c b/src/gallium/drivers/llvmpipe/lp_texture.c
index ba0e7f8..dd1837b 100644
--- a/src/gallium/drivers/llvmpipe/lp_texture.c
+++ b/src/gallium/drivers/llvmpipe/lp_texture.c
@@ -428,6 +428,9 @@ llvmpipe_resource_from_handle(struct pipe_screen *screen,
    struct sw_winsys *winsys = llvmpipe_screen(screen)->winsys;
    struct llvmpipe_resource *lpr;
 
+   if (whandle->offset != 0)
+      return NULL;
+
    /* XXX Seems like from_handled depth textures doesn't work that well */
 
    lpr = CALLOC_STRUCT(llvmpipe_resource);
diff --git a/src/gallium/drivers/nouveau/nv30/nv30_resource.c b/src/gallium/drivers/nouveau/nv30/nv30_resource.c
index 38fac8a..9228f1d 100644
--- a/src/gallium/drivers/nouveau/nv30/nv30_resource.c
+++ b/src/gallium/drivers/nouveau/nv30/nv30_resource.c
@@ -26,6 +26,8 @@
 #include "util/u_format.h"
 #include "util/u_inlines.h"
 
+#include "state_tracker/drm_driver.h"
+
 #include "nv30/nv30_screen.h"
 #include "nv30/nv30_context.h"
 #include "nv30/nv30_resource.h"
@@ -68,6 +70,8 @@ nv30_resource_from_handle(struct pipe_screen *pscreen,
                           const struct pipe_resource *tmpl,
                           struct winsys_handle *handle)
 {
+   if (handle->offset != 0)
+      return NULL;
    if (tmpl->target == PIPE_BUFFER)
       return NULL;
    else
diff --git a/src/gallium/drivers/nouveau/nv50/nv50_resource.c b/src/gallium/drivers/nouveau/nv50/nv50_resource.c
index d289b4a..487aa6f 100644
--- a/src/gallium/drivers/nouveau/nv50/nv50_resource.c
+++ b/src/gallium/drivers/nouveau/nv50/nv50_resource.c
@@ -3,6 +3,8 @@
 #include "util/u_inlines.h"
 #include "util/u_format.h"
 
+#include "state_tracker/drm_driver.h"
+
 #include "nouveau_screen.h"
 
 #include "nv50/nv50_resource.h"
@@ -24,6 +26,8 @@ nv50_resource_from_handle(struct pipe_screen * screen,
                           const struct pipe_resource *templ,
                           struct winsys_handle *whandle)
 {
+   if (whandle->offset != 0)
+      return NULL;
    if (templ->target == PIPE_BUFFER)
       return NULL;
    else
diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_resource.c b/src/gallium/drivers/nouveau/nvc0/nvc0_resource.c
index 12b5a02..94cd47e 100644
--- a/src/gallium/drivers/nouveau/nvc0/nvc0_resource.c
+++ b/src/gallium/drivers/nouveau/nvc0/nvc0_resource.c
@@ -1,5 +1,6 @@
 
 #include "pipe/p_context.h"
+#include "state_tracker/drm_driver.h"
 #include "nvc0/nvc0_resource.h"
 #include "nouveau_screen.h"
 
@@ -21,6 +22,8 @@ nvc0_resource_from_handle(struct pipe_screen * screen,
                           const struct pipe_resource *templ,
                           struct winsys_handle *whandle)
 {
+   if (whandle->offset != 0)
+      return NULL;
    if (templ->target == PIPE_BUFFER) {
       return NULL;
    } else {
diff --git a/src/gallium/drivers/r300/r300_texture.c b/src/gallium/drivers/r300/r300_texture.c
index ffe8c00..deae7d6 100644
--- a/src/gallium/drivers/r300/r300_texture.c
+++ b/src/gallium/drivers/r300/r300_texture.c
@@ -38,6 +38,8 @@
 
 #include "pipe/p_screen.h"
 
+#include "state_tracker/drm_driver.h"
+
 unsigned r300_get_swizzle_combined(const unsigned char *swizzle_format,
                                    const unsigned char *swizzle_view,
                                    boolean dxtc_swizzle)
@@ -1103,6 +1105,9 @@ struct pipe_resource *r300_texture_from_handle(struct pipe_screen *screen,
     enum radeon_bo_layout microtile, macrotile;
     unsigned stride;
 
+    if (whandle->offset != 0)
+       return NULL;
+
     /* Support only 2D textures without mipmaps */
     if ((base->target != PIPE_TEXTURE_2D &&
           base->target != PIPE_TEXTURE_RECT) ||
diff --git a/src/gallium/drivers/radeon/r600_texture.c b/src/gallium/drivers/radeon/r600_texture.c
index 17aca01..0ad4f66 100644
--- a/src/gallium/drivers/radeon/r600_texture.c
+++ b/src/gallium/drivers/radeon/r600_texture.c
@@ -29,6 +29,7 @@
 #include "util/u_format.h"
 #include "util/u_memory.h"
 #include "util/u_pack_color.h"
+#include "state_tracker/drm_driver.h"
 #include <errno.h>
 #include <inttypes.h>
 
@@ -792,6 +793,9 @@ static struct pipe_resource *r600_texture_from_handle(struct pipe_screen *screen
 	bool scanout;
 	int r;
 
+	if (whandle->offset != 0)
+		return NULL;
+
 	/* Support only 2D textures without mipmaps */
 	if ((templ->target != PIPE_TEXTURE_2D && templ->target != PIPE_TEXTURE_RECT) ||
 	      templ->depth0 != 1 || templ->last_level != 0)
diff --git a/src/gallium/drivers/softpipe/sp_texture.c b/src/gallium/drivers/softpipe/sp_texture.c
index c2df71e..cb0d6b8 100644
--- a/src/gallium/drivers/softpipe/sp_texture.c
+++ b/src/gallium/drivers/softpipe/sp_texture.c
@@ -38,6 +38,8 @@
 #include "util/u_memory.h"
 #include "util/u_transfer.h"
 
+#include "state_tracker/drm_driver.h"
+
 #include "sp_context.h"
 #include "sp_flush.h"
 #include "sp_texture.h"
@@ -215,6 +217,9 @@ softpipe_resource_from_handle(struct pipe_screen *screen,
    if (!spr)
       return NULL;
 
+   if (whandle->offset != 0)
+      return NULL;
+
    spr->base = *templat;
    pipe_reference_init(&spr->base.reference, 1);
    spr->base.screen = screen;
diff --git a/src/gallium/drivers/svga/svga_resource.c b/src/gallium/drivers/svga/svga_resource.c
index b295b44..12fdfe7 100644
--- a/src/gallium/drivers/svga/svga_resource.c
+++ b/src/gallium/drivers/svga/svga_resource.c
@@ -25,6 +25,8 @@
 
 #include "util/u_debug.h"
 
+#include "state_tracker/drm_driver.h"
+
 #include "svga_resource.h"
 #include "svga_resource_buffer.h"
 #include "svga_resource_texture.h"
@@ -49,6 +51,8 @@ svga_resource_from_handle(struct pipe_screen * screen,
                           const struct pipe_resource *template,
                           struct winsys_handle *whandle)
 {
+   if (whandle->offset != 0)
+      return NULL;
    if (template->target == PIPE_BUFFER)
       return NULL;
    else
diff --git a/src/gallium/drivers/vc4/vc4_resource.c b/src/gallium/drivers/vc4/vc4_resource.c
index a71ae5b..4958852 100644
--- a/src/gallium/drivers/vc4/vc4_resource.c
+++ b/src/gallium/drivers/vc4/vc4_resource.c
@@ -28,6 +28,8 @@
 #include "util/u_surface.h"
 #include "util/u_blitter.h"
 
+#include "state_tracker/drm_driver.h"
+
 #include "vc4_screen.h"
 #include "vc4_context.h"
 #include "vc4_resource.h"
@@ -329,6 +331,9 @@ vc4_resource_from_handle(struct pipe_screen *pscreen,
         struct pipe_resource *prsc = &rsc->base.b;
         struct vc4_resource_slice *slice = &rsc->slices[0];
 
+        if (handle->offset != 0)
+                return NULL;
+
         if (!rsc)
                 return NULL;
 
diff --git a/src/gallium/include/state_tracker/drm_driver.h b/src/gallium/include/state_tracker/drm_driver.h
index 740c4bb..4b7045d 100644
--- a/src/gallium/include/state_tracker/drm_driver.h
+++ b/src/gallium/include/state_tracker/drm_driver.h
@@ -35,6 +35,11 @@ struct winsys_handle
     * Output for texture_get_handle.
     */
    unsigned stride;
+   /**
+    * Input to texture_from_handle.
+    * TODO: does this ever make sense for output?
+    */
+   unsigned offset;
 };
 
 
diff --git a/src/gallium/state_trackers/dri/dri2.c b/src/gallium/state_trackers/dri/dri2.c
index 98746a6..decba94 100644
--- a/src/gallium/state_trackers/dri/dri2.c
+++ b/src/gallium/state_trackers/dri/dri2.c
@@ -777,7 +777,7 @@ dri2_create_image_from_fd(__DRIscreen *_screen,
    struct winsys_handle whandle;
    int format, pitch, cpp;
 
-   if (num_fds != 1 || offsets[0] != 0) {
+   if (num_fds != 1) {
       *error = __DRI_IMAGE_ERROR_BAD_MATCH;
       return NULL;
    }
@@ -798,6 +798,7 @@ dri2_create_image_from_fd(__DRIscreen *_screen,
    memset(&whandle, 0, sizeof(whandle));
    whandle.type = DRM_API_HANDLE_TYPE_FD;
    whandle.handle = (unsigned)fds[0];
+   whandle.offset = offsets[0];
 
    img = dri2_create_image_from_winsys(_screen, width, height, format,
                                        &whandle, pitch, loaderPrivate);
diff --git a/src/gallium/state_trackers/egl/wayland/native_drm.c b/src/gallium/state_trackers/egl/wayland/native_drm.c
index e1aeeeb..2fdb000 100644
--- a/src/gallium/state_trackers/egl/wayland/native_drm.c
+++ b/src/gallium/state_trackers/egl/wayland/native_drm.c
@@ -101,6 +101,7 @@ wayland_create_drm_buffer(struct wayland_display *display,
    resource = resource_surface_get_single_resource(surface->rsurf, attachment);
    resource_surface_get_size(surface->rsurf, &width, &height);
 
+   memset(&wsh, 0, sizeof(wsh));
    wsh.type = DRM_API_HANDLE_TYPE_SHARED;
    screen->resource_get_handle(screen, resource, &wsh);
 
-- 
1.9.3



More information about the mesa-dev mailing list