iris: Don't leak surface states for compressed resources

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 <mesa-stable>
Reviewed-by: Tapani Pälli <tapani.palli@intel.com>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17598>
This commit is contained in:
Nanley Chery 2022-07-15 11:51:55 -04:00 committed by Marge Bot
parent 96a79a5f3a
commit bca601ffe9

View file

@ -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;