[Mesa-dev] [PATCH 05/19] st_glsl_to_tgsi: add temp_array_decl structure

Nicolai Hähnle nhaehnle at gmail.com
Tue Aug 9 10:36:34 UTC 2016


From: Nicolai Hähnle <nicolai.haehnle at amd.com>

We will use it to save the type-based usagemask.

While we're at it, rename the variable to temp_arrays etc. analogous to
{input,output}_arrays.
---
 src/mesa/state_tracker/st_glsl_to_tgsi.cpp | 36 +++++++++++++++++-------------
 1 file changed, 20 insertions(+), 16 deletions(-)

diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index aa83f0a..0913dbb 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -339,20 +339,24 @@ public:
 static st_src_reg undef_src = st_src_reg(PROGRAM_UNDEFINED, 0, GLSL_TYPE_ERROR);
 static st_dst_reg undef_dst = st_dst_reg(PROGRAM_UNDEFINED, SWIZZLE_NOOP, GLSL_TYPE_ERROR);
 
 struct array_decl {
    unsigned mesa_index;
    unsigned array_id;
    unsigned array_size;
    enum glsl_base_type array_type;
 };
 
+struct temp_array_decl {
+   unsigned size;
+};
+
 static enum glsl_base_type
 find_array_type(struct array_decl *arrays, unsigned count, unsigned array_id)
 {
    unsigned i;
 
    for (i = 0; i < count; i++) {
       struct array_decl *decl = &arrays[i];
 
       if (array_id == decl->array_id) {
          return decl->array_type;
@@ -374,23 +378,23 @@ public:
    function_entry *current_function;
 
    struct gl_context *ctx;
    struct gl_program *prog;
    struct gl_shader_program *shader_program;
    struct gl_linked_shader *shader;
    struct gl_shader_compiler_options *options;
 
    int next_temp;
 
-   unsigned *array_sizes;
-   unsigned max_num_arrays;
-   unsigned next_array;
+   struct temp_array_decl *temp_arrays;
+   unsigned max_num_temp_arrays;
+   unsigned num_temp_arrays;
 
    struct array_decl input_arrays[PIPE_MAX_SHADER_INPUTS];
    unsigned num_input_arrays;
    struct array_decl output_arrays[PIPE_MAX_SHADER_OUTPUTS];
    unsigned num_output_arrays;
 
    int num_address_regs;
    uint32_t samplers_used;
    glsl_base_type sampler_types[PIPE_MAX_SAMPLERS];
    int sampler_targets[PIPE_MAX_SAMPLERS];   /**< One of TGSI_TEXTURE_* */
@@ -1208,30 +1212,30 @@ type_has_array_or_matrix(const glsl_type *type)
 st_src_reg
 glsl_to_tgsi_visitor::get_temp(const glsl_type *type)
 {
    st_src_reg src;
 
    src.type = native_integers ? type->base_type : GLSL_TYPE_FLOAT;
    src.reladdr = NULL;
    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);
+      if (num_temp_arrays >= max_num_temp_arrays) {
+         max_num_temp_arrays += 32;
+         temp_arrays = (temp_array_decl*)
+            realloc(temp_arrays, sizeof(temp_arrays[0]) * max_num_temp_arrays);
       }
 
       src.file = PROGRAM_ARRAY;
-      src.index = next_array << 16 | 0x8000;
-      array_sizes[next_array] = type_size(type);
-      ++next_array;
+      src.index = num_temp_arrays << 16 | 0x8000;
+      temp_arrays[num_temp_arrays].size = type_size(type);
+      ++num_temp_arrays;
 
    } else {
       src.file = PROGRAM_TEMPORARY;
       src.index = next_temp;
       next_temp += type_size(type);
    }
 
    if (type->is_array() || type->is_record()) {
       src.swizzle = SWIZZLE_NOOP;
    } else {
@@ -4273,23 +4277,23 @@ glsl_to_tgsi_visitor::visit(ir_barrier *ir)
 
    emit_asm(ir, TGSI_OPCODE_BARRIER);
 }
 
 glsl_to_tgsi_visitor::glsl_to_tgsi_visitor()
 {
    STATIC_ASSERT(sizeof(samplers_used) * 8 >= PIPE_MAX_SAMPLERS);
 
    result.file = PROGRAM_UNDEFINED;
    next_temp = 1;
-   array_sizes = NULL;
-   max_num_arrays = 0;
-   next_array = 0;
+   temp_arrays = NULL;
+   max_num_temp_arrays = 0;
+   num_temp_arrays = 0;
    num_input_arrays = 0;
    num_output_arrays = 0;
    next_signature_id = 1;
    num_immediates = 0;
    current_function = NULL;
    num_address_regs = 0;
    samplers_used = 0;
    buffers_used = 0;
    images_used = 0;
    indirect_addr_consts = false;
@@ -4302,21 +4306,21 @@ glsl_to_tgsi_visitor::glsl_to_tgsi_visitor()
    shader_program = NULL;
    shader = NULL;
    options = NULL;
    have_sqrt = false;
    have_fma = false;
    use_shared_memory = false;
 }
 
 glsl_to_tgsi_visitor::~glsl_to_tgsi_visitor()
 {
-   free(array_sizes);
+   free(temp_arrays);
    ralloc_free(mem_ctx);
 }
 
 extern "C" void free_glsl_to_tgsi_visitor(glsl_to_tgsi_visitor *v)
 {
    delete v;
 }
 
 
 /**
@@ -6027,27 +6031,27 @@ st_translate_program(
    }
 
    t->procType = procType;
    t->inputMapping = inputMapping;
    t->outputMapping = outputMapping;
    t->ureg = ureg;
 
    /*
     * Declare temporary arrays.
     */
-   t->num_temp_arrays = program->next_array;
+   t->num_temp_arrays = program->num_temp_arrays;
    if (t->num_temp_arrays) {
       t->temp_arrays = (struct ureg_dst*)
                        calloc(1, sizeof(t->temp_arrays[0]) * t->num_temp_arrays);
       for (i = 0; i < t->num_temp_arrays; ++i)
          t->temp_arrays[i] = ureg_DECL_array_temporary(
-            t->ureg, program->array_sizes[i], TGSI_WRITEMASK_XYZW, TRUE);
+            t->ureg, program->temp_arrays[i].size, TGSI_WRITEMASK_XYZW, TRUE);
    }
 
    /*
     * Declare input attributes.
     */
    switch (procType) {
    case PIPE_SHADER_FRAGMENT:
       for (i = 0; i < numInputs; i++) {
          unsigned array_id = 0;
          unsigned array_size;
-- 
2.7.4



More information about the mesa-dev mailing list