freedreno: use rsc->slice accessor everywhere
authorRob Clark <robdclark@chromium.org>
Sun, 5 May 2019 15:10:24 +0000 (08:10 -0700)
committerEric Anholt <eric@anholt.net>
Tue, 26 Nov 2019 18:46:07 +0000 (18:46 +0000)
This will make it easier to extract the slice table out into a layout
helper.

Acked-by: Rob Clark <robdclark@chromium.org>
14 files changed:
src/gallium/drivers/freedreno/a2xx/fd2_texture.c
src/gallium/drivers/freedreno/a3xx/fd3_gmem.c
src/gallium/drivers/freedreno/a3xx/fd3_resource.c
src/gallium/drivers/freedreno/a3xx/fd3_texture.c
src/gallium/drivers/freedreno/a4xx/fd4_gmem.c
src/gallium/drivers/freedreno/a4xx/fd4_texture.c
src/gallium/drivers/freedreno/a5xx/fd5_image.c
src/gallium/drivers/freedreno/a5xx/fd5_resource.c
src/gallium/drivers/freedreno/a5xx/fd5_texture.c
src/gallium/drivers/freedreno/a6xx/fd6_image.c
src/gallium/drivers/freedreno/a6xx/fd6_resource.c
src/gallium/drivers/freedreno/a6xx/fd6_texture.c
src/gallium/drivers/freedreno/freedreno_resource.c
src/gallium/drivers/freedreno/ir3/ir3_gallium.c

index b6ceb323f0b9d5873573b41fd70571fc08ce6e0f..3fc43e3c4e87730e9775730c0975531ddf0dcfee 100644 (file)
@@ -181,12 +181,13 @@ fd2_sampler_view_create(struct pipe_context *pctx, struct pipe_resource *prsc,
        so->base.reference.count = 1;
        so->base.context = pctx;
 
+       struct fd_resource_slice *slice0 = fd_resource_slice(rsc, 0);
        so->tex0 =
                A2XX_SQ_TEX_0_SIGN_X(fmt.sign) |
                A2XX_SQ_TEX_0_SIGN_Y(fmt.sign) |
                A2XX_SQ_TEX_0_SIGN_Z(fmt.sign) |
                A2XX_SQ_TEX_0_SIGN_W(fmt.sign) |
-               A2XX_SQ_TEX_0_PITCH(rsc->slices[0].pitch) |
+               A2XX_SQ_TEX_0_PITCH(slice0->pitch) |
                COND(rsc->tile_mode, A2XX_SQ_TEX_0_TILED);
        so->tex1 =
                A2XX_SQ_TEX_1_FORMAT(fmt.format) |
index 361dc356cf8115758e39d88336538c352b5124d5..20094431076853d700dd6c56dca3381dd291e066 100644 (file)
@@ -738,7 +738,10 @@ fd3_emit_sysmem_prep(struct fd_batch *batch)
                struct pipe_surface *psurf = pfb->cbufs[i];
                if (!psurf)
                        continue;
-               pitch = fd_resource(psurf->texture)->slices[psurf->u.tex.level].pitch;
+               struct fd_resource_slice *slice =
+                       fd_resource_slice(fd_resource(psurf->texture),
+                               psurf->u.tex.level);
+               pitch = slice->pitch;
        }
 
        fd3_emit_restore(batch, ring);
index 4f8e195f1991462a2a349409d1cc5d375e918425..7fce61be99bfa37a8889ea860d42bb2fe0c0bdc0 100644 (file)
@@ -73,12 +73,12 @@ setup_slices(struct fd_resource *rsc, uint32_t alignment, enum pipe_format forma
                 */
                if (prsc->target == PIPE_TEXTURE_3D && (
                                        level == 1 ||
-                                       (level > 1 && rsc->slices[level - 1].size0 > 0xf000)))
+                                       (level > 1 && fd_resource_slice(rsc, level - 1)->size0 > 0xf000)))
                        slice->size0 = align(blocks * rsc->cpp, alignment);
                else if (level == 0 || alignment == 1)
                        slice->size0 = align(blocks * rsc->cpp, alignment);
                else
-                       slice->size0 = rsc->slices[level - 1].size0;
+                       slice->size0 = fd_resource_slice(rsc, level - 1)->size0;
 
                size += slice->size0 * depth * prsc->array_size;
 
index 9fc91273b6d89d3c362ac3dace79c251aeb31eaf..3abdc1677c4303e2ae9ab20ae5fcc0f09ce706de 100644 (file)
@@ -222,7 +222,6 @@ fd3_sampler_view_create(struct pipe_context *pctx, struct pipe_resource *prsc,
        struct fd3_pipe_sampler_view *so = CALLOC_STRUCT(fd3_pipe_sampler_view);
        struct fd_resource *rsc = fd_resource(prsc);
        unsigned lvl;
-       uint32_t sz2 = 0;
 
        if (!so)
                return NULL;
@@ -264,22 +263,22 @@ fd3_sampler_view_create(struct pipe_context *pctx, struct pipe_resource *prsc,
                        A3XX_TEX_CONST_1_HEIGHT(u_minify(prsc->height0, lvl));
        }
        /* when emitted, A3XX_TEX_CONST_2_INDX() must be OR'd in: */
+       struct fd_resource_slice *slice = fd_resource_slice(rsc, lvl);
        so->texconst2 =
-                       A3XX_TEX_CONST_2_PITCH(fd3_pipe2nblocksx(cso->format, rsc->slices[lvl].pitch) * rsc->cpp);
+                       A3XX_TEX_CONST_2_PITCH(fd3_pipe2nblocksx(cso->format, slice->pitch) * rsc->cpp);
        switch (prsc->target) {
        case PIPE_TEXTURE_1D_ARRAY:
        case PIPE_TEXTURE_2D_ARRAY:
                so->texconst3 =
                                A3XX_TEX_CONST_3_DEPTH(prsc->array_size - 1) |
-                               A3XX_TEX_CONST_3_LAYERSZ1(rsc->slices[0].size0);
+                               A3XX_TEX_CONST_3_LAYERSZ1(slice->size0);
                break;
        case PIPE_TEXTURE_3D:
                so->texconst3 =
                                A3XX_TEX_CONST_3_DEPTH(u_minify(prsc->depth0, lvl)) |
-                               A3XX_TEX_CONST_3_LAYERSZ1(rsc->slices[lvl].size0);
-               while (lvl < cso->u.tex.last_level && sz2 != rsc->slices[lvl+1].size0)
-                       sz2 = rsc->slices[++lvl].size0;
-               so->texconst3 |= A3XX_TEX_CONST_3_LAYERSZ2(sz2);
+                               A3XX_TEX_CONST_3_LAYERSZ1(slice->size0);
+               so->texconst3 |= A3XX_TEX_CONST_3_LAYERSZ2(
+                               fd_resource_slice(rsc, prsc->last_level)->size0);
                break;
        default:
                so->texconst3 = 0x00000000;
index 9121776ce6b236b1a8b1de0f8ff5a3875e55592c..947a2f0b12b8195cbb4b20a45e994ac213d58d9b 100644 (file)
@@ -164,7 +164,7 @@ emit_gmem2mem_surf(struct fd_batch *batch, bool stencil,
                pformat = rsc->base.format;
        }
 
-       slice = &rsc->slices[psurf->u.tex.level];
+       slice = fd_resource_slice(rsc, psurf->u.tex.level);
        offset = fd_resource_offset(rsc, psurf->u.tex.level,
                        psurf->u.tex.first_layer);
 
index 9ee4d8bd463317d937a1ec082fe7d31a476ae2a9..d67e4da90535335786bb20cd2112cf9e7c7950d9 100644 (file)
@@ -222,9 +222,9 @@ fd4_sampler_view_create(struct pipe_context *pctx, struct pipe_resource *prsc,
 {
        struct fd4_pipe_sampler_view *so = CALLOC_STRUCT(fd4_pipe_sampler_view);
        struct fd_resource *rsc = fd_resource(prsc);
+       struct fd_resource_slice *slice = NULL;
        enum pipe_format format = cso->format;
        unsigned lvl, layers = 0;
-       uint32_t sz2 = 0;
 
        if (!so)
                return NULL;
@@ -267,6 +267,7 @@ fd4_sampler_view_create(struct pipe_context *pctx, struct pipe_resource *prsc,
                unsigned miplevels;
 
                lvl = fd_sampler_first_level(cso);
+               slice = fd_resource_slice(rsc, lvl);
                miplevels = fd_sampler_last_level(cso) - lvl;
                layers = cso->u.tex.last_layer - cso->u.tex.first_layer + 1;
 
@@ -277,8 +278,7 @@ fd4_sampler_view_create(struct pipe_context *pctx, struct pipe_resource *prsc,
                so->texconst2 =
                        A4XX_TEX_CONST_2_FETCHSIZE(fd4_pipe2fetchsize(format)) |
                        A4XX_TEX_CONST_2_PITCH(
-                                       util_format_get_nblocksx(
-                                                       format, rsc->slices[lvl].pitch) * rsc->cpp);
+                               util_format_get_nblocksx(format, slice->pitch) * rsc->cpp);
                so->offset = fd_resource_offset(rsc, lvl, cso->u.tex.first_layer);
        }
 
@@ -310,10 +310,9 @@ fd4_sampler_view_create(struct pipe_context *pctx, struct pipe_resource *prsc,
        case PIPE_TEXTURE_3D:
                so->texconst3 =
                        A4XX_TEX_CONST_3_DEPTH(u_minify(prsc->depth0, lvl)) |
-                       A4XX_TEX_CONST_3_LAYERSZ(rsc->slices[lvl].size0);
-               while (lvl < cso->u.tex.last_level && sz2 != rsc->slices[lvl+1].size0)
-                       sz2 = rsc->slices[++lvl].size0;
-               so->texconst4 = A4XX_TEX_CONST_4_LAYERSZ(sz2);
+                       A4XX_TEX_CONST_3_LAYERSZ(slice->size0);
+               so->texconst4 = A4XX_TEX_CONST_4_LAYERSZ(
+                       fd_resource_slice(rsc, prsc->last_level)->size0);
                break;
        default:
                so->texconst3 = 0x00000000;
index c53b2e9224539f0d2ade101ad6db886bcf3141be..2f3389072b04cf5398ffbe1e31f48f53021dbbfd 100644 (file)
@@ -62,6 +62,7 @@ static void translate_image(struct fd5_image *img, struct pipe_image_view *pimg)
        enum pipe_format format = pimg->format;
        struct pipe_resource *prsc = pimg->resource;
        struct fd_resource *rsc = fd_resource(prsc);
+       struct fd_resource_slice *slice = NULL;
        unsigned lvl;
 
        if (!pimg->resource) {
@@ -83,8 +84,9 @@ static void translate_image(struct fd5_image *img, struct pipe_image_view *pimg)
                img->pitch  = pimg->u.buf.size;
        } else {
                lvl = pimg->u.tex.level;
+               slice = fd_resource_slice(rsc, lvl);
                img->offset = fd_resource_offset(rsc, lvl, pimg->u.tex.first_layer);
-               img->pitch  = rsc->slices[lvl].pitch * rsc->cpp;
+               img->pitch  = slice->pitch * rsc->cpp;
        }
 
        img->width     = u_minify(prsc->width0, lvl);
@@ -110,7 +112,7 @@ static void translate_image(struct fd5_image *img, struct pipe_image_view *pimg)
                img->depth = layers;
                break;
        case PIPE_TEXTURE_3D:
-               img->array_pitch = rsc->slices[lvl].size0;
+               img->array_pitch = slice->size0;
                img->depth = u_minify(prsc->depth0, lvl);
                break;
        default:
index 71bcc3815284bf4b2bb08404a3fc6728a3223d6a..efd699c0060a2c032f52abd837413047a1f49f28 100644 (file)
@@ -102,12 +102,12 @@ setup_slices(struct fd_resource *rsc, uint32_t alignment, enum pipe_format forma
                 */
                if (prsc->target == PIPE_TEXTURE_3D && (
                                        level == 1 ||
-                                       (level > 1 && rsc->slices[level - 1].size0 > 0xf000)))
+                                       (level > 1 && fd_resource_slice(rsc, level - 1)->size0 > 0xf000)))
                        slice->size0 = align(blocks * rsc->cpp, alignment);
                else if (level == 0 || rsc->layer_first || alignment == 1)
                        slice->size0 = align(blocks * rsc->cpp, alignment);
                else
-                       slice->size0 = rsc->slices[level - 1].size0;
+                       slice->size0 = fd_resource_slice(rsc, level - 1)->size0;
 
 #if 0
                debug_printf("%s: %ux%ux%u@%u: %2u: stride=%4u, size=%7u, aligned_height=%3u\n",
index 23af2560cec247c57566c2e9ad4a605b245f8d6a..6b341d4b5b8babff07b4862b7ed179a95e36cda7 100644 (file)
@@ -198,6 +198,7 @@ fd5_sampler_view_create(struct pipe_context *pctx, struct pipe_resource *prsc,
 {
        struct fd5_pipe_sampler_view *so = CALLOC_STRUCT(fd5_pipe_sampler_view);
        struct fd_resource *rsc = fd_resource(prsc);
+       struct fd_resource_slice *slice = NULL;
        enum pipe_format format = cso->format;
        unsigned lvl, layers = 0;
 
@@ -255,6 +256,7 @@ fd5_sampler_view_create(struct pipe_context *pctx, struct pipe_resource *prsc,
                unsigned miplevels;
 
                lvl = fd_sampler_first_level(cso);
+               slice = fd_resource_slice(rsc, lvl);
                miplevels = fd_sampler_last_level(cso) - lvl;
                layers = cso->u.tex.last_layer - cso->u.tex.first_layer + 1;
 
@@ -265,8 +267,7 @@ fd5_sampler_view_create(struct pipe_context *pctx, struct pipe_resource *prsc,
                so->texconst2 =
                        A5XX_TEX_CONST_2_FETCHSIZE(fd5_pipe2fetchsize(format)) |
                        A5XX_TEX_CONST_2_PITCH(
-                                       util_format_get_nblocksx(
-                                                       format, rsc->slices[lvl].pitch) * rsc->cpp);
+                               util_format_get_nblocksx(format, slice->pitch) * rsc->cpp);
                so->offset = fd_resource_offset(rsc, lvl, cso->u.tex.first_layer);
        }
 
@@ -297,7 +298,7 @@ fd5_sampler_view_create(struct pipe_context *pctx, struct pipe_resource *prsc,
                break;
        case PIPE_TEXTURE_3D:
                so->texconst3 =
-                       A5XX_TEX_CONST_3_ARRAY_PITCH(rsc->slices[lvl].size0);
+                       A5XX_TEX_CONST_3_ARRAY_PITCH(slice->size0);
                so->texconst5 =
                        A5XX_TEX_CONST_5_DEPTH(u_minify(prsc->depth0, lvl));
                break;
index b6d3837994586d4082ad077f6a263b293d974d5a..c790ee6c5cb6a152bf617bd187814801a2ee41df 100644 (file)
@@ -97,11 +97,12 @@ static void translate_image(struct fd6_image *img, const struct pipe_image_view
                img->buffer = false;
 
                unsigned lvl = pimg->u.tex.level;
+               struct fd_resource_slice *slice = fd_resource_slice(rsc, lvl);
                unsigned layers = pimg->u.tex.last_layer - pimg->u.tex.first_layer + 1;
 
                img->ubwc_offset = fd_resource_ubwc_offset(rsc, lvl, pimg->u.tex.first_layer);
                img->offset = fd_resource_offset(rsc, lvl, pimg->u.tex.first_layer);
-               img->pitch  = rsc->slices[lvl].pitch * rsc->cpp;
+               img->pitch  = slice->pitch * rsc->cpp;
 
                switch (prsc->target) {
                case PIPE_TEXTURE_RECT:
@@ -120,7 +121,7 @@ static void translate_image(struct fd6_image *img, const struct pipe_image_view
                        img->depth = layers;
                        break;
                case PIPE_TEXTURE_3D:
-                       img->array_pitch = rsc->slices[lvl].size0;
+                       img->array_pitch = slice->size0;
                        img->depth  = u_minify(prsc->depth0, lvl);
                        break;
                default:
index e9f561e08b5211e3bc57d32e3882645ea74a580a..b52a7bbb43978c444521af0559702fc0bdbbc5b3 100644 (file)
@@ -133,10 +133,10 @@ setup_slices(struct fd_resource *rsc, uint32_t alignment, enum pipe_format forma
                 * range gets into range, we stop reducing it.
                 */
                if (prsc->target == PIPE_TEXTURE_3D) {
-                       if (level < 1 || (rsc->slices[level - 1].size0 > 0xf000)) {
+                       if (level < 1 || fd_resource_slice(rsc, level - 1)->size0 > 0xf000) {
                                slice->size0 = align(blocks * rsc->cpp, alignment);
                        } else {
-                               slice->size0 = rsc->slices[level - 1].size0;
+                               slice->size0 = fd_resource_slice(rsc, level - 1)->size0;
                        }
                } else {
                        slice->size0 = align(blocks * rsc->cpp, alignment);
index 6ef7b16ab87a90906574d3dfcfd637a451106cf2..f0565125dfcd0ebad4438cb153a72990af2f3215 100644 (file)
@@ -220,6 +220,7 @@ fd6_sampler_view_create(struct pipe_context *pctx, struct pipe_resource *prsc,
 {
        struct fd6_pipe_sampler_view *so = CALLOC_STRUCT(fd6_pipe_sampler_view);
        struct fd_resource *rsc = fd_resource(prsc);
+       struct fd_resource_slice *slice = NULL;
        enum pipe_format format = cso->format;
        unsigned lvl, layers = 0;
 
@@ -255,6 +256,7 @@ fd6_sampler_view_create(struct pipe_context *pctx, struct pipe_resource *prsc,
                unsigned miplevels;
 
                lvl = fd_sampler_first_level(cso);
+               slice = fd_resource_slice(rsc, lvl);
                miplevels = fd_sampler_last_level(cso) - lvl;
                layers = cso->u.tex.last_layer - cso->u.tex.first_layer + 1;
 
@@ -265,8 +267,7 @@ fd6_sampler_view_create(struct pipe_context *pctx, struct pipe_resource *prsc,
                so->texconst2 =
                        A6XX_TEX_CONST_2_FETCHSIZE(fd6_pipe2fetchsize(format)) |
                        A6XX_TEX_CONST_2_PITCH(
-                                       util_format_get_nblocksx(
-                                                       format, rsc->slices[lvl].pitch) * rsc->cpp);
+                               util_format_get_nblocksx(format, slice->pitch) * rsc->cpp);
                so->offset = fd_resource_offset(rsc, lvl, cso->u.tex.first_layer);
                so->ubwc_offset = fd_resource_ubwc_offset(rsc, lvl, cso->u.tex.first_layer);
                so->ubwc_enabled = fd_resource_ubwc_enabled(rsc, lvl);
@@ -308,8 +309,9 @@ fd6_sampler_view_create(struct pipe_context *pctx, struct pipe_resource *prsc,
                break;
        case PIPE_TEXTURE_3D:
                so->texconst3 =
-                       A6XX_TEX_CONST_3_MIN_LAYERSZ(rsc->slices[prsc->last_level].size0) |
-                       A6XX_TEX_CONST_3_ARRAY_PITCH(rsc->slices[lvl].size0);
+                       A6XX_TEX_CONST_3_MIN_LAYERSZ(
+                               fd_resource_slice(rsc, prsc->last_level)->size0) |
+                       A6XX_TEX_CONST_3_ARRAY_PITCH(slice->size0);
                so->texconst5 =
                        A6XX_TEX_CONST_5_DEPTH(u_minify(prsc->depth0, lvl));
                break;
index 082119b4e17b55b480acb8d6917428ee3f959727..fb3d6b65635d87a77137af2d911ceccb83d1bfc9 100644 (file)
@@ -544,12 +544,14 @@ fd_resource_transfer_map(struct pipe_context *pctx,
 
                staging_rsc = fd_alloc_staging(ctx, rsc, level, box);
                if (staging_rsc) {
+                       struct fd_resource_slice *staging_slice =
+                               fd_resource_slice(staging_rsc, 0);
                        // TODO for PIPE_TRANSFER_READ, need to do untiling blit..
                        trans->staging_prsc = &staging_rsc->base;
                        trans->base.stride = util_format_get_nblocksx(format,
-                               staging_rsc->slices[0].pitch) * staging_rsc->cpp;
+                               staging_slice->pitch) * staging_rsc->cpp;
                        trans->base.layer_stride = staging_rsc->layer_first ?
-                               staging_rsc->layer_size : staging_rsc->slices[0].size0;
+                               staging_rsc->layer_size : staging_slice->size0;
                        trans->staging_box = *box;
                        trans->staging_box.x = 0;
                        trans->staging_box.y = 0;
@@ -660,11 +662,13 @@ fd_resource_transfer_map(struct pipe_context *pctx,
                                 */
                                staging_rsc = fd_alloc_staging(ctx, rsc, level, box);
                                if (staging_rsc) {
+                                       struct fd_resource_slice *staging_slice =
+                                               fd_resource_slice(staging_rsc, 0);
                                        trans->staging_prsc = &staging_rsc->base;
                                        trans->base.stride = util_format_get_nblocksx(format,
-                                               staging_rsc->slices[0].pitch) * staging_rsc->cpp;
+                                               staging_slice->pitch) * staging_rsc->cpp;
                                        trans->base.layer_stride = staging_rsc->layer_first ?
-                                               staging_rsc->layer_size : staging_rsc->slices[0].size0;
+                                               staging_rsc->layer_size : staging_slice->size0;
                                        trans->staging_box = *box;
                                        trans->staging_box.x = 0;
                                        trans->staging_box.y = 0;
@@ -759,7 +763,7 @@ fd_resource_get_handle(struct pipe_screen *pscreen,
        handle->modifier = fd_resource_modifier(rsc);
 
        return fd_screen_bo_get_handle(pscreen, rsc->bo, rsc->scanout,
-                       rsc->slices[0].pitch * rsc->cpp, handle);
+                       fd_resource_slice(rsc, 0)->pitch * rsc->cpp, handle);
 }
 
 static uint32_t
@@ -797,12 +801,12 @@ setup_slices(struct fd_resource *rsc, uint32_t alignment, enum pipe_format forma
                 */
                if (prsc->target == PIPE_TEXTURE_3D && (
                                        level == 1 ||
-                                       (level > 1 && rsc->slices[level - 1].size0 > 0xf000)))
+                                       (level > 1 && fd_resource_slice(rsc, level - 1)->size0 > 0xf000)))
                        slice->size0 = align(blocks * rsc->cpp, alignment);
                else if (level == 0 || rsc->layer_first || alignment == 1)
                        slice->size0 = align(blocks * rsc->cpp, alignment);
                else
-                       slice->size0 = rsc->slices[level - 1].size0;
+                       slice->size0 = fd_resource_slice(rsc, level - 1)->size0;
 
                size += slice->size0 * depth * layers_in_level;
 
@@ -1090,7 +1094,7 @@ fd_resource_from_handle(struct pipe_screen *pscreen,
 {
        struct fd_screen *screen = fd_screen(pscreen);
        struct fd_resource *rsc = CALLOC_STRUCT(fd_resource);
-       struct fd_resource_slice *slice = &rsc->slices[0];
+       struct fd_resource_slice *slice = fd_resource_slice(rsc, 0);
        struct pipe_resource *prsc = &rsc->base;
        uint32_t pitchalign = fd_screen(pscreen)->gmem_alignw;
 
index 119f9660ac55f77c878e567c97697497eecc00de..db2e375228cc9f0a32ab8a00df5475b1dc6a87aa 100644 (file)
@@ -343,18 +343,19 @@ ir3_emit_image_dims(struct fd_screen *screen, const struct ir3_shader_variant *v
 
                        dims[off + 0] = util_format_get_blocksize(img->format);
                        if (img->resource->target != PIPE_BUFFER) {
-                               unsigned lvl = img->u.tex.level;
+                               struct fd_resource_slice *slice =
+                                       fd_resource_slice(rsc, img->u.tex.level);
                                /* note for 2d/cube/etc images, even if re-interpreted
                                 * as a different color format, the pixel size should
                                 * be the same, so use original dimensions for y and z
                                 * stride:
                                 */
-                               dims[off + 1] = rsc->slices[lvl].pitch * rsc->cpp;
+                               dims[off + 1] = slice->pitch * rsc->cpp;
                                /* see corresponding logic in fd_resource_offset(): */
                                if (rsc->layer_first) {
                                        dims[off + 2] = rsc->layer_size;
                                } else {
-                                       dims[off + 2] = rsc->slices[lvl].size0;
+                                       dims[off + 2] = slice->size0;
                                }
                        } else {
                                /* For buffer-backed images, the log2 of the format's