radeonsi: move translate_colorswap to common code
authorMarek Olšák <marek.olsak@amd.com>
Sun, 23 Feb 2014 17:44:46 +0000 (18:44 +0100)
committerMarek Olšák <marek.olsak@amd.com>
Tue, 4 Mar 2014 11:26:16 +0000 (12:26 +0100)
Also translate the Y__X swizzle.

Cc: mesa-stable@lists.freedesktop.org
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
src/gallium/drivers/radeon/r600_pipe_common.h
src/gallium/drivers/radeon/r600_texture.c
src/gallium/drivers/radeon/r600d_common.h
src/gallium/drivers/radeonsi/si_state.c

index 692de5ee6a475323bc803663715f56055c21926e..cf5aa08cad2e31e28c4ee1cf665595a799b4bc84 100644 (file)
@@ -420,6 +420,7 @@ struct pipe_surface *r600_create_surface_custom(struct pipe_context *pipe,
                                                struct pipe_resource *texture,
                                                const struct pipe_surface *templ,
                                                unsigned width, unsigned height);
+unsigned r600_translate_colorswap(enum pipe_format format);
 void r600_init_screen_texture_functions(struct r600_common_screen *rscreen);
 void r600_init_context_texture_functions(struct r600_common_context *rctx);
 
index 35ad97bd14163e74b5d22cd394b06cfa175493c3..81f32c0f4f3410cc53f084f46d5c5542991374fe 100644 (file)
@@ -1120,6 +1120,60 @@ static void r600_surface_destroy(struct pipe_context *pipe,
        FREE(surface);
 }
 
+unsigned r600_translate_colorswap(enum pipe_format format)
+{
+       const struct util_format_description *desc = util_format_description(format);
+
+#define HAS_SWIZZLE(chan,swz) (desc->swizzle[chan] == UTIL_FORMAT_SWIZZLE_##swz)
+
+       if (format == PIPE_FORMAT_R11G11B10_FLOAT) /* isn't plain */
+               return V_0280A0_SWAP_STD;
+
+       if (desc->layout != UTIL_FORMAT_LAYOUT_PLAIN)
+               return ~0U;
+
+       switch (desc->nr_channels) {
+       case 1:
+               if (HAS_SWIZZLE(0,X))
+                       return V_0280A0_SWAP_STD; /* X___ */
+               else if (HAS_SWIZZLE(3,X))
+                       return V_0280A0_SWAP_ALT_REV; /* ___X */
+               break;
+       case 2:
+               if ((HAS_SWIZZLE(0,X) && HAS_SWIZZLE(1,Y)) ||
+                   (HAS_SWIZZLE(0,X) && HAS_SWIZZLE(1,NONE)) ||
+                   (HAS_SWIZZLE(0,NONE) && HAS_SWIZZLE(1,Y)))
+                       return V_0280A0_SWAP_STD; /* XY__ */
+               else if ((HAS_SWIZZLE(0,Y) && HAS_SWIZZLE(1,X)) ||
+                        (HAS_SWIZZLE(0,Y) && HAS_SWIZZLE(1,NONE)) ||
+                        (HAS_SWIZZLE(0,NONE) && HAS_SWIZZLE(1,X)))
+                       return V_0280A0_SWAP_STD_REV; /* YX__ */
+               else if (HAS_SWIZZLE(0,X) && HAS_SWIZZLE(3,Y))
+                       return V_0280A0_SWAP_ALT; /* X__Y */
+               else if (HAS_SWIZZLE(0,Y) && HAS_SWIZZLE(3,X))
+                       return V_0280A0_SWAP_ALT_REV; /* Y__X */
+               break;
+       case 3:
+               if (HAS_SWIZZLE(0,X))
+                       return V_0280A0_SWAP_STD; /* XYZ */
+               else if (HAS_SWIZZLE(0,Z))
+                       return V_0280A0_SWAP_STD_REV; /* ZYX */
+               break;
+       case 4:
+               /* check the middle channels, the 1st and 4th channel can be NONE */
+               if (HAS_SWIZZLE(1,Y) && HAS_SWIZZLE(2,Z))
+                       return V_0280A0_SWAP_STD; /* XYZW */
+               else if (HAS_SWIZZLE(1,Z) && HAS_SWIZZLE(2,Y))
+                       return V_0280A0_SWAP_STD_REV; /* WZYX */
+               else if (HAS_SWIZZLE(1,Y) && HAS_SWIZZLE(2,X))
+                       return V_0280A0_SWAP_ALT; /* ZYXW */
+               else if (HAS_SWIZZLE(1,X) && HAS_SWIZZLE(2,Y))
+                       return V_0280A0_SWAP_ALT_REV; /* WXYZ */
+               break;
+       }
+       return ~0U;
+}
+
 void r600_init_screen_texture_functions(struct r600_common_screen *rscreen)
 {
        rscreen->b.resource_from_handle = r600_texture_from_handle;
index 357d26f4eb819da3880b9a442f75cfb15b829c43..0b97d324326b289dd99326760455ceba8fdf25a2 100644 (file)
 #define   C_028B20_BUFFER_3_EN                         0xFFFFFFF7
 #define R_028AD0_VGT_STRMOUT_BUFFER_SIZE_0                              0x028AD0
 
+#define     V_0280A0_SWAP_STD                          0x00000000
+#define     V_0280A0_SWAP_ALT                          0x00000001
+#define     V_0280A0_SWAP_STD_REV                      0x00000002
+#define     V_0280A0_SWAP_ALT_REV                      0x00000003
+
 /* EG+ */
 #define R_0084FC_CP_STRMOUT_CNTL                    0x0084FC
 #define   S_0084FC_OFFSET_UPDATE_DONE(x)               (((x) & 0x1) << 0)
index 00b0e64e33d7bedfef72004d4f555c832a713815..225753db9e6d1b7d85a62499a2d6f621e4e0fead 100644 (file)
@@ -905,58 +905,6 @@ static uint32_t si_translate_colorformat(enum pipe_format format)
        return V_028C70_COLOR_INVALID;
 }
 
-static uint32_t si_translate_colorswap(enum pipe_format format)
-{
-       const struct util_format_description *desc = util_format_description(format);
-
-#define HAS_SWIZZLE(chan,swz) (desc->swizzle[chan] == UTIL_FORMAT_SWIZZLE_##swz)
-
-       if (format == PIPE_FORMAT_R11G11B10_FLOAT) /* isn't plain */
-               return V_028C70_SWAP_STD;
-
-       if (desc->layout != UTIL_FORMAT_LAYOUT_PLAIN)
-               return ~0;
-
-       switch (desc->nr_channels) {
-       case 1:
-               if (HAS_SWIZZLE(0,X))
-                       return V_028C70_SWAP_STD; /* X___ */
-               else if (HAS_SWIZZLE(3,X))
-                       return V_028C70_SWAP_ALT_REV; /* ___X */
-               break;
-       case 2:
-               if ((HAS_SWIZZLE(0,X) && HAS_SWIZZLE(1,Y)) ||
-                   (HAS_SWIZZLE(0,X) && HAS_SWIZZLE(1,NONE)) ||
-                   (HAS_SWIZZLE(0,NONE) && HAS_SWIZZLE(1,Y)))
-                       return V_028C70_SWAP_STD; /* XY__ */
-               else if ((HAS_SWIZZLE(0,Y) && HAS_SWIZZLE(1,X)) ||
-                        (HAS_SWIZZLE(0,Y) && HAS_SWIZZLE(1,NONE)) ||
-                        (HAS_SWIZZLE(0,NONE) && HAS_SWIZZLE(1,X)))
-                       return V_028C70_SWAP_STD_REV; /* YX__ */
-               else if (HAS_SWIZZLE(0,X) && HAS_SWIZZLE(3,Y))
-                       return V_028C70_SWAP_ALT; /* X__Y */
-               break;
-       case 3:
-               if (HAS_SWIZZLE(0,X))
-                       return V_028C70_SWAP_STD; /* XYZ */
-               else if (HAS_SWIZZLE(0,Z))
-                       return V_028C70_SWAP_STD_REV; /* ZYX */
-               break;
-       case 4:
-               /* check the middle channels, the 1st and 4th channel can be NONE */
-               if (HAS_SWIZZLE(1,Y) && HAS_SWIZZLE(2,Z))
-                       return V_028C70_SWAP_STD; /* XYZW */
-               else if (HAS_SWIZZLE(1,Z) && HAS_SWIZZLE(2,Y))
-                       return V_028C70_SWAP_STD_REV; /* WZYX */
-               else if (HAS_SWIZZLE(1,Y) && HAS_SWIZZLE(2,X))
-                       return V_028C70_SWAP_ALT; /* ZYXW */
-               else if (HAS_SWIZZLE(1,X) && HAS_SWIZZLE(2,Y))
-                       return V_028C70_SWAP_ALT_REV; /* WXYZ */
-               break;
-       }
-       return ~0U;
-}
-
 static uint32_t si_colorformat_endian_swap(uint32_t colorformat)
 {
        if (SI_BIG_ENDIAN) {
@@ -1473,7 +1421,7 @@ static bool si_is_vertex_format_supported(struct pipe_screen *screen, enum pipe_
 static bool si_is_colorbuffer_format_supported(enum pipe_format format)
 {
        return si_translate_colorformat(format) != V_028C70_COLOR_INVALID &&
-               si_translate_colorswap(format) != ~0U;
+               r600_translate_colorswap(format) != ~0U;
 }
 
 static bool si_is_zs_format_supported(enum pipe_format format)
@@ -1641,7 +1589,7 @@ static void si_initialize_color_surface(struct si_context *sctx,
                R600_ERR("Invalid CB format: %d, disabling CB.\n", surf->base.format);
        }
        assert(format != V_028C70_COLOR_INVALID);
-       swap = si_translate_colorswap(surf->base.format);
+       swap = r600_translate_colorswap(surf->base.format);
        if (rtex->resource.b.b.usage == PIPE_USAGE_STAGING) {
                endian = V_028C70_ENDIAN_NONE;
        } else {