[Mesa-dev] [PATCH 3/3] panfrost: Set custom stride for textures when necessary

Alyssa Rosenzweig alyssa at rosenzweig.io
Tue May 14 23:25:28 UTC 2019


>From Gallium (and our) perspective, the stride of a BO is arbitrary. For
internal buffers, we can make it something nice, but for imported linear
buffers (e.g. EGL clients), we don't always have that luxury. To cope,
we calculate the expected stride of a texture, compare it to the BO's
actual reported stride, and if they differ, set the latter as a custom
stride.

Fixes rendering of windows not on tile boundaries (noticeable in Weston
with es2gears_wayland, for instance). Also, this should fix stride
issues with bufer reloading.

Signed-off-by: Alyssa Rosenzweig <alyssa at rosenzweig.io>
Cc: Tomeu Vizoso <tomeu.vizoso at collabora.com>
Cc: Boris Brezillon <boris.brezillon at collabora.com>
---
 src/gallium/drivers/panfrost/pan_context.c | 25 ++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/src/gallium/drivers/panfrost/pan_context.c b/src/gallium/drivers/panfrost/pan_context.c
index cab7c89ac8b..c4bb57d782e 100644
--- a/src/gallium/drivers/panfrost/pan_context.c
+++ b/src/gallium/drivers/panfrost/pan_context.c
@@ -1115,6 +1115,17 @@ panfrost_emit_for_draw(struct panfrost_context *ctx, bool with_vertex_data)
                                         }
                                 }
 
+                                /* Inject the strides */
+                                unsigned usage2 = ctx->sampler_views[t][i]->hw.format.usage2;
+
+                                if (usage2 & MALI_TEX_MANUAL_STRIDE) {
+                                        unsigned idx = tex_rsrc->last_level * tex_rsrc->array_size;
+                                        idx += tex_rsrc->array_size;
+
+                                        ctx->sampler_views[t][i]->hw.swizzled_bitmaps[idx] =
+                                                rsrc->bo->slices[0].stride;
+                                }
+
                                 trampolines[i] = panfrost_upload_transient(ctx, &ctx->sampler_views[t][i]->hw, sizeof(struct mali_texture_descriptor));
                         }
 
@@ -1951,6 +1962,7 @@ panfrost_create_sampler_view(
         pipe_reference(NULL, &texture->reference);
 
         struct panfrost_resource *prsrc = (struct panfrost_resource *) texture;
+        assert(prsrc->bo);
 
         so->base = *template;
         so->base.texture = texture;
@@ -1995,6 +2007,19 @@ panfrost_create_sampler_view(
                         break;
         }
 
+        /* Check if we need to set a custom stride by computing the "expected"
+         * stride and comparing it to what the BO actually wants. Only applies
+         * to linear textures TODO: Mipmap? */
+
+        unsigned actual_stride = prsrc->bo->slices[0].stride;
+
+        if (prsrc->bo->layout == PAN_LINEAR &&
+            template->u.tex.last_level == 0 &&
+            template->u.tex.first_level == 0 &&
+            (texture->width0 * bytes_per_pixel) != actual_stride) {
+                usage2_layout |= MALI_TEX_MANUAL_STRIDE;
+        }
+
         struct mali_texture_descriptor texture_descriptor = {
                 .width = MALI_POSITIVE(texture->width0),
                 .height = MALI_POSITIVE(texture->height0),
-- 
2.20.1



More information about the mesa-dev mailing list