nir: Add an interface to turn a nir_src into a nir_ssa_def.
authorEric Anholt <eric@anholt.net>
Fri, 27 Mar 2015 21:19:46 +0000 (14:19 -0700)
committerEric Anholt <eric@anholt.net>
Fri, 3 Apr 2015 18:50:22 +0000 (11:50 -0700)
We use nir_ssa_defs for nir_builder args, so this takes a nir_src and
makes one so it can be passed in.

Reviewed-by: Jason Ekstrand <jason.ekstrand@intel.com>
src/glsl/nir/nir_builder.h

index ecbdbe3d12d35487a577631dc1f11dfdd4795a7c..587d014d3f406302ac48b41cafad58a56494d4ba 100644 (file)
@@ -225,4 +225,23 @@ nir_swizzle(nir_builder *build, nir_ssa_def *src, unsigned swiz[4],
                      nir_imov_alu(build, alu_src, num_components);
 }
 
+/**
+ * Turns a nir_src into a nir_ssa_def * so it can be passed to
+ * nir_build_alu()-based builder calls.
+ */
+static inline nir_ssa_def *
+nir_ssa_for_src(nir_builder *build, nir_src src, int num_components)
+{
+   if (src.is_ssa && src.ssa->num_components == num_components)
+      return src.ssa;
+
+   nir_alu_src alu;
+   memset(&alu, 0, sizeof(alu));
+   alu.src = src;
+   for (int j = 0; j < 4; j++)
+      alu.swizzle[j] = j;
+
+   return nir_imov_alu(build, alu, num_components);
+}
+
 #endif /* NIR_BUILDER_H */