From: Michel Dänzer Date: Wed, 17 Jul 2019 10:18:11 +0000 (+0200) Subject: st/mesa: Try re-importing resource if necessary in st_vdpau_map_surface X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=22c7738520e2642a7f297d9b85f3dbfba37ca862;p=mesa.git st/mesa: Try re-importing resource if necessary in st_vdpau_map_surface This can be the case if the resource was obtained from st_vdpau_output/video_surface_gallium. st_vdpau_output/video_surface_dma_buf do a similar dance internally. v2: * Pass PIPE_HANDLE_USAGE_FRAMEBUFFER_WRITE instead of 0 for usage. Bugzilla: https://bugs.freedesktop.org/111099 Acked-by: Pierre-Eric Pelloux-Prayer # v1 Reviewed-by: Marek Olšák --- diff --git a/src/mesa/state_tracker/st_vdpau.c b/src/mesa/state_tracker/st_vdpau.c index bfc6adf7f77..6a439b89d59 100644 --- a/src/mesa/state_tracker/st_vdpau.c +++ b/src/mesa/state_tracker/st_vdpau.c @@ -185,6 +185,7 @@ st_vdpau_map_surface(struct gl_context *ctx, GLenum target, GLenum access, const void *vdpSurface, GLuint index) { struct st_context *st = st_context(ctx); + struct pipe_screen *screen = st->pipe->screen; struct st_texture_object *stObj = st_texture_object(texObj); struct st_texture_image *stImage = st_texture_image(texImage); @@ -207,15 +208,26 @@ st_vdpau_map_surface(struct gl_context *ctx, GLenum target, GLenum access, } } - if (!res) { - _mesa_error(ctx, GL_INVALID_OPERATION, "VDPAUMapSurfacesNV"); - return; + /* If the resource is from a different screen, try re-importing it */ + if (res && res->screen != screen) { + struct pipe_resource *new_res = NULL; + struct winsys_handle whandle = { .type = WINSYS_HANDLE_TYPE_FD }; + unsigned usage = PIPE_HANDLE_USAGE_FRAMEBUFFER_WRITE; + + if (screen->get_param(screen, PIPE_CAP_DMABUF) && + res->screen->get_param(res->screen, PIPE_CAP_DMABUF) && + res->screen->resource_get_handle(res->screen, NULL, res, &whandle, + usage)) { + new_res = screen->resource_from_handle(screen, res, &whandle, usage); + close(whandle.handle); + } + + pipe_resource_reference(&res, NULL); + res = new_res; } - /* do we have different screen objects ? */ - if (res->screen != st->pipe->screen) { + if (!res) { _mesa_error(ctx, GL_INVALID_OPERATION, "VDPAUMapSurfacesNV"); - pipe_resource_reference(&res, NULL); return; }