From: Rob Clark Date: Sun, 5 May 2019 15:10:24 +0000 (-0700) Subject: freedreno: use rsc->slice accessor everywhere X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=9e9a26c768b070d57f5f00abc982c548a5320a5e;p=mesa.git freedreno: use rsc->slice accessor everywhere This will make it easier to extract the slice table out into a layout helper. Acked-by: Rob Clark --- diff --git a/src/gallium/drivers/freedreno/a2xx/fd2_texture.c b/src/gallium/drivers/freedreno/a2xx/fd2_texture.c index b6ceb323f0b..3fc43e3c4e8 100644 --- a/src/gallium/drivers/freedreno/a2xx/fd2_texture.c +++ b/src/gallium/drivers/freedreno/a2xx/fd2_texture.c @@ -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) | diff --git a/src/gallium/drivers/freedreno/a3xx/fd3_gmem.c b/src/gallium/drivers/freedreno/a3xx/fd3_gmem.c index 361dc356cf8..20094431076 100644 --- a/src/gallium/drivers/freedreno/a3xx/fd3_gmem.c +++ b/src/gallium/drivers/freedreno/a3xx/fd3_gmem.c @@ -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); diff --git a/src/gallium/drivers/freedreno/a3xx/fd3_resource.c b/src/gallium/drivers/freedreno/a3xx/fd3_resource.c index 4f8e195f199..7fce61be99b 100644 --- a/src/gallium/drivers/freedreno/a3xx/fd3_resource.c +++ b/src/gallium/drivers/freedreno/a3xx/fd3_resource.c @@ -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; diff --git a/src/gallium/drivers/freedreno/a3xx/fd3_texture.c b/src/gallium/drivers/freedreno/a3xx/fd3_texture.c index 9fc91273b6d..3abdc1677c4 100644 --- a/src/gallium/drivers/freedreno/a3xx/fd3_texture.c +++ b/src/gallium/drivers/freedreno/a3xx/fd3_texture.c @@ -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; diff --git a/src/gallium/drivers/freedreno/a4xx/fd4_gmem.c b/src/gallium/drivers/freedreno/a4xx/fd4_gmem.c index 9121776ce6b..947a2f0b12b 100644 --- a/src/gallium/drivers/freedreno/a4xx/fd4_gmem.c +++ b/src/gallium/drivers/freedreno/a4xx/fd4_gmem.c @@ -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); diff --git a/src/gallium/drivers/freedreno/a4xx/fd4_texture.c b/src/gallium/drivers/freedreno/a4xx/fd4_texture.c index 9ee4d8bd463..d67e4da9053 100644 --- a/src/gallium/drivers/freedreno/a4xx/fd4_texture.c +++ b/src/gallium/drivers/freedreno/a4xx/fd4_texture.c @@ -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; diff --git a/src/gallium/drivers/freedreno/a5xx/fd5_image.c b/src/gallium/drivers/freedreno/a5xx/fd5_image.c index c53b2e92245..2f3389072b0 100644 --- a/src/gallium/drivers/freedreno/a5xx/fd5_image.c +++ b/src/gallium/drivers/freedreno/a5xx/fd5_image.c @@ -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: diff --git a/src/gallium/drivers/freedreno/a5xx/fd5_resource.c b/src/gallium/drivers/freedreno/a5xx/fd5_resource.c index 71bcc381528..efd699c0060 100644 --- a/src/gallium/drivers/freedreno/a5xx/fd5_resource.c +++ b/src/gallium/drivers/freedreno/a5xx/fd5_resource.c @@ -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", diff --git a/src/gallium/drivers/freedreno/a5xx/fd5_texture.c b/src/gallium/drivers/freedreno/a5xx/fd5_texture.c index 23af2560cec..6b341d4b5b8 100644 --- a/src/gallium/drivers/freedreno/a5xx/fd5_texture.c +++ b/src/gallium/drivers/freedreno/a5xx/fd5_texture.c @@ -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; diff --git a/src/gallium/drivers/freedreno/a6xx/fd6_image.c b/src/gallium/drivers/freedreno/a6xx/fd6_image.c index b6d38379945..c790ee6c5cb 100644 --- a/src/gallium/drivers/freedreno/a6xx/fd6_image.c +++ b/src/gallium/drivers/freedreno/a6xx/fd6_image.c @@ -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: diff --git a/src/gallium/drivers/freedreno/a6xx/fd6_resource.c b/src/gallium/drivers/freedreno/a6xx/fd6_resource.c index e9f561e08b5..b52a7bbb439 100644 --- a/src/gallium/drivers/freedreno/a6xx/fd6_resource.c +++ b/src/gallium/drivers/freedreno/a6xx/fd6_resource.c @@ -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); diff --git a/src/gallium/drivers/freedreno/a6xx/fd6_texture.c b/src/gallium/drivers/freedreno/a6xx/fd6_texture.c index 6ef7b16ab87..f0565125dfc 100644 --- a/src/gallium/drivers/freedreno/a6xx/fd6_texture.c +++ b/src/gallium/drivers/freedreno/a6xx/fd6_texture.c @@ -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; diff --git a/src/gallium/drivers/freedreno/freedreno_resource.c b/src/gallium/drivers/freedreno/freedreno_resource.c index 082119b4e17..fb3d6b65635 100644 --- a/src/gallium/drivers/freedreno/freedreno_resource.c +++ b/src/gallium/drivers/freedreno/freedreno_resource.c @@ -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; diff --git a/src/gallium/drivers/freedreno/ir3/ir3_gallium.c b/src/gallium/drivers/freedreno/ir3/ir3_gallium.c index 119f9660ac5..db2e375228c 100644 --- a/src/gallium/drivers/freedreno/ir3/ir3_gallium.c +++ b/src/gallium/drivers/freedreno/ir3/ir3_gallium.c @@ -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