[Mesa-dev] [PATCH 09/22] glsl: Fix calculation of std140 offset alignment for mat2s.

Kenneth Graunke kenneth at whitecape.org
Mon Aug 6 12:49:47 PDT 2012


On 07/31/2012 03:01 PM, Eric Anholt wrote:
> We were getting the base offset of a vec2, not of a vec2[2] like the quoted
> spec text says we should.
> ---
>  src/glsl/glsl_types.cpp |   13 +++++++++----
>  1 file changed, 9 insertions(+), 4 deletions(-)
> 
> diff --git a/src/glsl/glsl_types.cpp b/src/glsl/glsl_types.cpp
> index 3d78660..8e7ae42 100644
> --- a/src/glsl/glsl_types.cpp
> +++ b/src/glsl/glsl_types.cpp
> @@ -694,14 +694,19 @@ glsl_type::std140_base_alignment(bool row_major) const
>      *     row vectors with <C> components each, according to rule (4).
>      */
>     if (this->is_matrix()) {
> -      const struct glsl_type *vec_type;
> +      const struct glsl_type *vec_type, *array_type;
> +      int c = this->matrix_columns;
> +      int r = this->vector_elements;
> +
>        if (row_major) {
> -	 vec_type = get_instance(GLSL_TYPE_FLOAT, this->vector_elements, 1);
> +	 vec_type = get_instance(GLSL_TYPE_FLOAT, r, 1);
> +	 array_type = glsl_type::get_array_instance(vec_type, c);
>        } else {
> -	 vec_type = get_instance(GLSL_TYPE_FLOAT, this->matrix_columns, 1);
> +	 vec_type = get_instance(GLSL_TYPE_FLOAT, c, 1);
> +	 array_type = glsl_type::get_array_instance(vec_type, r);
>        }

Your row major and column major cases are backwards.  It turns out to be
the same since std140_base_alignment of any array type is the same.

Please reverse the then/else cases.  Then it's:
Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>

>  
> -      return vec_type->std140_base_alignment(false);
> +      return array_type->std140_base_alignment(false);
>     }
>  
>     /* (9) If the member is a structure, the base alignment of the
> 


More information about the mesa-dev mailing list