[Mesa-dev] [PATCH 3/4] glsl-to-tgsi: Use TGSI_FILE_TEMPORARY_ARRAY for indirect addressing

Tom Stellard tom at stellard.net
Thu Nov 8 06:48:04 PST 2012


Hi Brian,

Thanks for your review, I've noticed a few problems with this series
while working on the R600 LLVM backend.  I'll post updated patches that
incorporate your comments once I get everything sorted out.

On Wed, Nov 07, 2012 at 05:48:38PM -0700, Brian Paul wrote:
> On 11/05/2012 01:14 PM, Tom Stellard wrote:
> >From: Tom Stellard<thomas.stellard at amd.com>
> >
> >---
> >  src/mesa/main/mtypes.h                     |  1 +
> >  src/mesa/state_tracker/st_glsl_to_tgsi.cpp | 31 +++++++++++++++++++++++++++++-
> >  2 files changed, 31 insertions(+), 1 deletion(-)
> >
> >diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
> >index c8f2ca3..4aba5e8 100644
> >--- a/src/mesa/main/mtypes.h
> >+++ b/src/mesa/main/mtypes.h
> >@@ -1861,6 +1861,7 @@ typedef enum
> >     PROGRAM_SAMPLER,     /**<  for shader samplers, compile-time only */
> >     PROGRAM_SYSTEM_VALUE,/**<  InstanceId, PrimitiveID, etc. */
> >     PROGRAM_UNDEFINED,   /**<  Invalid/TBD value */
> >+   PROGRAM_ARRAY,       /**<  Values used by indirect addressing. */
> >     PROGRAM_FILE_MAX
> >  } gl_register_file;
> >
> >diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
> >index 14b72dc..151d40b 100644
> >--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
> >+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
> >@@ -306,6 +306,7 @@ public:
> >
> >     int glsl_version;
> >     bool native_integers;
> >+   bool temp_array_supported;
> >
> >     variable_storage *find_variable_storage(ir_variable *var);
> >
> >@@ -992,6 +993,12 @@ glsl_to_tgsi_visitor::get_temp(const glsl_type *type)
> >     } else {
> >        src.swizzle = swizzle_for_size(type->vector_elements);
> >     }
> >+
> >+   if (this->temp_array_supported&&
> >+       (type->is_array() || type->is_matrix())) {
> >+      src.file = PROGRAM_ARRAY;
> >+   }
> 
> So any GLSL array will wind up as PROGRAM_ARRAY /
> TGSI_FILE_TEMPORARY_ARRAY even if it's only indexed with
> compile-time constant expressions?
> 

This is how the code works now.  I think I'll add an optimization pass
that converts PROGRAM_ARRAY to PROGRAM_TEMP in in this case.  I'm not
sure there is a good way to handle this during the GLSL->TGSI
conversion.

-Tom
> 
> >+
> >     src.negate = 0;
> >
> >     return src;
> >@@ -2860,6 +2867,8 @@ glsl_to_tgsi_visitor::glsl_to_tgsi_visitor()
> >     indirect_addr_consts = false;
> >     glsl_version = 0;
> >     native_integers = false;
> >+   temp_array_supported = false;
> >+
> >     mem_ctx = ralloc_context(NULL);
> >     ctx = NULL;
> >     prog = NULL;
> >@@ -3690,6 +3699,7 @@ get_pixel_transfer_visitor(struct st_fragment_program *fp,
> >     v->shader_program = NULL;
> >     v->glsl_version = original->glsl_version;
> >     v->native_integers = original->native_integers;
> >+   v->temp_array_supported = original->temp_array_supported;
> >     v->options = original->options;
> >     v->next_temp = original->next_temp;
> >     v->num_address_regs = original->num_address_regs;
> >@@ -3821,6 +3831,7 @@ get_bitmap_visitor(struct st_fragment_program *fp,
> >     v->shader_program = NULL;
> >     v->glsl_version = original->glsl_version;
> >     v->native_integers = original->native_integers;
> >+   v->temp_array_supported = original->temp_array_supported;
> >     v->options = original->options;
> >     v->next_temp = original->next_temp;
> >     v->num_address_regs = original->num_address_regs;
> >@@ -3887,6 +3898,7 @@ struct st_translate {
> >     struct ureg_program *ureg;
> >
> >     struct ureg_dst temps[MAX_TEMPS];
> >+   struct ureg_dst array_temps[MAX_TEMPS];
> >     struct ureg_src *constants;
> >     struct ureg_src *immediates;
> >     struct ureg_dst outputs[PIPE_MAX_SHADER_OUTPUTS];
> >@@ -4030,6 +4042,11 @@ dst_register(struct st_translate *t,
> >     case PROGRAM_ADDRESS:
> >        return t->address[index];
> >
> >+   case PROGRAM_ARRAY:
> >+      if (ureg_dst_is_undef(t->array_temps[index]))
> >+         t->array_temps[index] = ureg_DECL_temporary_array(t->ureg, index);
> >+      return t->array_temps[index];
> >+
> >     default:
> >        assert(!"unknown dst register file");
> >        return ureg_dst_undef();
> >@@ -4085,6 +4102,12 @@ src_register(struct st_translate *t,
> >        assert(index<  (int) Elements(t->systemValues));
> >        return t->systemValues[index];
> >
> >+   case PROGRAM_ARRAY:
> >+      assert(index<  (int) Elements(t->array_temps));
> >+      if (ureg_dst_is_undef(t->array_temps[index]))
> >+         t->array_temps[index] = ureg_DECL_temporary_array(t->ureg, index);
> >+      return ureg_src(t->array_temps[index]);
> >+
> >     default:
> >        assert(!"unknown src register file");
> >        return ureg_src_undef();
> >@@ -4684,7 +4707,6 @@ st_translate_program(
> >         * (Note: the number of temporaries is equal to program->next_temp)
> >         */
> >        for (i = 0; i<  (unsigned)program->next_temp; i++) {
> >-         /* XXX use TGSI_FILE_TEMPORARY_ARRAY when it's supported by ureg */
> >           t->temps[i] = ureg_DECL_local_temporary(t->ureg);
> >        }
> >     }
> >@@ -4816,19 +4838,24 @@ get_mesa_program(struct gl_context *ctx,
> >     bool progress;
> >     struct gl_shader_compiler_options *options =
> >           &ctx->ShaderCompilerOptions[_mesa_shader_type_to_index(shader->Type)];
> >+   struct pipe_screen *pscreen = st_context(ctx)->pipe->screen;
> >+   unsigned processor_type;
> >
> >     switch (shader->Type) {
> >     case GL_VERTEX_SHADER:
> >        target = GL_VERTEX_PROGRAM_ARB;
> >        target_string = "vertex";
> >+      processor_type = PIPE_SHADER_VERTEX;
> >        break;
> >     case GL_FRAGMENT_SHADER:
> >        target = GL_FRAGMENT_PROGRAM_ARB;
> >        target_string = "fragment";
> >+      processor_type = PIPE_SHADER_FRAGMENT;
> >        break;
> >     case GL_GEOMETRY_SHADER:
> >        target = GL_GEOMETRY_PROGRAM_NV;
> >        target_string = "geometry";
> >+      processor_type = PIPE_SHADER_GEOMETRY;
> >        break;
> >     default:
> >        assert(!"should not be reached");
> >@@ -4848,6 +4875,8 @@ get_mesa_program(struct gl_context *ctx,
> >     v->options = options;
> >     v->glsl_version = ctx->Const.GLSLVersion;
> >     v->native_integers = ctx->Const.NativeIntegers;
> >+   v->temp_array_supported = pscreen->get_shader_param(pscreen, processor_type,
> >+                                    PIPE_SHADER_CAP_INDIRECT_TEMP_ARRAY_ADDR );
> >
> >     _mesa_generate_parameters_list_for_uniforms(shader_program, shader,
> >  					       prog->Parameters);
> 
> Reviewed-by: Brian Paul <brianp at vmware.com>
> 
> Patch 4 looks OK too, but I'm not an r600 person.
> 
> -Brian


More information about the mesa-dev mailing list