From 62ed14b3868e304371b3e096da94c6dc3e24a299 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Louis-Francis=20Ratt=C3=A9-Boulianne?= Date: Wed, 24 Jan 2024 00:57:55 -0500 Subject: [PATCH] panfrost: add copy_resource flag to pan_resource_modifier_convert MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When converting the modifier for a resource, it's not always needed to blit the content as well. Creating a new resource with the right format/modifier might be enough. Signed-off-by: Louis-Francis Ratté-Boulianne Reviewed-by: Erik Faye-Lund Fixes: 33b48a55857 ("panfrost: Add debug flag to force packing of AFBC textures on upload") Part-of: --- src/gallium/drivers/panfrost/pan_context.c | 2 +- src/gallium/drivers/panfrost/pan_resource.c | 59 ++++++++++----------- src/gallium/drivers/panfrost/pan_resource.h | 3 +- 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/gallium/drivers/panfrost/pan_context.c b/src/gallium/drivers/panfrost/pan_context.c index 7408bd7d189..bc9006c14d2 100644 --- a/src/gallium/drivers/panfrost/pan_context.c +++ b/src/gallium/drivers/panfrost/pan_context.c @@ -284,7 +284,7 @@ panfrost_set_shader_images(struct pipe_context *pctx, */ if (drm_is_afbc(rsrc->image.layout.modifier)) { pan_resource_modifier_convert( - ctx, rsrc, DRM_FORMAT_MOD_ARM_16X16_BLOCK_U_INTERLEAVED, + ctx, rsrc, DRM_FORMAT_MOD_ARM_16X16_BLOCK_U_INTERLEAVED, true, "Shader image"); } diff --git a/src/gallium/drivers/panfrost/pan_resource.c b/src/gallium/drivers/panfrost/pan_resource.c index 77bd26d6cca..9ac92812cd8 100644 --- a/src/gallium/drivers/panfrost/pan_resource.c +++ b/src/gallium/drivers/panfrost/pan_resource.c @@ -1321,46 +1321,45 @@ panfrost_ptr_map(struct pipe_context *pctx, struct pipe_resource *resource, void pan_resource_modifier_convert(struct panfrost_context *ctx, struct panfrost_resource *rsrc, uint64_t modifier, - const char *reason) + bool copy_resource, const char *reason) { assert(!rsrc->modifier_constant); - 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); struct panfrost_resource *tmp_rsrc = pan_resource(tmp_prsrc); - struct pipe_blit_info blit = { - .dst.resource = &tmp_rsrc->base, - .dst.format = tmp_rsrc->base.format, - .src.resource = &rsrc->base, - .src.format = rsrc->base.format, - .mask = util_format_get_mask(tmp_rsrc->base.format), - .filter = PIPE_TEX_FILTER_NEAREST, - }; + if (copy_resource) { + struct pipe_blit_info blit = { + .dst.resource = &tmp_rsrc->base, + .dst.format = tmp_rsrc->base.format, + .src.resource = &rsrc->base, + .src.format = rsrc->base.format, + .mask = util_format_get_mask(tmp_rsrc->base.format), + .filter = PIPE_TEX_FILTER_NEAREST, + }; - /* data_valid is not valid until flushed */ - panfrost_flush_writer(ctx, rsrc, "AFBC decompressing blit"); + /* data_valid is not valid until flushed */ + panfrost_flush_writer(ctx, rsrc, "AFBC decompressing blit"); - for (int i = 0; i <= rsrc->base.last_level; i++) { - if (BITSET_TEST(rsrc->valid.data, i)) { - blit.dst.level = blit.src.level = i; + for (int i = 0; i <= rsrc->base.last_level; i++) { + if (BITSET_TEST(rsrc->valid.data, i)) { + blit.dst.level = blit.src.level = i; - u_box_3d(0, 0, 0, u_minify(rsrc->base.width0, i), - u_minify(rsrc->base.height0, i), - util_num_layers(&rsrc->base, i), &blit.dst.box); - blit.src.box = blit.dst.box; + u_box_3d(0, 0, 0, u_minify(rsrc->base.width0, i), + u_minify(rsrc->base.height0, i), + util_num_layers(&rsrc->base, i), &blit.dst.box); + blit.src.box = blit.dst.box; - panfrost_blit_no_afbc_legalization(&ctx->base, &blit); + panfrost_blit_no_afbc_legalization(&ctx->base, &blit); + } } - } - /* we lose track of tmp_rsrc after this point, and the BO migration - * (from tmp_rsrc to rsrc) doesn't transfer the last_writer to rsrc - */ - panfrost_flush_writer(ctx, tmp_rsrc, "AFBC decompressing blit"); + /* we lose track of tmp_rsrc after this point, and the BO migration + * (from tmp_rsrc to rsrc) doesn't transfer the last_writer to rsrc + */ + panfrost_flush_writer(ctx, tmp_rsrc, "AFBC decompressing blit"); + } panfrost_bo_unreference(rsrc->bo); @@ -1369,7 +1368,7 @@ pan_resource_modifier_convert(struct panfrost_context *ctx, panfrost_bo_reference(rsrc->bo); panfrost_resource_setup(pan_device(ctx->base.screen), rsrc, modifier, - blit.dst.format); + tmp_rsrc->base.format); /* panfrost_resource_setup will force the modifier to stay constant when * called with a specific modifier. We don't want that here, we want to * be able to convert back to another modifier if needed */ @@ -1394,7 +1393,7 @@ pan_legalize_afbc_format(struct panfrost_context *ctx, 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, + ctx, rsrc, DRM_FORMAT_MOD_ARM_16X16_BLOCK_U_INTERLEAVED, true, "Reinterpreting AFBC surface as incompatible format"); return; } @@ -1402,7 +1401,7 @@ pan_legalize_afbc_format(struct panfrost_context *ctx, 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"); + true, "Legalizing resource to allow writing"); } static bool diff --git a/src/gallium/drivers/panfrost/pan_resource.h b/src/gallium/drivers/panfrost/pan_resource.h index d6533349aca..f41b94f3f51 100644 --- a/src/gallium/drivers/panfrost/pan_resource.h +++ b/src/gallium/drivers/panfrost/pan_resource.h @@ -191,7 +191,8 @@ void panfrost_pack_afbc(struct panfrost_context *ctx, void pan_resource_modifier_convert(struct panfrost_context *ctx, struct panfrost_resource *rsrc, - uint64_t modifier, const char *reason); + uint64_t modifier, bool copy_resource, + const char *reason); void pan_legalize_afbc_format(struct panfrost_context *ctx, struct panfrost_resource *rsrc,