From bca601ffe92be0933bb706e4ad320676a0da8477 Mon Sep 17 00:00:00 2001 From: Nanley Chery Date: Fri, 15 Jul 2022 11:51:55 -0400 Subject: [PATCH] iris: Don't leak surface states for compressed resources MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this patch, we were leaking surface states in iris_create_surface. Specifically, when we failed to create an uncompressed ISL surface and view for a compressed resource, we didn't free surface states we allocated for it. Fix this by attempting to create the uncompressed surface and view before we allocate the surface states. Cc: 22.1 Reviewed-by: Tapani Pälli Reviewed-by: Lionel Landwerlin Part-of: --- src/gallium/drivers/iris/iris_state.c | 50 ++++++++++++++------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/src/gallium/drivers/iris/iris_state.c b/src/gallium/drivers/iris/iris_state.c index 9e5c49ed094..600ece94fd9 100644 --- a/src/gallium/drivers/iris/iris_state.c +++ b/src/gallium/drivers/iris/iris_state.c @@ -2710,6 +2710,32 @@ iris_create_surface(struct pipe_context *ctx, } #endif + struct isl_surf isl_surf; + uint64_t offset_B = 0; + uint32_t tile_x_el = 0, tile_y_el = 0; + if (isl_format_is_compressed(res->surf.format)) { + /* The resource has a compressed format, which is not renderable, but we + * have a renderable view format. We must be attempting to upload + * blocks of compressed data via an uncompressed view. + * + * In this case, we can assume there are no auxiliary buffers, a single + * miplevel, and that the resource is single-sampled. Gallium may try + * and create an uncompressed view with multiple layers, however. + */ + assert(res->aux.usage == ISL_AUX_USAGE_NONE); + assert(res->surf.samples == 1); + assert(view->levels == 1); + + bool ok = isl_surf_get_uncompressed_surf(&screen->isl_dev, + &res->surf, view, + &isl_surf, view, &offset_B, + &tile_x_el, &tile_y_el); + if (!ok) { + free(surf); + return NULL; + } + } + surf->clear_color = res->aux.clear_color; /* Bail early for depth/stencil - we don't want SURFACE_STATE for them. */ @@ -2750,30 +2776,6 @@ iris_create_surface(struct pipe_context *ctx, return psurf; } - /* The resource has a compressed format, which is not renderable, but we - * have a renderable view format. We must be attempting to upload blocks - * of compressed data via an uncompressed view. - * - * In this case, we can assume there are no auxiliary buffers, a single - * miplevel, and that the resource is single-sampled. Gallium may try - * and create an uncompressed view with multiple layers, however. - */ - assert(!isl_format_is_compressed(fmt.fmt)); - assert(res->aux.usage == ISL_AUX_USAGE_NONE); - assert(res->surf.samples == 1); - assert(view->levels == 1); - - struct isl_surf isl_surf; - uint64_t offset_B = 0; - uint32_t tile_x_el = 0, tile_y_el = 0; - bool ok = isl_surf_get_uncompressed_surf(&screen->isl_dev, &res->surf, - view, &isl_surf, view, - &offset_B, &tile_x_el, &tile_y_el); - if (!ok) { - free(surf); - return NULL; - } - psurf->width = isl_surf.logical_level0_px.width; psurf->height = isl_surf.logical_level0_px.height;