From 587d1f75fbe69c4a1678e5b1d22e0e8a2f87f2b4 Mon Sep 17 00:00:00 2001 From: Nanley Chery Date: Wed, 13 Jan 2021 14:31:05 -0800 Subject: [PATCH] gallium: Flush GL API resources in eglCreateImage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some drivers need to be able to remove compression from resources before they are handed to consumers that wouldn't understand or expect it. Cc: mesa-stable Reviewed-by: Marek Olšák Part-of: (cherry picked from commit b26f510978d3695dcede49892d6702a605cfbcc5) --- .pick_status.json | 2 +- src/gallium/frontends/dri/dri_helpers.c | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index ab8fa12b5ad..24306db0922 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -355,7 +355,7 @@ "description": "gallium: Flush GL API resources in eglCreateImage", "nominated": true, "nomination_type": 0, - "resolution": 0, + "resolution": 1, "master_sha": null, "because_sha": null }, diff --git a/src/gallium/frontends/dri/dri_helpers.c b/src/gallium/frontends/dri/dri_helpers.c index c73e442444c..bf71e23e91e 100644 --- a/src/gallium/frontends/dri/dri_helpers.c +++ b/src/gallium/frontends/dri/dri_helpers.c @@ -258,7 +258,9 @@ dri2_create_image_from_renderbuffer2(__DRIcontext *context, int renderbuffer, void *loaderPrivate, unsigned *error) { - struct gl_context *ctx = ((struct st_context *)dri_context(context)->st)->ctx; + struct st_context *st_ctx = (struct st_context *)dri_context(context)->st; + struct gl_context *ctx = st_ctx->ctx; + struct pipe_context *p_ctx = st_ctx->pipe; struct gl_renderbuffer *rb; struct pipe_resource *tex; __DRIimage *img; @@ -300,6 +302,13 @@ dri2_create_image_from_renderbuffer2(__DRIcontext *context, pipe_resource_reference(&img->texture, tex); + /* If the resource supports EGL_MESA_image_dma_buf_export, make sure that + * it's in a shareable state. Do this now while we still have the access to + * the context. + */ + if (dri2_get_mapping_by_format(img->dri_format)) + p_ctx->flush_resource(p_ctx, tex); + *error = __DRI_IMAGE_ERROR_SUCCESS; return img; } @@ -338,7 +347,9 @@ dri2_create_from_texture(__DRIcontext *context, int target, unsigned texture, void *loaderPrivate) { __DRIimage *img; - struct gl_context *ctx = ((struct st_context *)dri_context(context)->st)->ctx; + struct st_context *st_ctx = (struct st_context *)dri_context(context)->st; + struct gl_context *ctx = st_ctx->ctx; + struct pipe_context *p_ctx = st_ctx->pipe; struct gl_texture_object *obj; struct pipe_resource *tex; GLuint face = 0; @@ -389,6 +400,13 @@ dri2_create_from_texture(__DRIcontext *context, int target, unsigned texture, pipe_resource_reference(&img->texture, tex); + /* If the resource supports EGL_MESA_image_dma_buf_export, make sure that + * it's in a shareable state. Do this now while we still have the access to + * the context. + */ + if (dri2_get_mapping_by_format(img->dri_format)) + p_ctx->flush_resource(p_ctx, tex); + *error = __DRI_IMAGE_ERROR_SUCCESS; return img; }