[Mesa-dev] [PATCH] glsl: Simplify aggregate type inference to prepare for ARB_arrays_of_arrays.
Matt Turner
mattst88 at gmail.com
Tue Jan 21 16:29:34 PST 2014
On Tue, Jan 21, 2014 at 4:14 PM, Paul Berry <stereotype441 at gmail.com> wrote:
> Most of the time it is not necessary to perform type inference to
> compile GLSL; the type of every expression can be inferred from the
> contents of the expression itself (and previous type declarations).
> The exception is aggregate initializers: their type is determined by
> the LHS of the variable being assigned to. For example, in the
> statement:
>
> mat2 foo = { { 1, 2 }, { 3, 4 } };
>
> the type of { 1, 2 } is only known to be vec2 (as opposed to, say,
> ivec2, uvec2, int[2], or a struct) because of the fact that the result
> is being assigned to a mat2.
>
> Previous to this patch, we handled this situation by doing some type
> inference during parsing: when parsing a declaration like the one
> above, we would call _mesa_set_aggregate_type(), which would infer the
> type of each aggregate initializer and store it in the corresponding
> ast_aggregate_initializer::constructor_type field. Since this
> happened at parse time, we couldn't do the type inference using
> glsl_type objects; we had to use ast_type_specifiers, which are much
> more awkward to work with. Things are about to get more complicated
> when we add support for ARB_arrays_of_arrays.
>
> This patch simplifies things by postponing the call to
> _mesa_set_aggregate_type() until ast-to-hir time, when we have access
> to glsl_type objects. As a side benefit, we only need to have one
> call to _mesa_set_aggregate_type() now, instead of six.
> ---
>
> Timothy: I was inspired to write this patch by the complexities you
> encountered during "[PATCH V2 5/8] glsl: Aggregate initializer support
> for arrays of array". Can you try rebasing your series on top of this
> patch to see if it simplifies things? I believe that with these
> changes, you should be able to drop patch 5/8 entirely.
>
> src/glsl/ast.h | 16 +++--
> src/glsl/ast_function.cpp | 8 +--
> src/glsl/ast_to_hir.cpp | 7 +++
> src/glsl/glsl_parser.yy | 27 --------
> src/glsl/glsl_parser_extras.cpp | 136 +++++++---------------------------------
> 5 files changed, 46 insertions(+), 148 deletions(-)
Nice! This is much better.
Reviewed-by: Matt Turner <mattst88 at gmail.com>
More information about the mesa-dev
mailing list