Module: Mesa
Branch: staging/22.1
Commit: 76ddaeb32afa627d771fb27182c82f100d979894
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=76ddaeb32afa627d771fb27182c82f100d979894

Author: Nanley Chery <[email protected]>
Date:   Fri Jul 15 13:42:18 2022 -0400

iris: Don't leak compressed resources in iris_create_surface

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 <mesa-stable>
Reviewed-by: Tapani Pälli <[email protected]>
Reviewed-by: Lionel Landwerlin <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17598>
(cherry picked from commit 6c65e990b6e2d640492c4db66adaa5ac48825571)

---

 .pick_status.json                     |  2 +-
 src/gallium/drivers/iris/iris_state.c | 29 +++++++++++++----------------
 2 files changed, 14 insertions(+), 17 deletions(-)

diff --git a/.pick_status.json b/.pick_status.json
index 5db006b6d41..f3dc093edc8 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -2029,7 +2029,7 @@
         "description": "iris: Don't leak compressed resources in 
iris_create_surface",
         "nominated": true,
         "nomination_type": 0,
-        "resolution": 0,
+        "resolution": 1,
         "main_sha": null,
         "because_sha": null
     },
diff --git a/src/gallium/drivers/iris/iris_state.c 
b/src/gallium/drivers/iris/iris_state.c
index 5c769ddfef6..4070265e475 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,

Reply via email to