[Mesa-dev] [PATCH 2/3] panfrost/midgard: Share swizzle compose

Alyssa Rosenzweig alyssa.rosenzweig at collabora.com
Fri Jun 21 12:28:48 UTC 2019


Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig at collabora.com>
---
 .../drivers/panfrost/midgard/helpers.h        | 29 +++++++++++++++++++
 .../drivers/panfrost/midgard/midgard_ra.c     |  9 +-----
 2 files changed, 30 insertions(+), 8 deletions(-)

diff --git a/src/gallium/drivers/panfrost/midgard/helpers.h b/src/gallium/drivers/panfrost/midgard/helpers.h
index ff069d3f8bb..cbf51fe882a 100644
--- a/src/gallium/drivers/panfrost/midgard/helpers.h
+++ b/src/gallium/drivers/panfrost/midgard/helpers.h
@@ -264,4 +264,33 @@ vector_alu_from_unsigned(unsigned u)
         return s;
 }
 
+/* Composes two swizzles */
+static inline unsigned
+pan_compose_swizzle(unsigned left, unsigned right)
+{
+        unsigned out = 0;
+
+        for (unsigned c = 0; c < 4; ++c) {
+                unsigned s = (left >> (2*c)) & 0x3;
+                unsigned q = (right >> (2*s)) & 0x3;
+
+                out |= (q << (2*c));
+        }
+
+        return out;
+}
+
+/* Applies a swizzle to an ALU source */
+
+static inline unsigned
+vector_alu_apply_swizzle(unsigned src, unsigned swizzle)
+{
+        midgard_vector_alu_src s =
+                vector_alu_from_unsigned(src);
+
+        s.swizzle = pan_compose_swizzle(s.swizzle, swizzle);
+
+        return vector_alu_srco_unsigned(s);
+}
+
 #endif
diff --git a/src/gallium/drivers/panfrost/midgard/midgard_ra.c b/src/gallium/drivers/panfrost/midgard/midgard_ra.c
index 7fd5e5b49e3..40a73709871 100644
--- a/src/gallium/drivers/panfrost/midgard/midgard_ra.c
+++ b/src/gallium/drivers/panfrost/midgard/midgard_ra.c
@@ -92,14 +92,7 @@ static unsigned
 compose_swizzle(unsigned swizzle, unsigned mask,
                 struct phys_reg reg, struct phys_reg dst)
 {
-        unsigned out = 0;
-
-        for (unsigned c = 0; c < 4; ++c) {
-                unsigned s = (swizzle >> (2*c)) & 0x3;
-                unsigned q = (reg.swizzle >> (2*s)) & 0x3;
-
-                out |= (q << (2*c));
-        }
+        unsigned out = pan_compose_swizzle(swizzle, reg.swizzle);
 
         /* Based on the register mask, we need to adjust over. E.g if we're
          * writing to yz, a base swizzle of xy__ becomes _xy_. Save the
-- 
2.20.1



More information about the mesa-dev mailing list