panfrost: Implement pipe screen's resource_label interface

Extend the panfrost resource screen interface with a function that lets
the pipe resource the BO belongs to share a label pointer for debugging
purposes.

Then append this resource label to the existing driver tag and label the
backing kernel BO accordingly.

A panfrost_resource::user_label field was added to store the argument
user label. Because in the case of an AFBC-packed resource, user tagging
can happen before the packed BO is created, we need to store it
separately, so that all the necessary label fields are available before
a complete label can be given to the kernel driver.

Signed-off-by: Adrián Larumbe <adrian.larumbe@collabora.com>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/34224>
This commit is contained in:
Adrián Larumbe
2025-06-12 01:46:21 +01:00
committed by Marge Bot
parent a4ffd2395f
commit b351600436
+40 -5
View File
@@ -252,17 +252,20 @@ panfrost_resource_type_str(struct panfrost_resource *rsrc)
static char *
panfrost_resource_new_label(struct panfrost_resource *rsrc,
uint64_t modifier)
uint64_t modifier,
const char *user_label)
{
char *new_label = NULL;
asprintf(&new_label,
"%s format=%s extent=%ux%ux%u array_size=%u mip_count=%u samples=%u modifier=0x%"PRIx64,
"%s format=%s extent=%ux%ux%u array_size=%u mip_count=%u samples=%u modifier=0x%"PRIx64"%s%s",
panfrost_resource_type_str(rsrc),
util_format_short_name(rsrc->base.format),
rsrc->base.width0, rsrc->base.height0, rsrc->base.depth0,
rsrc->base.array_size, rsrc->base.last_level,
rsrc->base.nr_storage_samples, modifier);
rsrc->base.nr_storage_samples, modifier,
user_label ? " user_label=" : "",
user_label ? : "");
return new_label;
}
@@ -370,6 +373,30 @@ panfrost_resource_from_handle(struct pipe_screen *pscreen,
return prsc;
}
static void
panfrost_set_resource_label(UNUSED struct pipe_screen *pscreen,
struct pipe_resource *presource,
const char *user_label)
{
struct panfrost_resource *rsrc = pan_resource(presource);
const char *new_label;
/* We don't manage labels for resources with imported BOs */
if (!rsrc->owns_label)
return;
new_label = panfrost_resource_new_label(rsrc,
rsrc->image.props.modifier,
user_label);
if (!new_label)
return;
char *old_label = (char *)panfrost_bo_set_label(rsrc->bo, new_label);
if (old_label)
free(old_label);
}
static bool
panfrost_resource_get_handle(struct pipe_screen *pscreen,
struct pipe_context *ctx, struct pipe_resource *pt,
@@ -1025,7 +1052,7 @@ panfrost_resource_create_with_modifier(struct pipe_screen *screen,
flags |= PAN_BO_SHAREABLE;
char *res_label =
panfrost_resource_new_label(so, so->image.props.modifier);
panfrost_resource_new_label(so, so->image.props.modifier , NULL);
so->bo =
panfrost_bo_create(dev, so->plane.layout.data_size_B, flags, res_label);
@@ -2039,8 +2066,15 @@ panfrost_pack_afbc(struct panfrost_context *ctx,
perf_debug(ctx, "%i%%: %i KB -> %i KB\n", ratio, old_size / 1024,
new_size / 1024);
const char *old_user_label = NULL;
if (prsrc->bo->label) {
old_user_label = strstr(prsrc->bo->label, "user_label=");
if (old_user_label)
old_user_label += strlen("user_label=");
}
char *new_label =
panfrost_resource_new_label(prsrc, dst_modifier);
panfrost_resource_new_label(prsrc, dst_modifier, old_user_label);
struct panfrost_bo *dst =
panfrost_bo_create(dev, new_size, 0, new_label);
@@ -2330,6 +2364,7 @@ panfrost_resource_screen_init(struct pipe_screen *pscreen)
pscreen->resource_destroy = u_transfer_helper_resource_destroy;
pscreen->resource_from_handle = panfrost_resource_from_handle;
pscreen->resource_get_handle = panfrost_resource_get_handle;
pscreen->set_resource_label = panfrost_set_resource_label;
pscreen->resource_get_param = panfrost_resource_get_param;
pscreen->transfer_helper = u_transfer_helper_create(
&transfer_vtbl,