/* 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])
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));
}