freedreno: Introduce a fd_resource_layer_stride() helper.
authorEric Anholt <eric@anholt.net>
Wed, 20 Nov 2019 20:55:56 +0000 (12:55 -0800)
committerEric Anholt <eric@anholt.net>
Tue, 26 Nov 2019 18:46:07 +0000 (18:46 +0000)
This factors out a bit of duplicated code, but will also make the shared
resource layout transition process clearer.

Acked-by: Rob Clark <robdclark@chromium.org>
src/gallium/drivers/freedreno/freedreno_resource.c
src/gallium/drivers/freedreno/freedreno_resource.h

index fb3d6b65635d87a77137af2d911ceccb83d1bfc9..dbb84b11dbcb430de0d674736bcc4f0d2573f2f8 100644 (file)
@@ -531,7 +531,7 @@ fd_resource_transfer_map(struct pipe_context *pctx,
        ptrans->usage = usage;
        ptrans->box = *box;
        ptrans->stride = util_format_get_nblocksx(format, slice->pitch) * rsc->cpp;
-       ptrans->layer_stride = rsc->layer_first ? rsc->layer_size : slice->size0;
+       ptrans->layer_stride = fd_resource_layer_stride(rsc, level);
 
        /* we always need a staging texture for tiled buffers:
         *
@@ -550,8 +550,7 @@ fd_resource_transfer_map(struct pipe_context *pctx,
                        trans->staging_prsc = &staging_rsc->base;
                        trans->base.stride = util_format_get_nblocksx(format,
                                staging_slice->pitch) * staging_rsc->cpp;
-                       trans->base.layer_stride = staging_rsc->layer_first ?
-                               staging_rsc->layer_size : staging_slice->size0;
+                       trans->base.layer_stride = fd_resource_layer_stride(staging_rsc, 0);
                        trans->staging_box = *box;
                        trans->staging_box.x = 0;
                        trans->staging_box.y = 0;
@@ -667,8 +666,8 @@ fd_resource_transfer_map(struct pipe_context *pctx,
                                        trans->staging_prsc = &staging_rsc->base;
                                        trans->base.stride = util_format_get_nblocksx(format,
                                                staging_slice->pitch) * staging_rsc->cpp;
-                                       trans->base.layer_stride = staging_rsc->layer_first ?
-                                               staging_rsc->layer_size : staging_slice->size0;
+                                       trans->base.layer_stride =
+                                               fd_resource_layer_stride(staging_rsc, 0);
                                        trans->staging_box = *box;
                                        trans->staging_box.x = 0;
                                        trans->staging_box.y = 0;
index b16e5a2781cca2a383fe680b44bf3ad24762b1ef..1d3931b2a03b944dfb65cfc15068b7a8c270c25b 100644 (file)
@@ -156,17 +156,22 @@ fd_resource_slice(struct fd_resource *rsc, unsigned level)
        return &rsc->slices[level];
 }
 
+static inline uint32_t
+fd_resource_layer_stride(struct fd_resource *rsc, unsigned level)
+{
+       if (rsc->layer_first)
+               return rsc->layer_size;
+       else
+               return fd_resource_slice(rsc, level)->size0;
+}
+
 /* get offset for specified mipmap level and texture/array layer */
 static inline uint32_t
 fd_resource_offset(struct fd_resource *rsc, unsigned level, unsigned layer)
 {
        struct fd_resource_slice *slice = fd_resource_slice(rsc, level);
-       unsigned offset;
-       if (rsc->layer_first) {
-               offset = slice->offset + (rsc->layer_size * layer);
-       } else {
-               offset = slice->offset + (slice->size0 * layer);
-       }
+       unsigned offset = slice->offset;
+       offset += fd_resource_layer_stride(rsc, level) * layer;
        debug_assert(offset < fd_bo_size(rsc->bo));
        return offset + rsc->offset;
 }