Bug 75224

Summary: GLSL: vectorize optimization goes wrong on dot products
Product: Mesa Reporter: Aras Pranckevicius <aras>
Component: glsl-compilerAssignee: Matt Turner <mattst88>
Status: RESOLVED FIXED QA Contact: Intel 3D Bugs Mailing List <intel-3d-bugs>
Severity: normal    
Priority: medium    
Version: git   
Hardware: All   
OS: All   
Whiteboard:
i915 platform: i915 features:

Description Aras Pranckevicius 2014-02-19 19:01:49 UTC
"Vectorize multiple scalar assignments" optimization (added in 4bd6e0d7c69 on master) goes wrong on dot products.

For example, on a fragment shader like this:

varying vec3 inA;
varying vec2 inB;
void main()
{
	vec2 v;
	v.x = dot(inA.xy, inB);
	v.y = dot(inA.yz, inB);
	gl_FragColor = vec4(v.x, v.y, 0.0, 1.0);
}

It produces two problems:

1) tries to vectorize both dots into a v=dot(inA.xy,inB), which is different result.
2) in the result it ends up with an expression node of vec2 type, but a ir_binop_dot operation. asserts in ir_validate in debug build.

It feels like these kinds of "horizontal" operations (probably only dot?) shouldn't be attempted to vectorize.
Comment 1 Matt Turner 2014-02-19 19:11:01 UTC
Oh, I definitely saw this problem before. I'll handle it.
Comment 2 Aras Pranckevicius 2014-02-19 19:13:56 UTC
Locally I could fix this with:

/* Upon entering an ir_binop_dot, remove the current assignment from
 * further consideration. Dot product is "horizontal" instruction
 * that we can't vectorize.
 */
ir_visitor_status
ir_vectorize_visitor::visit_enter(ir_expression *ir)
{
   if (ir->operation == ir_binop_dot) {
      this->current_assignment = NULL;
      return visit_continue_with_parent;
   }
   return visit_continue;
}


But not sure if that's the correct approach.
Comment 3 Matt Turner 2014-02-23 00:46:21 UTC
I've sent two patches to fix this:

http://patchwork.freedesktop.org/patch/20935/
http://patchwork.freedesktop.org/patch/20936/
Comment 4 Aras Pranckevicius 2014-02-23 08:52:09 UTC
LGTM
Comment 5 Matt Turner 2014-03-04 08:02:13 UTC
Committed. I think Ian's picked it over to the release branch too.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.