gallium: add external usage flags to resource_from(get)_handle (v2)
authorMarek Olšák <marek.olsak@amd.com>
Wed, 24 Feb 2016 17:51:15 +0000 (18:51 +0100)
committerMarek Olšák <marek.olsak@amd.com>
Wed, 9 Mar 2016 14:02:25 +0000 (15:02 +0100)
This will allow drivers to make better decisions about texture sharing
for DRI2, DRI3, Wayland, and OpenCL.

v2: add read/write flags, take advantage of __DRI_IMAGE_USE_BACKBUFFER

Reviewed-by: Axel Davy <axel.davy@ens.fr>
30 files changed:
src/gallium/auxiliary/util/u_transfer.c
src/gallium/auxiliary/util/u_transfer.h
src/gallium/auxiliary/vl/vl_winsys_dri.c
src/gallium/drivers/ddebug/dd_screen.c
src/gallium/drivers/freedreno/freedreno_resource.c
src/gallium/drivers/i915/i915_resource.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/nouveau/nv30/nv30_resource.c
src/gallium/drivers/nouveau/nv50/nv50_resource.c
src/gallium/drivers/nouveau/nvc0/nvc0_resource.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/svga/svga_resource.c
src/gallium/drivers/trace/tr_screen.c
src/gallium/drivers/vc4/vc4_resource.c
src/gallium/drivers/virgl/virgl_resource.c
src/gallium/include/pipe/p_defines.h
src/gallium/include/pipe/p_screen.h
src/gallium/state_trackers/dri/dri2.c
src/gallium/state_trackers/dri/dri_screen.h
src/gallium/state_trackers/nine/swapchain9.c
src/gallium/state_trackers/va/buffer.c
src/gallium/state_trackers/va/surface.c
src/gallium/state_trackers/xa/xa_tracker.c
src/gallium/winsys/sw/wrapper/wrapper_sw_winsys.c

index adae84bbfab791a7f2d1825e7745956fbebef74f..0610535cd2c95fc4acbb69d12f63284c1493d213 100644 (file)
@@ -98,7 +98,8 @@ u_resource( struct pipe_resource *res )
 
 boolean u_resource_get_handle_vtbl(struct pipe_screen *screen,
                                    struct pipe_resource *resource,
-                                   struct winsys_handle *handle)
+                                   struct winsys_handle *handle,
+                                   unsigned usage)
 {
    struct u_resource *ur = u_resource(resource);
    return ur->vtbl->resource_get_handle(screen, resource, handle);
index 6c25ee0f024e08b82431a55214f554c97266e9fd..660dc161d33b01ed65ee91955fef4f8111959760 100644 (file)
@@ -78,7 +78,8 @@ struct u_resource {
 
 boolean u_resource_get_handle_vtbl(struct pipe_screen *screen,
                                    struct pipe_resource *resource,
-                                   struct winsys_handle *handle);
+                                   struct winsys_handle *handle,
+                                   unsigned usage);
 
 void u_resource_destroy_vtbl(struct pipe_screen *screen,
                              struct pipe_resource *resource);
index 758f50d7c23e32d24bbca29b686b85ed7dfa6529..01365260312e492cdf3590e12cb2d99ce3277808 100644 (file)
@@ -248,7 +248,8 @@ vl_dri2_screen_texture_from_drawable(struct vl_screen *vscreen, void *drawable)
    template.flags = 0;
 
    tex = scrn->base.pscreen->resource_from_handle(scrn->base.pscreen, &template,
-                                                  &dri2_handle);
+                                                  &dri2_handle,
+                                                  PIPE_HANDLE_USAGE_READ_WRITE);
    free(reply);
 
    return tex;
index 3706b2d63f52b35570d612781bd79bfdc1f31df7..fbc0bec73ddcbe4cbb59c9992d6d3b59c1ff2d97 100644 (file)
@@ -179,11 +179,12 @@ dd_screen_resource_create(struct pipe_screen *_screen,
 static struct pipe_resource *
 dd_screen_resource_from_handle(struct pipe_screen *_screen,
                                const struct pipe_resource *templ,
-                               struct winsys_handle *handle)
+                               struct winsys_handle *handle,
+                               unsigned usage)
 {
    struct pipe_screen *screen = dd_screen(_screen)->screen;
    struct pipe_resource *res =
-      screen->resource_from_handle(screen, templ, handle);
+      screen->resource_from_handle(screen, templ, handle, usage);
 
    if (!res)
       return NULL;
@@ -218,11 +219,12 @@ dd_screen_resource_destroy(struct pipe_screen *_screen,
 static boolean
 dd_screen_resource_get_handle(struct pipe_screen *_screen,
                               struct pipe_resource *resource,
-                              struct winsys_handle *handle)
+                              struct winsys_handle *handle,
+                              unsigned usage)
 {
    struct pipe_screen *screen = dd_screen(_screen)->screen;
 
-   return screen->resource_get_handle(screen, resource, handle);
+   return screen->resource_get_handle(screen, resource, handle, usage);
 }
 
 
index bcdd518c8bf7c0e2ddfa3cab6b6f68fce582be25..9aded3bb7fe84ce29b89006093b729025190b11b 100644 (file)
@@ -637,7 +637,8 @@ fail:
 static struct pipe_resource *
 fd_resource_from_handle(struct pipe_screen *pscreen,
                const struct pipe_resource *tmpl,
-               struct winsys_handle *handle)
+               struct winsys_handle *handle,
+                unsigned usage)
 {
        struct fd_resource *rsc = CALLOC_STRUCT(fd_resource);
        struct fd_resource_slice *slice = &rsc->slices[0];
index 627ed2b4445156a87d2d3a857a3a3ed26a811bb2..3ffb0b7a5d234f82b1563f3fe3448ca4524297ff 100644 (file)
@@ -23,7 +23,8 @@ i915_resource_create(struct pipe_screen *screen,
 static struct pipe_resource *
 i915_resource_from_handle(struct pipe_screen * screen,
                         const struct pipe_resource *template,
-                        struct winsys_handle *whandle)
+                        struct winsys_handle *whandle,
+                          unsigned usage)
 {
    if (template->target == PIPE_BUFFER)
       return NULL;
index 9026ba9a9838a1e16d752a002647e36e7d48db83..8c888c529c49d6d128677cb58bc9af27db38b2da 100644 (file)
@@ -714,7 +714,8 @@ ilo_resource_create(struct pipe_screen *screen,
 static struct pipe_resource *
 ilo_resource_from_handle(struct pipe_screen *screen,
                          const struct pipe_resource *templ,
-                         struct winsys_handle *handle)
+                         struct winsys_handle *handle,
+                         unsigned usage)
 {
    if (templ->target == PIPE_BUFFER)
       return NULL;
@@ -725,7 +726,8 @@ ilo_resource_from_handle(struct pipe_screen *screen,
 static boolean
 ilo_resource_get_handle(struct pipe_screen *screen,
                         struct pipe_resource *res,
-                        struct winsys_handle *handle)
+                        struct winsys_handle *handle,
+                        unsigned usage)
 {
    if (res->target == PIPE_BUFFER)
       return false;
index ae266ceb082cb47ca5aaf72b1e2d404dbb2d356a..c2ca8b8d6a01bdd64743d8516dbecfb70bf4f790 100644 (file)
@@ -434,7 +434,8 @@ llvmpipe_resource_data(struct pipe_resource *resource)
 static struct pipe_resource *
 llvmpipe_resource_from_handle(struct pipe_screen *screen,
                               const struct pipe_resource *template,
-                              struct winsys_handle *whandle)
+                              struct winsys_handle *whandle,
+                              unsigned usage)
 {
    struct sw_winsys *winsys = llvmpipe_screen(screen)->winsys;
    struct llvmpipe_resource *lpr;
@@ -485,7 +486,8 @@ no_lpr:
 static boolean
 llvmpipe_resource_get_handle(struct pipe_screen *screen,
                             struct pipe_resource *pt,
-                            struct winsys_handle *whandle)
+                            struct winsys_handle *whandle,
+                             unsigned usage)
 {
    struct sw_winsys *winsys = llvmpipe_screen(screen)->winsys;
    struct llvmpipe_resource *lpr = llvmpipe_resource(pt);
index 165284a90bfd0262360a217ea75372a4a59dc949..fd0a5d0f830e85f7622d2636f1a3c7224ec93923 100644 (file)
@@ -114,14 +114,15 @@ static struct pipe_resource *noop_resource_create(struct pipe_screen *screen,
 
 static struct pipe_resource *noop_resource_from_handle(struct pipe_screen *screen,
                                                        const struct pipe_resource *templ,
-                                                       struct winsys_handle *handle)
+                                                       struct winsys_handle *handle,
+                                                       unsigned usage)
 {
        struct noop_pipe_screen *noop_screen = (struct noop_pipe_screen*)screen;
        struct pipe_screen *oscreen = noop_screen->oscreen;
        struct pipe_resource *result;
        struct pipe_resource *noop_resource;
 
-       result = oscreen->resource_from_handle(oscreen, templ, handle);
+       result = oscreen->resource_from_handle(oscreen, templ, handle, usage);
        noop_resource = noop_resource_create(screen, result);
        pipe_resource_reference(&result, NULL);
        return noop_resource;
@@ -129,7 +130,8 @@ static struct pipe_resource *noop_resource_from_handle(struct pipe_screen *scree
 
 static boolean noop_resource_get_handle(struct pipe_screen *screen,
                                        struct pipe_resource *resource,
-                                       struct winsys_handle *handle)
+                                       struct winsys_handle *handle,
+                                        unsigned usage)
 {
        return FALSE;
 }
index a98a6464de8e37ff62fde0bed05d1f4ac120d408..4d215d2e61663fb6c84e4fdb8ae6b317f5a18573 100644 (file)
@@ -66,7 +66,8 @@ nv30_resource_create(struct pipe_screen *pscreen,
 static struct pipe_resource *
 nv30_resource_from_handle(struct pipe_screen *pscreen,
                           const struct pipe_resource *tmpl,
-                          struct winsys_handle *handle)
+                          struct winsys_handle *handle,
+                          unsigned usage)
 {
    if (tmpl->target == PIPE_BUFFER)
       return NULL;
index 5d415ae77ebba6de49007b393fac626c086ea84f..ad5f3b814db80d0a3c83dd5a001f38ef08c72e53 100644 (file)
@@ -22,7 +22,8 @@ nv50_resource_create(struct pipe_screen *screen,
 static struct pipe_resource *
 nv50_resource_from_handle(struct pipe_screen * screen,
                           const struct pipe_resource *templ,
-                          struct winsys_handle *whandle)
+                          struct winsys_handle *whandle,
+                          unsigned usage)
 {
    if (templ->target == PIPE_BUFFER)
       return NULL;
index 7fbc6e1fd8e4ff940ceea98430ad5fcd21be556d..c034d0fd011c601c964a55d5b8b79cdf452f1016 100644 (file)
@@ -19,7 +19,8 @@ nvc0_resource_create(struct pipe_screen *screen,
 static struct pipe_resource *
 nvc0_resource_from_handle(struct pipe_screen * screen,
                           const struct pipe_resource *templ,
-                          struct winsys_handle *whandle)
+                          struct winsys_handle *whandle,
+                          unsigned usage)
 {
    if (templ->target == PIPE_BUFFER) {
       return NULL;
index e90e741a3535fe847879cc4e8036ac74a14d1722..2b9018a5de3eff8b1399760a83d18387f551b355 100644 (file)
@@ -971,7 +971,8 @@ static void r300_texture_destroy(struct pipe_screen *screen,
 
 boolean r300_resource_get_handle(struct pipe_screen* screen,
                                  struct pipe_resource *texture,
-                                 struct winsys_handle *whandle)
+                                 struct winsys_handle *whandle,
+                                 unsigned usage)
 {
     struct radeon_winsys *rws = r300_screen(screen)->rws;
     struct r300_resource* tex = (struct r300_resource*)texture;
@@ -1097,7 +1098,8 @@ struct pipe_resource *r300_texture_create(struct pipe_screen *screen,
 
 struct pipe_resource *r300_texture_from_handle(struct pipe_screen *screen,
                                                const struct pipe_resource *base,
-                                               struct winsys_handle *whandle)
+                                               struct winsys_handle *whandle,
+                                               unsigned usage)
 {
     struct r300_screen *rscreen = r300_screen(screen);
     struct radeon_winsys *rws = rscreen->rws;
index 213bdffc2ed1c3e80887c35e42328013a2fb8ece..4c339429eca50dc91de3096a03be69251bff9efd 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "pipe/p_compiler.h"
 #include "pipe/p_format.h"
+#include "pipe/p_screen.h"
 
 struct pipe_screen;
 struct pipe_context;
@@ -62,12 +63,14 @@ void r300_texture_setup_format_state(struct r300_screen *screen,
 
 boolean r300_resource_get_handle(struct pipe_screen* screen,
                                 struct pipe_resource *texture,
-                                struct winsys_handle *whandle);
+                                struct winsys_handle *whandle,
+                                 unsigned usage);
 
 struct pipe_resource*
 r300_texture_from_handle(struct pipe_screen* screen,
                         const struct pipe_resource* base,
-                        struct winsys_handle *whandle);
+                        struct winsys_handle *whandle,
+                         unsigned usage);
 
 struct pipe_resource*
 r300_texture_create(struct pipe_screen* screen,
index 0b31d0a1f010732de88d33e3a95085dff321c12c..e441936b4473b5e557c0bc7107c3998797e388cf 100644 (file)
@@ -230,7 +230,8 @@ static int r600_setup_surface(struct pipe_screen *screen,
 
 static boolean r600_texture_get_handle(struct pipe_screen* screen,
                                       struct pipe_resource *ptex,
-                                      struct winsys_handle *whandle)
+                                      struct winsys_handle *whandle,
+                                       unsigned usage)
 {
        struct r600_texture *rtex = (struct r600_texture*)ptex;
        struct r600_resource *resource = &rtex->resource;
@@ -877,7 +878,8 @@ struct pipe_resource *r600_texture_create(struct pipe_screen *screen,
 
 static struct pipe_resource *r600_texture_from_handle(struct pipe_screen *screen,
                                                      const struct pipe_resource *templ,
-                                                     struct winsys_handle *whandle)
+                                                     struct winsys_handle *whandle,
+                                                      unsigned usage)
 {
        struct r600_common_screen *rscreen = (struct r600_common_screen*)screen;
        struct pb_buffer *buf = NULL;
index ac764029a2f3898bdda223f03beab36bb3798079..c2950e4a703c6eae6106d9db0890d7942ed3122b 100644 (file)
@@ -160,13 +160,14 @@ rbug_screen_resource_create(struct pipe_screen *_screen,
 static struct pipe_resource *
 rbug_screen_resource_from_handle(struct pipe_screen *_screen,
                                  const struct pipe_resource *templ,
-                                 struct winsys_handle *handle)
+                                 struct winsys_handle *handle,
+                                 unsigned usage)
 {
    struct rbug_screen *rb_screen = rbug_screen(_screen);
    struct pipe_screen *screen = rb_screen->screen;
    struct pipe_resource *result;
 
-   result = screen->resource_from_handle(screen, templ, handle);
+   result = screen->resource_from_handle(screen, templ, handle, usage);
 
    result = rbug_resource_create(rbug_screen(_screen), result);
 
@@ -176,14 +177,15 @@ rbug_screen_resource_from_handle(struct pipe_screen *_screen,
 static boolean
 rbug_screen_resource_get_handle(struct pipe_screen *_screen,
                                 struct pipe_resource *_resource,
-                                struct winsys_handle *handle)
+                                struct winsys_handle *handle,
+                                unsigned usage)
 {
    struct rbug_screen *rb_screen = rbug_screen(_screen);
    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);
+   return screen->resource_get_handle(screen, resource, handle, usage);
 }
 
 
index 52df89504b8a97de1508ef8371c9ca401bfffd3c..52ec373f8f2d6c8a4a481cc7b8010405eb9c37b4 100644 (file)
@@ -218,7 +218,8 @@ softpipe_resource_destroy(struct pipe_screen *pscreen,
 static struct pipe_resource *
 softpipe_resource_from_handle(struct pipe_screen *screen,
                               const struct pipe_resource *templat,
-                              struct winsys_handle *whandle)
+                              struct winsys_handle *whandle,
+                              unsigned usage)
 {
    struct sw_winsys *winsys = softpipe_screen(screen)->winsys;
    struct softpipe_resource *spr = CALLOC_STRUCT(softpipe_resource);
@@ -251,7 +252,8 @@ softpipe_resource_from_handle(struct pipe_screen *screen,
 static boolean
 softpipe_resource_get_handle(struct pipe_screen *screen,
                              struct pipe_resource *pt,
-                             struct winsys_handle *whandle)
+                             struct winsys_handle *whandle,
+                             unsigned usage)
 {
    struct sw_winsys *winsys = softpipe_screen(screen)->winsys;
    struct softpipe_resource *spr = softpipe_resource(pt);
index 1c3bcd67afa4fa6d4a3ec836ad900c2ef2d3380d..264ac335405b79ae97b6e9814540c345e6da890c 100644 (file)
@@ -47,7 +47,8 @@ svga_resource_create(struct pipe_screen *screen,
 static struct pipe_resource *
 svga_resource_from_handle(struct pipe_screen * screen,
                           const struct pipe_resource *template,
-                          struct winsys_handle *whandle)
+                          struct winsys_handle *whandle,
+                          unsigned usage)
 {
    if (template->target == PIPE_BUFFER)
       return NULL;
index 0612109c8009fd72a40dff3a81e5674f3d3eb18e..b24e1856acaf24bfc84caeca528e38a6dd8ef192 100644 (file)
@@ -313,7 +313,8 @@ trace_screen_resource_create(struct pipe_screen *_screen,
 static struct pipe_resource *
 trace_screen_resource_from_handle(struct pipe_screen *_screen,
                                  const struct pipe_resource *templ,
-                                 struct winsys_handle *handle)
+                                 struct winsys_handle *handle,
+                                  unsigned usage)
 {
    struct trace_screen *tr_screen = trace_screen(_screen);
    struct pipe_screen *screen = tr_screen->screen;
@@ -321,7 +322,7 @@ trace_screen_resource_from_handle(struct pipe_screen *_screen,
 
    /* TODO trace call */
 
-   result = screen->resource_from_handle(screen, templ, handle);
+   result = screen->resource_from_handle(screen, templ, handle, usage);
 
    result = trace_resource_create(trace_screen(_screen), result);
 
@@ -331,7 +332,8 @@ trace_screen_resource_from_handle(struct pipe_screen *_screen,
 static boolean
 trace_screen_resource_get_handle(struct pipe_screen *_screen,
                                 struct pipe_resource *_resource,
-                                struct winsys_handle *handle)
+                                struct winsys_handle *handle,
+                                 unsigned usage)
 {
    struct trace_screen *tr_screen = trace_screen(_screen);
    struct trace_resource *tr_resource = trace_resource(_resource);
@@ -340,7 +342,7 @@ trace_screen_resource_get_handle(struct pipe_screen *_screen,
 
    /* TODO trace call */
 
-   return screen->resource_get_handle(screen, resource, handle);
+   return screen->resource_get_handle(screen, resource, handle, usage);
 }
 
 
index 036da329987e827d88b6d54dd53c9f87b04e04a0..ea212af0512fdc25bc93862a18a6554daa48347b 100644 (file)
@@ -523,7 +523,8 @@ fail:
 static struct pipe_resource *
 vc4_resource_from_handle(struct pipe_screen *pscreen,
                          const struct pipe_resource *tmpl,
-                         struct winsys_handle *handle)
+                         struct winsys_handle *handle,
+                         unsigned usage)
 {
         struct vc4_resource *rsc = vc4_resource_setup(pscreen, tmpl);
         struct pipe_resource *prsc = &rsc->base.b;
index 0b2fc4ec49720449941d0ac6833eed00c61365ca..2b3794765e23e2953990231fd15888e1763fb68e 100644 (file)
@@ -64,7 +64,8 @@ static struct pipe_resource *virgl_resource_create(struct pipe_screen *screen,
 
 static struct pipe_resource *virgl_resource_from_handle(struct pipe_screen *screen,
                                                         const struct pipe_resource *templ,
-                                                        struct winsys_handle *whandle)
+                                                        struct winsys_handle *whandle,
+                                                        unsigned usage)
 {
     struct virgl_screen *vs = virgl_screen(screen);
     if (templ->target == PIPE_BUFFER)
index a91e6e55055d673d5aaaf8b871b93a971aa23cd8..c9149bea309c8dfb73f7bf32f9246ea423b6702e 100644 (file)
@@ -529,6 +529,17 @@ enum pipe_reset_status
 };
 
 
+/**
+ * resource_get_handle flags.
+ */
+/* Requires pipe_context::flush_resource before external use. */
+#define PIPE_HANDLE_USAGE_EXPLICIT_FLUSH  (1 << 0)
+/* Expected external use of the resource: */
+#define PIPE_HANDLE_USAGE_READ            (1 << 1)
+#define PIPE_HANDLE_USAGE_WRITE           (1 << 2)
+#define PIPE_HANDLE_USAGE_READ_WRITE      (PIPE_HANDLE_USAGE_READ | \
+                                           PIPE_HANDLE_USAGE_WRITE)
+
 /**
  * Implementation capabilities/limits which are queried through
  * pipe_screen::get_param()
index 211bc2440f90485dcefa5b61c38b22130b941f5f..4f30e75ab494dda90aca0789807c5f3f8b57b1d5 100644 (file)
@@ -182,10 +182,13 @@ struct pipe_screen {
     * NOTE: in the case of DRM_API_HANDLE_TYPE_FD handles, the caller
     * retains ownership of the FD.  (This is consistent with
     * EGL_EXT_image_dma_buf_import)
+    *
+    * \param usage  A combination of PIPE_HANDLE_USAGE_* flags.
     */
    struct pipe_resource * (*resource_from_handle)(struct pipe_screen *,
                                                  const struct pipe_resource *templat,
-                                                 struct winsys_handle *handle);
+                                                 struct winsys_handle *handle,
+                                                 unsigned usage);
 
    /**
     * Create a resource from user memory. This maps the user memory into
@@ -203,10 +206,13 @@ struct pipe_screen {
     * 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)
+    *
+    * \param usage  A combination of PIPE_HANDLE_USAGE_* flags.
     */
    boolean (*resource_get_handle)(struct pipe_screen *,
                                  struct pipe_resource *tex,
-                                 struct winsys_handle *handle);
+                                 struct winsys_handle *handle,
+                                 unsigned usage);
 
 
    void (*resource_destroy)(struct pipe_screen *,
index a11a6cbbb0c0b319d6fc082c5afc1f1b9a023880..7f7fbc47e6ddba24a23bfd7245ce7761bbe59d43 100644 (file)
@@ -354,7 +354,8 @@ dri2_allocate_buffer(__DRIscreen *sPriv,
       whandle.type = DRM_API_HANDLE_TYPE_KMS;
 
    screen->base.screen->resource_get_handle(screen->base.screen,
-         buffer->resource, &whandle);
+         buffer->resource, &whandle,
+         PIPE_HANDLE_USAGE_EXPLICIT_FLUSH | PIPE_HANDLE_USAGE_READ);
 
    buffer->base.attachment = attachment;
    buffer->base.name = whandle.handle;
@@ -539,7 +540,8 @@ dri2_allocate_textures(struct dri_context *ctx,
             whandle.type = DRM_API_HANDLE_TYPE_KMS;
          drawable->textures[statt] =
             screen->base.screen->resource_from_handle(screen->base.screen,
-                  &templ, &whandle);
+                  &templ, &whandle,
+                  PIPE_HANDLE_USAGE_EXPLICIT_FLUSH | PIPE_HANDLE_USAGE_READ);
          assert(drawable->textures[statt]);
       }
    }
@@ -756,7 +758,7 @@ dri2_create_image_from_winsys(__DRIscreen *_screen,
    whandle->stride = pitch * util_format_get_blocksize(pf);
 
    img->texture = screen->base.screen->resource_from_handle(screen->base.screen,
-         &templ, whandle);
+         &templ, whandle, PIPE_HANDLE_USAGE_READ_WRITE);
    if (!img->texture) {
       FREE(img);
       return NULL;
@@ -765,6 +767,7 @@ dri2_create_image_from_winsys(__DRIscreen *_screen,
    img->level = 0;
    img->layer = 0;
    img->dri_format = format;
+   img->use = 0;
    img->loader_private = loaderPrivate;
 
    return img;
@@ -884,6 +887,7 @@ dri2_create_image(__DRIscreen *_screen,
    img->layer = 0;
    img->dri_format = format;
    img->dri_components = 0;
+   img->use = use;
 
    img->loader_private = loaderPrivate;
    return img;
@@ -893,31 +897,38 @@ static GLboolean
 dri2_query_image(__DRIimage *image, int attrib, int *value)
 {
    struct winsys_handle whandle;
+   unsigned usage;
+
+   if (image->use & __DRI_IMAGE_USE_BACKBUFFER)
+      usage = PIPE_HANDLE_USAGE_EXPLICIT_FLUSH | PIPE_HANDLE_USAGE_READ;
+   else
+      usage = PIPE_HANDLE_USAGE_READ_WRITE;
+
    memset(&whandle, 0, sizeof(whandle));
 
    switch (attrib) {
    case __DRI_IMAGE_ATTRIB_STRIDE:
       whandle.type = DRM_API_HANDLE_TYPE_KMS;
       image->texture->screen->resource_get_handle(image->texture->screen,
-            image->texture, &whandle);
+            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);
+         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);
+         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);
+         image->texture, &whandle, usage);
       *value = whandle.handle;
       return GL_TRUE;
    case __DRI_IMAGE_ATTRIB_FORMAT:
index 45459906588f1e46e9a987aa6330d4d8698f97f0..dc4692a1c6ba23c5aaa365279e220bfa3facbf6b 100644 (file)
@@ -109,6 +109,7 @@ struct __DRIimageRec {
    unsigned layer;
    uint32_t dri_format;
    uint32_t dri_components;
+   unsigned use;
 
    void *loader_private;
 
index 1ab339c459c89e502cfb150e5490f6fe7365ada3..e2fb4d4a1e3197de8e455e0e1c20065e406bf9d3 100644 (file)
@@ -87,7 +87,9 @@ 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, resource, &whandle,
+                                      PIPE_HANDLE_USAGE_EXPLICIT_FLUSH |
+                                      PIPE_HANDLE_USAGE_READ);
     stride = whandle.stride;
     dmaBufFd = whandle.handle;
     ID3DPresent_NewD3DWindowBufferFromDmaBuf(This->present,
index c2c24d693f27e3902e78ce0f1a01a3d9816fda35..2fd86612e9a9b0e8bbffc28b137a6567026aed80 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, &whandle))
+         if (!screen->resource_get_handle(screen, buf->derived_surface.resource,
+                                          &whandle, PIPE_HANDLE_USAGE_READ_WRITE))
             return VA_STATUS_ERROR_INVALID_BUFFER;
 
          buf_info->handle = (intptr_t)whandle.handle;
index 84a94949c47a77a6d3c4d7cd42fa31746a0e9e41..861dac260a9d770fe7c9105cb76e75e66c4a5c75 100644 (file)
@@ -470,7 +470,8 @@ suface_from_external_memory(VADriverContextP ctx, vlVaSurface *surface,
    whandle.handle = memory_attibute->buffers[index];
    whandle.stride = memory_attibute->pitches[index];
 
-   resource = pscreen->resource_from_handle(pscreen, &res_templ, &whandle);
+   resource = pscreen->resource_from_handle(pscreen, &res_templ, &whandle,
+                                            PIPE_HANDLE_USAGE_READ_WRITE);
 
    if (!resource)
       return VA_STATUS_ERROR_ALLOCATION_FAILED;
index d57464b7d60f88057831ff30279d378a9e96e2ac..f09baed1d849539a6b5c154e8d69228e2e66b591 100644 (file)
@@ -362,7 +362,8 @@ surface_create(struct xa_tracker *xa,
        template->bind |= PIPE_BIND_SCANOUT;
 
     if (whandle)
-       srf->tex = xa->screen->resource_from_handle(xa->screen, template, whandle);
+       srf->tex = xa->screen->resource_from_handle(xa->screen, template, whandle,
+                                                    PIPE_HANDLE_USAGE_READ_WRITE);
     else
        srf->tex = xa->screen->resource_create(xa->screen, template);
     if (!srf->tex)
@@ -548,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->tex, &whandle,
+                                      PIPE_HANDLE_USAGE_READ_WRITE);
     if (!res)
        return -XA_ERR_INVAL;
 
index 4d87a580cb1c6cf76a14a0af8a55bd4baac529ed..e130cd256e98562797d05d5ff1fa5d090ef2d35d 100644 (file)
@@ -185,7 +185,8 @@ wsw_dt_from_handle(struct sw_winsys *ws,
    struct wrapper_sw_winsys *wsw = wrapper_sw_winsys(ws);
    struct pipe_resource *tex;
 
-   tex = wsw->screen->resource_from_handle(wsw->screen, templ, whandle);
+   tex = wsw->screen->resource_from_handle(wsw->screen, templ, whandle,
+                                           PIPE_HANDLE_USAGE_READ_WRITE);
    if (!tex)
       return NULL;
 
@@ -201,7 +202,8 @@ 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, tex, whandle,
+                                           PIPE_HANDLE_USAGE_READ_WRITE);
 }
 
 static void *