nir: add nir_channel() to get at single components of vec's
authorRob Clark <robclark@freedesktop.org>
Thu, 10 Sep 2015 20:06:05 +0000 (16:06 -0400)
committerRob Clark <robclark@freedesktop.org>
Sun, 13 Sep 2015 15:08:27 +0000 (11:08 -0400)
Rather than make yet another copy of channel(), let's move it into nir.

Signed-off-by: Rob Clark <robclark@freedesktop.org>
Reviewed-by: Jason Ekstrand <jason.ekstrand@intel.com>
src/glsl/nir/nir_builder.h
src/glsl/nir/nir_lower_tex_projector.c
src/glsl/nir/nir_normalize_cubemap_coords.c

index ffa31c90a45cb4c7f756ca1232bf79c8ed82ce90..cf50f699eae76a62739523911d9691c7f95742e0 100644 (file)
@@ -216,6 +216,12 @@ nir_swizzle(nir_builder *build, nir_ssa_def *src, unsigned swiz[4],
                      nir_imov_alu(build, alu_src, num_components);
 }
 
+static inline nir_ssa_def *
+nir_channel(nir_builder *b, nir_ssa_def *def, int c)
+{
+   return nir_swizzle(b, def, (unsigned[4]){c, c, c, c}, 1, false);
+}
+
 /**
  * Turns a nir_src into a nir_ssa_def * so it can be passed to
  * nir_build_alu()-based builder calls.
index 6530021c8b75a0a1182687edd0b8e57c6c157d6a..9afa42f23a962c22163c1b0d071cc9a3b4b6c06a 100644 (file)
 #include "nir.h"
 #include "nir_builder.h"
 
-static nir_ssa_def *
-channel(nir_builder *b, nir_ssa_def *def, int c)
-{
-   return nir_swizzle(b, def, (unsigned[4]){c, c, c, c}, 1, false);
-}
-
 static bool
 nir_lower_tex_projector_block(nir_block *block, void *void_state)
 {
@@ -79,21 +73,21 @@ nir_lower_tex_projector_block(nir_block *block, void *void_state)
             switch (tex->coord_components) {
             case 4:
                projected = nir_vec4(b,
-                                    channel(b, projected, 0),
-                                    channel(b, projected, 1),
-                                    channel(b, projected, 2),
-                                    channel(b, unprojected, 3));
+                                    nir_channel(b, projected, 0),
+                                    nir_channel(b, projected, 1),
+                                    nir_channel(b, projected, 2),
+                                    nir_channel(b, unprojected, 3));
                break;
             case 3:
                projected = nir_vec3(b,
-                                    channel(b, projected, 0),
-                                    channel(b, projected, 1),
-                                    channel(b, unprojected, 2));
+                                    nir_channel(b, projected, 0),
+                                    nir_channel(b, projected, 1),
+                                    nir_channel(b, unprojected, 2));
                break;
             case 2:
                projected = nir_vec2(b,
-                                    channel(b, projected, 0),
-                                    channel(b, unprojected, 1));
+                                    nir_channel(b, projected, 0),
+                                    nir_channel(b, unprojected, 1));
                break;
             default:
                unreachable("bad texture coord count for array");
index 75b647f96cb8cdcbd146952556fa2e69fc2c895e..ca68bd7a94cc23d811af6cb8870335f1124ad52a 100644 (file)
  * or 1.0.  This is based on the old GLSL IR based pass by Eric.
  */
 
-static nir_ssa_def *
-channel(nir_builder *b, nir_ssa_def *def, int c)
-{
-   return nir_swizzle(b, def, (unsigned[4]){c, c, c, c}, 1, false);
-}
-
 static bool
 normalize_cubemap_coords_block(nir_block *block, void *void_state)
 {
@@ -63,9 +57,9 @@ normalize_cubemap_coords_block(nir_block *block, void *void_state)
          assert(orig_coord->num_components >= 3);
 
          nir_ssa_def *abs = nir_fabs(b, orig_coord);
-         nir_ssa_def *norm = nir_fmax(b, channel(b, abs, 0),
-                                         nir_fmax(b, channel(b, abs, 1),
-                                                     channel(b, abs, 2)));
+         nir_ssa_def *norm = nir_fmax(b, nir_channel(b, abs, 0),
+                                         nir_fmax(b, nir_channel(b, abs, 1),
+                                                     nir_channel(b, abs, 2)));
 
          nir_ssa_def *normalized = nir_fmul(b, orig_coord, nir_frcp(b, norm));
 
@@ -74,10 +68,10 @@ normalize_cubemap_coords_block(nir_block *block, void *void_state)
           */
          if (tex->coord_components == 4) {
             normalized = nir_vec4(b,
-                                  channel(b, normalized, 0),
-                                  channel(b, normalized, 1),
-                                  channel(b, normalized, 2),
-                                  channel(b, orig_coord, 3));
+                                  nir_channel(b, normalized, 0),
+                                  nir_channel(b, normalized, 1),
+                                  nir_channel(b, normalized, 2),
+                                  nir_channel(b, orig_coord, 3));
          }
 
          nir_instr_rewrite_src(&tex->instr,