From 82db518f1519cec9e3842f23455a105e2006afbd Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Wed, 24 Feb 2016 18:51:15 +0100 Subject: [PATCH] gallium: add external usage flags to resource_from(get)_handle (v2) 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 --- src/gallium/auxiliary/util/u_transfer.c | 3 ++- src/gallium/auxiliary/util/u_transfer.h | 3 ++- src/gallium/auxiliary/vl/vl_winsys_dri.c | 3 ++- src/gallium/drivers/ddebug/dd_screen.c | 10 +++++--- .../drivers/freedreno/freedreno_resource.c | 3 ++- src/gallium/drivers/i915/i915_resource.c | 3 ++- src/gallium/drivers/ilo/ilo_resource.c | 6 +++-- src/gallium/drivers/llvmpipe/lp_texture.c | 6 +++-- src/gallium/drivers/noop/noop_pipe.c | 8 +++--- .../drivers/nouveau/nv30/nv30_resource.c | 3 ++- .../drivers/nouveau/nv50/nv50_resource.c | 3 ++- .../drivers/nouveau/nvc0/nvc0_resource.c | 3 ++- src/gallium/drivers/r300/r300_texture.c | 6 +++-- src/gallium/drivers/r300/r300_texture.h | 7 ++++-- src/gallium/drivers/radeon/r600_texture.c | 6 +++-- src/gallium/drivers/rbug/rbug_screen.c | 10 +++++--- src/gallium/drivers/softpipe/sp_texture.c | 6 +++-- src/gallium/drivers/svga/svga_resource.c | 3 ++- src/gallium/drivers/trace/tr_screen.c | 10 +++++--- src/gallium/drivers/vc4/vc4_resource.c | 3 ++- src/gallium/drivers/virgl/virgl_resource.c | 3 ++- src/gallium/include/pipe/p_defines.h | 11 ++++++++ src/gallium/include/pipe/p_screen.h | 10 ++++++-- src/gallium/state_trackers/dri/dri2.c | 25 +++++++++++++------ src/gallium/state_trackers/dri/dri_screen.h | 1 + src/gallium/state_trackers/nine/swapchain9.c | 4 ++- src/gallium/state_trackers/va/buffer.c | 3 ++- src/gallium/state_trackers/va/surface.c | 3 ++- src/gallium/state_trackers/xa/xa_tracker.c | 6 +++-- .../winsys/sw/wrapper/wrapper_sw_winsys.c | 6 +++-- 30 files changed, 123 insertions(+), 54 deletions(-) diff --git a/src/gallium/auxiliary/util/u_transfer.c b/src/gallium/auxiliary/util/u_transfer.c index adae84bbfab..0610535cd2c 100644 --- a/src/gallium/auxiliary/util/u_transfer.c +++ b/src/gallium/auxiliary/util/u_transfer.c @@ -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); diff --git a/src/gallium/auxiliary/util/u_transfer.h b/src/gallium/auxiliary/util/u_transfer.h index 6c25ee0f024..660dc161d33 100644 --- a/src/gallium/auxiliary/util/u_transfer.h +++ b/src/gallium/auxiliary/util/u_transfer.h @@ -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); diff --git a/src/gallium/auxiliary/vl/vl_winsys_dri.c b/src/gallium/auxiliary/vl/vl_winsys_dri.c index 758f50d7c23..01365260312 100644 --- a/src/gallium/auxiliary/vl/vl_winsys_dri.c +++ b/src/gallium/auxiliary/vl/vl_winsys_dri.c @@ -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; diff --git a/src/gallium/drivers/ddebug/dd_screen.c b/src/gallium/drivers/ddebug/dd_screen.c index 3706b2d63f5..fbc0bec73dd 100644 --- a/src/gallium/drivers/ddebug/dd_screen.c +++ b/src/gallium/drivers/ddebug/dd_screen.c @@ -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); } diff --git a/src/gallium/drivers/freedreno/freedreno_resource.c b/src/gallium/drivers/freedreno/freedreno_resource.c index bcdd518c8bf..9aded3bb7fe 100644 --- a/src/gallium/drivers/freedreno/freedreno_resource.c +++ b/src/gallium/drivers/freedreno/freedreno_resource.c @@ -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]; diff --git a/src/gallium/drivers/i915/i915_resource.c b/src/gallium/drivers/i915/i915_resource.c index 627ed2b4445..3ffb0b7a5d2 100644 --- a/src/gallium/drivers/i915/i915_resource.c +++ b/src/gallium/drivers/i915/i915_resource.c @@ -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; diff --git a/src/gallium/drivers/ilo/ilo_resource.c b/src/gallium/drivers/ilo/ilo_resource.c index 9026ba9a983..8c888c529c4 100644 --- a/src/gallium/drivers/ilo/ilo_resource.c +++ b/src/gallium/drivers/ilo/ilo_resource.c @@ -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; diff --git a/src/gallium/drivers/llvmpipe/lp_texture.c b/src/gallium/drivers/llvmpipe/lp_texture.c index ae266ceb082..c2ca8b8d6a0 100644 --- a/src/gallium/drivers/llvmpipe/lp_texture.c +++ b/src/gallium/drivers/llvmpipe/lp_texture.c @@ -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); diff --git a/src/gallium/drivers/noop/noop_pipe.c b/src/gallium/drivers/noop/noop_pipe.c index 165284a90bf..fd0a5d0f830 100644 --- a/src/gallium/drivers/noop/noop_pipe.c +++ b/src/gallium/drivers/noop/noop_pipe.c @@ -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; } diff --git a/src/gallium/drivers/nouveau/nv30/nv30_resource.c b/src/gallium/drivers/nouveau/nv30/nv30_resource.c index a98a6464de8..4d215d2e616 100644 --- a/src/gallium/drivers/nouveau/nv30/nv30_resource.c +++ b/src/gallium/drivers/nouveau/nv30/nv30_resource.c @@ -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; diff --git a/src/gallium/drivers/nouveau/nv50/nv50_resource.c b/src/gallium/drivers/nouveau/nv50/nv50_resource.c index 5d415ae77eb..ad5f3b814db 100644 --- a/src/gallium/drivers/nouveau/nv50/nv50_resource.c +++ b/src/gallium/drivers/nouveau/nv50/nv50_resource.c @@ -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; diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_resource.c b/src/gallium/drivers/nouveau/nvc0/nvc0_resource.c index 7fbc6e1fd8e..c034d0fd011 100644 --- a/src/gallium/drivers/nouveau/nvc0/nvc0_resource.c +++ b/src/gallium/drivers/nouveau/nvc0/nvc0_resource.c @@ -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; diff --git a/src/gallium/drivers/r300/r300_texture.c b/src/gallium/drivers/r300/r300_texture.c index e90e741a353..2b9018a5de3 100644 --- a/src/gallium/drivers/r300/r300_texture.c +++ b/src/gallium/drivers/r300/r300_texture.c @@ -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; diff --git a/src/gallium/drivers/r300/r300_texture.h b/src/gallium/drivers/r300/r300_texture.h index 213bdffc2ed..4c339429eca 100644 --- a/src/gallium/drivers/r300/r300_texture.h +++ b/src/gallium/drivers/r300/r300_texture.h @@ -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, diff --git a/src/gallium/drivers/radeon/r600_texture.c b/src/gallium/drivers/radeon/r600_texture.c index 0b31d0a1f01..e441936b447 100644 --- a/src/gallium/drivers/radeon/r600_texture.c +++ b/src/gallium/drivers/radeon/r600_texture.c @@ -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; diff --git a/src/gallium/drivers/rbug/rbug_screen.c b/src/gallium/drivers/rbug/rbug_screen.c index ac764029a2f..c2950e4a703 100644 --- a/src/gallium/drivers/rbug/rbug_screen.c +++ b/src/gallium/drivers/rbug/rbug_screen.c @@ -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); } diff --git a/src/gallium/drivers/softpipe/sp_texture.c b/src/gallium/drivers/softpipe/sp_texture.c index 52df89504b8..52ec373f8f2 100644 --- a/src/gallium/drivers/softpipe/sp_texture.c +++ b/src/gallium/drivers/softpipe/sp_texture.c @@ -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); diff --git a/src/gallium/drivers/svga/svga_resource.c b/src/gallium/drivers/svga/svga_resource.c index 1c3bcd67afa..264ac335405 100644 --- a/src/gallium/drivers/svga/svga_resource.c +++ b/src/gallium/drivers/svga/svga_resource.c @@ -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; diff --git a/src/gallium/drivers/trace/tr_screen.c b/src/gallium/drivers/trace/tr_screen.c index 0612109c800..b24e1856aca 100644 --- a/src/gallium/drivers/trace/tr_screen.c +++ b/src/gallium/drivers/trace/tr_screen.c @@ -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); } diff --git a/src/gallium/drivers/vc4/vc4_resource.c b/src/gallium/drivers/vc4/vc4_resource.c index 036da329987..ea212af0512 100644 --- a/src/gallium/drivers/vc4/vc4_resource.c +++ b/src/gallium/drivers/vc4/vc4_resource.c @@ -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; diff --git a/src/gallium/drivers/virgl/virgl_resource.c b/src/gallium/drivers/virgl/virgl_resource.c index 0b2fc4ec497..2b3794765e2 100644 --- a/src/gallium/drivers/virgl/virgl_resource.c +++ b/src/gallium/drivers/virgl/virgl_resource.c @@ -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) diff --git a/src/gallium/include/pipe/p_defines.h b/src/gallium/include/pipe/p_defines.h index a91e6e55055..c9149bea309 100644 --- a/src/gallium/include/pipe/p_defines.h +++ b/src/gallium/include/pipe/p_defines.h @@ -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() diff --git a/src/gallium/include/pipe/p_screen.h b/src/gallium/include/pipe/p_screen.h index 211bc2440f9..4f30e75ab49 100644 --- a/src/gallium/include/pipe/p_screen.h +++ b/src/gallium/include/pipe/p_screen.h @@ -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 *, diff --git a/src/gallium/state_trackers/dri/dri2.c b/src/gallium/state_trackers/dri/dri2.c index a11a6cbbb0c..7f7fbc47e6d 100644 --- a/src/gallium/state_trackers/dri/dri2.c +++ b/src/gallium/state_trackers/dri/dri2.c @@ -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: diff --git a/src/gallium/state_trackers/dri/dri_screen.h b/src/gallium/state_trackers/dri/dri_screen.h index 45459906588..dc4692a1c6b 100644 --- a/src/gallium/state_trackers/dri/dri_screen.h +++ b/src/gallium/state_trackers/dri/dri_screen.h @@ -109,6 +109,7 @@ struct __DRIimageRec { unsigned layer; uint32_t dri_format; uint32_t dri_components; + unsigned use; void *loader_private; diff --git a/src/gallium/state_trackers/nine/swapchain9.c b/src/gallium/state_trackers/nine/swapchain9.c index 1ab339c459c..e2fb4d4a1e3 100644 --- a/src/gallium/state_trackers/nine/swapchain9.c +++ b/src/gallium/state_trackers/nine/swapchain9.c @@ -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, diff --git a/src/gallium/state_trackers/va/buffer.c b/src/gallium/state_trackers/va/buffer.c index c2c24d693f2..2fd86612e9a 100644 --- a/src/gallium/state_trackers/va/buffer.c +++ b/src/gallium/state_trackers/va/buffer.c @@ -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; diff --git a/src/gallium/state_trackers/va/surface.c b/src/gallium/state_trackers/va/surface.c index 84a94949c47..861dac260a9 100644 --- a/src/gallium/state_trackers/va/surface.c +++ b/src/gallium/state_trackers/va/surface.c @@ -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; diff --git a/src/gallium/state_trackers/xa/xa_tracker.c b/src/gallium/state_trackers/xa/xa_tracker.c index d57464b7d60..f09baed1d84 100644 --- a/src/gallium/state_trackers/xa/xa_tracker.c +++ b/src/gallium/state_trackers/xa/xa_tracker.c @@ -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; diff --git a/src/gallium/winsys/sw/wrapper/wrapper_sw_winsys.c b/src/gallium/winsys/sw/wrapper/wrapper_sw_winsys.c index 4d87a580cb1..e130cd256e9 100644 --- a/src/gallium/winsys/sw/wrapper/wrapper_sw_winsys.c +++ b/src/gallium/winsys/sw/wrapper/wrapper_sw_winsys.c @@ -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 * -- 2.30.2