[Mesa-dev] [PATCH 2/5] glsl: add glsl_type::uniform_locations() helper function

Ian Romanick idr at freedesktop.org
Wed Jun 4 18:15:59 PDT 2014


On 05/26/2014 01:32 AM, Tapani Pälli wrote:
> This function calculates the number of uniform locations required
> by the type in UniformRemapTable.
> 
> Signed-off-by: Tapani Pälli <tapani.palli at intel.com>

With the two things mentioned below fixed,

Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>

> ---
>  src/glsl/glsl_types.cpp | 26 ++++++++++++++++++++++++++
>  src/glsl/glsl_types.h   |  6 ++++++
>  2 files changed, 32 insertions(+)
> 
> diff --git a/src/glsl/glsl_types.cpp b/src/glsl/glsl_types.cpp
> index 849a79a..7d326f1 100644
> --- a/src/glsl/glsl_types.cpp
> +++ b/src/glsl/glsl_types.cpp
> @@ -677,6 +677,32 @@ glsl_type::component_slots() const
>     return 0;
>  }
>  
> +unsigned
> +glsl_type::uniform_locations() const
> +{
> +   if (this->is_matrix())
> +      return 1;
> +
> +   unsigned size = 0;
> +
> +   switch (this->base_type) {
> +   case GLSL_TYPE_STRUCT:
> +   case GLSL_TYPE_INTERFACE:
> +      for (unsigned i = 0; i < this->length; i++)
> +	 size += this->fields.structure[i].type->uniform_locations();

Tab

> +      return size;
> +   case GLSL_TYPE_ARRAY:
> +      return this->length * this->fields.array->uniform_locations();
> +   default:
> +      break;
> +   }
> +
> +   /* The location count for many types match with component_slots() result,
> +    * all expections should be handled above.
> +    */
> +   return component_slots();
> +}
> +
>  bool
>  glsl_type::can_implicitly_convert_to(const glsl_type *desired) const
>  {
> diff --git a/src/glsl/glsl_types.h b/src/glsl/glsl_types.h
> index dca5492..fb66a48 100644
> --- a/src/glsl/glsl_types.h
> +++ b/src/glsl/glsl_types.h
> @@ -256,6 +256,12 @@ struct glsl_type {
>     unsigned component_slots() const;
>  
>     /**
> +    * Calculate the number of uniform locations required by this type in the
> +    * UniformRemapTable.

Rather than mention the internal data structure (that may change name or
go away some day), you could instead say that this is the number of
unique values from glGetUniformLocation for the elements of the type.

> +    */
> +   unsigned uniform_locations() const;
> +
> +   /**
>      * Calculate the number of attribute slots required to hold this type
>      *
>      * This implements the language rules of GLSL 1.50 for counting the number
> 



More information about the mesa-dev mailing list