[Mesa-dev] [PATCH] glsl: Fix array indexing when constant folding built-in functions.

Ian Romanick idr at freedesktop.org
Mon Apr 1 11:30:09 PDT 2013


On 03/29/2013 02:13 PM, Paul Berry wrote:
> Mesa constant-folds built-in functions by using a miniature GLSL
> interpreter (see
> ir_function_signature::constant_expression_evaluate_expression_list()).
> This interpreter had a bug in its handling of array indexing, which
> caused expressions like "m[i][j]" (where m is a matrix) to be handled
> incorrectly.  Specifically, it incorrectly treated j as indexing into
> the whole matrix (rather than indexing just into the vector m[i]); as
> a result the offset computed for m[i] was lost and m[i][j] was treated
> as m[j][0].
>
> Fixes piglit tests inverse-mat[234].{vert,frag}.
>
> NOTE: This is a candidate for the 9.1 branch.

Good catch.  The test case fails only in 9.1 and later because it 
requires OpenGL 3.1, but I think the bug exists in earlier versions.

Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=57436

I already pushed my work-around to master (but not to 9.1).  You can 
revert it when you push this change if you like.

> ---
>   src/glsl/ir_constant_expression.cpp | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp
> index c2d0dc4..c09e56a 100644
> --- a/src/glsl/ir_constant_expression.cpp
> +++ b/src/glsl/ir_constant_expression.cpp
> @@ -1398,7 +1398,7 @@ ir_dereference_array::constant_referenced(struct hash_table *variable_context,
>         return;
>      }
>
> -   const glsl_type *vt = substore->type;
> +   const glsl_type *vt = array->type;
>      if (vt->is_array()) {
>         store = substore->get_array_element(index);
>         offset = 0;



More information about the mesa-dev mailing list