<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, May 11, 2016 at 12:09 PM, Rob Clark <span dir="ltr"><<a href="mailto:robdclark@gmail.com" target="_blank">robdclark@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">From: Rob Clark <<a href="mailto:robclark@freedesktop.org">robclark@freedesktop.org</a>><br>
<br>
It's what all the call-sites once, so gets rid of a bunch of inlined<br>
glsl_get_base_type() at the call-sites.<br></blockquote><div><br></div><div>Thank you!  This has been bothering me for a while.  At some point in the future, a glsl_get_base_type_bit_size() helper may be useful but there's no need for all the wrapping.<br><br></div><div>Reviewed-by: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Signed-off-by: Rob Clark <<a href="mailto:robclark@freedesktop.org">robclark@freedesktop.org</a>><br>
---<br>
Plus, for mediump, going to need glsl_get_base_type() to take a<br>
precision param.. this should make it less of a challenge to stay<br>
in 80 columns..<br>
<br>
 src/compiler/nir/glsl_to_nir.cpp            | 16 ++++++++--------<br>
 src/compiler/nir/nir.c                      |  2 +-<br>
 src/compiler/nir/nir_builder.h              |  2 +-<br>
 src/compiler/nir/nir_lower_locals_to_regs.c |  2 +-<br>
 src/compiler/nir/nir_lower_var_copies.c     |  3 +--<br>
 src/compiler/nir/nir_lower_vars_to_ssa.c    |  2 +-<br>
 src/compiler/nir_types.h                    |  4 ++--<br>
 src/compiler/spirv/spirv_to_nir.c           |  6 +++---<br>
 src/compiler/spirv/vtn_variables.c          |  4 ++--<br>
 9 files changed, 20 insertions(+), 21 deletions(-)<br>
<br>
diff --git a/src/compiler/nir/glsl_to_nir.cpp b/src/compiler/nir/glsl_to_nir.cpp<br>
index ee39a3c..9e53e59 100644<br>
--- a/src/compiler/nir/glsl_to_nir.cpp<br>
+++ b/src/compiler/nir/glsl_to_nir.cpp<br>
@@ -857,7 +857,7 @@ nir_visitor::visit(ir_call *ir)<br>
          instr->num_components = type->vector_elements;<br>
<br>
          /* Setup destination register */<br>
-         unsigned bit_size = glsl_get_bit_size(type->base_type);<br>
+         unsigned bit_size = glsl_get_bit_size(type);<br>
          nir_ssa_dest_init(&instr->instr, &instr->dest,<br>
                            type->vector_elements, bit_size, NULL);<br>
<br>
@@ -943,7 +943,7 @@ nir_visitor::visit(ir_call *ir)<br>
          instr->num_components = type->vector_elements;<br>
<br>
          /* Setup destination register */<br>
-         unsigned bit_size = glsl_get_bit_size(type->base_type);<br>
+         unsigned bit_size = glsl_get_bit_size(type);<br>
          nir_ssa_dest_init(&instr->instr, &instr->dest,<br>
                            type->vector_elements, bit_size, NULL);<br>
<br>
@@ -1006,7 +1006,7 @@ nir_visitor::visit(ir_call *ir)<br>
<br>
          /* Atomic result */<br>
          assert(ir->return_deref);<br>
-         unsigned bit_size = glsl_get_bit_size(ir->return_deref->type->base_type);<br>
+         unsigned bit_size = glsl_get_bit_size(ir->return_deref->type);<br>
          nir_ssa_dest_init(&instr->instr, &instr->dest,<br>
                            ir->return_deref->type->vector_elements,<br>
                            bit_size, NULL);<br>
@@ -1187,7 +1187,7 @@ nir_visitor::evaluate_rvalue(ir_rvalue* ir)<br>
       load_instr->num_components = ir->type->vector_elements;<br>
       load_instr->variables[0] = this->deref_head;<br>
       ralloc_steal(load_instr, load_instr->variables[0]);<br>
-      unsigned bit_size = glsl_get_bit_size(ir->type->base_type);<br>
+      unsigned bit_size = glsl_get_bit_size(ir->type);<br>
       add_instr(&load_instr->instr, ir->type->vector_elements, bit_size);<br>
    }<br>
<br>
@@ -1208,7 +1208,7 @@ nir_visitor::visit(ir_expression *ir)<br>
    case ir_binop_ubo_load: {<br>
       nir_intrinsic_instr *load =<br>
          nir_intrinsic_instr_create(this->shader, nir_intrinsic_load_ubo);<br>
-      unsigned bit_size = glsl_get_bit_size(ir->type->base_type);<br>
+      unsigned bit_size = glsl_get_bit_size(ir->type);<br>
       load->num_components = ir->type->vector_elements;<br>
       load->src[0] = nir_src_for_ssa(evaluate_rvalue(ir->operands[0]));<br>
       load->src[1] = nir_src_for_ssa(evaluate_rvalue(ir->operands[1]));<br>
@@ -1277,7 +1277,7 @@ nir_visitor::visit(ir_expression *ir)<br>
           intrin->intrinsic == nir_intrinsic_interp_var_at_sample)<br>
          intrin->src[0] = nir_src_for_ssa(evaluate_rvalue(ir->operands[1]));<br>
<br>
-      unsigned bit_size =  glsl_get_bit_size(deref->type->base_type);<br>
+      unsigned bit_size =  glsl_get_bit_size(deref->type);<br>
       add_instr(&intrin->instr, deref->type->vector_elements, bit_size);<br>
<br>
       if (swizzle) {<br>
@@ -1497,7 +1497,7 @@ nir_visitor::visit(ir_expression *ir)<br>
          nir_intrinsic_get_buffer_size);<br>
       load->num_components = ir->type->vector_elements;<br>
       load->src[0] = nir_src_for_ssa(evaluate_rvalue(ir->operands[0]));<br>
-      unsigned bit_size = glsl_get_bit_size(ir->type->base_type);<br>
+      unsigned bit_size = glsl_get_bit_size(ir->type);<br>
       add_instr(&load->instr, ir->type->vector_elements, bit_size);<br>
       return;<br>
    }<br>
@@ -1935,7 +1935,7 @@ nir_visitor::visit(ir_texture *ir)<br>
<br>
    assert(src_number == num_srcs);<br>
<br>
-   unsigned bit_size = glsl_get_bit_size(ir->type->base_type);<br>
+   unsigned bit_size = glsl_get_bit_size(ir->type);<br>
    add_instr(&instr->instr, nir_tex_instr_dest_size(instr), bit_size);<br>
 }<br>
<br>
diff --git a/src/compiler/nir/nir.c b/src/compiler/nir/nir.c<br>
index 867a43c..71adcb3 100644<br>
--- a/src/compiler/nir/nir.c<br>
+++ b/src/compiler/nir/nir.c<br>
@@ -694,7 +694,7 @@ nir_deref_get_const_initializer_load(nir_shader *shader, nir_deref_var *deref)<br>
       tail = tail->child;<br>
    }<br>
<br>
-   unsigned bit_size = glsl_get_bit_size(glsl_get_base_type(tail->type));<br>
+   unsigned bit_size = glsl_get_bit_size(tail->type);<br>
    nir_load_const_instr *load =<br>
       nir_load_const_instr_create(shader, glsl_get_vector_elements(tail->type),<br>
                                   bit_size);<br>
diff --git a/src/compiler/nir/nir_builder.h b/src/compiler/nir/nir_builder.h<br>
index 4fa9779..a142d48 100644<br>
--- a/src/compiler/nir/nir_builder.h<br>
+++ b/src/compiler/nir/nir_builder.h<br>
@@ -403,7 +403,7 @@ nir_load_var(nir_builder *build, nir_variable *var)<br>
    load->num_components = num_components;<br>
    load->variables[0] = nir_deref_var_create(load, var);<br>
    nir_ssa_dest_init(&load->instr, &load->dest, num_components,<br>
-                     glsl_get_bit_size(glsl_get_base_type(var->type)), NULL);<br>
+                     glsl_get_bit_size(var->type), NULL);<br>
    nir_builder_instr_insert(build, &load->instr);<br>
    return &load->dest.ssa;<br>
 }<br>
diff --git a/src/compiler/nir/nir_lower_locals_to_regs.c b/src/compiler/nir/nir_lower_locals_to_regs.c<br>
index 7c52c16..61cc7fa 100644<br>
--- a/src/compiler/nir/nir_lower_locals_to_regs.c<br>
+++ b/src/compiler/nir/nir_lower_locals_to_regs.c<br>
@@ -119,7 +119,7 @@ get_reg_for_deref(nir_deref_var *deref, struct locals_to_regs_state *state)<br>
    nir_register *reg = nir_local_reg_create(state->impl);<br>
    reg->num_components = glsl_get_vector_elements(tail->type);<br>
    reg->num_array_elems = array_size > 1 ? array_size : 0;<br>
-   reg->bit_size = glsl_get_bit_size(glsl_get_base_type(tail->type));<br>
+   reg->bit_size = glsl_get_bit_size(tail->type);<br>
<br>
    _mesa_hash_table_insert_pre_hashed(state->regs_table, hash, deref, reg);<br>
    nir_array_add(&state->derefs_array, nir_deref_var *, deref);<br>
diff --git a/src/compiler/nir/nir_lower_var_copies.c b/src/compiler/nir/nir_lower_var_copies.c<br>
index 1a7e2ee..b7e9989 100644<br>
--- a/src/compiler/nir/nir_lower_var_copies.c<br>
+++ b/src/compiler/nir/nir_lower_var_copies.c<br>
@@ -116,8 +116,7 @@ emit_copy_load_store(nir_intrinsic_instr *copy_instr,<br>
       assert(src_tail->type == dest_tail->type);<br>
<br>
       unsigned num_components = glsl_get_vector_elements(src_tail->type);<br>
-      unsigned bit_size =<br>
-         glsl_get_bit_size(glsl_get_base_type(src_tail->type));<br>
+      unsigned bit_size = glsl_get_bit_size(src_tail->type);<br>
<br>
       nir_intrinsic_instr *load =<br>
          nir_intrinsic_instr_create(mem_ctx, nir_intrinsic_load_var);<br>
diff --git a/src/compiler/nir/nir_lower_vars_to_ssa.c b/src/compiler/nir/nir_lower_vars_to_ssa.c<br>
index eae4075..d62cec0 100644<br>
--- a/src/compiler/nir/nir_lower_vars_to_ssa.c<br>
+++ b/src/compiler/nir/nir_lower_vars_to_ssa.c<br>
@@ -725,7 +725,7 @@ nir_lower_vars_to_ssa_impl(nir_function_impl *impl)<br>
       node->pb_value =<br>
          nir_phi_builder_add_value(state.phi_builder,<br>
                                    glsl_get_vector_elements(node->type),<br>
-                                   glsl_get_bit_size(glsl_get_base_type(node->type)),<br>
+                                   glsl_get_bit_size(node->type),<br>
                                    store_blocks);<br>
<br>
       if (node->deref->var->constant_initializer) {<br>
diff --git a/src/compiler/nir_types.h b/src/compiler/nir_types.h<br>
index 31e4d20..7d9917f 100644<br>
--- a/src/compiler/nir_types.h<br>
+++ b/src/compiler/nir_types.h<br>
@@ -82,9 +82,9 @@ unsigned glsl_get_record_location_offset(const struct glsl_type *type,<br>
                                          unsigned length);<br>
<br>
 static inline unsigned<br>
-glsl_get_bit_size(enum glsl_base_type type)<br>
+glsl_get_bit_size(const struct glsl_type *type)<br>
 {<br>
-   switch (type) {<br>
+   switch (glsl_get_base_type(type)) {<br>
    case GLSL_TYPE_INT:<br>
    case GLSL_TYPE_UINT:<br>
    case GLSL_TYPE_BOOL:<br>
diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c<br>
index 8d4f771..c65f971 100644<br>
--- a/src/compiler/spirv/spirv_to_nir.c<br>
+++ b/src/compiler/spirv/spirv_to_nir.c<br>
@@ -38,7 +38,7 @@ vtn_undef_ssa_value(struct vtn_builder *b, const struct glsl_type *type)<br>
<br>
    if (glsl_type_is_vector_or_scalar(type)) {<br>
       unsigned num_components = glsl_get_vector_elements(val->type);<br>
-      unsigned bit_size = glsl_get_bit_size(glsl_get_base_type(val->type));<br>
+      unsigned bit_size = glsl_get_bit_size(val->type);<br>
       val->def = nir_ssa_undef(&b->nb, num_components, bit_size);<br>
    } else {<br>
       unsigned elems = glsl_get_length(val->type);<br>
@@ -1034,7 +1034,7 @@ vtn_handle_constant(struct vtn_builder *b, SpvOp opcode,<br>
<br>
          unsigned num_components = glsl_get_vector_elements(val->const_type);<br>
          unsigned bit_size =<br>
-            glsl_get_bit_size(glsl_get_base_type(val->const_type));<br>
+            glsl_get_bit_size(val->const_type);<br>
<br>
          nir_const_value src[3];<br>
          assert(count <= 7);<br>
@@ -1783,7 +1783,7 @@ vtn_ssa_transpose(struct vtn_builder *b, struct vtn_ssa_value *src)<br>
    for (unsigned i = 0; i < glsl_get_matrix_columns(dest->type); i++) {<br>
       nir_alu_instr *vec = create_vec(b->shader,<br>
                                       glsl_get_matrix_columns(src->type),<br>
-                                      glsl_get_bit_size(glsl_get_base_type(src->type)));<br>
+                                      glsl_get_bit_size(src->type));<br>
       if (glsl_type_is_vector_or_scalar(src->type)) {<br>
           vec->src[0].src = nir_src_for_ssa(src->def);<br>
           vec->src[0].swizzle[0] = i;<br>
diff --git a/src/compiler/spirv/vtn_variables.c b/src/compiler/spirv/vtn_variables.c<br>
index d2f174c..bbe1166 100644<br>
--- a/src/compiler/spirv/vtn_variables.c<br>
+++ b/src/compiler/spirv/vtn_variables.c<br>
@@ -191,7 +191,7 @@ _vtn_local_load_store(struct vtn_builder *b, bool load, nir_deref_var *deref,<br>
       if (load) {<br>
          nir_ssa_dest_init(&intrin->instr, &intrin->dest,<br>
                            intrin->num_components,<br>
-                           glsl_get_bit_size(glsl_get_base_type(tail->type)),<br>
+                           glsl_get_bit_size(tail->type),<br>
                            NULL);<br>
          inout->def = &intrin->dest.ssa;<br>
       } else {<br>
@@ -414,7 +414,7 @@ _vtn_load_store_tail(struct vtn_builder *b, nir_intrinsic_op op, bool load,<br>
    if (load) {<br>
       nir_ssa_dest_init(&instr->instr, &instr->dest,<br>
                         instr->num_components,<br>
-                        glsl_get_bit_size(glsl_get_base_type(type)), NULL);<br>
+                        glsl_get_bit_size(type), NULL);<br>
       (*inout)->def = &instr->dest.ssa;<br>
    }<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
2.5.5<br>
<br>
</font></span></blockquote></div><br></div></div>