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:
*
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;
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;
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;
}