diff options
author | Rob Clark <[email protected]> | 2014-12-12 17:20:50 -0500 |
---|---|---|
committer | Rob Clark <[email protected]> | 2014-12-13 15:09:37 -0500 |
commit | 7474de2235beee9240be702ab99b93989fa7c7c1 (patch) | |
tree | 8893d371f3d74405edf037c129f9b8f2c5234146 /src/gallium/drivers/freedreno | |
parent | 23caba862a001f82ef352307a79bebf7ef910959 (diff) |
freedreno: helper to calc layer/level offset
Rather than duplicating this everywhere. Especially as on a4xx the
layout of layers and levels differs based on texture type.
Signed-off-by: Rob Clark <[email protected]>
Diffstat (limited to 'src/gallium/drivers/freedreno')
-rw-r--r-- | src/gallium/drivers/freedreno/a3xx/fd3_emit.c | 6 | ||||
-rw-r--r-- | src/gallium/drivers/freedreno/a3xx/fd3_gmem.c | 17 | ||||
-rw-r--r-- | src/gallium/drivers/freedreno/a4xx/fd4_emit.c | 6 | ||||
-rw-r--r-- | src/gallium/drivers/freedreno/a4xx/fd4_gmem.c | 15 | ||||
-rw-r--r-- | src/gallium/drivers/freedreno/freedreno_resource.h | 8 |
5 files changed, 31 insertions, 21 deletions
diff --git a/src/gallium/drivers/freedreno/a3xx/fd3_emit.c b/src/gallium/drivers/freedreno/a3xx/fd3_emit.c index f9dada79073..443a59de52b 100644 --- a/src/gallium/drivers/freedreno/a3xx/fd3_emit.c +++ b/src/gallium/drivers/freedreno/a3xx/fd3_emit.c @@ -297,8 +297,8 @@ fd3_emit_gmem_restore_tex(struct fd_ringbuffer *ring, struct pipe_surface *psurf { struct fd_resource *rsc = fd_resource(psurf->texture); unsigned lvl = psurf->u.tex.level; - struct fd_resource_slice *slice = &rsc->slices[lvl]; - uint32_t layer_offset = slice->size0 * psurf->u.tex.first_layer; + struct fd_resource_slice *slice = fd_resource_slice(rsc, lvl); + uint32_t offset = fd_resource_offset(rsc, lvl, psurf->u.tex.first_layer); enum pipe_format format = fd3_gmem_restore_format(psurf->format); debug_assert(psurf->u.tex.first_layer == psurf->u.tex.last_layer); @@ -345,7 +345,7 @@ fd3_emit_gmem_restore_tex(struct fd_ringbuffer *ring, struct pipe_surface *psurf CP_LOAD_STATE_0_NUM_UNIT(1)); OUT_RING(ring, CP_LOAD_STATE_1_STATE_TYPE(ST_CONSTANTS) | CP_LOAD_STATE_1_EXT_SRC_ADDR(0)); - OUT_RELOC(ring, rsc->bo, layer_offset, 0, 0); + OUT_RELOC(ring, rsc->bo, offset, 0, 0); } void diff --git a/src/gallium/drivers/freedreno/a3xx/fd3_gmem.c b/src/gallium/drivers/freedreno/a3xx/fd3_gmem.c index a196c9c926d..f92ccedd939 100644 --- a/src/gallium/drivers/freedreno/a3xx/fd3_gmem.c +++ b/src/gallium/drivers/freedreno/a3xx/fd3_gmem.c @@ -64,20 +64,21 @@ emit_mrt(struct fd_ringbuffer *ring, unsigned nr_bufs, struct fd_resource_slice *slice = NULL; uint32_t stride = 0; uint32_t base = 0; - uint32_t layer_offset = 0; + uint32_t offset = 0; if ((i < nr_bufs) && bufs[i]) { struct pipe_surface *psurf = bufs[i]; rsc = fd_resource(psurf->texture); - slice = &rsc->slices[psurf->u.tex.level]; + slice = fd_resource_slice(rsc, psurf->u.tex.level); format = fd3_pipe2color(psurf->format); swap = fd3_pipe2swap(psurf->format); srgb = util_format_is_srgb(psurf->format); debug_assert(psurf->u.tex.first_layer == psurf->u.tex.last_layer); - layer_offset = slice->size0 * psurf->u.tex.first_layer; + offset = fd_resource_offset(rsc, psurf->u.tex.level, + psurf->u.tex.first_layer); if (bin_w) { stride = bin_w * rsc->cpp; @@ -99,8 +100,7 @@ emit_mrt(struct fd_ringbuffer *ring, unsigned nr_bufs, if (bin_w || (i >= nr_bufs)) { OUT_RING(ring, A3XX_RB_MRT_BUF_BASE_COLOR_BUF_BASE(base)); } else { - OUT_RELOCW(ring, rsc->bo, - slice->offset + layer_offset, 0, -1); + OUT_RELOCW(ring, rsc->bo, offset, 0, -1); } OUT_PKT0(ring, REG_A3XX_SP_FS_IMAGE_OUTPUT_REG(i), 1); @@ -309,8 +309,9 @@ emit_gmem2mem_surf(struct fd_context *ctx, { struct fd_ringbuffer *ring = ctx->ring; struct fd_resource *rsc = fd_resource(psurf->texture); - struct fd_resource_slice *slice = &rsc->slices[psurf->u.tex.level]; - uint32_t layer_offset = slice->size0 * psurf->u.tex.first_layer; + struct fd_resource_slice *slice = fd_resource_slice(rsc, psurf->u.tex.level); + uint32_t offset = fd_resource_offset(rsc, psurf->u.tex.level, + psurf->u.tex.first_layer); debug_assert(psurf->u.tex.first_layer == psurf->u.tex.last_layer); @@ -319,7 +320,7 @@ emit_gmem2mem_surf(struct fd_context *ctx, A3XX_RB_COPY_CONTROL_MODE(mode) | A3XX_RB_COPY_CONTROL_GMEM_BASE(base)); - OUT_RELOCW(ring, rsc->bo, slice->offset + layer_offset, 0, -1); /* RB_COPY_DEST_BASE */ + OUT_RELOCW(ring, rsc->bo, offset, 0, -1); /* RB_COPY_DEST_BASE */ OUT_RING(ring, A3XX_RB_COPY_DEST_PITCH_PITCH(slice->pitch * rsc->cpp)); OUT_RING(ring, A3XX_RB_COPY_DEST_INFO_TILE(LINEAR) | A3XX_RB_COPY_DEST_INFO_FORMAT(fd3_pipe2color(psurf->format)) | diff --git a/src/gallium/drivers/freedreno/a4xx/fd4_emit.c b/src/gallium/drivers/freedreno/a4xx/fd4_emit.c index 839d3e8e441..d278bb5e009 100644 --- a/src/gallium/drivers/freedreno/a4xx/fd4_emit.c +++ b/src/gallium/drivers/freedreno/a4xx/fd4_emit.c @@ -231,8 +231,8 @@ fd4_emit_gmem_restore_tex(struct fd_ringbuffer *ring, struct pipe_surface *psurf { struct fd_resource *rsc = fd_resource(psurf->texture); unsigned lvl = psurf->u.tex.level; - struct fd_resource_slice *slice = &rsc->slices[lvl]; - uint32_t layer_offset = slice->size0 * psurf->u.tex.first_layer; + struct fd_resource_slice *slice = fd_resource_slice(rsc, lvl); + uint32_t offset = fd_resource_offset(rsc, lvl, psurf->u.tex.first_layer); enum pipe_format format = fd4_gmem_restore_format(psurf->format); debug_assert(psurf->u.tex.first_layer == psurf->u.tex.last_layer); @@ -268,7 +268,7 @@ fd4_emit_gmem_restore_tex(struct fd_ringbuffer *ring, struct pipe_surface *psurf A4XX_TEX_CONST_1_HEIGHT(psurf->height)); OUT_RING(ring, A4XX_TEX_CONST_2_PITCH(slice->pitch * rsc->cpp)); OUT_RING(ring, 0x00000000); - OUT_RELOC(ring, rsc->bo, layer_offset, 0, 0); + OUT_RELOC(ring, rsc->bo, offset, 0, 0); OUT_RING(ring, 0x00000000); OUT_RING(ring, 0x00000000); OUT_RING(ring, 0x00000000); diff --git a/src/gallium/drivers/freedreno/a4xx/fd4_gmem.c b/src/gallium/drivers/freedreno/a4xx/fd4_gmem.c index 3c900522443..e45e209e59e 100644 --- a/src/gallium/drivers/freedreno/a4xx/fd4_gmem.c +++ b/src/gallium/drivers/freedreno/a4xx/fd4_gmem.c @@ -63,19 +63,20 @@ emit_mrt(struct fd_ringbuffer *ring, unsigned nr_bufs, struct fd_resource_slice *slice = NULL; uint32_t stride = 0; uint32_t base = 0; - uint32_t layer_offset = 0; + uint32_t offset = 0; if ((i < nr_bufs) && bufs[i]) { struct pipe_surface *psurf = bufs[i]; rsc = fd_resource(psurf->texture); - slice = &rsc->slices[psurf->u.tex.level]; + slice = fd_resource_slice(rsc, psurf->u.tex.level); format = fd4_pipe2color(psurf->format); swap = fd4_pipe2swap(psurf->format); debug_assert(psurf->u.tex.first_layer == psurf->u.tex.last_layer); - layer_offset = slice->size0 * psurf->u.tex.first_layer; + offset = fd_resource_offset(rsc, psurf->u.tex.level, + psurf->u.tex.first_layer); if (bin_w) { stride = bin_w * rsc->cpp; @@ -96,8 +97,7 @@ emit_mrt(struct fd_ringbuffer *ring, unsigned nr_bufs, if (bin_w || (i >= nr_bufs)) { OUT_RING(ring, base); } else { - OUT_RELOCW(ring, rsc->bo, - slice->offset + layer_offset, 0, -1); + OUT_RELOCW(ring, rsc->bo, offset, 0, -1); } OUT_RING(ring, A4XX_RB_MRT_CONTROL3_STRIDE(stride)); } @@ -126,7 +126,8 @@ emit_gmem2mem_surf(struct fd_context *ctx, struct fd_ringbuffer *ring = ctx->ring; struct fd_resource *rsc = fd_resource(psurf->texture); struct fd_resource_slice *slice = &rsc->slices[psurf->u.tex.level]; - uint32_t layer_offset = slice->size0 * psurf->u.tex.first_layer; + uint32_t offset = fd_resource_offset(rsc, psurf->u.tex.level, + psurf->u.tex.first_layer); debug_assert(psurf->u.tex.first_layer == psurf->u.tex.last_layer); @@ -134,7 +135,7 @@ emit_gmem2mem_surf(struct fd_context *ctx, OUT_RING(ring, A4XX_RB_COPY_CONTROL_MSAA_RESOLVE(MSAA_ONE) | A4XX_RB_COPY_CONTROL_MODE(RB_COPY_RESOLVE) | A4XX_RB_COPY_CONTROL_GMEM_BASE(base)); - OUT_RELOCW(ring, rsc->bo, slice->offset + layer_offset, 0, 0); /* RB_COPY_DEST_BASE */ + OUT_RELOCW(ring, rsc->bo, offset, 0, 0); /* RB_COPY_DEST_BASE */ OUT_RING(ring, A4XX_RB_COPY_DEST_PITCH_PITCH(slice->pitch * rsc->cpp)); OUT_RING(ring, A4XX_RB_COPY_DEST_INFO_TILE(TILE4_LINEAR) | A4XX_RB_COPY_DEST_INFO_FORMAT(fd4_pipe2color(psurf->format)) | diff --git a/src/gallium/drivers/freedreno/freedreno_resource.h b/src/gallium/drivers/freedreno/freedreno_resource.h index 7e10d7a6416..1073eb7547e 100644 --- a/src/gallium/drivers/freedreno/freedreno_resource.h +++ b/src/gallium/drivers/freedreno/freedreno_resource.h @@ -67,6 +67,14 @@ fd_resource_slice(struct fd_resource *rsc, unsigned level) return &rsc->slices[level]; } +/* 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); + return slice->offset + (slice->size0 * layer); +} + void fd_resource_screen_init(struct pipe_screen *pscreen); void fd_resource_context_init(struct pipe_context *pctx); |