From 6c65e990b6e2d640492c4db66adaa5ac48825571 Mon Sep 17 00:00:00 2001 From: Nanley Chery Date: Fri, 15 Jul 2022 13:42:18 -0400 Subject: [PATCH] iris: Don't leak compressed resources in iris_create_surface MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this patch, we were leaking compressed resources in iris_create_surface. Specifically, when we failed to create an uncompressed ISL surface and view for a compressed resource, we didn't unreference the resource pointer we referenced into the pipe_surface. Fix this by delaying the pipe_surface initialization code to after attempting to create the uncompressed surface and view. Cc: 22.1 Reviewed-by: Tapani Pälli Reviewed-by: Lionel Landwerlin Part-of: --- src/gallium/drivers/iris/iris_state.c | 29 ++++++++++++--------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/src/gallium/drivers/iris/iris_state.c b/src/gallium/drivers/iris/iris_state.c index 600ece94fd9..daff435c4cd 100644 --- a/src/gallium/drivers/iris/iris_state.c +++ b/src/gallium/drivers/iris/iris_state.c @@ -2634,23 +2634,11 @@ iris_create_surface(struct pipe_context *ctx, } struct iris_surface *surf = calloc(1, sizeof(struct iris_surface)); - struct pipe_surface *psurf = &surf->base; struct iris_resource *res = (struct iris_resource *) tex; if (!surf) return NULL; - pipe_reference_init(&psurf->reference, 1); - pipe_resource_reference(&psurf->texture, tex); - psurf->context = ctx; - psurf->format = tmpl->format; - psurf->width = tex->width0; - psurf->height = tex->height0; - psurf->texture = tex; - psurf->u.tex.first_layer = tmpl->u.tex.first_layer; - psurf->u.tex.last_layer = tmpl->u.tex.last_layer; - psurf->u.tex.level = tmpl->u.tex.level; - uint32_t array_len = tmpl->u.tex.last_layer - tmpl->u.tex.first_layer + 1; struct isl_view *view = &surf->view; @@ -2710,7 +2698,7 @@ iris_create_surface(struct pipe_context *ctx, } #endif - struct isl_surf isl_surf; + struct isl_surf isl_surf = res->surf; uint64_t offset_B = 0; uint32_t tile_x_el = 0, tile_y_el = 0; if (isl_format_is_compressed(res->surf.format)) { @@ -2738,6 +2726,18 @@ iris_create_surface(struct pipe_context *ctx, surf->clear_color = res->aux.clear_color; + struct pipe_surface *psurf = &surf->base; + pipe_reference_init(&psurf->reference, 1); + pipe_resource_reference(&psurf->texture, tex); + psurf->context = ctx; + psurf->format = tmpl->format; + psurf->width = isl_surf.logical_level0_px.width; + psurf->height = isl_surf.logical_level0_px.height; + psurf->texture = tex; + psurf->u.tex.first_layer = tmpl->u.tex.first_layer; + psurf->u.tex.last_layer = tmpl->u.tex.last_layer; + psurf->u.tex.level = tmpl->u.tex.level; + /* Bail early for depth/stencil - we don't want SURFACE_STATE for them. */ if (res->surf.usage & (ISL_SURF_USAGE_DEPTH_BIT | ISL_SURF_USAGE_STENCIL_BIT)) @@ -2776,9 +2776,6 @@ iris_create_surface(struct pipe_context *ctx, return psurf; } - psurf->width = isl_surf.logical_level0_px.width; - psurf->height = isl_surf.logical_level0_px.height; - struct isl_surf_fill_state_info f = { .surf = &isl_surf, .view = view,