Bug 82574 - GLSL: opt_vectorize goes wrong on texture lookups
Summary: GLSL: opt_vectorize goes wrong on texture lookups
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-08-13 17:38 UTC by Aras Pranckevicius
Modified: 2014-08-14 16:59 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.