Bug 82574

Summary: GLSL: opt_vectorize goes wrong on texture lookups
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 CC: idr
Version: git   
Hardware: All   
OS: All   
Whiteboard:
i915 platform: i915 features:

Description Aras Pranckevicius 2014-08-13 17:38:18 UTC
Looks like opt_vectorize is too eager on texture lookups. For example, a shader like this (which does a color correction effect by looking up R,G,B channels into a ramp texture):

uniform sampler2D _MainTex;
uniform sampler2D _RampTex;
varying vec2 varUV;
void main()
{
  vec4 orig = texture2D (_MainTex, varUV);
  float rr = texture2D (_RampTex, orig.xx).x;
  float gg = texture2D (_RampTex, orig.yy).y;
  float bb = texture2D (_RampTex, orig.zz).z;
  vec4 color = vec4 (rr, gg, bb, orig.w);
  gl_FragData[0] = color;
}

These 3 lookups effectively get vectorized into something like a:

  t.xyz = texture2DProj (_RampTex, t.xyz).xyz;


I can make this bug go away by stopping vectorizing on texture samples, i.e. adding something like this to opt_vectorize.cpp:


/**
 * Upon entering an ir_texture, remove the current assignment from
 * further consideration. Vectorizing multiple texture lookups into one
 * is wrong.
 */
ir_visitor_status
ir_vectorize_visitor::visit_enter(ir_texture *)
{
   this->current_assignment = NULL;
   return visit_continue_with_parent;
}
Comment 1 Matt Turner 2014-08-13 20:57:54 UTC
(In reply to comment #0)
> I can make this bug go away by stopping vectorizing on texture samples, i.e.
> adding something like this to opt_vectorize.cpp:
> 
> 
> /**
>  * Upon entering an ir_texture, remove the current assignment from
>  * further consideration. Vectorizing multiple texture lookups into one
>  * is wrong.
>  */
> ir_visitor_status
> ir_vectorize_visitor::visit_enter(ir_texture *)
> {
>    this->current_assignment = NULL;
>    return visit_continue_with_parent;
> }

Cool. Can you send that as a patch to mesa-dev?
Comment 2 Aras Pranckevicius 2014-08-14 08:28:54 UTC
Patch sent: http://lists.freedesktop.org/archives/mesa-dev/2014-August/065661.html

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.