Mesa (main): intel/isl: Add a helper for swizzling color values

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Apr 4 22:14:56 UTC 2022


Module: Mesa
Branch: main
Commit: 257a20f40d909ef324afe1f5cc357e2f5a2258d5
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=257a20f40d909ef324afe1f5cc357e2f5a2258d5

Author: Jason Ekstrand <jason.ekstrand at collabora.com>
Date:   Tue Mar 29 10:42:08 2022 -0500

intel/isl: Add a helper for swizzling color values

Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15624>

---

 src/intel/isl/isl.c | 32 ++++++++++++++++++++++++++++++++
 src/intel/isl/isl.h |  5 +++++
 2 files changed, 37 insertions(+)

diff --git a/src/intel/isl/isl.c b/src/intel/isl/isl.c
index bd41684c1fe..56e10f256c7 100644
--- a/src/intel/isl/isl.c
+++ b/src/intel/isl/isl.c
@@ -3328,6 +3328,38 @@ isl_swizzle_invert(struct isl_swizzle swizzle)
    return (struct isl_swizzle) { chans[0], chans[1], chans[2], chans[3] };
 }
 
+static uint32_t
+isl_color_value_channel(union isl_color_value src,
+                        enum isl_channel_select chan,
+                        uint32_t one)
+{
+   if (chan == ISL_CHANNEL_SELECT_ZERO)
+      return 0;
+   if (chan == ISL_CHANNEL_SELECT_ONE)
+      return one;
+
+   assert(chan >= ISL_CHANNEL_SELECT_RED);
+   assert(chan < ISL_CHANNEL_SELECT_RED + 4);
+
+   return src.u32[chan - ISL_CHANNEL_SELECT_RED];
+}
+
+/** Applies an inverse swizzle to a color value */
+union isl_color_value
+isl_color_value_swizzle(union isl_color_value src,
+                        struct isl_swizzle swizzle,
+                        bool is_float)
+{
+   uint32_t one = is_float ? 0x3f800000 : 1;
+
+   return (union isl_color_value) { .u32 = {
+      isl_color_value_channel(src, swizzle.r, one),
+      isl_color_value_channel(src, swizzle.g, one),
+      isl_color_value_channel(src, swizzle.b, one),
+      isl_color_value_channel(src, swizzle.a, one),
+   } };
+}
+
 /** Applies an inverse swizzle to a color value */
 union isl_color_value
 isl_color_value_swizzle_inv(union isl_color_value src,
diff --git a/src/intel/isl/isl.h b/src/intel/isl/isl.h
index 3f84a3a5988..c2db422fc8e 100644
--- a/src/intel/isl/isl.h
+++ b/src/intel/isl/isl.h
@@ -2013,6 +2013,11 @@ enum isl_format isl_format_rgb_to_rgba(enum isl_format rgb) ATTRIBUTE_CONST;
 enum isl_format isl_format_rgb_to_rgbx(enum isl_format rgb) ATTRIBUTE_CONST;
 enum isl_format isl_format_rgbx_to_rgba(enum isl_format rgb) ATTRIBUTE_CONST;
 
+union isl_color_value
+isl_color_value_swizzle(union isl_color_value src,
+                        struct isl_swizzle swizzle,
+                        bool is_float);
+
 union isl_color_value
 isl_color_value_swizzle_inv(union isl_color_value src,
                             struct isl_swizzle swizzle);



More information about the mesa-commit mailing list