[Mesa-dev] [PATCH] glsl: Fix type error when lowering integer divisions

Eric Anholt eric at anholt.net
Sat Aug 13 10:04:44 PDT 2011


On Fri, 12 Aug 2011 10:38:35 -0700, Paul Berry <stereotype441 at gmail.com> wrote:
> This patch fixes a bug when lowering an integer division:
> 
>   x/y
> 
> to a multiplication by a reciprocal:
> 
>   int(float(x)*reciprocal(float(y)))
> 
> If x was a a plain int and y was an ivecN, the lowering pass
> incorrectly assigned the type of the product to be float, when in fact
> it should be vecN.  This caused mesa to abort with an IR validation
> error.
> 
> Fixes piglit tests {fs,vs}-op-div-int-ivec{2,3,4}.
> ---
>  src/glsl/lower_instructions.cpp |    4 ++++
>  1 files changed, 4 insertions(+), 0 deletions(-)
> 
> diff --git a/src/glsl/lower_instructions.cpp b/src/glsl/lower_instructions.cpp
> index 806f863..23aa19b 100644
> --- a/src/glsl/lower_instructions.cpp
> +++ b/src/glsl/lower_instructions.cpp
> @@ -166,6 +166,10 @@ lower_instructions_visitor::div_to_mul_rcp(ir_expression *ir)
>        else
>  	 op0 = new(ir) ir_expression(ir_unop_u2f, vec_type, ir->operands[0], NULL);
>  
> +      vec_type = glsl_type::get_instance(GLSL_TYPE_FLOAT,
> +					 ir->type->vector_elements,
> +					 ir->type->matrix_columns);
> +
>        op0 = new(ir) ir_expression(ir_binop_mul, vec_type, op0, op1);
>  
>        if (ir->operands[1]->type->base_type == GLSL_TYPE_INT) {

You could just drop the type argument to ir_expression and let it figure
out the right answer for you.

Oh, and we'll want a test to make sure we're not doing this
approximation when we shouldn't be in GLSL 1.30 -- we have actual
integer division hardware we should be using.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20110813/1b906f90/attachment.pgp>


More information about the mesa-dev mailing list