summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRob Clark <[email protected]>2015-09-18 13:23:36 -0400
committerRob Clark <[email protected]>2015-09-18 21:07:50 -0400
commite4dfcdcbecee9d11709e85524222d748d0e27112 (patch)
tree798754df3e9990e79a065b62bbc60b1f5b25ae81
parentc71cb670ba786a4bc443d23e6aa4b866e069dcd2 (diff)
nir/build: add nir_vec() helper
Signed-off-by: Rob Clark <[email protected]> Reviewed-by: Connor Abbott <[email protected]>
-rw-r--r--src/glsl/nir/nir_builder.h18
-rw-r--r--src/glsl/nir/nir_lower_load_const_to_scalar.c15
-rw-r--r--src/glsl/nir/nir_lower_tex.c18
3 files changed, 20 insertions, 31 deletions
diff --git a/src/glsl/nir/nir_builder.h b/src/glsl/nir/nir_builder.h
index 47533302a6d..8db5fcf039d 100644
--- a/src/glsl/nir/nir_builder.h
+++ b/src/glsl/nir/nir_builder.h
@@ -173,6 +173,24 @@ nir_##op(nir_builder *build, nir_ssa_def *src0, \
#include "nir_builder_opcodes.h"
+static inline nir_ssa_def *
+nir_vec(nir_builder *build, nir_ssa_def **comp, unsigned num_components)
+{
+ switch (num_components) {
+ case 4:
+ return nir_vec4(build, comp[0], comp[1], comp[2], comp[3]);
+ case 3:
+ return nir_vec3(build, comp[0], comp[1], comp[2]);
+ case 2:
+ return nir_vec2(build, comp[0], comp[1]);
+ case 1:
+ return comp[0];
+ default:
+ unreachable("bad component count");
+ return NULL;
+ }
+}
+
/**
* Similar to nir_fmov, but takes a nir_alu_src instead of a nir_ssa_def.
*/
diff --git a/src/glsl/nir/nir_lower_load_const_to_scalar.c b/src/glsl/nir/nir_lower_load_const_to_scalar.c
index 704f8cebfd8..84d0c1453cb 100644
--- a/src/glsl/nir/nir_lower_load_const_to_scalar.c
+++ b/src/glsl/nir/nir_lower_load_const_to_scalar.c
@@ -55,20 +55,7 @@ lower_load_const_instr_scalar(nir_load_const_instr *lower)
}
/* Batch things back together into a vector. */
- nir_ssa_def *vec;
- switch (lower->def.num_components) {
- case 2:
- vec = nir_vec2(&b, loads[0], loads[1]);
- break;
- case 3:
- vec = nir_vec3(&b, loads[0], loads[1], loads[2]);
- break;
- case 4:
- vec = nir_vec4(&b, loads[0], loads[1], loads[2], loads[3]);
- break;
- default:
- unreachable("Unknown load_const component count.");
- }
+ nir_ssa_def *vec = nir_vec(&b, loads, lower->def.num_components);
/* Replace the old load with a reference to our reconstructed vector. */
nir_ssa_def_rewrite_uses(&lower->def, nir_src_for_ssa(vec));
diff --git a/src/glsl/nir/nir_lower_tex.c b/src/glsl/nir/nir_lower_tex.c
index e2f095a5532..8aaa48ab568 100644
--- a/src/glsl/nir/nir_lower_tex.c
+++ b/src/glsl/nir/nir_lower_tex.c
@@ -205,23 +205,7 @@ saturate_src(nir_builder *b, nir_tex_instr *tex, unsigned sat_mask)
}
/* and move the result back into a single vecN: */
- switch (tex->coord_components) {
- case 4:
- src = nir_vec4(b, comp[0], comp[1], comp[2], comp[3]);
- break;
- case 3:
- src = nir_vec3(b, comp[0], comp[1], comp[2]);
- break;
- case 2:
- src = nir_vec2(b, comp[0], comp[1]);
- break;
- case 1:
- src = comp[0];
- break;
- default:
- unreachable("bad texture coord count");
- break;
- }
+ src = nir_vec(b, comp, tex->coord_components);
nir_instr_rewrite_src(&tex->instr,
&tex->src[i].src,