summaryrefslogtreecommitdiffstats
path: root/src/compiler
diff options
context:
space:
mode:
authorJason Ekstrand <[email protected]>2016-05-02 16:29:05 -0700
committerJason Ekstrand <[email protected]>2016-05-14 13:34:40 -0700
commit87a41e862b5344da6271d533552a890d59f07a4b (patch)
treeaeb344b6b75a3dda917b0621797e6f45ab5a5e09 /src/compiler
parentfc58cb543fe2430576216680c4f6a55ec22b937e (diff)
nir/builder: Add a helper for grabbing multiple channels from an ssa def
This is similar to nir_channel except that it lets you grab more than one channel by providing a mask. Reviewed-by: Kenneth Graunke <[email protected]>
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/nir/nir_builder.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/compiler/nir/nir_builder.h b/src/compiler/nir/nir_builder.h
index 14159fa79a5..09cdf72bfff 100644
--- a/src/compiler/nir/nir_builder.h
+++ b/src/compiler/nir/nir_builder.h
@@ -324,6 +324,20 @@ nir_channel(nir_builder *b, nir_ssa_def *def, unsigned c)
return nir_swizzle(b, def, swizzle, 1, false);
}
+static inline nir_ssa_def *
+nir_channels(nir_builder *b, nir_ssa_def *def, unsigned mask)
+{
+ unsigned num_channels = 0, swizzle[4] = { 0, 0, 0, 0 };
+
+ for (unsigned i = 0; i < 4; i++) {
+ if ((mask & (1 << i)) == 0)
+ continue;
+ swizzle[num_channels++] = i;
+ }
+
+ return nir_swizzle(b, def, swizzle, num_channels, false);
+}
+
/**
* Turns a nir_src into a nir_ssa_def * so it can be passed to
* nir_build_alu()-based builder calls.