freedreno: Make the slice pitch be bytes, not pixels.
authorEric Anholt <eric@anholt.net>
Tue, 14 Apr 2020 18:14:31 +0000 (11:14 -0700)
committerMarge Bot <eric+marge@anholt.net>
Thu, 23 Apr 2020 16:37:50 +0000 (16:37 +0000)
Back in a2xx, HW pitches were in pixels, so storing that was reasonable.
Ever since then, the HW wants pitches in bytes, and we have only one
instance of using pitch in pixels in the code (a3xx sysmem path).

Flip things around so that only a2xx has to worry about the cpp for
looking at pitches.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4558>

28 files changed:
src/freedreno/fdl/fd6_layout.c
src/freedreno/fdl/fd6_layout_test.c
src/freedreno/fdl/freedreno_layout.c
src/freedreno/fdl/freedreno_layout.h
src/freedreno/vulkan/tu_image.c
src/gallium/drivers/freedreno/a2xx/fd2_gmem.c
src/gallium/drivers/freedreno/a2xx/fd2_resource.c
src/gallium/drivers/freedreno/a2xx/fd2_texture.c
src/gallium/drivers/freedreno/a3xx/fd3_emit.c
src/gallium/drivers/freedreno/a3xx/fd3_format.c
src/gallium/drivers/freedreno/a3xx/fd3_format.h
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_emit.c
src/gallium/drivers/freedreno/a4xx/fd4_gmem.c
src/gallium/drivers/freedreno/a4xx/fd4_texture.c
src/gallium/drivers/freedreno/a5xx/fd5_blitter.c
src/gallium/drivers/freedreno/a5xx/fd5_gmem.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_blitter.c
src/gallium/drivers/freedreno/a6xx/fd6_gmem.c
src/gallium/drivers/freedreno/a6xx/fd6_image.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 0f8f14dfc2dd48cfc2b751878f4955bc773bdd4a..033b5c33f996f70322523e985e0f65850c50a5c1 100644 (file)
@@ -155,12 +155,15 @@ fdl6_layout(struct fdl_layout *layout,
                if (level == mip_levels - 1)
                        height = align(height, 32);
 
-               slice->pitch = util_align_npot(u_minify(pitch0, level),
+               uint32_t pitch_pixels = util_align_npot(u_minify(pitch0, level),
                                fdl6_pitchalign(layout, ta, level));
 
                slice->offset = layout->size;
                uint32_t blocks = util_format_get_nblocks(format,
-                               slice->pitch, height);
+                               pitch_pixels, height);
+
+               slice->pitch = util_format_get_nblocksx(format, pitch_pixels) *
+                       layout->cpp;
 
                /* 1d array and 2d array textures must all have the same layer size
                 * for each miplevel on a6xx. 3d textures can have different layer
index 0f31ebb3ca888ede530e1d619abee01b899cfd30..378e6f10aa9d39af9ac59ef6adc9bab6298e99bf 100644 (file)
@@ -400,12 +400,6 @@ static bool test_layout(const struct testcase *testcase)
                        MAX2(testcase->array_size, 1),
                        testcase->is_3d);
 
-       /* Our pitch values in the testcases[] layouts are in bytes straight out
-        * of the traces, while fdl is in pixels.  Rescale now.
-        */
-       for (int l = 0; l < mip_levels; l++)
-               layout.slices[l].pitch *= layout.cpp;
-
        /* fdl lays out UBWC data before the color data, while all we have
         * recorded in this testcase are the color offsets.  Shift the fdl layout
         * down so we can compare color offsets.
index 0c50608ff156b7530cb31b0b70d630fb3d20efb7..9f8f660b80af726faee84db78c6df543c45c5d3b 100644 (file)
@@ -56,9 +56,9 @@ fdl_dump_layout(struct fdl_layout *layout)
                                u_minify(layout->depth0, level),
                                layout->cpp, layout->nr_samples,
                                level,
-                               slice->pitch * layout->cpp,
+                               slice->pitch,
                                slice->size0, ubwc_slice->size0,
-                               slice->size0 / (slice->pitch * layout->cpp),
+                               slice->size0 / slice->pitch,
                                slice->offset, ubwc_slice->offset,
                                layout->layer_size, layout->ubwc_layer_size,
                                fdl_tile_mode(layout, level));
index aa46859a2c30ef873d4f96d1401ea6e049fffb5c..011cf131dea18dfb2200f4fad5b79ea0ebd25fe5 100644 (file)
@@ -79,7 +79,7 @@
 
 struct fdl_slice {
        uint32_t offset;         /* offset of first layer in slice */
-       uint32_t pitch;
+       uint32_t pitch;          /* pitch in bytes between rows. */
        uint32_t size0;          /* size of first layer in slice */
 };
 
index d6abef7406368dc5a0d2748fe842c1160148bd10..c4ac2f8c83062417fae7ac2ca3c7560c12f681ec 100644 (file)
@@ -282,8 +282,7 @@ tu_image_view_init(struct tu_image_view *iview,
    uint64_t ubwc_addr = image->bo->iova + image->bo_offset +
       fdl_ubwc_offset(layout, range->baseMipLevel, range->baseArrayLayer);
 
-   uint32_t pitch = layout->slices[range->baseMipLevel].pitch * layout->cpp /
-                     util_format_get_blockwidth(layout->format);
+   uint32_t pitch = layout->slices[range->baseMipLevel].pitch;
    uint32_t ubwc_pitch = layout->ubwc_slices[range->baseMipLevel].pitch;
    uint32_t layer_size = fdl_layer_stride(layout, range->baseMipLevel);
 
@@ -513,7 +512,7 @@ tu_GetImageSubresourceLayout(VkDevice _device,
                                         pSubresource->arrayLayer);
    pLayout->size = slice->size0;
    pLayout->rowPitch =
-      slice->pitch * vk_format_get_blocksize(image->vk_format);
+      slice->pitch * vk_format_get_blockheight(image->vk_format);
    pLayout->arrayPitch = image->layout.layer_size;
    pLayout->depthPitch = slice->size0;
 
index 0ba2b4acb45a591ff452cbd5faaeaa760b3fb94b..1d14c66b67e000380b766cdec4add2cf28d643ed 100644 (file)
@@ -93,8 +93,9 @@ emit_gmem2mem_surf(struct fd_batch *batch, uint32_t base,
        uint32_t offset =
                fd_resource_offset(rsc, psurf->u.tex.level, psurf->u.tex.first_layer);
        enum pipe_format format = fd_gmem_restore_format(psurf->format);
+       uint32_t pitch = slice->pitch >> fdl_cpp_shift(&rsc->layout);
 
-       assert((slice->pitch & 31) == 0);
+       assert((pitch & 31) == 0);
        assert((offset & 0xfff) == 0);
 
        if (!rsc->valid)
@@ -109,7 +110,7 @@ emit_gmem2mem_surf(struct fd_batch *batch, uint32_t base,
        OUT_RING(ring, CP_REG(REG_A2XX_RB_COPY_CONTROL));
        OUT_RING(ring, 0x00000000);             /* RB_COPY_CONTROL */
        OUT_RELOCW(ring, rsc->bo, offset, 0, 0);     /* RB_COPY_DEST_BASE */
-       OUT_RING(ring, slice->pitch >> 5); /* RB_COPY_DEST_PITCH */
+       OUT_RING(ring, pitch >> 5); /* RB_COPY_DEST_PITCH */
        OUT_RING(ring,                          /* RB_COPY_DEST_INFO */
                        A2XX_RB_COPY_DEST_INFO_FORMAT(fd2_pipe2color(format)) |
                        COND(!rsc->layout.tile_mode, A2XX_RB_COPY_DEST_INFO_LINEAR) |
@@ -245,7 +246,7 @@ emit_mem2gmem_surf(struct fd_batch *batch, uint32_t base,
        OUT_RING(ring, A2XX_SQ_TEX_0_CLAMP_X(SQ_TEX_WRAP) |
                        A2XX_SQ_TEX_0_CLAMP_Y(SQ_TEX_WRAP) |
                        A2XX_SQ_TEX_0_CLAMP_Z(SQ_TEX_WRAP) |
-                       A2XX_SQ_TEX_0_PITCH(slice->pitch));
+                       A2XX_SQ_TEX_0_PITCH(slice->pitch >> fdl_cpp_shift(&rsc->layout)));
        OUT_RELOC(ring, rsc->bo, offset,
                        A2XX_SQ_TEX_1_FORMAT(fd2_pipe2surface(format).format) |
                        A2XX_SQ_TEX_1_CLAMP_POLICY(SQ_TEX_CLAMP_POLICY_OGL), 0);
@@ -438,15 +439,16 @@ fd2_emit_sysmem_prep(struct fd_batch *batch)
        struct fdl_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);
+       uint32_t pitch = slice->pitch >> fdl_cpp_shift(&rsc->layout);
 
-       assert((slice->pitch & 31) == 0);
+       assert((pitch & 31) == 0);
        assert((offset & 0xfff) == 0);
 
        fd2_emit_restore(ctx, ring);
 
        OUT_PKT3(ring, CP_SET_CONSTANT, 2);
        OUT_RING(ring, CP_REG(REG_A2XX_RB_SURFACE_INFO));
-       OUT_RING(ring, A2XX_RB_SURFACE_INFO_SURFACE_PITCH(slice->pitch));
+       OUT_RING(ring, A2XX_RB_SURFACE_INFO_SURFACE_PITCH(pitch));
 
        OUT_PKT3(ring, CP_SET_CONSTANT, 2);
        OUT_RING(ring, CP_REG(REG_A2XX_RB_COLOR_INFO));
index bccce004a713f422b2ca6336b54b025796e65b0b..1cd3e9da884965b96edb148bbd56cdca202af45f 100644 (file)
@@ -61,7 +61,7 @@ fd2_setup_slices(struct fd_resource *rsc)
                        height = util_next_power_of_two(height);
                }
 
-               slice->pitch = width;
+               slice->pitch = util_format_get_nblocksx(format, width) * rsc->layout.cpp;
                slice->offset = size;
 
                blocks = util_format_get_nblocks(format, width, height);
index 7e25fc368d4627bd3bc696715d4bef379a93603f..938fc6951d8392e0adf2170e5b56e1b96b32cfa2 100644 (file)
@@ -187,7 +187,8 @@ fd2_sampler_view_create(struct pipe_context *pctx, struct pipe_resource *prsc,
                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(slice0->pitch) |
+               A2XX_SQ_TEX_0_PITCH(slice0->pitch >> fdl_cpp_shift(&rsc->layout) *
+                               util_format_get_blockwidth(rsc->layout.format)) |
                COND(rsc->layout.tile_mode, A2XX_SQ_TEX_0_TILED);
        so->tex1 =
                A2XX_SQ_TEX_1_FORMAT(fmt.format) |
index 6509435636c2730c9fcd3d7f9bc8ab44914af8c6..ee75455c2ef4ce60fee17dd0dc0b20d7ba20317b 100644 (file)
@@ -322,7 +322,7 @@ fd3_emit_gmem_restore_tex(struct fd_ringbuffer *ring,
                OUT_RING(ring, A3XX_TEX_CONST_1_FETCHSIZE(TFETCH_DISABLE) |
                                 A3XX_TEX_CONST_1_WIDTH(psurf[i]->width) |
                                 A3XX_TEX_CONST_1_HEIGHT(psurf[i]->height));
-               OUT_RING(ring, A3XX_TEX_CONST_2_PITCH(slice->pitch * rsc->layout.cpp) |
+               OUT_RING(ring, A3XX_TEX_CONST_2_PITCH(slice->pitch) |
                                 A3XX_TEX_CONST_2_INDX(BASETABLE_SZ * i));
                OUT_RING(ring, 0x00000000);
        }
index d5e9b156ade07df8186db4c69d7cd94b06d6119f..d83738a8989b25b6194a57b3aa93d9765a7a619e 100644 (file)
@@ -344,14 +344,6 @@ fd3_pipe2fetchsize(enum pipe_format format)
        }
 }
 
-unsigned
-fd3_pipe2nblocksx(enum pipe_format format, unsigned width)
-{
-       if (util_format_description(format)->layout == UTIL_FORMAT_LAYOUT_RGTC)
-               format = PIPE_FORMAT_R8G8B8A8_UNORM;
-       return util_format_get_nblocksx(format, width);
-}
-
 enum a3xx_color_fmt
 fd3_fs_output_format(enum pipe_format format)
 {
index 48721c6d89153df9c2ac17374e4445a830005688..1e4597242ebee6d2ae0e1e238c0f5cdf930759d4 100644 (file)
@@ -36,7 +36,6 @@ enum a3xx_tex_fetchsize fd3_pipe2fetchsize(enum pipe_format format);
 enum a3xx_color_fmt fd3_pipe2color(enum pipe_format format);
 enum a3xx_color_fmt fd3_fs_output_format(enum pipe_format format);
 enum a3xx_color_swap fd3_pipe2swap(enum pipe_format format);
-unsigned fd3_pipe2nblocksx(enum pipe_format format, unsigned width);
 
 uint32_t fd3_tex_swiz(enum pipe_format format, unsigned swizzle_r,
                unsigned swizzle_g, unsigned swizzle_b, unsigned swizzle_a);
index ff9f4357368527e66483aa24229feed1f8910923..a0fc1d3f96e78a80beaa4f9d8748389488a8bb07 100644 (file)
@@ -100,7 +100,7 @@ emit_mrt(struct fd_ringbuffer *ring, unsigned nr_bufs,
                                        base = bases[i];
                                }
                        } else {
-                               stride = slice->pitch * rsc->layout.cpp;
+                               stride = slice->pitch;
                                tile_mode = rsc->layout.tile_mode;
                        }
                } else if (i < nr_bufs && bases) {
@@ -345,7 +345,7 @@ emit_gmem2mem_surf(struct fd_batch *batch,
                                 A3XX_RB_COPY_CONTROL_DEPTH32_RESOLVE));
 
        OUT_RELOCW(ring, rsc->bo, offset, 0, -1);    /* RB_COPY_DEST_BASE */
-       OUT_RING(ring, A3XX_RB_COPY_DEST_PITCH_PITCH(slice->pitch * rsc->layout.cpp));
+       OUT_RING(ring, A3XX_RB_COPY_DEST_PITCH_PITCH(slice->pitch));
        OUT_RING(ring, A3XX_RB_COPY_DEST_INFO_TILE(rsc->layout.tile_mode) |
                        A3XX_RB_COPY_DEST_INFO_FORMAT(fd3_pipe2color(format)) |
                        A3XX_RB_COPY_DEST_INFO_COMPONENT_ENABLE(0xf) |
@@ -739,10 +739,9 @@ fd3_emit_sysmem_prep(struct fd_batch *batch)
                struct pipe_surface *psurf = pfb->cbufs[i];
                if (!psurf)
                        continue;
-               struct fdl_slice *slice =
-                       fd_resource_slice(fd_resource(psurf->texture),
-                               psurf->u.tex.level);
-               pitch = slice->pitch;
+               struct fd_resource *rsc = fd_resource(psurf->texture);
+               struct fdl_slice *slice = fd_resource_slice(rsc, psurf->u.tex.level);
+               pitch = slice->pitch / rsc->layout.cpp;
        }
 
        fd3_emit_restore(batch, ring);
index 6089ca01e40ede9afd2b637e588708feda2c44c6..0a58c16abc6d04d676253d3ca53cf71b37e89025 100644 (file)
@@ -63,6 +63,8 @@ setup_slices(struct fd_resource *rsc, uint32_t alignment, enum pipe_format forma
                        slice->pitch = width = align(width, pitchalign);
                        blocks = util_format_get_nblocks(format, slice->pitch, height);
                }
+               slice->pitch = util_format_get_nblocksx(format, slice->pitch) *
+                       rsc->layout.cpp;
 
                slice->offset = size;
                /* 1d array and 2d array textures must all have the same layer size
index 50664f1c280388e69490477600fd7a5fc6f9eb89..bd4c57e10ad8e610b0f26bd4674a51c8f3c5d49c 100644 (file)
@@ -265,7 +265,7 @@ fd3_sampler_view_create(struct pipe_context *pctx, struct pipe_resource *prsc,
        /* when emitted, A3XX_TEX_CONST_2_INDX() must be OR'd in: */
        struct fdl_slice *slice = fd_resource_slice(rsc, lvl);
        so->texconst2 =
-                       A3XX_TEX_CONST_2_PITCH(fd3_pipe2nblocksx(cso->format, slice->pitch) * rsc->layout.cpp);
+                       A3XX_TEX_CONST_2_PITCH(slice->pitch);
        switch (prsc->target) {
        case PIPE_TEXTURE_1D_ARRAY:
        case PIPE_TEXTURE_2D_ARRAY:
index 8d07ceff9bbdec1ddbf783be10ef5b48cf636b93..7394993d5a769e74270d9f7c1f78e30cddc380e3 100644 (file)
@@ -323,7 +323,7 @@ fd4_emit_gmem_restore_tex(struct fd_ringbuffer *ring, unsigned nr_bufs,
                                                        PIPE_SWIZZLE_Z, PIPE_SWIZZLE_W));
                        OUT_RING(ring, A4XX_TEX_CONST_1_WIDTH(bufs[i]->width) |
                                        A4XX_TEX_CONST_1_HEIGHT(bufs[i]->height));
-                       OUT_RING(ring, A4XX_TEX_CONST_2_PITCH(slice->pitch * rsc->layout.cpp) |
+                       OUT_RING(ring, A4XX_TEX_CONST_2_PITCH(slice->pitch) |
                                        A4XX_TEX_CONST_2_FETCHSIZE(fd4_pipe2fetchsize(format)));
                        OUT_RING(ring, 0x00000000);
                        OUT_RELOC(ring, rsc->bo, offset, 0, 0);
index 5f565e08d656c3a8f0db7bfd1f7c27b019ae078b..57f23a8304f35d5d71c67c4cb67c004e838c9e75 100644 (file)
@@ -103,7 +103,7 @@ emit_mrt(struct fd_ringbuffer *ring, unsigned nr_bufs,
                                        base = bases[i];
                                }
                        } else {
-                               stride = slice->pitch * rsc->layout.cpp;
+                               stride = slice->pitch;
                        }
                } else if ((i < nr_bufs) && bases) {
                        base = bases[i];
@@ -175,7 +175,7 @@ emit_gmem2mem_surf(struct fd_batch *batch, bool stencil,
                        A4XX_RB_COPY_CONTROL_MODE(RB_COPY_RESOLVE) |
                        A4XX_RB_COPY_CONTROL_GMEM_BASE(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->layout.cpp));
+       OUT_RING(ring, A4XX_RB_COPY_DEST_PITCH_PITCH(slice->pitch));
        OUT_RING(ring, A4XX_RB_COPY_DEST_INFO_TILE(TILE4_LINEAR) |
                        A4XX_RB_COPY_DEST_INFO_FORMAT(fd4_pipe2color(pformat)) |
                        A4XX_RB_COPY_DEST_INFO_COMPONENT_ENABLE(0xf) |
index de4e2d271440f9f0f0431c2011e515f48babf128..a9d7d0d43ebc2da6ddf083dcfaa5b3df3a0f1052 100644 (file)
@@ -277,8 +277,7 @@ fd4_sampler_view_create(struct pipe_context *pctx, struct pipe_resource *prsc,
                        A4XX_TEX_CONST_1_HEIGHT(u_minify(prsc->height0, lvl));
                so->texconst2 =
                        A4XX_TEX_CONST_2_FETCHSIZE(fd4_pipe2fetchsize(format)) |
-                       A4XX_TEX_CONST_2_PITCH(
-                               util_format_get_nblocksx(format, slice->pitch) * rsc->layout.cpp);
+                       A4XX_TEX_CONST_2_PITCH(slice->pitch);
                so->offset = fd_resource_offset(rsc, lvl, cso->u.tex.first_layer);
        }
 
index cffcae86a8b7d87dd9cbd10875a0721cc68c1a0c..bd4c35603f7557c53fd682179703823a8ab63fe7 100644 (file)
@@ -348,8 +348,8 @@ emit_blit(struct fd_ringbuffer *ring, const struct pipe_blit_info *info)
        sswap = fd5_pipe2swap(info->src.format);
        dswap = fd5_pipe2swap(info->dst.format);
 
-       spitch = sslice->pitch * src->layout.cpp;
-       dpitch = dslice->pitch * dst->layout.cpp;
+       spitch = sslice->pitch;
+       dpitch = dslice->pitch;
 
        /* if dtile, then dswap ignored by hw, and likewise if stile then sswap
         * ignored by hw.. but in this case we have already rejected the blit
index eb8b5404e8605fcef61c6e3ba4b1c00d8a109aa4..f087e04cf9b0baaebf1cde757908b7caa2a3a478 100644 (file)
@@ -89,7 +89,7 @@ emit_mrt(struct fd_ringbuffer *ring, unsigned nr_bufs,
                                size = stride * gmem->bin_h;
                                base = gmem->cbuf_base[i];
                        } else {
-                               stride = slice->pitch * rsc->layout.cpp;
+                               stride = slice->pitch;
                                size = slice->size0;
 
                                tile_mode = fd_resource_tile_mode(psurf->texture, psurf->u.tex.level);
@@ -145,7 +145,7 @@ emit_zs(struct fd_ringbuffer *ring, struct pipe_surface *zsbuf,
                        size = stride * gmem->bin_h;
                } else {
                        struct fdl_slice *slice = fd_resource_slice(rsc, 0);
-                       stride = slice->pitch * rsc->layout.cpp;
+                       stride = slice->pitch;
                        size = slice->size0;
                }
 
@@ -192,7 +192,7 @@ emit_zs(struct fd_ringbuffer *ring, struct pipe_surface *zsbuf,
                                size = stride * gmem->bin_h;
                        } else {
                                struct fdl_slice *slice = fd_resource_slice(rsc->stencil, 0);
-                               stride = slice->pitch * rsc->layout.cpp;
+                               stride = slice->pitch;
                                size = slice->size0;
                        }
 
@@ -491,7 +491,7 @@ emit_mem2gmem_surf(struct fd_batch *batch, uint32_t base,
                OUT_RING(ring, A5XX_RB_MRT_BUF_INFO_COLOR_FORMAT(format) |
                                A5XX_RB_MRT_BUF_INFO_COLOR_TILE_MODE(rsc->layout.tile_mode) |
                                A5XX_RB_MRT_BUF_INFO_COLOR_SWAP(WZYX));
-               OUT_RING(ring, A5XX_RB_MRT_PITCH(slice->pitch * rsc->layout.cpp));
+               OUT_RING(ring, A5XX_RB_MRT_PITCH(slice->pitch));
                OUT_RING(ring, A5XX_RB_MRT_ARRAY_PITCH(slice->size0));
                OUT_RELOC(ring, rsc->bo, 0, 0, 0);  /* BASE_LO/HI */
 
@@ -635,7 +635,7 @@ emit_gmem2mem_surf(struct fd_batch *batch, uint32_t base,
        OUT_RING(ring, 0x00000004 |   /* XXX RB_RESOLVE_CNTL_3 */
                        COND(tiled, A5XX_RB_RESOLVE_CNTL_3_TILED));
        OUT_RELOCW(ring, rsc->bo, offset, 0, 0);     /* RB_BLIT_DST_LO/HI */
-       OUT_RING(ring, A5XX_RB_BLIT_DST_PITCH(slice->pitch * rsc->layout.cpp));
+       OUT_RING(ring, A5XX_RB_BLIT_DST_PITCH(slice->pitch));
        OUT_RING(ring, A5XX_RB_BLIT_DST_ARRAY_PITCH(slice->size0));
 
        OUT_PKT4(ring, REG_A5XX_RB_BLIT_CNTL, 1);
index 4da1f16385aa59c34f3ce968f5fafb9614065627..5117527b2b40be7aebf5b032c346ff564cb63119 100644 (file)
@@ -86,7 +86,7 @@ static void translate_image(struct fd5_image *img, struct pipe_image_view *pimg)
                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  = slice->pitch * rsc->layout.cpp;
+               img->pitch  = slice->pitch;
        }
 
        img->width     = u_minify(prsc->width0, lvl);
index 3fe730a99c84f0c9e2bdaeca13f63a15cae850ac..e4420e681516f1e745452f215174baf41b2c4cb5 100644 (file)
@@ -84,14 +84,17 @@ setup_slices(struct fd_resource *rsc, uint32_t alignment, enum pipe_format forma
                                aligned_height = align(aligned_height, 32);
                }
 
+               unsigned pitch_pixels;
                if (layout == UTIL_FORMAT_LAYOUT_ASTC)
-                       slice->pitch =
+                       pitch_pixels =
                                util_align_npot(width, pitchalign * util_format_get_blockwidth(format));
                else
-                       slice->pitch = align(width, pitchalign);
+                       pitch_pixels = align(width, pitchalign);
 
                slice->offset = size;
-               blocks = util_format_get_nblocks(format, slice->pitch, aligned_height);
+               blocks = util_format_get_nblocks(format, pitch_pixels, aligned_height);
+               slice->pitch = util_format_get_nblocksx(format, pitch_pixels) *
+                       rsc->layout.cpp;
 
                /* 1d array and 2d array textures must all have the same layer size
                 * for each miplevel on a3xx. 3d textures can have different layer
index 5ec8e546eca2c1374d09577bd69ec3d4319f4f0e..fdfb2c7d943bf2ed068ec4b228533696df20882c 100644 (file)
@@ -275,8 +275,7 @@ fd5_sampler_view_create(struct pipe_context *pctx, struct pipe_resource *prsc,
                        A5XX_TEX_CONST_1_HEIGHT(u_minify(prsc->height0, lvl));
                so->texconst2 =
                        A5XX_TEX_CONST_2_FETCHSIZE(fd5_pipe2fetchsize(format)) |
-                       A5XX_TEX_CONST_2_PITCH(
-                               util_format_get_nblocksx(format, slice->pitch) * rsc->layout.cpp);
+                       A5XX_TEX_CONST_2_PITCH(slice->pitch);
                so->offset = fd_resource_offset(rsc, lvl, cso->u.tex.first_layer);
        }
 
index d129183bfae5d13390cf85431b273e0b8997fab6..2da8438fbc387d4fc2875c5dd30b284f15c65041 100644 (file)
@@ -339,7 +339,6 @@ emit_blit_or_clear_texture(struct fd_context *ctx, struct fd_ringbuffer *ring,
        enum a6xx_format sfmt, dfmt;
        enum a6xx_tile_mode stile, dtile;
        enum a3xx_color_swap sswap, dswap;
-       unsigned spitch, dpitch;
        int sx1, sy1, sx2, sy2;
        int dx1, dy1, dx2, dy2;
 
@@ -371,12 +370,6 @@ emit_blit_or_clear_texture(struct fd_context *ctx, struct fd_ringbuffer *ring,
        sswap = fd6_resource_swap(src, info->src.format);
        dswap = fd6_resource_swap(dst, info->dst.format);
 
-       /* Use the underlying resource format so that we get the right block width
-        * for compressed textures.
-        */
-       spitch = util_format_get_nblocksx(src->base.format, sslice->pitch) * src->layout.cpp;
-       dpitch = util_format_get_nblocksx(dst->base.format, dslice->pitch) * dst->layout.cpp;
-
        uint32_t nr_samples = fd_resource_nr_samples(&dst->base);
        sx1 = sbox->x * nr_samples;
        sy1 = sbox->y;
@@ -507,7 +500,7 @@ emit_blit_or_clear_texture(struct fd_context *ctx, struct fd_ringbuffer *ring,
                OUT_RING(ring, A6XX_SP_PS_2D_SRC_SIZE_WIDTH(width) |
                                 A6XX_SP_PS_2D_SRC_SIZE_HEIGHT(height)); /* SP_PS_2D_SRC_SIZE */
                OUT_RELOC(ring, src->bo, soff, 0, 0);    /* SP_PS_2D_SRC_LO/HI */
-               OUT_RING(ring, A6XX_SP_PS_2D_SRC_PITCH_PITCH(spitch));
+               OUT_RING(ring, A6XX_SP_PS_2D_SRC_PITCH_PITCH(sslice->pitch));
 
                OUT_RING(ring, 0x00000000);
                OUT_RING(ring, 0x00000000);
@@ -533,7 +526,7 @@ emit_blit_or_clear_texture(struct fd_context *ctx, struct fd_ringbuffer *ring,
                                 COND(util_format_is_srgb(info->dst.format), A6XX_RB_2D_DST_INFO_SRGB) |
                                 COND(dubwc_enabled, A6XX_RB_2D_DST_INFO_FLAGS));
                OUT_RELOCW(ring, dst->bo, doff, 0, 0);    /* RB_2D_DST_LO/HI */
-               OUT_RING(ring, A6XX_RB_2D_DST_SIZE_PITCH(dpitch));
+               OUT_RING(ring, A6XX_RB_2D_DST_SIZE_PITCH(dslice->pitch));
                OUT_RING(ring, 0x00000000);
                OUT_RING(ring, 0x00000000);
                OUT_RING(ring, 0x00000000);
index b42287486a8354bfcb74e7826363ae1e75d0315a..0ce85ea380cd5939a23fd83a8088cd21fb29a32f 100644 (file)
@@ -112,7 +112,7 @@ emit_mrt(struct fd_ringbuffer *ring, struct pipe_framebuffer_state *pfb,
                offset = fd_resource_offset(rsc, psurf->u.tex.level,
                                psurf->u.tex.first_layer);
 
-               stride = slice->pitch * rsc->layout.cpp;
+               stride = slice->pitch;
                swap = fd6_resource_swap(rsc, pformat);
 
                tile_mode = fd_resource_tile_mode(psurf->texture, psurf->u.tex.level);
@@ -173,7 +173,7 @@ emit_zs(struct fd_ringbuffer *ring, struct pipe_surface *zsbuf,
                struct fd_resource *rsc = fd_resource(zsbuf->texture);
                enum a6xx_depth_format fmt = fd6_pipe2depth(zsbuf->format);
                struct fdl_slice *slice = fd_resource_slice(rsc, 0);
-               uint32_t stride = slice->pitch * rsc->layout.cpp;
+               uint32_t stride = slice->pitch;
                uint32_t size = slice->size0;
                uint32_t base = gmem ? gmem->zsbuf_base[0] : 0;
                uint32_t offset = fd_resource_offset(rsc, zsbuf->u.tex.level,
@@ -216,7 +216,7 @@ emit_zs(struct fd_ringbuffer *ring, struct pipe_surface *zsbuf,
 
                if (rsc->stencil) {
                        struct fdl_slice *slice = fd_resource_slice(rsc->stencil, 0);
-                       stride = slice->pitch * rsc->stencil->layout.cpp;
+                       stride = slice->pitch;
                        size = slice->size0;
                        uint32_t base = gmem ? gmem->zsbuf_base[1] : 0;
 
@@ -949,7 +949,7 @@ emit_blit(struct fd_batch *batch,
        debug_assert(psurf->u.tex.first_layer == psurf->u.tex.last_layer);
 
        enum a6xx_format format = fd6_pipe2color(pfmt);
-       uint32_t stride = slice->pitch * rsc->layout.cpp;
+       uint32_t stride = slice->pitch;
        uint32_t size = slice->size0;
        enum a3xx_color_swap swap = fd6_resource_swap(rsc, pfmt);
        enum a3xx_msaa_samples samples =
index 6ac3cc5c4c9dc111b5a6c706d8b39e7bffad632e..0de77381d07450ea1a5faf936e417b5c2b5ea493 100644 (file)
@@ -102,7 +102,7 @@ static void translate_image(struct fd6_image *img, const struct pipe_image_view
 
                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  = slice->pitch * rsc->layout.cpp;
+               img->pitch  = slice->pitch;
 
                switch (prsc->target) {
                case PIPE_TEXTURE_RECT:
index e0883815ca989c3bfbcb94629ce2cba79903ac43..5fa64e1da49b675f7b8ff2aa2cba091a3b8d85d5 100644 (file)
@@ -266,8 +266,7 @@ fd6_sampler_view_create(struct pipe_context *pctx, struct pipe_resource *prsc,
                        A6XX_TEX_CONST_1_HEIGHT(u_minify(prsc->height0, lvl));
                so->texconst2 =
                        A6XX_TEX_CONST_2_FETCHSIZE(fd6_pipe2fetchsize(format)) |
-                       A6XX_TEX_CONST_2_PITCH(
-                               util_format_get_nblocksx(format, slice->pitch) * rsc->layout.cpp);
+                       A6XX_TEX_CONST_2_PITCH(slice->pitch);
                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);
index 7c61fb72911f75dea10a0c56a49a5523157ba0a0..04e0553f670bc2728d7555c4ee1971ff0dbc257f 100644 (file)
@@ -542,7 +542,7 @@ fd_resource_transfer_map(struct pipe_context *pctx,
        ptrans->level = level;
        ptrans->usage = usage;
        ptrans->box = *box;
-       ptrans->stride = util_format_get_nblocksx(format, slice->pitch) * rsc->layout.cpp;
+       ptrans->stride = slice->pitch;
        ptrans->layer_stride = fd_resource_layer_stride(rsc, level);
 
        /* we always need a staging texture for tiled buffers:
@@ -560,8 +560,7 @@ fd_resource_transfer_map(struct pipe_context *pctx,
                                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_slice->pitch) * staging_rsc->layout.cpp;
+                       trans->base.stride = staging_slice->pitch;
                        trans->base.layer_stride = fd_resource_layer_stride(staging_rsc, 0);
                        trans->staging_box = *box;
                        trans->staging_box.x = 0;
@@ -661,8 +660,7 @@ fd_resource_transfer_map(struct pipe_context *pctx,
                                        struct fdl_slice *staging_slice =
                                                fd_resource_slice(staging_rsc, 0);
                                        trans->staging_prsc = &staging_rsc->base;
-                                       trans->base.stride = util_format_get_nblocksx(format,
-                                               staging_slice->pitch) * staging_rsc->layout.cpp;
+                                       trans->base.stride = staging_slice->pitch;
                                        trans->base.layer_stride =
                                                fd_resource_layer_stride(staging_rsc, 0);
                                        trans->staging_box = *box;
@@ -759,7 +757,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,
-                       fd_resource_slice(rsc, 0)->pitch * rsc->layout.cpp, handle);
+                       fd_resource_slice(rsc, 0)->pitch, handle);
 }
 
 static uint32_t
@@ -783,10 +781,10 @@ setup_slices(struct fd_resource *rsc, uint32_t alignment, enum pipe_format forma
                uint32_t blocks;
 
                if (layout == UTIL_FORMAT_LAYOUT_ASTC)
-                       slice->pitch = width =
-                               util_align_npot(width, pitchalign * util_format_get_blockwidth(format));
+                       width = util_align_npot(width, pitchalign * util_format_get_blockwidth(format));
                else
-                       slice->pitch = width = align(width, pitchalign);
+                       width = align(width, pitchalign);
+               slice->pitch = util_format_get_nblocksx(format, width) * rsc->layout.cpp;
                slice->offset = size;
                blocks = util_format_get_nblocks(format, width, height);
                /* 1d array and 2d array textures must all have the same layer size
@@ -1051,7 +1049,7 @@ fd_resource_from_handle(struct pipe_screen *pscreen,
        struct fd_resource *rsc = CALLOC_STRUCT(fd_resource);
        struct fdl_slice *slice = fd_resource_slice(rsc, 0);
        struct pipe_resource *prsc = &rsc->base;
-       uint32_t pitchalign = fd_screen(pscreen)->gmem_alignw;
+       uint32_t pitchalign = fd_screen(pscreen)->gmem_alignw * rsc->layout.cpp;
 
        DBG("target=%d, format=%s, %ux%ux%u, array_size=%u, last_level=%u, "
                        "nr_samples=%u, usage=%u, bind=%x, flags=%x",
@@ -1077,11 +1075,11 @@ fd_resource_from_handle(struct pipe_screen *pscreen,
                goto fail;
 
        rsc->internal_format = tmpl->format;
-       slice->pitch = handle->stride / rsc->layout.cpp;
+       slice->pitch = handle->stride;
        slice->offset = handle->offset;
        slice->size0 = handle->stride * prsc->height0;
 
-       if ((slice->pitch < align(prsc->width0, pitchalign)) ||
+       if ((slice->pitch < align(prsc->width0 * rsc->layout.cpp, pitchalign)) ||
                        (slice->pitch & (pitchalign - 1)))
                goto fail;
 
index 158869a610133a6a142a4ee5edbf75dffaea5d34..04474097f552fc6079bb05279003cb63bd424625 100644 (file)
@@ -369,7 +369,7 @@ ir3_emit_image_dims(struct fd_screen *screen, const struct ir3_shader_variant *v
                                 * be the same, so use original dimensions for y and z
                                 * stride:
                                 */
-                               dims[off + 1] = slice->pitch * rsc->layout.cpp;
+                               dims[off + 1] = slice->pitch;
                                /* see corresponding logic in fd_resource_offset(): */
                                if (rsc->layout.layer_first) {
                                        dims[off + 2] = rsc->layout.layer_size;