Bug 37383 - incorrect GLSL optimization
Summary: incorrect GLSL optimization
Alias: None
Product: Mesa
Classification: Unclassified
Component: glsl-compiler (show other bugs)
Version: git
Hardware: x86 (IA32) Linux (All)
: medium normal
Assignee: Ian Romanick
QA Contact:
Depends on:
Reported: 2011-05-19 11:50 UTC by matthias.bentrup
Modified: 2011-07-07 14:21 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:

MESA_GLSL=dump output (19.69 KB, text/plain)
2011-05-19 11:50 UTC, matthias.bentrup

Description matthias.bentrup 2011-05-19 11:50:57 UTC
Created attachment 46917 [details]
MESA_GLSL=dump output

I have a problem with a GLSL fragment shader. As you see in the attached dump file, the shader assigns constant zero to dstColor.w after linking, but the expression that is optimized away can (and should) be nonzero.

If I rewrite the shader to assign all components in one step everything works as it should.

I have tested this on MESA r600g, nouveau and softpipe renderers and get the same result on each. NVidia and AMD proprietary drivers compute the correct alpha value.

OpenGL vendor string: X.Org
OpenGL renderer string: Gallium 0.4 on AMD JUNIPER
OpenGL version string: 2.1 Mesa 7.11-devel
OpenGL shading language version string: 1.20
Comment 1 Ian Romanick 2011-06-27 15:31:44 UTC
It's also worth nothing that if the line

  dstColor.a *= 1.0 - srcColor.a;

is changed to

  dstColor.a = 1.0 - srcColor.a;

Mesa also produces correct code.  That at least narrows down where things might be going wrong.
Comment 2 Ian Romanick 2011-06-27 15:32:37 UTC
Also, would it be possible for you to make a piglit shader-runner test out of this (with an appropriate Signed-off-by)?
Comment 3 Ian Romanick 2011-06-27 16:40:48 UTC
Patch posted to mesa-dev mailing list:

Comment 4 Ian Romanick 2011-07-07 14:21:02 UTC
Fix on master by the commit below.  This commit has been cherry-picked to 7.11 (42cd619) and 7.10 (cb6dd6c).

commit 0eb97979584b73907327eebc547302e6b8d8976a
Author: Ian Romanick <ian.d.romanick@intel.com>
Date:   Mon Jun 27 16:33:13 2011 -0700

    glsl: Track initial mask in constant propagation live set
    The set of values initially available (before any kills) must be
    tracked with each constant in the set.  Otherwise the wrong component
    can be selected after earlier components have been killed.
    NOTE: This is a candidate for the 7.10 and 7.11 branches.
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=37383
    Reviewed-by: Eric Anholt <eric@anholt.net>
    Cc: Kenneth Graunke <kenneth@whitecape.org>
    Cc: Matthias Bentrup <matthias.bentrup@googlemail.com>

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.