[Mesa-dev] [PATCH v3 3/3] gallium: push offset down to driver

Stanimir Varbanov stanimir.varbanov at linaro.org
Thu May 26 22:10:37 UTC 2016


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

Signed-off-by: Stanimir Varbanov <stanimir.varbanov at linaro.org>
---

Tesing has been done for freedreno, and compile tested following
gallium drivers:
nouveau,svga,virgl,r600,r300,radeonsi,swrast,i915,ilo 

 src/gallium/drivers/nouveau/nouveau_screen.c      |  6 ++++++
 src/gallium/drivers/vc4/vc4_screen.c              |  7 +++++++
 src/gallium/state_trackers/dri/dri2.c             |  7 ++-----
 src/gallium/winsys/i915/drm/i915_drm_buffer.c     |  3 +++
 src/gallium/winsys/intel/drm/intel_drm_winsys.c   |  5 +++++
 src/gallium/winsys/radeon/drm/radeon_drm_bo.c     |  6 ++++++
 src/gallium/winsys/svga/drm/vmw_screen_dri.c      | 12 ++++++++++++
 src/gallium/winsys/sw/kms-dri/kms_dri_sw_winsys.c |  6 ++++++
 src/gallium/winsys/virgl/drm/virgl_drm_winsys.c   |  6 ++++++
 9 files changed, 53 insertions(+), 5 deletions(-)

diff --git a/src/gallium/drivers/nouveau/nouveau_screen.c b/src/gallium/drivers/nouveau/nouveau_screen.c
index 4ca9e5c06cde..2c421cc748c1 100644
--- a/src/gallium/drivers/nouveau/nouveau_screen.c
+++ b/src/gallium/drivers/nouveau/nouveau_screen.c
@@ -89,6 +89,12 @@ nouveau_screen_bo_from_handle(struct pipe_screen *pscreen,
    struct nouveau_bo *bo = 0;
    int ret;
 
+   if (whandle->offset != 0) {
+      debug_printf("%s: attempt to import unsupported winsys offset %d\n",
+                   __FUNCTION__, whandle->offset);
+      return NULL;
+   }
+
    if (whandle->type != DRM_API_HANDLE_TYPE_SHARED &&
        whandle->type != DRM_API_HANDLE_TYPE_FD) {
       debug_printf("%s: attempt to import unsupported handle type %d\n",
diff --git a/src/gallium/drivers/vc4/vc4_screen.c b/src/gallium/drivers/vc4/vc4_screen.c
index 5ab1682b25a5..733275a8f7b9 100644
--- a/src/gallium/drivers/vc4/vc4_screen.c
+++ b/src/gallium/drivers/vc4/vc4_screen.c
@@ -559,6 +559,13 @@ vc4_screen_bo_from_handle(struct pipe_screen *pscreen,
 {
         struct vc4_screen *screen = vc4_screen(pscreen);
 
+        if (whandle->offset != 0) {
+                fprintf(stderr,
+                        "Attempt to import unsupported winsys offset %u\n",
+                        whandle->offset);
+                return NULL;
+        }
+
         switch (whandle->type) {
         case DRM_API_HANDLE_TYPE_SHARED:
                 return vc4_bo_open_name(screen, whandle->handle, whandle->stride);
diff --git a/src/gallium/state_trackers/dri/dri2.c b/src/gallium/state_trackers/dri/dri2.c
index 182d4e6b3e2e..8dea6715d7dd 100644
--- a/src/gallium/state_trackers/dri/dri2.c
+++ b/src/gallium/state_trackers/dri/dri2.c
@@ -790,8 +790,6 @@ dri2_create_image_from_winsys(__DRIscreen *_screen,
    templ.depth0 = 1;
    templ.array_size = 1;
 
-   whandle->offset = 0;
-
    img->texture = screen->base.screen->resource_from_handle(screen->base.screen,
          &templ, whandle, PIPE_HANDLE_USAGE_READ_WRITE);
    if (!img->texture) {
@@ -842,7 +840,7 @@ dri2_create_image_from_fd(__DRIscreen *_screen,
    __DRIimage *img = NULL;
    unsigned err = __DRI_IMAGE_ERROR_SUCCESS;
 
-   if (num_fds != 1 || offsets[0] != 0) {
+   if (num_fds != 1) {
       err = __DRI_IMAGE_ERROR_BAD_MATCH;
       goto exit;
    }
@@ -1056,8 +1054,6 @@ dri2_from_names(__DRIscreen *screen, int width, int height, int format,
 
    if (num_names != 1)
       return NULL;
-   if (offsets[0] != 0)
-      return NULL;
 
    format = convert_fourcc(format, &dri_components);
    if (format == -1)
@@ -1067,6 +1063,7 @@ dri2_from_names(__DRIscreen *screen, int width, int height, int format,
    whandle.type = DRM_API_HANDLE_TYPE_SHARED;
    whandle.handle = names[0];
    whandle.stride = strides[0];
+   whandle.offset = offsets[0];
 
    img = dri2_create_image_from_winsys(screen, width, height, format,
                                        &whandle, loaderPrivate);
diff --git a/src/gallium/winsys/i915/drm/i915_drm_buffer.c b/src/gallium/winsys/i915/drm/i915_drm_buffer.c
index c0698529e1cf..ba454ecf54c0 100644
--- a/src/gallium/winsys/i915/drm/i915_drm_buffer.c
+++ b/src/gallium/winsys/i915/drm/i915_drm_buffer.c
@@ -101,6 +101,9 @@ i915_drm_buffer_from_handle(struct i915_winsys *iws,
    if ((whandle->type != DRM_API_HANDLE_TYPE_SHARED) && (whandle->type != DRM_API_HANDLE_TYPE_FD))
       return NULL;
 
+   if (whandle->offset != 0)
+      return NULL;
+
    buf = CALLOC_STRUCT(i915_drm_buffer);
    if (!buf)
       return NULL;
diff --git a/src/gallium/winsys/intel/drm/intel_drm_winsys.c b/src/gallium/winsys/intel/drm/intel_drm_winsys.c
index 1c5aabe33044..d3bc43030771 100644
--- a/src/gallium/winsys/intel/drm/intel_drm_winsys.c
+++ b/src/gallium/winsys/intel/drm/intel_drm_winsys.c
@@ -313,6 +313,11 @@ intel_winsys_import_handle(struct intel_winsys *winsys,
    drm_intel_bo *bo;
    int err;
 
+   if (handle->offset != 0) {
+      debug_error("attempt to import unsupported winsys offset");
+      return NULL;
+   }
+
    switch (handle->type) {
    case DRM_API_HANDLE_TYPE_SHARED:
       {
diff --git a/src/gallium/winsys/radeon/drm/radeon_drm_bo.c b/src/gallium/winsys/radeon/drm/radeon_drm_bo.c
index 950cbb3e55f2..2c10e2eb6226 100644
--- a/src/gallium/winsys/radeon/drm/radeon_drm_bo.c
+++ b/src/gallium/winsys/radeon/drm/radeon_drm_bo.c
@@ -858,6 +858,12 @@ static struct pb_buffer *radeon_winsys_bo_from_handle(struct radeon_winsys *rws,
     unsigned handle;
     uint64_t size = 0;
 
+    if (!offset && whandle->offset != 0) {
+        fprintf(stderr, "attempt to import unsupported winsys offset %u\n",
+                whandle->offset);
+        return NULL;
+    }
+
     /* We must maintain a list of pairs <handle, bo>, so that we always return
      * the same BO for one particular handle. If we didn't do that and created
      * more than one BO for the same handle and then relocated them in a CS,
diff --git a/src/gallium/winsys/svga/drm/vmw_screen_dri.c b/src/gallium/winsys/svga/drm/vmw_screen_dri.c
index baa22a90beb9..eae678a63581 100644
--- a/src/gallium/winsys/svga/drm/vmw_screen_dri.c
+++ b/src/gallium/winsys/svga/drm/vmw_screen_dri.c
@@ -186,6 +186,12 @@ vmw_drm_gb_surface_from_handle(struct svga_winsys_screen *sws,
     uint32_t handle;
     int ret;
 
+    if (whandle->offset != 0) {
+       fprintf(stderr, "Attempt to import unsupported winsys offset %u\n",
+               whandle->offset);
+       return NULL;
+    }
+
     ret = vmw_ioctl_gb_surface_ref(vws, whandle, &flags, format,
                                    &mip_levels, &handle, &desc.region);
 
@@ -253,6 +259,12 @@ vmw_drm_surface_from_handle(struct svga_winsys_screen *sws,
     int ret;
     int i;
 
+    if (whandle->offset != 0) {
+       fprintf(stderr, "Attempt to import unsupported winsys offset %u\n",
+               whandle->offset);
+       return NULL;
+    }
+
     switch (whandle->type) {
     case DRM_API_HANDLE_TYPE_SHARED:
     case DRM_API_HANDLE_TYPE_KMS:
diff --git a/src/gallium/winsys/sw/kms-dri/kms_dri_sw_winsys.c b/src/gallium/winsys/sw/kms-dri/kms_dri_sw_winsys.c
index 9aaee8844be2..21ac0d7dae83 100644
--- a/src/gallium/winsys/sw/kms-dri/kms_dri_sw_winsys.c
+++ b/src/gallium/winsys/sw/kms-dri/kms_dri_sw_winsys.c
@@ -266,6 +266,12 @@ kms_sw_displaytarget_from_handle(struct sw_winsys *ws,
    assert(whandle->type == DRM_API_HANDLE_TYPE_KMS ||
           whandle->type == DRM_API_HANDLE_TYPE_FD);
 
+   if (whandle->offset != 0) {
+      DEBUG_PRINT("KMS-DEBUG: attempt to import unsupported winsys offset %d\n",
+                  whandle->offset);
+      return NULL;
+   }
+
    switch(whandle->type) {
    case DRM_API_HANDLE_TYPE_FD:
       kms_sw_dt = kms_sw_displaytarget_add_from_prime(kms_sw, whandle->handle);
diff --git a/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c b/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c
index ba009882ec20..c77b8994291b 100644
--- a/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c
+++ b/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c
@@ -380,6 +380,12 @@ virgl_drm_winsys_resource_create_handle(struct virgl_winsys *qws,
    struct virgl_hw_res *res;
    uint32_t handle = whandle->handle;
 
+   if (whandle->offset != 0) {
+      fprintf(stderr, "attempt to import unsupported winsys offset %u\n",
+              whandle->offset);
+      return NULL;
+   }
+
    pipe_mutex_lock(qdws->bo_handles_mutex);
 
    if (whandle->type == DRM_API_HANDLE_TYPE_SHARED) {
-- 
2.7.4



More information about the mesa-dev mailing list