aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlyssa Rosenzweig <[email protected]>2019-07-05 06:26:48 -0700
committerAlyssa Rosenzweig <[email protected]>2019-07-10 06:12:09 -0700
commitced132d2038efdb40ef42e9467956166ac6331c5 (patch)
treed5fb7eb4dcaaff60d183f76c0f84c68880318258 /src
parentda5382c0d87990c51b947bcc6035564e96a6a364 (diff)
panfrost/mfbd: Cleanup format code selection
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 <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/gallium/drivers/panfrost/pan_blending.c5
-rw-r--r--src/gallium/drivers/panfrost/pan_mfbd.c162
2 files changed, 95 insertions, 72 deletions
diff --git a/src/gallium/drivers/panfrost/pan_blending.c b/src/gallium/drivers/panfrost/pan_blending.c
index 3acda3101c3..9e38b1c56f6 100644
--- a/src/gallium/drivers/panfrost/pan_blending.c
+++ b/src/gallium/drivers/panfrost/pan_blending.c
@@ -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;
diff --git a/src/gallium/drivers/panfrost/pan_mfbd.c b/src/gallium/drivers/panfrost/pan_mfbd.c
index 9515b616314..99fa3331ccd 100644
--- a/src/gallium/drivers/panfrost/pan_mfbd.c
+++ b/src/gallium/drivers/panfrost/pan_mfbd.c
@@ -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;