panfrost/mfbd: Cleanup format code selection
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Fri, 5 Jul 2019 13:26:48 +0000 (06:26 -0700)
committerAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Wed, 10 Jul 2019 13:12:09 +0000 (06:12 -0700)
Rather than have random variables flying around and a long if-else
chain, use a switch. They're literally *designed* for this.

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
src/gallium/drivers/panfrost/pan_blending.c
src/gallium/drivers/panfrost/pan_mfbd.c

index 3acda3101c3f65333933b1544d9517cd70afcbd6..9e38b1c56f69da4b58d10de8646ae061acbda0a8 100644 (file)
@@ -122,6 +122,11 @@ panfrost_can_fixed_blend(enum pipe_format format)
                 case PIPE_FORMAT_B10G10R10A2_UNORM:
                 case PIPE_FORMAT_R10G10B10X2_UNORM:
                 case PIPE_FORMAT_B10G10R10X2_UNORM:
+                case PIPE_FORMAT_B4G4R4A4_UNORM:
+                case PIPE_FORMAT_B4G4R4X4_UNORM:
+                case PIPE_FORMAT_A4R4_UNORM:
+                case PIPE_FORMAT_R4A4_UNORM:
+                case PIPE_FORMAT_A4B4G4R4_UNORM:
                         return true;
                 default:
                         return false;
index 9515b6163147e9e67dd2cd09f7ce90907e0d6ab0..99fa3331ccde8217eb1b13bd0104c76d25cb0efd 100644 (file)
@@ -79,79 +79,97 @@ panfrost_mfbd_format(struct pipe_surface *surf)
         if (desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB)
                 fmt.flags |= MALI_MFBD_FORMAT_SRGB;
 
-        /* Set flags for alternative formats */
+        /* sRGB handled as a dedicated flag */
+        enum pipe_format linearized = util_format_linear(surf->format);
+
+        /* If RGB, we're good to go */
+        if (util_format_is_unorm8(desc))
+                return fmt;
 
-        bool float_16 =
-                surf->format == PIPE_FORMAT_R16_FLOAT ||
-                surf->format == PIPE_FORMAT_R16_UINT ||
-                surf->format == PIPE_FORMAT_R16_SINT ||
-                surf->format == PIPE_FORMAT_B5G5R5A1_UNORM;
-
-        bool float_32 =
-                surf->format == PIPE_FORMAT_R11G11B10_FLOAT ||
-                surf->format == PIPE_FORMAT_R16G16_FLOAT ||
-                surf->format == PIPE_FORMAT_R16G16_UINT ||
-                surf->format == PIPE_FORMAT_R16G16_SINT ||
-                surf->format == PIPE_FORMAT_R32_FLOAT ||
-                surf->format == PIPE_FORMAT_R32_UINT ||
-                surf->format == PIPE_FORMAT_R32_SINT ||
-                surf->format == PIPE_FORMAT_R10G10B10A2_UINT;
-
-        bool rgb10_unorm =
-                surf->format == PIPE_FORMAT_R10G10B10A2_UNORM ||
-                surf->format == PIPE_FORMAT_B10G10R10A2_UNORM ||
-                surf->format == PIPE_FORMAT_R10G10B10X2_UNORM ||
-                surf->format == PIPE_FORMAT_B10G10R10X2_UNORM;
-
-        bool float_64 =
-                surf->format == PIPE_FORMAT_R32G32_FLOAT ||
-                surf->format == PIPE_FORMAT_R32G32_SINT ||
-                surf->format == PIPE_FORMAT_R32G32_UINT ||
-                surf->format == PIPE_FORMAT_R16G16B16A16_FLOAT ||
-                surf->format == PIPE_FORMAT_R16G16B16A16_SINT ||
-                surf->format == PIPE_FORMAT_R16G16B16A16_UINT;
-
-        bool float_128 =
-                surf->format == PIPE_FORMAT_R32G32B32A32_FLOAT ||
-                surf->format == PIPE_FORMAT_R32G32B32A32_SINT ||
-                surf->format == PIPE_FORMAT_R32G32B32A32_UINT;
-
-        if (surf->format == PIPE_FORMAT_B5G6R5_UNORM) {
-                fmt.unk1 = 0x14000000;
-                fmt.nr_channels = MALI_POSITIVE(2);
-                fmt.unk3 |= 0x1;
-        } else if (surf->format == PIPE_FORMAT_B4G4R4A4_UNORM) {
-                /* XXX: why does the specialized code not work but the generic
-                 * 16-bit code work? */
-#if 0
-                fmt.unk1 = 0x10000000;
-                fmt.unk3 = 0x5;
-                fmt.nr_channels = MALI_POSITIVE(1);
-#endif
-
-                fmt.unk1 = 0x84000000;
-                fmt.unk3 = 0x0;
-                fmt.nr_channels = MALI_POSITIVE(2);
-        } else if (rgb10_unorm) {
-                fmt.unk1 = 0x08000000;
-                fmt.unk3 = 0x6;
-                fmt.nr_channels = MALI_POSITIVE(1);
-        } else if (float_32) {
-                fmt.unk1 = 0x88000000;
-                fmt.unk3 = 0x0;
-                fmt.nr_channels = MALI_POSITIVE(4);
-        } else if (float_16) {
-                fmt.unk1 = 0x84000000;
-                fmt.unk3 = 0x0;
-                fmt.nr_channels = MALI_POSITIVE(2);
-        } else if (float_64) {
-                fmt.unk1 = 0x8c000000;
-                fmt.unk3 = 0x1;
-                fmt.nr_channels = MALI_POSITIVE(2);
-        } else if (float_128) {
-                fmt.unk1 = 0x90000000;
-                fmt.unk3 = 0x1;
-                fmt.nr_channels = MALI_POSITIVE(4);
+        /* Set flags for alternative formats */
+             
+        switch (linearized) {
+                case PIPE_FORMAT_B5G6R5_UNORM:
+                        fmt.unk1 = 0x14000000;
+                        fmt.nr_channels = MALI_POSITIVE(2);
+                        fmt.unk3 |= 0x1;
+                        break;
+
+                case PIPE_FORMAT_A4B4G4R4_UNORM:
+                case PIPE_FORMAT_B4G4R4A4_UNORM:
+                        fmt.unk1 = 0x10000000;
+                        fmt.unk3 = 0x5;
+                        fmt.nr_channels = MALI_POSITIVE(1);
+                        break;
+
+                case PIPE_FORMAT_R10G10B10A2_UNORM:
+                case PIPE_FORMAT_B10G10R10A2_UNORM:
+                case PIPE_FORMAT_R10G10B10X2_UNORM:
+                case PIPE_FORMAT_B10G10R10X2_UNORM:
+                        fmt.unk1 = 0x08000000;
+                        fmt.unk3 = 0x6;
+                        fmt.nr_channels = MALI_POSITIVE(1);
+                        break;
+
+                        /* Generic 8-bit */
+                case PIPE_FORMAT_R8_UINT:
+                case PIPE_FORMAT_R8_SINT:
+                        fmt.unk1 = 0x80000000;
+                        fmt.unk3 = 0x0;
+                        fmt.nr_channels = MALI_POSITIVE(1);
+                        break;
+
+                        /* Generic 32-bit */
+                case PIPE_FORMAT_R11G11B10_FLOAT:
+                case PIPE_FORMAT_R8G8B8A8_UINT:
+                case PIPE_FORMAT_R8G8B8A8_SINT:
+                case PIPE_FORMAT_R16G16_FLOAT:
+                case PIPE_FORMAT_R16G16_UINT:
+                case PIPE_FORMAT_R16G16_SINT:
+                case PIPE_FORMAT_R32_FLOAT:
+                case PIPE_FORMAT_R32_UINT:
+                case PIPE_FORMAT_R32_SINT:
+                case PIPE_FORMAT_R10G10B10A2_UINT:
+                        fmt.unk1 = 0x88000000;
+                        fmt.unk3 = 0x0;
+                        fmt.nr_channels = MALI_POSITIVE(4);
+                        break;
+
+                        /* Generic 16-bit */
+                case PIPE_FORMAT_R8G8_UINT:
+                case PIPE_FORMAT_R8G8_SINT:
+                case PIPE_FORMAT_R16_FLOAT:
+                case PIPE_FORMAT_R16_UINT:
+                case PIPE_FORMAT_R16_SINT:
+                case PIPE_FORMAT_B5G5R5A1_UNORM:
+                        fmt.unk1 = 0x84000000;
+                        fmt.unk3 = 0x0;
+                        fmt.nr_channels = MALI_POSITIVE(2);
+                        break;
+
+                        /* Generic 64-bit */
+                case PIPE_FORMAT_R32G32_FLOAT:
+                case PIPE_FORMAT_R32G32_SINT:
+                case PIPE_FORMAT_R32G32_UINT:
+                case PIPE_FORMAT_R16G16B16A16_FLOAT:
+                case PIPE_FORMAT_R16G16B16A16_SINT:
+                case PIPE_FORMAT_R16G16B16A16_UINT:
+                        fmt.unk1 = 0x8c000000;
+                        fmt.unk3 = 0x1;
+                        fmt.nr_channels = MALI_POSITIVE(2);
+                        break;
+
+                        /* Generic 128-bit */
+                case PIPE_FORMAT_R32G32B32A32_FLOAT:
+                case PIPE_FORMAT_R32G32B32A32_SINT:
+                case PIPE_FORMAT_R32G32B32A32_UINT:
+                        fmt.unk1 = 0x90000000;
+                        fmt.unk3 = 0x1;
+                        fmt.nr_channels = MALI_POSITIVE(4);
+                        break;
+
+                default:
+                        unreachable("Invalid format rendering");
         }
 
         return fmt;