panfrost: Inline panfrost_get_default_swizzle
authorIcecream95 <ixn@keemail.me>
Fri, 14 Feb 2020 07:22:38 +0000 (20:22 +1300)
committerMarge Bot <eric+marge@anholt.net>
Fri, 14 Feb 2020 12:53:36 +0000 (12:53 +0000)
This commit replaces panfrost_get_default_swizzle with an inlined
implementation where the returned values can be determined at compile
time.

According to perf, this previously used about 2% CPU for Openarena.

Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3824>

src/gallium/drivers/panfrost/pan_assemble.c
src/gallium/drivers/panfrost/pan_context.h
src/gallium/drivers/panfrost/pan_format.c
src/gallium/drivers/panfrost/pan_format.h
src/gallium/drivers/panfrost/pan_varyings.c

index 03ca63ccc3262526008ee07c1748a74386bf346a..6f84248b2f1fb1ddfd8b5315f550054d9c6cedc2 100644 (file)
@@ -27,6 +27,7 @@
 #include <string.h>
 #include "pan_bo.h"
 #include "pan_context.h"
+#include "pan_format.h"
 #include "pan_util.h"
 
 #include "compiler/nir/nir.h"
index 79d082da11f818c8a5cae9f54f2a684ddd908d00..fcfcafb135a484a49f44ff136b151080cd48777b 100644 (file)
@@ -297,9 +297,6 @@ panfrost_emit_for_draw(struct panfrost_context *ctx, bool with_vertex_data);
 struct panfrost_transfer
 panfrost_vertex_tiler_job(struct panfrost_context *ctx, bool is_tiler);
 
-unsigned
-panfrost_get_default_swizzle(unsigned components);
-
 void
 panfrost_flush(
         struct pipe_context *pipe,
index 4f138ca402701c89485d25c58e6263d2feb4a1fd..f8e3277150fa8ce26376cdaaad3e31f512a2eb22 100644 (file)
@@ -72,20 +72,6 @@ panfrost_translate_swizzle_4(const unsigned char swizzle[4])
         return out;
 }
 
-unsigned
-panfrost_get_default_swizzle(unsigned components)
-{
-        unsigned char default_swizzles[4][4] = {
-                {PIPE_SWIZZLE_X, PIPE_SWIZZLE_0, PIPE_SWIZZLE_0, PIPE_SWIZZLE_1},
-                {PIPE_SWIZZLE_X, PIPE_SWIZZLE_Y, PIPE_SWIZZLE_0, PIPE_SWIZZLE_1},
-                {PIPE_SWIZZLE_X, PIPE_SWIZZLE_Y, PIPE_SWIZZLE_Z, PIPE_SWIZZLE_1},
-                {PIPE_SWIZZLE_X, PIPE_SWIZZLE_Y, PIPE_SWIZZLE_Z, PIPE_SWIZZLE_W},
-        };
-
-        assert(components >= 1 && components <= 4);
-        return panfrost_translate_swizzle_4(default_swizzles[components - 1]);
-}
-
 static unsigned
 panfrost_translate_channel_width(unsigned size)
 {
index 8468904da239f9356ee230f2a67fa2f0d52bd57e..b82493df42571c9d6ea4f95fe5a23ae1fb397d92 100644 (file)
@@ -31,9 +31,6 @@
 unsigned
 panfrost_translate_swizzle_4(const unsigned char swizzle[4]);
 
-unsigned
-panfrost_get_default_swizzle(unsigned components);
-
 enum mali_format
 panfrost_find_format(const struct util_format_description *desc);
 
@@ -43,6 +40,27 @@ panfrost_invert_swizzle(const unsigned char *in, unsigned char *out);
 bool
 panfrost_is_z24s8_variant(enum pipe_format fmt);
 
+static inline unsigned
+panfrost_get_default_swizzle(unsigned components)
+{
+        switch (components) {
+        case 1:
+                return (MALI_CHANNEL_RED << 0) | (MALI_CHANNEL_ZERO << 3) |
+                        (MALI_CHANNEL_ZERO << 6) | (MALI_CHANNEL_ONE << 9);
+        case 2:
+                return (MALI_CHANNEL_RED << 0) | (MALI_CHANNEL_GREEN << 3) |
+                        (MALI_CHANNEL_ZERO << 6) | (MALI_CHANNEL_ONE << 9);
+        case 3:
+                return (MALI_CHANNEL_RED << 0) | (MALI_CHANNEL_GREEN << 3) |
+                        (MALI_CHANNEL_BLUE << 6) | (MALI_CHANNEL_ONE << 9);
+        case 4:
+                return (MALI_CHANNEL_RED << 0) | (MALI_CHANNEL_GREEN << 3) |
+                        (MALI_CHANNEL_BLUE << 6) | (MALI_CHANNEL_ALPHA << 9);
+        default:
+                unreachable("Invalid number of components");
+        }
+}
+
 #endif
 
 
index 0ec4d5633d2f36e558f32eccf5e5c7ba584dbddc..52496aa26d7c8fda7e7c495cf8f4e26107b8d94a 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "pan_bo.h"
 #include "pan_context.h"
+#include "pan_format.h"
 #include "util/u_prim.h"
 
 static mali_ptr