summaryrefslogtreecommitdiffstats
path: root/src/gallium
diff options
context:
space:
mode:
authorEric Anholt <[email protected]>2019-11-20 12:55:56 -0800
committerEric Anholt <[email protected]>2019-11-26 18:46:07 +0000
commit6b09227ededd930736dfd5c4eda140afd2185c8d (patch)
tree67518cc6095de216a4e0aff7723cb9c7f98a6004 /src/gallium
parent9e9a26c768b070d57f5f00abc982c548a5320a5e (diff)
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 <[email protected]>
Diffstat (limited to 'src/gallium')
-rw-r--r--src/gallium/drivers/freedreno/freedreno_resource.c9
-rw-r--r--src/gallium/drivers/freedreno/freedreno_resource.h17
2 files changed, 15 insertions, 11 deletions
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;
}