nir: Add nir_op_vec helper
authorKarol Herbst <kherbst@redhat.com>
Wed, 20 Mar 2019 17:11:20 +0000 (18:11 +0100)
committerKarol Herbst <kherbst@redhat.com>
Sat, 4 May 2019 10:27:51 +0000 (12:27 +0200)
with that we can simplify code where nir vectors are created

v2: merge both lines in nir_vec

Signed-off-by: Karol Herbst <kherbst@redhat.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
src/compiler/nir/nir.h
src/compiler/nir/nir_builder.h
src/compiler/spirv/spirv_to_nir.c

index ed21032e5e1c48b87f68989afd4301146ff0c094..37161e83e4d403cbf0c4a045b7df185ac89ffa21 100644 (file)
@@ -862,6 +862,18 @@ nir_get_nir_type_for_glsl_type(const struct glsl_type *type)
 nir_op nir_type_conversion_op(nir_alu_type src, nir_alu_type dst,
                               nir_rounding_mode rnd);
 
+static inline nir_op
+nir_op_vec(unsigned components)
+{
+   switch (components) {
+   case  1: return nir_op_imov;
+   case  2: return nir_op_vec2;
+   case  3: return nir_op_vec3;
+   case  4: return nir_op_vec4;
+   default: unreachable("bad component count");
+   }
+}
+
 typedef enum {
    NIR_OP_IS_COMMUTATIVE = (1 << 0),
    NIR_OP_IS_ASSOCIATIVE = (1 << 1),
index 5f6bb0b1d5a218b270bd5b464512037dc446335e..ced009a66c7c2d175f146d59c022fba9189b92f4 100644 (file)
@@ -489,19 +489,7 @@ nir_build_alu_src_arr(nir_builder *build, nir_op op, nir_ssa_def **srcs)
 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;
-   }
+   return nir_build_alu_src_arr(build, nir_op_vec(num_components), comp);
 }
 
 /**
index 7d2fafe4bdec149a16dbb005fe36e7365d308dfb..5e91f8815e8140671967670a347255701e056673 100644 (file)
@@ -2984,15 +2984,7 @@ vtn_handle_atomics(struct vtn_builder *b, SpvOp opcode,
 static nir_alu_instr *
 create_vec(struct vtn_builder *b, unsigned num_components, unsigned bit_size)
 {
-   nir_op op;
-   switch (num_components) {
-   case 1: op = nir_op_imov; break;
-   case 2: op = nir_op_vec2; break;
-   case 3: op = nir_op_vec3; break;
-   case 4: op = nir_op_vec4; break;
-   default: vtn_fail("bad vector size: %u", num_components);
-   }
-
+   nir_op op = nir_op_vec(num_components);
    nir_alu_instr *vec = nir_alu_instr_create(b->shader, op);
    nir_ssa_dest_init(&vec->instr, &vec->dest.dest, num_components,
                      bit_size, NULL);