spirv: Call nir_builder directly for vector_extract
authorJason Ekstrand <jason@jlekstrand.net>
Thu, 9 Apr 2020 22:03:37 +0000 (17:03 -0500)
committerMarge Bot <eric+marge@anholt.net>
Fri, 17 Apr 2020 19:21:44 +0000 (19:21 +0000)
The nir_builder helper already handles checking if the component
selector is an immediate and returns an undef in the OOB case.

Reviewed-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4495>

src/compiler/spirv/spirv_to_nir.c
src/compiler/spirv/vtn_amd.c
src/compiler/spirv/vtn_glsl450.c
src/compiler/spirv/vtn_opencl.c
src/compiler/spirv/vtn_private.h
src/compiler/spirv/vtn_variables.c

index a4f8ce279875caf97a1ac02e4a83cb0e38cb4346..2cc8f2570c78247084808136093eb1c2a8197716 100644 (file)
@@ -3311,15 +3311,6 @@ vtn_ssa_transpose(struct vtn_builder *b, struct vtn_ssa_value *src)
    return dest;
 }
 
-nir_ssa_def *
-vtn_vector_extract(struct vtn_builder *b, nir_ssa_def *src, unsigned index)
-{
-   if (index > src->num_components)
-      return nir_ssa_undef(&b->nb, src->num_components, src->bit_size);
-   else
-      return nir_channel(&b->nb, src, index);
-}
-
 nir_ssa_def *
 vtn_vector_insert(struct vtn_builder *b, nir_ssa_def *src, nir_ssa_def *insert,
                   unsigned index)
@@ -3341,13 +3332,6 @@ vtn_vector_insert(struct vtn_builder *b, nir_ssa_def *src, nir_ssa_def *insert,
    return &vec->dest.dest.ssa;
 }
 
-nir_ssa_def *
-vtn_vector_extract_dynamic(struct vtn_builder *b, nir_ssa_def *src,
-                           nir_ssa_def *index)
-{
-   return nir_vector_extract(&b->nb, src, nir_i2i(&b->nb, index, 32));
-}
-
 nir_ssa_def *
 vtn_vector_insert_dynamic(struct vtn_builder *b, nir_ssa_def *src,
                           nir_ssa_def *insert, nir_ssa_def *index)
@@ -3506,7 +3490,7 @@ vtn_composite_extract(struct vtn_builder *b, struct vtn_ssa_value *src,
 
          struct vtn_ssa_value *ret = rzalloc(b, struct vtn_ssa_value);
          ret->type = glsl_scalar_type(glsl_get_base_type(cur->type));
-         ret->def = vtn_vector_extract(b, cur->def, indices[i]);
+         ret->def = nir_channel(&b->nb, cur->def, indices[i]);
          return ret;
       } else {
          vtn_fail_if(indices[i] >= glsl_get_length(cur->type),
@@ -3527,8 +3511,8 @@ vtn_handle_composite(struct vtn_builder *b, SpvOp opcode,
 
    switch (opcode) {
    case SpvOpVectorExtractDynamic:
-      ssa->def = vtn_vector_extract_dynamic(b, vtn_ssa_value(b, w[3])->def,
-                                            vtn_ssa_value(b, w[4])->def);
+      ssa->def = nir_vector_extract(&b->nb, vtn_ssa_value(b, w[3])->def,
+                                    vtn_ssa_value(b, w[4])->def);
       break;
 
    case SpvOpVectorInsertDynamic:
index 55f87c2f98e64859bc27c6ef5ea90f9232b89ceb..195baef9c00146f1824ec976da22b48d77d0c626 100644 (file)
@@ -219,13 +219,8 @@ vtn_handle_amd_shader_explicit_vertex_parameter_instruction(struct vtn_builder *
 
    if (vec_array_deref) {
       assert(vec_deref);
-      if (nir_src_is_const(vec_deref->arr.index)) {
-         val->ssa->def = vtn_vector_extract(b, &intrin->dest.ssa,
-                                            nir_src_as_uint(vec_deref->arr.index));
-      } else {
-         val->ssa->def = vtn_vector_extract_dynamic(b, &intrin->dest.ssa,
-                                                    vec_deref->arr.index.ssa);
-      }
+      val->ssa->def = nir_vector_extract(&b->nb, &intrin->dest.ssa,
+                                         vec_deref->arr.index.ssa);
    } else {
       val->ssa->def = &intrin->dest.ssa;
    }
index 2ecd0295bc8219eaab0904272b1c5c8c57ae6cc8..2d4743d59f0a9e598d808d6651fab4674d8fcded 100644 (file)
@@ -591,13 +591,8 @@ handle_glsl450_interpolation(struct vtn_builder *b, enum GLSLstd450 opcode,
 
    if (vec_array_deref) {
       assert(vec_deref);
-      if (nir_src_is_const(vec_deref->arr.index)) {
-         val->ssa->def = vtn_vector_extract(b, &intrin->dest.ssa,
-                                            nir_src_as_uint(vec_deref->arr.index));
-      } else {
-         val->ssa->def = vtn_vector_extract_dynamic(b, &intrin->dest.ssa,
-                                                    vec_deref->arr.index.ssa);
-      }
+      val->ssa->def = nir_vector_extract(&b->nb, &intrin->dest.ssa,
+                                         vec_deref->arr.index.ssa);
    } else {
       val->ssa->def = &intrin->dest.ssa;
    }
index da191f2b80a58230f377043928e5dca9c1212bca..eb8aaac7d1cb8e40908bfac7c4274d5c41c8f644 100644 (file)
@@ -243,7 +243,7 @@ _handle_v_load_store(struct vtn_builder *b, enum OpenCLstd_Entrypoints opcode,
       } else {
          struct vtn_ssa_value *ssa = vtn_create_ssa_value(b, glsl_scalar_type(glsl_get_base_type(dest_type)));
          struct vtn_ssa_value *val = vtn_ssa_value(b, w[5]);
-         ssa->def = vtn_vector_extract(b, val->def, i);
+         ssa->def = nir_channel(&b->nb, val->def, i);
          vtn_local_store(b, ssa, arr_deref, p->type->access);
       }
    }
index b7eb31089cdbb10302522bed5401739e391f2429..3624ac3fa7e3996eedf4960663402bdca81b22ed 100644 (file)
@@ -797,10 +797,6 @@ struct vtn_ssa_value *vtn_create_ssa_value(struct vtn_builder *b,
 struct vtn_ssa_value *vtn_ssa_transpose(struct vtn_builder *b,
                                         struct vtn_ssa_value *src);
 
-nir_ssa_def *vtn_vector_extract(struct vtn_builder *b, nir_ssa_def *src,
-                                unsigned index);
-nir_ssa_def *vtn_vector_extract_dynamic(struct vtn_builder *b, nir_ssa_def *src,
-                                        nir_ssa_def *index);
 nir_ssa_def *vtn_vector_insert(struct vtn_builder *b, nir_ssa_def *src,
                                nir_ssa_def *insert, unsigned index);
 nir_ssa_def *vtn_vector_insert_dynamic(struct vtn_builder *b, nir_ssa_def *src,
index 1bb48642b3f11447784dd5c8bece54d20828b3fa..8bb00a5dd407444adcae72bd92edc56f3ea3ef6a 100644 (file)
@@ -735,11 +735,7 @@ vtn_local_load(struct vtn_builder *b, nir_deref_instr *src,
 
    if (src_tail != src) {
       val->type = src->type;
-      if (nir_src_is_const(src->arr.index))
-         val->def = vtn_vector_extract(b, val->def,
-                                       nir_src_as_uint(src->arr.index));
-      else
-         val->def = vtn_vector_extract_dynamic(b, val->def, src->arr.index.ssa);
+      val->def = nir_vector_extract(&b->nb, val->def, src->arr.index.ssa);
    }
 
    return val;