Bug 75224 - GLSL: vectorize optimization goes wrong on dot products
Summary: GLSL: vectorize optimization goes wrong on dot products
Status: RESOLVED FIXED
Alias: None
Product: Mesa
Classification: Unclassified
Component: glsl-compiler (show other bugs)
Version: git
Hardware: All All
: medium normal
Assignee: Matt Turner
QA Contact: Intel 3D Bugs Mailing List
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-02-19 19:01 UTC by Aras Pranckevicius
Modified: 2014-03-04 08:02 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments

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.