Mesa (master): panfrost: add resource modifier conversion

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Jan 27 12:52:33 UTC 2021


Module: Mesa
Branch: master
Commit: f63a35baee5101cf999a2fd96420c4148984df51
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=f63a35baee5101cf999a2fd96420c4148984df51

Author: Italo Nicola <italonicola at collabora.com>
Date:   Wed Dec 16 14:15:28 2020 +0000

panfrost: add resource modifier conversion

Adds a helper function to convert a resource to a chosen modifier.

Signed-off-by: Italo Nicola <italonicola at collabora.com>
Reviewed-by: Boris Brezillon <boris.brezillon at collabora.com>
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig at collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8066>

---

 src/gallium/drivers/panfrost/pan_resource.c | 49 +++++++++++++++++++++++++++++
 src/gallium/drivers/panfrost/pan_resource.h |  4 +++
 2 files changed, 53 insertions(+)

diff --git a/src/gallium/drivers/panfrost/pan_resource.c b/src/gallium/drivers/panfrost/pan_resource.c
index a2f618ea550..d4de275cd40 100644
--- a/src/gallium/drivers/panfrost/pan_resource.c
+++ b/src/gallium/drivers/panfrost/pan_resource.c
@@ -1114,6 +1114,55 @@ panfrost_ptr_map(struct pipe_context *pctx,
         }
 }
 
+void
+pan_resource_modifier_convert(struct panfrost_context *ctx,
+                              struct panfrost_resource *rsrc,
+                              uint64_t modifier)
+{
+        assert(!rsrc->modifier_constant);
+
+        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 = {0};
+
+        unsigned depth = rsrc->base.target == PIPE_TEXTURE_3D ?
+                rsrc->base.depth0 : rsrc->base.array_size;
+
+        struct pipe_box box =
+                { 0, 0, 0, rsrc->base.width0, rsrc->base.height0, depth };
+
+        for (int i = 0; i <= rsrc->base.last_level; i++) {
+                if (!rsrc->layout.slices[i].initialized)
+                        continue;
+
+                blit.dst.resource = &tmp_rsrc->base;
+                blit.dst.format   = pan_blit_format(tmp_rsrc->base.format);
+                blit.dst.level    = i;
+                blit.dst.box      = box;
+                blit.src.resource = &rsrc->base;
+                blit.src.format   = pan_blit_format(rsrc->base.format);
+                blit.src.level    = i;
+                blit.src.box      = box;
+                blit.mask = util_format_get_mask(blit.dst.format);
+                blit.filter = PIPE_TEX_FILTER_NEAREST;
+
+                panfrost_blit(&ctx->base, &blit);
+        }
+
+        panfrost_bo_unreference(rsrc->bo);
+        if (rsrc->checksum_bo)
+                panfrost_bo_unreference(rsrc->checksum_bo);
+
+        rsrc->bo = tmp_rsrc->bo;
+        panfrost_bo_reference(rsrc->bo);
+
+        panfrost_resource_setup(pan_device(ctx->base.screen), rsrc, NULL, modifier);
+        pipe_resource_reference(&tmp_prsrc, NULL);
+}
+
 static bool
 panfrost_should_linear_convert(struct panfrost_resource *prsrc,
                                struct pipe_transfer *transfer)
diff --git a/src/gallium/drivers/panfrost/pan_resource.h b/src/gallium/drivers/panfrost/pan_resource.h
index a7d8265d560..cd780edde00 100644
--- a/src/gallium/drivers/panfrost/pan_resource.h
+++ b/src/gallium/drivers/panfrost/pan_resource.h
@@ -146,5 +146,9 @@ panfrost_translate_texture_dimension(enum pipe_texture_target t) {
         }
 }
 
+void
+pan_resource_modifier_convert(struct panfrost_context *ctx,
+                              struct panfrost_resource *rsrc,
+                              uint64_t modifier);
 
 #endif /* PAN_RESOURCE_H */



More information about the mesa-commit mailing list