[Mesa-dev] [PATCH] glsl: Fix type mismatch when incrementing or decrementing uint.

Kenneth Graunke kenneth at whitecape.org
Mon Oct 31 23:24:55 PDT 2011


On 10/31/2011 08:34 PM, Paul Berry wrote:
> When converting an expression like "++x" to GLSL IR we were failing to
> account for the possibility that x might be an unsigned integral type.
> As a result the user would receive a bogus error message "Could not
> implicitly convert operands to arithmetic operator".
> 
> Fixes piglit tests {vs,fs}-{increment,decrement}-uint.
> ---
>  src/glsl/ast_to_hir.cpp |   31 +++++++++++++++++++++++--------
>  1 files changed, 23 insertions(+), 8 deletions(-)
> 
> diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
> index 7584fdf..a4eec50 100644
> --- a/src/glsl/ast_to_hir.cpp
> +++ b/src/glsl/ast_to_hir.cpp
> @@ -935,6 +935,27 @@ check_builtin_array_max_size(const char *name, unsigned size,
>     return false;
>  }
>  
> +/**
> + * Create the constant 1, with the given GLSL type, for use in increment and
> + * decrement operators.
> + *
> + * If the given type is invalid for increment and decrement operators, return
> + * a floating point 1--the error will be detected later.
> + */
> +static ir_rvalue *
> +constant_one_for_inc_dec(void *ctx, const glsl_type *type)
> +{
> +   switch (type->base_type) {
> +   case GLSL_TYPE_UINT:
> +      return new(ctx) ir_constant((unsigned) 1);
> +   case GLSL_TYPE_INT:
> +      return new(ctx) ir_constant(1);
> +   default:
> +   case GLSL_TYPE_FLOAT:
> +      return new(ctx) ir_constant(1.0f);
> +   }
> +}

Perhaps it would be cleaner to add a new ir_constant::one static method
similar to ir_constant::zero?  There's nothing really inc/dec specific
about this, and it might be more useful in general...

Otherwise, looks like a good fix.  Thanks!

Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
(if you decide to go with this instead of taking my suggestion)


More information about the mesa-dev mailing list