gallium: add a pipe_context parameter to resource_get_handle

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>
This commit is contained in:
Marek Olšák 2016-08-21 12:24:59 +02:00
parent b662c70aea
commit 9daaa6f5a6
21 changed files with 46 additions and 16 deletions

View 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)

View 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);

View 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;

View 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);
}

View 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)

View 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)

View 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)

View 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)

View 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);

View 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)

View 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);
}

View 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)

View 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);
}

View 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);

View 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)

View 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 |

View 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;

View 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;

View 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;

View 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;

View 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);
}