glsl: Fix type error when lowering integer divisions
authorPaul Berry <stereotype441@gmail.com>
Fri, 12 Aug 2011 17:20:34 +0000 (10:20 -0700)
committerPaul Berry <stereotype441@gmail.com>
Tue, 16 Aug 2011 18:00:46 +0000 (11:00 -0700)
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 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}.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/glsl/lower_instructions.cpp

index 806f863..23aa19b 100644 (file)
@@ -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) {