On 31 October 2011 23:24, Kenneth Graunke <span dir="ltr"><<a href="mailto:kenneth@whitecape.org">kenneth@whitecape.org</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div><div></div><div class="h5">On 10/31/2011 08:34 PM, Paul Berry wrote:<br>
> When converting an expression like "++x" to GLSL IR we were failing to<br>
> account for the possibility that x might be an unsigned integral type.<br>
> As a result the user would receive a bogus error message "Could not<br>
> implicitly convert operands to arithmetic operator".<br>
><br>
> Fixes piglit tests {vs,fs}-{increment,decrement}-uint.<br>
> ---<br>
> src/glsl/ast_to_hir.cpp | 31 +++++++++++++++++++++++--------<br>
> 1 files changed, 23 insertions(+), 8 deletions(-)<br>
><br>
> diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp<br>
> index 7584fdf..a4eec50 100644<br>
> --- a/src/glsl/ast_to_hir.cpp<br>
> +++ b/src/glsl/ast_to_hir.cpp<br>
> @@ -935,6 +935,27 @@ check_builtin_array_max_size(const char *name, unsigned size,<br>
> return false;<br>
> }<br>
><br>
> +/**<br>
> + * Create the constant 1, with the given GLSL type, for use in increment and<br>
> + * decrement operators.<br>
> + *<br>
> + * If the given type is invalid for increment and decrement operators, return<br>
> + * a floating point 1--the error will be detected later.<br>
> + */<br>
> +static ir_rvalue *<br>
> +constant_one_for_inc_dec(void *ctx, const glsl_type *type)<br>
> +{<br>
> + switch (type->base_type) {<br>
> + case GLSL_TYPE_UINT:<br>
> + return new(ctx) ir_constant((unsigned) 1);<br>
> + case GLSL_TYPE_INT:<br>
> + return new(ctx) ir_constant(1);<br>
> + default:<br>
> + case GLSL_TYPE_FLOAT:<br>
> + return new(ctx) ir_constant(1.0f);<br>
> + }<br>
> +}<br>
<br>
</div></div>Perhaps it would be cleaner to add a new ir_constant::one static method<br>
similar to ir_constant::zero? There's nothing really inc/dec specific<br>
about this, and it might be more useful in general...<br></blockquote><div><br>The difficulty is that this function doesn't actually return a constant 1 of the given type--it returns a constant 1 of a type which is suitable for incrementing and decrementing values of the given type. For example, if type is vec4, this function creates a constant value of 1.0 having type float. (My comments in the code seem to contradict this--I'll fix that). IMHO, that makes this function specific enough to increment/decrement that it belongs here.<br>
</div></div>