[Mesa-dev] [PATCH 09/11] glsl_to_tgsi: each reladdr object should have only one parent

Nicolai Hähnle nhaehnle at gmail.com
Mon Oct 2 10:58:55 UTC 2017


On 29.09.2017 14:25, Marek Olšák wrote:
> From: Marek Olšák <marek.olsak at amd.com>
> 
> required by rename_temp_registers.
> ---
>   src/mesa/state_tracker/st_glsl_to_tgsi_private.cpp | 66 ++++++++++++++++++++--
>   src/mesa/state_tracker/st_glsl_to_tgsi_private.h   |  4 ++
>   2 files changed, 65 insertions(+), 5 deletions(-)
> 
> diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi_private.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi_private.cpp
> index 0075ae8..5fb7b357 100644
> --- a/src/mesa/state_tracker/st_glsl_to_tgsi_private.cpp
> +++ b/src/mesa/state_tracker/st_glsl_to_tgsi_private.cpp
> @@ -37,20 +37,36 @@ static int swizzle_for_type(const glsl_type *type, int component = 0)
>            num_elements = type->vector_elements;
>      }
>   
>      int swizzle = swizzle_for_size(num_elements);
>      assert(num_elements + component <= 4);
>   
>      swizzle += component * MAKE_SWIZZLE4(1, 1, 1, 1);
>      return swizzle;
>   }
>   
> +static st_src_reg *
> +dup_reladdr(const st_src_reg *input)
> +{
> +   if (!input)
> +      return NULL;
> +
> +   st_src_reg *reg = ralloc(input, st_src_reg);
> +   if (!reg) {
> +      assert("can't create reladdr, expect shader breakage");

Add a ! for this to fire.

Cheers,
Nicolai


> +      return NULL;
> +   }
> +
> +   *reg = *input;
> +   return reg;
> +}
> +
>   st_src_reg::st_src_reg(gl_register_file file, int index, const glsl_type *type,
>                          int component, unsigned array_id)
>   {
>      assert(file != PROGRAM_ARRAY || array_id != 0);
>      this->file = file;
>      this->index = index;
>      this->swizzle = swizzle_for_type(type, component);
>      this->negate = 0;
>      this->abs = 0;
>      this->index2D = 0;
> @@ -109,54 +125,76 @@ st_src_reg::st_src_reg()
>      this->negate = 0;
>      this->abs = 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::st_src_reg(const st_src_reg &reg)
> +{
> +   *this = reg;
> +}
> +
> +void st_src_reg::operator=(const st_src_reg &reg)
> +{
> +   this->type = reg.type;
> +   this->file = reg.file;
> +   this->index = reg.index;
> +   this->index2D = reg.index2D;
> +   this->swizzle = reg.swizzle;
> +   this->negate = reg.negate;
> +   this->abs = reg.abs;
> +   this->reladdr = dup_reladdr(reg.reladdr);
> +   this->reladdr2 = dup_reladdr(reg.reladdr2);
> +   this->has_index2 = reg.has_index2;
> +   this->double_reg2 = reg.double_reg2;
> +   this->array_id = reg.array_id;
> +   this->is_double_vertex_input = reg.is_double_vertex_input;
> +}
> +
>   st_src_reg::st_src_reg(st_dst_reg reg)
>   {
>      this->type = reg.type;
>      this->file = reg.file;
>      this->index = reg.index;
>      this->swizzle = SWIZZLE_XYZW;
>      this->negate = 0;
>      this->abs = 0;
> -   this->reladdr = reg.reladdr;
> +   this->reladdr = dup_reladdr(reg.reladdr);
>      this->index2D = reg.index2D;
> -   this->reladdr2 = reg.reladdr2;
> +   this->reladdr2 = dup_reladdr(reg.reladdr2);
>      this->has_index2 = reg.has_index2;
>      this->double_reg2 = false;
>      this->array_id = reg.array_id;
>      this->is_double_vertex_input = false;
>   }
>   
>   st_src_reg st_src_reg::get_abs()
>   {
>      st_src_reg reg = *this;
>      reg.negate = 0;
>      reg.abs = 1;
>      return reg;
>   }
>   
>   st_dst_reg::st_dst_reg(st_src_reg reg)
>   {
>      this->type = reg.type;
>      this->file = reg.file;
>      this->index = reg.index;
>      this->writemask = WRITEMASK_XYZW;
> -   this->reladdr = reg.reladdr;
> +   this->reladdr = dup_reladdr(reg.reladdr);
>      this->index2D = reg.index2D;
> -   this->reladdr2 = reg.reladdr2;
> +   this->reladdr2 = dup_reladdr(reg.reladdr2);
>      this->has_index2 = reg.has_index2;
>      this->array_id = reg.array_id;
>   }
>   
>   st_dst_reg::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;
> @@ -186,11 +224,29 @@ st_dst_reg::st_dst_reg()
>   {
>      this->type = GLSL_TYPE_ERROR;
>      this->file = PROGRAM_UNDEFINED;
>      this->index = 0;
>      this->index2D = 0;
>      this->writemask = 0;
>      this->reladdr = NULL;
>      this->reladdr2 = NULL;
>      this->has_index2 = false;
>      this->array_id = 0;
> -}
> \ No newline at end of file
> +}
> +
> +st_dst_reg::st_dst_reg(const st_dst_reg &reg)
> +{
> +   *this = reg;
> +}
> +
> +void st_dst_reg::operator=(const st_dst_reg &reg)
> +{
> +   this->type = reg.type;
> +   this->file = reg.file;
> +   this->index = reg.index;
> +   this->writemask = reg.writemask;
> +   this->reladdr = dup_reladdr(reg.reladdr);
> +   this->index2D = reg.index2D;
> +   this->reladdr2 = dup_reladdr(reg.reladdr2);
> +   this->has_index2 = reg.has_index2;
> +   this->array_id = reg.array_id;
> +}
> diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi_private.h b/src/mesa/state_tracker/st_glsl_to_tgsi_private.h
> index c92d96c..b9112e5 100644
> --- a/src/mesa/state_tracker/st_glsl_to_tgsi_private.h
> +++ b/src/mesa/state_tracker/st_glsl_to_tgsi_private.h
> @@ -40,20 +40,22 @@ class st_dst_reg;
>   class st_src_reg {
>   public:
>      st_src_reg(gl_register_file file, int index, const glsl_type *type,
>                 int component = 0, unsigned array_id = 0);
>   
>      st_src_reg(gl_register_file file, int index, enum glsl_base_type type);
>   
>      st_src_reg(gl_register_file file, int index, enum glsl_base_type type, int index2D);
>   
>      st_src_reg();
> +   st_src_reg(const st_src_reg &reg);
> +   void operator=(const st_src_reg &reg);
>   
>      explicit st_src_reg(st_dst_reg reg);
>   
>      st_src_reg get_abs();
>   
>      int32_t index; /**< temporary index, VERT_ATTRIB_*, VARYING_SLOT_*, etc. */
>      int16_t index2D;
>   
>      uint16_t swizzle; /**< SWIZZLE_XYZWONEZERO swizzles from Mesa. */
>      int negate:4; /**< NEGATE_XYZW mask from mesa */
> @@ -74,20 +76,22 @@ public:
>   
>   };
>   
>   class st_dst_reg {
>   public:
>      st_dst_reg(gl_register_file file, int writemask, enum glsl_base_type type, int index);
>   
>      st_dst_reg(gl_register_file file, int writemask, enum glsl_base_type type);
>   
>      st_dst_reg();
> +   st_dst_reg(const st_dst_reg &reg);
> +   void operator=(const st_dst_reg &reg);
>   
>      explicit st_dst_reg(st_src_reg reg);
>   
>      int32_t index; /**< temporary index, VERT_ATTRIB_*, VARYING_SLOT_*, etc. */
>      int16_t index2D;
>      gl_register_file file:5; /**< PROGRAM_* from Mesa */
>      unsigned writemask:4; /**< Bitfield of WRITEMASK_[XYZW] */
>      enum glsl_base_type type:5; /** GLSL_TYPE_* from GLSL IR (enum glsl_base_type) */
>      unsigned has_index2:1;
>      unsigned array_id:10;
> 


-- 
Lerne, wie die Welt wirklich ist,
Aber vergiss niemals, wie sie sein sollte.


More information about the mesa-dev mailing list