intel/isl: Add a helper for composing swizzles
authorJason Ekstrand <jason.ekstrand@intel.com>
Tue, 7 Feb 2017 17:14:46 +0000 (09:14 -0800)
committerJason Ekstrand <jason.ekstrand@intel.com>
Wed, 9 May 2018 18:16:33 +0000 (11:16 -0700)
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/intel/isl/isl.c
src/intel/isl/isl.h

index 1b270c1d7157cdefe9ed6b2ca176283f63c64309..5cd6ef954a1d9d5541945bdd4ac9f39012df6886 100644 (file)
@@ -2375,3 +2375,38 @@ isl_swizzle_supports_rendering(const struct gen_device_info *devinfo,
              swizzle.a == ISL_CHANNEL_SELECT_ALPHA;
    }
 }
+
+static enum isl_channel_select
+swizzle_select(enum isl_channel_select chan, struct isl_swizzle swizzle)
+{
+   switch (chan) {
+   case ISL_CHANNEL_SELECT_ZERO:
+   case ISL_CHANNEL_SELECT_ONE:
+      return chan;
+   case ISL_CHANNEL_SELECT_RED:
+      return swizzle.r;
+   case ISL_CHANNEL_SELECT_GREEN:
+      return swizzle.g;
+   case ISL_CHANNEL_SELECT_BLUE:
+      return swizzle.b;
+   case ISL_CHANNEL_SELECT_ALPHA:
+      return swizzle.a;
+   default:
+      unreachable("Invalid swizzle component");
+   }
+}
+
+/**
+ * Returns the single swizzle that is equivalent to applying the two given
+ * swizzles in sequence.
+ */
+struct isl_swizzle
+isl_swizzle_compose(struct isl_swizzle first, struct isl_swizzle second)
+{
+   return (struct isl_swizzle) {
+      .r = swizzle_select(first.r, second),
+      .g = swizzle_select(first.g, second),
+      .b = swizzle_select(first.b, second),
+      .a = swizzle_select(first.a, second),
+   };
+}
index fc1ff5f3f8862e2d34056fc293ea17f5194e1b7e..3c175d2d051cd9310ff9855a44ddefc58b12fb14 100644 (file)
@@ -1744,6 +1744,9 @@ bool
 isl_swizzle_supports_rendering(const struct gen_device_info *devinfo,
                                struct isl_swizzle swizzle);
 
+struct isl_swizzle
+isl_swizzle_compose(struct isl_swizzle first, struct isl_swizzle second);
+
 #define isl_surf_init(dev, surf, ...) \
    isl_surf_init_s((dev), (surf), \
                    &(struct isl_surf_init_info) {  __VA_ARGS__ });