freedreno/a6xx: Clean up mixed use of swap and swizzle for texture state
authorKristian H. Kristensen <hoegsberg@chromium.org>
Mon, 11 Feb 2019 23:09:21 +0000 (15:09 -0800)
committerKristian H. Kristensen <hoegsberg@chromium.org>
Wed, 13 Feb 2019 19:03:29 +0000 (11:03 -0800)
Signed-off-by: Kristian H. Kristensen <hoegsberg@chromium.org>
src/gallium/drivers/freedreno/a6xx/fd6_format.c
src/gallium/drivers/freedreno/a6xx/fd6_texture.c

index 35186f020db72fe925eb79f54754008f825abe62..6f2ee6ab68ac4c1c223b5f8b2b629a917d684feb 100644 (file)
@@ -441,32 +441,38 @@ fd6_tex_swiz(struct pipe_resource *prsc, enum pipe_format format,
 {
        const struct util_format_description *desc =
                        util_format_description(format);
-       unsigned char swiz[4] = {
-                       swizzle_r, swizzle_g, swizzle_b, swizzle_a,
-       }, rswiz[4], *swizp;
 
-       util_format_compose_swizzles(desc->swizzle, swiz, rswiz);
+       uint32_t swap = fd6_pipe2swap(format);
+       unsigned char swiz[4];
+       char uswiz[4] = { swizzle_r, swizzle_g, swizzle_b, swizzle_a };
 
-       if (fd_resource(prsc)->tile_mode) {
-               /* for tiled modes, we don't get SWAP, so manually apply that
-                * extra step of swizzle:
-                */
-               enum a3xx_color_swap swap = fd6_pipe2swap(format);
-               unsigned char swapswiz[][4] = {
-                               [WZYX] = { 0, 1, 2, 3 },
-                               [WXYZ] = { 2, 1, 0, 3 },
-                               [ZYXW] = { 3, 0, 1, 2 },
-                               [XYZW] = { 3, 2, 1, 0 },
+       /* Gallium expects stencil sampler to return (s,s,s,s), so massage
+        * the swizzle to do so.
+        */
+       if ((format == PIPE_FORMAT_X24S8_UINT)) {
+               char stencil_swiz[4] = {
+                       PIPE_SWIZZLE_X, PIPE_SWIZZLE_X, PIPE_SWIZZLE_X, PIPE_SWIZZLE_X
                };
-
-               util_format_compose_swizzles(swapswiz[swap], rswiz, swiz);
-               swizp = swiz;
+               util_format_compose_swizzles(stencil_swiz, uswiz, swiz);
+       } else if (swap != WZYX) {
+               /* Formats with a non-pass-through swap are permutations of RGBA
+                * formats. We program the permutation using the swap and don't
+                * need to compose the format swizzle with the user swizzle.
+                */
+               memcpy(swiz, uswiz, sizeof(swiz));
        } else {
-               swizp = rswiz;
+               /* Otherwise, it's an unswapped RGBA format or a format like L8 where
+                * we need the XXX1 swizzle from the gallium format description.
+                */
+               util_format_compose_swizzles(desc->swizzle, uswiz, swiz);
        }
 
-       return A6XX_TEX_CONST_0_SWIZ_X(fd6_pipe2swiz(swizp[0])) |
-                       A6XX_TEX_CONST_0_SWIZ_Y(fd6_pipe2swiz(swizp[1])) |
-                       A6XX_TEX_CONST_0_SWIZ_Z(fd6_pipe2swiz(swizp[2])) |
-                       A6XX_TEX_CONST_0_SWIZ_W(fd6_pipe2swiz(swizp[3]));
+       swap = fd_resource(prsc)->tile_mode ? WZYX : fd6_pipe2swap(format);
+
+       return
+               A6XX_TEX_CONST_0_SWAP(swap) |
+               A6XX_TEX_CONST_0_SWIZ_X(fd6_pipe2swiz(swiz[0])) |
+               A6XX_TEX_CONST_0_SWIZ_Y(fd6_pipe2swiz(swiz[1])) |
+               A6XX_TEX_CONST_0_SWIZ_Z(fd6_pipe2swiz(swiz[2])) |
+               A6XX_TEX_CONST_0_SWIZ_W(fd6_pipe2swiz(swiz[3]));
 }
index 0e2d9ee65d84d3eb2c28185f32745d95c7d81f26..cc86525ec639c22113164ab7455d09d1a4db3f29 100644 (file)
@@ -249,23 +249,6 @@ fd6_sampler_view_create(struct pipe_context *pctx, struct pipe_resource *prsc,
                fd6_tex_swiz(prsc, cso->format, cso->swizzle_r, cso->swizzle_g,
                                cso->swizzle_b, cso->swizzle_a);
 
-       /* NOTE: since we sample z24s8 using 8888_UINT format, the swizzle
-        * we get isn't quite right.  Use SWAP(XYZW) as a cheap and cheerful
-        * way to re-arrange things so stencil component is where the swiz
-        * expects.
-        *
-        * Note that gallium expects stencil sampler to return (s,s,s,s)
-        * which isn't quite true.  To make that happen we'd have to massage
-        * the swizzle.  But in practice only the .x component is used.
-        *
-        * Skip this in the tile case because tiled formats are not swapped
-        * and we have already applied the inverse swap in fd6_tex_swiz()
-        * to componsate for that.
-        */
-       if ((format == PIPE_FORMAT_X24S8_UINT) && !rsc->tile_mode) {
-               so->texconst0 |= A6XX_TEX_CONST_0_SWAP(XYZW);
-       }
-
        if (util_format_is_srgb(format)) {
                if (use_astc_srgb_workaround(pctx, format))
                        so->astc_srgb = true;