From: Eric Anholt Date: Wed, 20 Nov 2019 20:55:56 +0000 (-0800) Subject: freedreno: Introduce a fd_resource_layer_stride() helper. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6b09227ededd930736dfd5c4eda140afd2185c8d;p=mesa.git freedreno: Introduce a fd_resource_layer_stride() helper. This factors out a bit of duplicated code, but will also make the shared resource layout transition process clearer. Acked-by: Rob Clark --- diff --git a/src/gallium/drivers/freedreno/freedreno_resource.c b/src/gallium/drivers/freedreno/freedreno_resource.c index fb3d6b65635..dbb84b11dbc 100644 --- a/src/gallium/drivers/freedreno/freedreno_resource.c +++ b/src/gallium/drivers/freedreno/freedreno_resource.c @@ -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; diff --git a/src/gallium/drivers/freedreno/freedreno_resource.h b/src/gallium/drivers/freedreno/freedreno_resource.h index b16e5a2781c..1d3931b2a03 100644 --- a/src/gallium/drivers/freedreno/freedreno_resource.h +++ b/src/gallium/drivers/freedreno/freedreno_resource.h @@ -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; }