gallium: add a pipe_context parameter to resource_get_handle
authorMarek Olšák <marek.olsak@amd.com>
Sun, 21 Aug 2016 10:24:59 +0000 (12:24 +0200)
committerMarek Olšák <marek.olsak@amd.com>
Thu, 25 Aug 2016 12:09:48 +0000 (14:09 +0200)
radeonsi needs to do some operations (DCC decompression) for OpenGL-OpenCL
interop and this is the only way to make it coherent with the current
context. It can optionally be set to NULL.

Reviewed-by: Brian Paul <brianp@vmware.com>
21 files changed:
src/gallium/auxiliary/util/u_transfer.c
src/gallium/auxiliary/util/u_transfer.h
src/gallium/auxiliary/vl/vl_winsys_dri3.c
src/gallium/drivers/ddebug/dd_screen.c
src/gallium/drivers/ilo/ilo_resource.c
src/gallium/drivers/llvmpipe/lp_texture.c
src/gallium/drivers/noop/noop_pipe.c
src/gallium/drivers/r300/r300_texture.c
src/gallium/drivers/r300/r300_texture.h
src/gallium/drivers/radeon/r600_texture.c
src/gallium/drivers/rbug/rbug_screen.c
src/gallium/drivers/softpipe/sp_texture.c
src/gallium/drivers/trace/tr_screen.c
src/gallium/include/pipe/p_screen.h
src/gallium/state_trackers/dri/dri2.c
src/gallium/state_trackers/nine/swapchain9.c
src/gallium/state_trackers/va/buffer.c
src/gallium/state_trackers/vdpau/output.c
src/gallium/state_trackers/vdpau/surface.c
src/gallium/state_trackers/xa/xa_tracker.c
src/gallium/winsys/sw/wrapper/wrapper_sw_winsys.c

index 82cf68db958bccc58e678dffbeea3da887fbe3da..ba4b9dcc6b345d553cbaf86bca8e6a2e779e5207 100644 (file)
@@ -111,6 +111,7 @@ u_resource( struct pipe_resource *res )
 }
 
 boolean u_resource_get_handle_vtbl(struct pipe_screen *screen,
+                                   struct pipe_context *ctx,
                                    struct pipe_resource *resource,
                                    struct winsys_handle *handle,
                                    unsigned usage)
index 7f680bc658262fbb55f2cf7fc8c764274c56dc36..ab787abdce39fd861c197bab1c21832cbb87479b 100644 (file)
@@ -73,6 +73,7 @@ struct u_resource {
 
 
 boolean u_resource_get_handle_vtbl(struct pipe_screen *screen,
+                                   struct pipe_context *ctx,
                                    struct pipe_resource *resource,
                                    struct winsys_handle *handle,
                                    unsigned usage);
index 61d6205b3261ca2f21bdb57477261e7fb5be34f1..3d596a6d11273d393c78d43672c14d4d3d6afeaf 100644 (file)
@@ -243,7 +243,7 @@ dri3_alloc_back_buffer(struct vl_dri3_screen *scrn)
    memset(&whandle, 0, sizeof(whandle));
    whandle.type= DRM_API_HANDLE_TYPE_FD;
    usage = PIPE_HANDLE_USAGE_EXPLICIT_FLUSH | PIPE_HANDLE_USAGE_READ;
-   scrn->base.pscreen->resource_get_handle(scrn->base.pscreen,
+   scrn->base.pscreen->resource_get_handle(scrn->base.pscreen, NULL,
                                            buffer->texture, &whandle,
                                            usage);
    buffer_fd = whandle.handle;
index 3deba0a6e27819836b7543b674e7d718ecb2ca25..4050e39a124e53d555e99cf56c7b830811fa996b 100644 (file)
@@ -237,13 +237,15 @@ dd_screen_resource_destroy(struct pipe_screen *_screen,
 
 static boolean
 dd_screen_resource_get_handle(struct pipe_screen *_screen,
+                              struct pipe_context *_pipe,
                               struct pipe_resource *resource,
                               struct winsys_handle *handle,
                               unsigned usage)
 {
    struct pipe_screen *screen = dd_screen(_screen)->screen;
+   struct pipe_context *pipe = dd_context(_pipe)->pipe;
 
-   return screen->resource_get_handle(screen, resource, handle, usage);
+   return screen->resource_get_handle(screen, pipe, resource, handle, usage);
 }
 
 
index 0afbfc69ee065323e8a59057ddbf29ebf27974e4..7961288179dbff6e0fa8c0f59586ff211fc2c60c 100644 (file)
@@ -725,6 +725,7 @@ ilo_resource_from_handle(struct pipe_screen *screen,
 
 static boolean
 ilo_resource_get_handle(struct pipe_screen *screen,
+                        struct pipe_context *ctx,
                         struct pipe_resource *res,
                         struct winsys_handle *handle,
                         unsigned usage)
index 0d4c4efe0b972b7951a992ab8a76d6200362e064..733253b0b088bef243801afb9976cdedc0e80d89 100644 (file)
@@ -485,6 +485,7 @@ no_lpr:
 
 static boolean
 llvmpipe_resource_get_handle(struct pipe_screen *screen,
+                             struct pipe_context *ctx,
                             struct pipe_resource *pt,
                             struct winsys_handle *whandle,
                              unsigned usage)
index cf20681e306097b457c42267091620854bd666c1..4eb6051d9bcff7d9b30defb0d107e0d96d62e94a 100644 (file)
@@ -135,6 +135,7 @@ static struct pipe_resource *noop_resource_from_handle(struct pipe_screen *scree
 }
 
 static boolean noop_resource_get_handle(struct pipe_screen *screen,
+                                       struct pipe_context *ctx,
                                        struct pipe_resource *resource,
                                        struct winsys_handle *handle,
                                         unsigned usage)
index 2fc93c2dfd6a634580e4a9efbc8807f727fc57c3..5f459e4819e7b87a4456f04982b7cb30d6c46627 100644 (file)
@@ -1036,6 +1036,7 @@ static void r300_texture_destroy(struct pipe_screen *screen,
 }
 
 boolean r300_resource_get_handle(struct pipe_screen* screen,
+                                 struct pipe_context *ctx,
                                  struct pipe_resource *texture,
                                  struct winsys_handle *whandle,
                                  unsigned usage)
index 4c339429eca50dc91de3096a03be69251bff9efd..33416710e435601044c71e3cee0e192860644307 100644 (file)
@@ -62,6 +62,7 @@ void r300_texture_setup_format_state(struct r300_screen *screen,
                                      struct r300_texture_format_state *out);
 
 boolean r300_resource_get_handle(struct pipe_screen* screen,
+                                 struct pipe_context *ctx,
                                 struct pipe_resource *texture,
                                 struct winsys_handle *whandle,
                                  unsigned usage);
index 8c7bfa328d95408b8aeebb75f32cd3cbdc897d10..9629fbbccb8e82838ad03b1fdad10ca56c85c06e 100644 (file)
@@ -511,6 +511,7 @@ static void r600_degrade_tile_mode_to_linear(struct r600_common_context *rctx,
 }
 
 static boolean r600_texture_get_handle(struct pipe_screen* screen,
+                                      struct pipe_context *ctx,
                                       struct pipe_resource *resource,
                                       struct winsys_handle *whandle,
                                        unsigned usage)
index 8d216691fdb7d65538cd147e04cba8cfd8f4234e..3742c103306efa61d0989191f0478d7b541670d9 100644 (file)
@@ -176,16 +176,19 @@ rbug_screen_resource_from_handle(struct pipe_screen *_screen,
 
 static boolean
 rbug_screen_resource_get_handle(struct pipe_screen *_screen,
+                                struct pipe_context *_pipe,
                                 struct pipe_resource *_resource,
                                 struct winsys_handle *handle,
                                 unsigned usage)
 {
    struct rbug_screen *rb_screen = rbug_screen(_screen);
+   struct rbug_context *rb_pipe = rbug_context(_pipe);
    struct rbug_resource *rb_resource = rbug_resource(_resource);
    struct pipe_screen *screen = rb_screen->screen;
    struct pipe_resource *resource = rb_resource->resource;
 
-   return screen->resource_get_handle(screen, resource, handle, usage);
+   return screen->resource_get_handle(screen, rb_pipe ? rb_pipe->pipe : NULL,
+                                      resource, handle, usage);
 }
 
 
index 9c64397d0b9763e48abf49ee20bc09a866ba05fe..8dca15860e41b52f00aa50b58e04cac7fd7d8d44 100644 (file)
@@ -251,6 +251,7 @@ softpipe_resource_from_handle(struct pipe_screen *screen,
 
 static boolean
 softpipe_resource_get_handle(struct pipe_screen *screen,
+                             struct pipe_context *ctx,
                              struct pipe_resource *pt,
                              struct winsys_handle *whandle,
                              unsigned usage)
index 67241ca2ba1cf7d397fb3cbd152758864bd7d5e3..493725cbcaa05fea7b9b5b8e5eca99d81f665de3 100644 (file)
@@ -333,18 +333,21 @@ trace_screen_resource_from_handle(struct pipe_screen *_screen,
 
 static boolean
 trace_screen_resource_get_handle(struct pipe_screen *_screen,
+                                 struct pipe_context *_pipe,
                                 struct pipe_resource *_resource,
                                 struct winsys_handle *handle,
                                  unsigned usage)
 {
    struct trace_screen *tr_screen = trace_screen(_screen);
+   struct trace_context *tr_pipe = _pipe ? trace_context(_pipe) : NULL;
    struct trace_resource *tr_resource = trace_resource(_resource);
    struct pipe_screen *screen = tr_screen->screen;
    struct pipe_resource *resource = tr_resource->resource;
 
    /* TODO trace call */
 
-   return screen->resource_get_handle(screen, resource, handle, usage);
+   return screen->resource_get_handle(screen, tr_pipe ? tr_pipe->pipe : NULL,
+                                      resource, handle, usage);
 }
 
 
index dd40e07b7eeb148e1926266f0af205ff77c45a6c..255647ed2730f8f97a9b20578e9d665cd8b0def3 100644 (file)
@@ -206,6 +206,12 @@ struct pipe_screen {
     * that the texture is created with a special usage flag like
     * DISPLAYTARGET or PRIMARY.
     *
+    * The context parameter can optionally be used to flush the resource and
+    * the context to make sure the resource is coherent with whatever user
+    * will use it. Some drivers may also use the context to convert
+    * the resource into a format compatible for sharing. The use case is
+    * OpenGL-OpenCL interop. The context parameter is allowed to be NULL.
+    *
     * NOTE: in the case of DRM_API_HANDLE_TYPE_FD handles, the caller
     * takes ownership of the FD.  (This is consistent with
     * EGL_MESA_image_dma_buf_export)
@@ -213,6 +219,7 @@ struct pipe_screen {
     * \param usage  A combination of PIPE_HANDLE_USAGE_* flags.
     */
    boolean (*resource_get_handle)(struct pipe_screen *,
+                                  struct pipe_context *context,
                                  struct pipe_resource *tex,
                                  struct winsys_handle *handle,
                                  unsigned usage);
index 9803b0e1971b90ab6c1fa844a1fdf0886fbcc244..f391c77b657c46406353f12fb1d8ffb7fe712a0d 100644 (file)
@@ -404,7 +404,7 @@ dri2_allocate_buffer(__DRIscreen *sPriv,
    else
       whandle.type = DRM_API_HANDLE_TYPE_KMS;
 
-   screen->base.screen->resource_get_handle(screen->base.screen,
+   screen->base.screen->resource_get_handle(screen->base.screen, NULL,
          buffer->resource, &whandle,
          PIPE_HANDLE_USAGE_EXPLICIT_FLUSH | PIPE_HANDLE_USAGE_READ);
 
@@ -963,25 +963,25 @@ dri2_query_image(__DRIimage *image, int attrib, int *value)
    case __DRI_IMAGE_ATTRIB_STRIDE:
       whandle.type = DRM_API_HANDLE_TYPE_KMS;
       image->texture->screen->resource_get_handle(image->texture->screen,
-            image->texture, &whandle, usage);
+            NULL, image->texture, &whandle, usage);
       *value = whandle.stride;
       return GL_TRUE;
    case __DRI_IMAGE_ATTRIB_HANDLE:
       whandle.type = DRM_API_HANDLE_TYPE_KMS;
       image->texture->screen->resource_get_handle(image->texture->screen,
-         image->texture, &whandle, usage);
+         NULL, image->texture, &whandle, usage);
       *value = whandle.handle;
       return GL_TRUE;
    case __DRI_IMAGE_ATTRIB_NAME:
       whandle.type = DRM_API_HANDLE_TYPE_SHARED;
       image->texture->screen->resource_get_handle(image->texture->screen,
-         image->texture, &whandle, usage);
+         NULL, image->texture, &whandle, usage);
       *value = whandle.handle;
       return GL_TRUE;
    case __DRI_IMAGE_ATTRIB_FD:
       whandle.type= DRM_API_HANDLE_TYPE_FD;
       image->texture->screen->resource_get_handle(image->texture->screen,
-         image->texture, &whandle, usage);
+         NULL, image->texture, &whandle, usage);
       *value = whandle.handle;
       return GL_TRUE;
    case __DRI_IMAGE_ATTRIB_FORMAT:
@@ -1720,7 +1720,8 @@ dri2_interop_export_object(__DRIcontext *_ctx,
    memset(&whandle, 0, sizeof(whandle));
    whandle.type = DRM_API_HANDLE_TYPE_FD;
 
-   success = screen->resource_get_handle(screen, res, &whandle, usage);
+   success = screen->resource_get_handle(screen, st->pipe, res, &whandle,
+                                         usage);
    mtx_unlock(&ctx->Shared->Mutex);
 
    if (!success)
index 08ee482f0d391e0d306b4eae287bfc3a51dc0088..bc1c4b108cb6d971f713e3fa8669ee37f97c7a1d 100644 (file)
@@ -88,7 +88,8 @@ D3DWindowBuffer_create(struct NineSwapChain9 *This,
 
     memset(&whandle, 0, sizeof(whandle));
     whandle.type = DRM_API_HANDLE_TYPE_FD;
-    This->screen->resource_get_handle(This->screen, resource, &whandle,
+    This->screen->resource_get_handle(This->screen, This->pipe, resource,
+                                      &whandle,
                                       for_frontbuffer_reading ?
                                           PIPE_HANDLE_USAGE_WRITE :
                                           PIPE_HANDLE_USAGE_EXPLICIT_FLUSH |
index dfcebbe4bd5dbc99f388cbe1232d8e62157ddf9b..3c9b9d1a1e52479ca00d7ed7fbfb5c9ad82d6eeb 100644 (file)
@@ -302,7 +302,8 @@ vlVaAcquireBufferHandle(VADriverContextP ctx, VABufferID buf_id,
          memset(&whandle, 0, sizeof(whandle));
          whandle.type = DRM_API_HANDLE_TYPE_FD;
 
-         if (!screen->resource_get_handle(screen, buf->derived_surface.resource,
+         if (!screen->resource_get_handle(screen, drv->pipe,
+                                          buf->derived_surface.resource,
                                           &whandle, PIPE_HANDLE_USAGE_READ_WRITE))
             return VA_STATUS_ERROR_INVALID_BUFFER;
 
index 0b4f081be3e79981fdb2c9a5c8e5d6af5d31dd0d..85751ea57014d91db004aef018d6aee8fa585081 100644 (file)
@@ -796,7 +796,8 @@ VdpStatus vlVdpOutputSurfaceDMABuf(VdpVideoSurface surface,
    whandle.type = DRM_API_HANDLE_TYPE_FD;
 
    pscreen = vlsurface->surface->texture->screen;
-   if (!pscreen->resource_get_handle(pscreen, vlsurface->surface->texture, &whandle,
+   if (!pscreen->resource_get_handle(pscreen, vlsurface->device->context,
+                                     vlsurface->surface->texture, &whandle,
                                     PIPE_HANDLE_USAGE_READ_WRITE))
       return VDP_STATUS_NO_IMPLEMENTATION;
 
index 177483e0f6f039b64962c9e44932ba0146a32c51..69afce0049966c3ac34968c464ee57241fce398c 100644 (file)
@@ -470,7 +470,8 @@ VdpStatus vlVdpVideoSurfaceDMABuf(VdpVideoSurface surface,
    whandle.layer = surf->u.tex.first_layer;
 
    pscreen = surf->texture->screen;
-   if (!pscreen->resource_get_handle(pscreen, surf->texture, &whandle,
+   if (!pscreen->resource_get_handle(pscreen, p_surf->device->context,
+                                     surf->texture, &whandle,
                                     PIPE_HANDLE_USAGE_READ_WRITE))
       return VDP_STATUS_NO_IMPLEMENTATION;
 
index e091b0834111bd0053a85952829a7e6a5752f88e..d98bd2dc922e37fbff8930079779994f659da006 100644 (file)
@@ -549,7 +549,8 @@ xa_surface_handle(struct xa_surface *srf,
 
     memset(&whandle, 0, sizeof(whandle));
     whandle.type = handle_type(type);
-    res = screen->resource_get_handle(screen, srf->tex, &whandle,
+    res = screen->resource_get_handle(screen, srf->xa->default_ctx->pipe,
+                                      srf->tex, &whandle,
                                       PIPE_HANDLE_USAGE_READ_WRITE);
     if (!res)
        return -XA_ERR_INVAL;
index e130cd256e98562797d05d5ff1fa5d090ef2d35d..47cf7f028705c9c05e0841252b27adb41027861b 100644 (file)
@@ -202,7 +202,7 @@ wsw_dt_get_handle(struct sw_winsys *ws,
    struct wrapper_sw_displaytarget *wdt = wrapper_sw_displaytarget(dt);
    struct pipe_resource *tex = wdt->tex;
 
-   return wsw->screen->resource_get_handle(wsw->screen, tex, whandle,
+   return wsw->screen->resource_get_handle(wsw->screen, NULL, tex, whandle,
                                            PIPE_HANDLE_USAGE_READ_WRITE);
 }