panfrost: Legalize resource when attaching to a batch
Make sure we don't convert the texture for nothing by only legalizing when creating a batch instead of on surface creation. Also, to avoid recursive blit, we need to legalize the destination resource before blitting. Finally, make sure the resource has a sparse memory layout if AFBC compressed. The GPU doesn't support rendering to a AFBC-packed texture. Signed-off-by: Louis-Francis Ratté-Boulianne <lfrb@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25012>
This commit is contained in:

committed by
Marge Bot

parent
bc55d150a9
commit
e9d523bb92
@@ -90,6 +90,10 @@ panfrost_blit(struct pipe_context *pipe, const struct pipe_blit_info *info)
|
||||
if (!util_blitter_is_blit_supported(ctx->blitter, info))
|
||||
unreachable("Unsupported blit\n");
|
||||
|
||||
/* Legalize here because it could trigger a recursive blit otherwise */
|
||||
pan_legalize_afbc_format(ctx, pan_resource(info->dst.resource),
|
||||
info->dst.format, true);
|
||||
|
||||
panfrost_blitter_save(ctx, info->render_condition_enable
|
||||
? PAN_RENDER_BLIT_COND
|
||||
: PAN_RENDER_BLIT);
|
||||
|
@@ -4224,7 +4224,8 @@ panfrost_create_sampler_view(struct pipe_context *pctx,
|
||||
struct panfrost_sampler_view *so =
|
||||
rzalloc(pctx, struct panfrost_sampler_view);
|
||||
|
||||
pan_legalize_afbc_format(ctx, pan_resource(texture), template->format);
|
||||
pan_legalize_afbc_format(ctx, pan_resource(texture), template->format,
|
||||
false);
|
||||
|
||||
pipe_reference(NULL, &texture->reference);
|
||||
|
||||
|
@@ -68,6 +68,7 @@ panfrost_batch_add_surface(struct panfrost_batch *batch,
|
||||
{
|
||||
if (surf) {
|
||||
struct panfrost_resource *rsrc = pan_resource(surf->texture);
|
||||
pan_legalize_afbc_format(batch->ctx, rsrc, surf->format, true);
|
||||
panfrost_batch_write_rsrc(batch, rsrc, PIPE_SHADER_FRAGMENT);
|
||||
}
|
||||
}
|
||||
|
@@ -257,11 +257,8 @@ static struct pipe_surface *
|
||||
panfrost_create_surface(struct pipe_context *pipe, struct pipe_resource *pt,
|
||||
const struct pipe_surface *surf_tmpl)
|
||||
{
|
||||
struct panfrost_context *ctx = pan_context(pipe);
|
||||
struct pipe_surface *ps = NULL;
|
||||
|
||||
pan_legalize_afbc_format(ctx, pan_resource(pt), surf_tmpl->format);
|
||||
|
||||
ps = CALLOC_STRUCT(pipe_surface);
|
||||
|
||||
if (ps) {
|
||||
@@ -1180,7 +1177,8 @@ pan_resource_modifier_convert(struct panfrost_context *ctx,
|
||||
{
|
||||
assert(!rsrc->modifier_constant);
|
||||
|
||||
perf_debug_ctx(ctx, "Disabling AFBC with a blit. Reason: %s", reason);
|
||||
perf_debug_ctx(ctx, "%s AFBC with a blit. Reason: %s",
|
||||
drm_is_afbc(modifier) ? "Unpacking" : "Disabling", reason);
|
||||
|
||||
struct pipe_resource *tmp_prsrc = panfrost_resource_create_with_modifier(
|
||||
ctx->base.screen, &rsrc->base, modifier);
|
||||
@@ -1228,20 +1226,25 @@ pan_resource_modifier_convert(struct panfrost_context *ctx,
|
||||
void
|
||||
pan_legalize_afbc_format(struct panfrost_context *ctx,
|
||||
struct panfrost_resource *rsrc,
|
||||
enum pipe_format format)
|
||||
enum pipe_format format, bool write)
|
||||
{
|
||||
struct panfrost_device *dev = pan_device(ctx->base.screen);
|
||||
|
||||
if (!drm_is_afbc(rsrc->image.layout.modifier))
|
||||
return;
|
||||
|
||||
if (panfrost_afbc_format(dev->arch, rsrc->base.format) ==
|
||||
panfrost_afbc_format(dev->arch, format))
|
||||
if (panfrost_afbc_format(dev->arch, rsrc->base.format) !=
|
||||
panfrost_afbc_format(dev->arch, format)) {
|
||||
pan_resource_modifier_convert(
|
||||
ctx, rsrc, DRM_FORMAT_MOD_ARM_16X16_BLOCK_U_INTERLEAVED,
|
||||
"Reinterpreting AFBC surface as incompatible format");
|
||||
return;
|
||||
}
|
||||
|
||||
pan_resource_modifier_convert(
|
||||
ctx, rsrc, DRM_FORMAT_MOD_ARM_16X16_BLOCK_U_INTERLEAVED,
|
||||
"Reinterpreting AFBC surface as incompatible format");
|
||||
if (write && (rsrc->image.layout.modifier & AFBC_FORMAT_MOD_SPARSE) == 0)
|
||||
pan_resource_modifier_convert(
|
||||
ctx, rsrc, rsrc->image.layout.modifier | AFBC_FORMAT_MOD_SPARSE,
|
||||
"Legalizing resource to allow writing");
|
||||
}
|
||||
|
||||
static bool
|
||||
|
@@ -190,6 +190,6 @@ void pan_resource_modifier_convert(struct panfrost_context *ctx,
|
||||
|
||||
void pan_legalize_afbc_format(struct panfrost_context *ctx,
|
||||
struct panfrost_resource *rsrc,
|
||||
enum pipe_format format);
|
||||
enum pipe_format format, bool write);
|
||||
|
||||
#endif /* PAN_RESOURCE_H */
|
||||
|
Reference in New Issue
Block a user