Module: Mesa Branch: staging/23.0 Commit: b1e25936085ca738aace7f4c8dd6594ea47fbb41 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=b1e25936085ca738aace7f4c8dd6594ea47fbb41
Author: Charmaine Lee <[email protected]> Date: Wed Feb 8 14:01:14 2023 -0500 svga: fix resource_get_handle from resource created without SHARED bind flag When an EGLImage is created from a 2D texture and used for texture sharing, the texture surface might not have been created with the SHARED bind flag. To allow these surfaces for sharing, this patch sets the USAGE SHARED bit for surfaces that can be potentially used for sharing even when the SHARED bind flag is not originally set. Instead of unconditionally enabling the SHARED bind flag for all surfaces and unnecessarily bypass the surface cache optimization, this patch only enables the USAGE SHARED bit for surfaces that also have the RENDER TARGET bind flag. When the surface handle is inquired and if the surface is currently marked as cachable, we will need to unset the cachable bit so the surface handle will not be recycled again. This patch fixes an assertion in svga_resource_get_handle() when the EGL_MESA_image_dma_buf_export extension is used in webgl benchamrk running from firefox in Fedora 37. Cc: mesa-stable Reviewed-by: Martin Krastev <[email protected]> Reviewed-by: Jose Fonseca <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21393> (cherry picked from commit 75b7296fc36d302a4901da93f4cd3e51e6e6f8f1) --- .pick_status.json | 2 +- src/gallium/drivers/svga/svga_resource_texture.c | 4 +++- src/gallium/drivers/svga/svga_screen_cache.c | 6 +++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 9d5525cefc1..d6f4f040fcf 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -274,7 +274,7 @@ "description": "svga: fix resource_get_handle from resource created without SHARED bind flag", "nominated": true, "nomination_type": 0, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": null }, diff --git a/src/gallium/drivers/svga/svga_resource_texture.c b/src/gallium/drivers/svga/svga_resource_texture.c index 0ee7d2b5468..38f32ce3b84 100644 --- a/src/gallium/drivers/svga/svga_resource_texture.c +++ b/src/gallium/drivers/svga/svga_resource_texture.c @@ -209,7 +209,9 @@ svga_resource_get_handle(struct pipe_screen *screen, if (texture->target == PIPE_BUFFER) return false; - assert(svga_texture(texture)->key.cachable == 0); + SVGA_DBG(DEBUG_DMA, "%s: texture=%p cachable=%d\n", __FUNCTION__, + texture, svga_texture(texture)->key.cachable); + svga_texture(texture)->key.cachable = 0; stride = util_format_get_nblocksx(texture->format, texture->width0) * diff --git a/src/gallium/drivers/svga/svga_screen_cache.c b/src/gallium/drivers/svga/svga_screen_cache.c index e70b7fded13..32306d0f962 100644 --- a/src/gallium/drivers/svga/svga_screen_cache.c +++ b/src/gallium/drivers/svga/svga_screen_cache.c @@ -573,7 +573,11 @@ svga_screen_surface_create(struct svga_screen *svgascreen, /* Unable to recycle surface, allocate a new one */ unsigned usage = 0; - if (!key->cachable) + /* mark the surface as shareable if the surface is not + * cachable or the RENDER_TARGET bind flag is set. + */ + if (!key->cachable || + ((bind_flags & PIPE_BIND_RENDER_TARGET) != 0)) usage |= SVGA_SURFACE_USAGE_SHARED; if (key->scanout) usage |= SVGA_SURFACE_USAGE_SCANOUT;
