panfrost: Simplify swizzle translation
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Fri, 14 Feb 2020 12:49:25 +0000 (07:49 -0500)
committerMarge Bot <eric+marge@anholt.net>
Fri, 14 Feb 2020 12:53:36 +0000 (12:53 +0000)
It lines up anyway, and Gallium shouldn't change this. (And if it does,
we'll deal with that then since CI would start failing.)

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3824>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3824>

src/gallium/drivers/panfrost/pan_format.c

index f8e3277150fa8ce26376cdaaad3e31f512a2eb22..b7f5e4449cf6e2fcf3e1033ab02dab7341eb73e4 100644 (file)
 /* From panwrap/panwrap-decoder, but we don't want to bring in all those headers */
 char *panwrap_format_name(enum mali_format format);
 
-/* Construct a default swizzle based on the number of components */
-
-static unsigned
-panfrost_translate_swizzle(enum pipe_swizzle s)
-{
-        switch (s) {
-        case PIPE_SWIZZLE_X:
-                return MALI_CHANNEL_RED;
-
-        case PIPE_SWIZZLE_Y:
-                return MALI_CHANNEL_GREEN;
-
-        case PIPE_SWIZZLE_Z:
-                return MALI_CHANNEL_BLUE;
-
-        case PIPE_SWIZZLE_W:
-                return MALI_CHANNEL_ALPHA;
-
-        case PIPE_SWIZZLE_0:
-        case PIPE_SWIZZLE_NONE:
-                return MALI_CHANNEL_ZERO;
-
-        case PIPE_SWIZZLE_1:
-                return MALI_CHANNEL_ONE;
-
-        default:
-                unreachable("INvalid swizzle");
-        }
-}
-
-/* Translate a Gallium swizzle quad to a 12-bit Mali swizzle code */
+/* Translate a Gallium swizzle quad to a 12-bit Mali swizzle code. Gallium
+ * swizzles line up with Mali swizzles for the XYZW01, but Gallium has an
+ * additional "NONE" field that we have to mask out to zero. Additionally,
+ * Gallium swizzles are sparse but Mali swizzles are packed */
 
 unsigned
 panfrost_translate_swizzle_4(const unsigned char swizzle[4])
@@ -65,7 +38,7 @@ panfrost_translate_swizzle_4(const unsigned char swizzle[4])
         unsigned out = 0;
 
         for (unsigned i = 0; i < 4; ++i) {
-                unsigned translated = panfrost_translate_swizzle(swizzle[i]);
+                unsigned translated = (swizzle[i] > PIPE_SWIZZLE_1) ? PIPE_SWIZZLE_0 : swizzle[i];
                 out |= (translated << (3*i));
         }