[Mesa-dev] [PATCH 01/14] glsl_to_tgsi: use array_id for temp arrays instead of hacking high bits

Marek Olšák maraeo at gmail.com
Mon Oct 17 13:39:13 UTC 2016


From: Marek Olšák <marek.olsak at amd.com>

---
 src/mesa/state_tracker/st_glsl_to_tgsi.cpp | 31 ++++++++++++++++++------------
 1 file changed, 19 insertions(+), 12 deletions(-)

diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index fd2485d..5bc2661 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -83,54 +83,57 @@ static int swizzle_for_type(const glsl_type *type, int component = 0)
    swizzle += component * MAKE_SWIZZLE4(1, 1, 1, 1);
    return swizzle;
 }
 
 /**
  * This struct is a corresponding struct to TGSI ureg_src.
  */
 class st_src_reg {
 public:
    st_src_reg(gl_register_file file, int index, const glsl_type *type,
-              int component = 0)
+              int component = 0, unsigned array_id = 0)
    {
+      assert(file != PROGRAM_ARRAY || array_id != 0);
       this->file = file;
       this->index = index;
       this->swizzle = swizzle_for_type(type, component);
       this->negate = 0;
       this->index2D = 0;
       this->type = type ? type->base_type : GLSL_TYPE_ERROR;
       this->reladdr = NULL;
       this->reladdr2 = NULL;
       this->has_index2 = false;
       this->double_reg2 = false;
-      this->array_id = 0;
+      this->array_id = array_id;
       this->is_double_vertex_input = false;
    }
 
    st_src_reg(gl_register_file file, int index, enum glsl_base_type type)
    {
+      assert(file != PROGRAM_ARRAY); /* need array_id > 0 */
       this->type = type;
       this->file = file;
       this->index = index;
       this->index2D = 0;
       this->swizzle = SWIZZLE_XYZW;
       this->negate = 0;
       this->reladdr = NULL;
       this->reladdr2 = NULL;
       this->has_index2 = false;
       this->double_reg2 = false;
       this->array_id = 0;
       this->is_double_vertex_input = false;
    }
 
    st_src_reg(gl_register_file file, int index, enum glsl_base_type type, int index2D)
    {
+      assert(file != PROGRAM_ARRAY); /* need array_id > 0 */
       this->type = type;
       this->file = file;
       this->index = index;
       this->index2D = index2D;
       this->swizzle = SWIZZLE_XYZW;
       this->negate = 0;
       this->reladdr = NULL;
       this->reladdr2 = NULL;
       this->has_index2 = false;
       this->double_reg2 = false;
@@ -172,33 +175,35 @@ public:
     */
    bool double_reg2;
    unsigned array_id;
    bool is_double_vertex_input;
 };
 
 class st_dst_reg {
 public:
    st_dst_reg(gl_register_file file, int writemask, enum glsl_base_type type, int index)
    {
+      assert(file != PROGRAM_ARRAY); /* need array_id > 0 */
       this->file = file;
       this->index = index;
       this->index2D = 0;
       this->writemask = writemask;
       this->reladdr = NULL;
       this->reladdr2 = NULL;
       this->has_index2 = false;
       this->type = type;
       this->array_id = 0;
    }
 
    st_dst_reg(gl_register_file file, int writemask, enum glsl_base_type type)
    {
+      assert(file != PROGRAM_ARRAY); /* need array_id > 0 */
       this->file = file;
       this->index = 0;
       this->index2D = 0;
       this->writemask = writemask;
       this->reladdr = NULL;
       this->reladdr2 = NULL;
       this->has_index2 = false;
       this->type = type;
       this->array_id = 0;
    }
@@ -289,21 +294,21 @@ public:
    class function_entry *function; /* Set on TGSI_OPCODE_CAL or TGSI_OPCODE_BGNSUB */
    const struct tgsi_opcode_info *info;
 };
 
 class variable_storage : public exec_node {
 public:
    variable_storage(ir_variable *var, gl_register_file file, int index,
                     unsigned array_id = 0)
       : file(file), index(index), component(0), var(var), array_id(array_id)
    {
-      /* empty */
+      assert(file != PROGRAM_ARRAY || array_id != 0);
    }
 
    gl_register_file file;
    int index;
 
    /* Explicit component location. This is given in terms of the GLSL-style
     * swizzles where each double is a single component, i.e. for 64-bit types
     * it can only be 0 or 1.
     */
    int component;
@@ -1255,21 +1260,22 @@ glsl_to_tgsi_visitor::get_temp(const glsl_type *type)
    src.negate = 0;
 
    if (!options->EmitNoIndirectTemp && type_has_array_or_matrix(type)) {
       if (next_array >= max_num_arrays) {
          max_num_arrays += 32;
          array_sizes = (unsigned*)
             realloc(array_sizes, sizeof(array_sizes[0]) * max_num_arrays);
       }
 
       src.file = PROGRAM_ARRAY;
-      src.index = next_array << 16 | 0x8000;
+      src.index = 0;
+      src.array_id = next_array + 1;
       array_sizes[next_array] = type_size(type);
       ++next_array;
 
    } else {
       src.file = PROGRAM_TEMPORARY;
       src.index = next_temp;
       next_temp += type_size(type);
    }
 
    if (type->is_array() || type->is_record()) {
@@ -1330,21 +1336,22 @@ glsl_to_tgsi_visitor::visit(ir_variable *ir)
          dst = undef_dst;
       } else {
          /* The variable_storage constructor allocates slots based on the size
           * of the type.  However, this had better match the number of state
           * elements that we're going to copy into the new temporary.
           */
          assert((int) ir->get_num_state_slots() == type_size(ir->type));
 
          dst = st_dst_reg(get_temp(ir->type));
 
-         storage = new(mem_ctx) variable_storage(ir, dst.file, dst.index);
+         storage = new(mem_ctx) variable_storage(ir, dst.file, dst.index,
+                                                 dst.array_id);
 
          this->variables.push_tail(storage);
       }
 
 
       for (unsigned int i = 0; i < ir->get_num_state_slots(); i++) {
          int index = _mesa_add_state_reference(this->prog->Parameters,
                                                (gl_state_index *)slots[i].tokens);
 
          if (storage->file == PROGRAM_STATE_VAR) {
@@ -2488,33 +2495,35 @@ glsl_to_tgsi_visitor::visit(ir_dereference_variable *ir)
       }
       case ir_var_system_value:
          entry = new(mem_ctx) variable_storage(var,
                                                PROGRAM_SYSTEM_VALUE,
                                                var->data.location);
          break;
       case ir_var_auto:
       case ir_var_temporary:
          st_src_reg src = get_temp(var->type);
 
-         entry = new(mem_ctx) variable_storage(var, src.file, src.index);
+         entry = new(mem_ctx) variable_storage(var, src.file, src.index,
+                                               src.array_id);
          this->variables.push_tail(entry);
 
          break;
       }
 
       if (!entry) {
          printf("Failed to make storage for %s\n", var->name);
          exit(1);
       }
    }
 
-   this->result = st_src_reg(entry->file, entry->index, var->type, entry->component);
+   this->result = st_src_reg(entry->file, entry->index, var->type,
+                             entry->component, entry->array_id);
    this->result.array_id = entry->array_id;
    if (this->shader->Stage == MESA_SHADER_VERTEX && var->data.mode == ir_var_shader_in && var->type->is_double())
       this->result.is_double_vertex_input = true;
    if (!native_integers)
       this->result.type = GLSL_TYPE_FLOAT;
 }
 
 static void
 shrink_array_declarations(struct inout_decl *decls, unsigned count,
                           GLbitfield64* usage_mask,
@@ -5489,30 +5498,28 @@ dst_register(struct st_translate *t, gl_register_file file, unsigned index,
          memset(t->temps + t->temps_size, 0, inc * sizeof(struct ureg_dst));
          t->temps_size += inc;
       }
 
       if (ureg_dst_is_undef(t->temps[index]))
          t->temps[index] = ureg_DECL_local_temporary(t->ureg);
 
       return t->temps[index];
 
    case PROGRAM_ARRAY:
-      array = index >> 16;
-
-      assert(array < t->num_temp_arrays);
+      assert(array_id && array_id <= t->num_temp_arrays);
+      array = array_id - 1;
 
       if (ureg_dst_is_undef(t->arrays[array]))
          t->arrays[array] = ureg_DECL_array_temporary(
             t->ureg, t->array_sizes[array], TRUE);
 
-      return ureg_dst_array_offset(t->arrays[array],
-                                   (int)(index & 0xFFFF) - 0x8000);
+      return ureg_dst_array_offset(t->arrays[array], index);
 
    case PROGRAM_OUTPUT:
       if (!array_id) {
          if (t->procType == PIPE_SHADER_FRAGMENT)
             assert(index < 2 * FRAG_RESULT_MAX);
          else if (t->procType == PIPE_SHADER_TESS_CTRL ||
                   t->procType == PIPE_SHADER_TESS_EVAL)
             assert(index < VARYING_SLOT_TESS_MAX);
          else
             assert(index < VARYING_SLOT_MAX);
-- 
2.7.4



More information about the mesa-dev mailing list