summaryrefslogtreecommitdiffstats
path: root/src/intel/isl/isl.c
diff options
context:
space:
mode:
authorJason Ekstrand <[email protected]>2017-02-08 17:59:43 -0800
committerJason Ekstrand <[email protected]>2018-05-09 11:16:33 -0700
commit1ef4f5aff1bb80685a7d8407ce74040f7494068f (patch)
treefd98d398882d3f67c7d7df4da3b616d1177e84f3 /src/intel/isl/isl.c
parent242f6f7492a0e5b0cafa003c61f1d9e8ccce8889 (diff)
intel/isl: Add a helper for inverting swizzles
Reviewed-by: Topi Pohjolainen <[email protected]>
Diffstat (limited to 'src/intel/isl/isl.c')
-rw-r--r--src/intel/isl/isl.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/intel/isl/isl.c b/src/intel/isl/isl.c
index 5cd6ef954a1..7dfead00dc6 100644
--- a/src/intel/isl/isl.c
+++ b/src/intel/isl/isl.c
@@ -2410,3 +2410,33 @@ isl_swizzle_compose(struct isl_swizzle first, struct isl_swizzle second)
.a = swizzle_select(first.a, second),
};
}
+
+/**
+ * Returns a swizzle that is the pseudo-inverse of this swizzle.
+ */
+struct isl_swizzle
+isl_swizzle_invert(struct isl_swizzle swizzle)
+{
+ /* Default to zero for channels which do not show up in the swizzle */
+ enum isl_channel_select chans[4] = {
+ ISL_CHANNEL_SELECT_ZERO,
+ ISL_CHANNEL_SELECT_ZERO,
+ ISL_CHANNEL_SELECT_ZERO,
+ ISL_CHANNEL_SELECT_ZERO,
+ };
+
+ /* We go in ABGR order so that, if there are any duplicates, the first one
+ * is taken if you look at it in RGBA order. This is what Haswell hardware
+ * does for render target swizzles.
+ */
+ if ((unsigned)(swizzle.a - ISL_CHANNEL_SELECT_RED) < 4)
+ chans[swizzle.a - ISL_CHANNEL_SELECT_RED] = ISL_CHANNEL_SELECT_ALPHA;
+ if ((unsigned)(swizzle.b - ISL_CHANNEL_SELECT_RED) < 4)
+ chans[swizzle.b - ISL_CHANNEL_SELECT_RED] = ISL_CHANNEL_SELECT_BLUE;
+ if ((unsigned)(swizzle.g - ISL_CHANNEL_SELECT_RED) < 4)
+ chans[swizzle.g - ISL_CHANNEL_SELECT_RED] = ISL_CHANNEL_SELECT_GREEN;
+ if ((unsigned)(swizzle.r - ISL_CHANNEL_SELECT_RED) < 4)
+ chans[swizzle.r - ISL_CHANNEL_SELECT_RED] = ISL_CHANNEL_SELECT_RED;
+
+ return (struct isl_swizzle) { chans[0], chans[1], chans[2], chans[3] };
+}