Bug 69226 - Cannot enable basic shaders with Second Life aborts attempt
Summary: Cannot enable basic shaders with Second Life aborts attempt
Status: RESOLVED NOTOURBUG
Alias: None
Product: Mesa
Classification: Unclassified
Component: glsl-compiler (show other bugs)
Version: 9.2
Hardware: Other All
: medium normal
Assignee: Ian Romanick
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-09-11 14:10 UTC by Shawn Starr
Modified: 2013-11-14 01:51 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments
GLSL (originally R600_DEBUG=sb) dump of shaders (1.71 MB, text/plain)
2013-09-11 14:10 UTC, Shawn Starr
Details

Description Shawn Starr 2013-09-11 14:10:47 UTC
Created attachment 85638 [details]
GLSL (originally R600_DEBUG=sb) dump of shaders

GLSL (originally R600_DEBUG=sb) dump of shaders
Comment 1 Shawn Starr 2013-09-11 14:13:16 UTC
2013-09-03T23:01:42Z WARNING("ShaderLoading"): LLError::NoClassInfo::loadShaderFile: GLSL Compilation Error: (0) in effects/MotionBlurF.glsl
2013-09-03T23:01:42Z WARNING("ShaderLoading"): 
LLError::NoClassInfo::dumpObjectLog: 0:22(1): error: syntax error, unexpected EXTENSION, expecting $end

All the GLSL programs fail this one has the following code in it:

GL_ARB_texture_rectangle is listed as supported extension in glxinfo.

GLSL program:

-- CUT --

/**
 * @file colorFilterF.glsl
 *
 * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
 * $License$
 */

#extension GL_ARB_texture_rectangle : enable

#ifdef DEFINE_GL_FRAGCOLOR
out vec4 frag_color;
#else
#define frag_color gl_FragColor
#endif

uniform sampler2DRect tex0;
uniform sampler2DRect tex1;
uniform mat4 inv_proj;
uniform mat4 prev_proj;
uniform vec2 screen_res;
uniform int blur_strength;

VARYING vec2 vary_texcoord0;

#define SAMPLE_COUNT 10

vec4 getPosition(vec2 pos_screen, out vec4 ndc)
{
        float depth = texture2DRect(tex1, pos_screen.xy).r;
        vec2 sc = pos_screen.xy*2.0;
        sc /= screen_res;
        sc -= vec2(1.0,1.0);
        ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0);
        vec4 pos = inv_proj * ndc;
        pos /= pos.w;
        pos.w = 1.0;
        return pos;
}

void main(void)
{
        vec4 ndc;
        vec4 pos = getPosition(vary_texcoord0,ndc);
        vec4 prev_pos = prev_proj * pos;
        prev_pos/=prev_pos.w;
        prev_pos.w = 1.0;
        vec2 vel = ((ndc.xy-prev_pos.xy) * .5) * screen_res * .01 * blur_strength * 1.0/SAMPLE_COUNT;
        float len = length(vel);
        vel = normalize(vel) * min(len, 50);
        vec3 color = texture2DRect(tex0, vary_texcoord0.st).rgb;
        vec2 texcoord = vary_texcoord0 + vel;
        for(int i = 1; i < SAMPLE_COUNT; ++i, texcoord += vel)
        {
                color += texture2DRect(tex0, texcoord.st).rgb;
        }
        frag_color = vec4(color / SAMPLE_COUNT, 1.0);
}

-- CUT --
Comment 2 Shawn Starr 2013-09-11 14:17:43 UTC
Tonight, I will use MESA_GLSL=dump and attach output to this bug.
Comment 3 Ian Romanick 2013-09-11 14:19:33 UTC
(In reply to comment #1)
> 2013-09-03T23:01:42Z WARNING("ShaderLoading"):
> LLError::NoClassInfo::loadShaderFile: GLSL Compilation Error: (0) in
> effects/MotionBlurF.glsl
> 2013-09-03T23:01:42Z WARNING("ShaderLoading"): 
> LLError::NoClassInfo::dumpObjectLog: 0:22(1): error: syntax error,
> unexpected EXTENSION, expecting $end

This usual means that there is something other than comments, whitespace, #version, or other #extension lines before the #extension.  What does MESA_GLSL=dump_on_error output?
Comment 4 Shawn Starr 2013-09-11 14:47:08 UTC
Will provide this tonight accordingly.
Comment 5 Shawn Starr 2013-09-12 01:34:35 UTC
From one shader program:

GLSL source for fragment shader 120:
#version 130
precision mediump int;
precision highp float;
#define DEFINE_GL_FRAGCOLOR 1
#define FXAA_GLSL_130 1
#define ATTRIBUTE in
#define VARYING in
#define VARYING_FLAT flat in
#define texture2D texture
#define textureCube texture
#define texture2DLod textureLod
#define shadow2D(a,b) vec2(texture(a,b))
#define NUM_TEX_UNITS 16
#define samples 0
/**
 * @file colorFilterF.glsl
 *
 * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
 * $License$
 */
 
#extension GL_ARB_texture_rectangle : enable
 
#ifdef DEFINE_GL_FRAGCOLOR
out vec4 frag_color;
#else
#define frag_color gl_FragColor
#endif

uniform sampler2DRect tex0;
uniform float vignette_strength;                                //0 - 1
uniform float vignette_radius;                                  //0 - 8
uniform float vignette_darkness;                                //0 - 1
uniform float vignette_desaturation;                    //0 - 10
uniform float vignette_chromatic_aberration;    //0 - .1
uniform vec2 screen_res;

VARYING vec2 vary_texcoord0;

float luminance(vec3 color)
{
        /// CALCULATING LUMINANCE (Using NTSC lum weights)
        /// http://en.wikipedia.org/wiki/Luma_%28video%29
        return dot(color, vec3(0.299, 0.587, 0.114));
}

void main(void) 
{
        vec3 color = texture2DRect(tex0, vary_texcoord0).rgb;
        vec2 norm_texcood = (vary_texcoord0/screen_res);
        vec2 offset = norm_texcood-vec2(.5);
        float vignette = clamp(pow(1 - dot(offset,offset),vignette_radius) + 1-vignette_strength, 0.0, 1.0);
        float inv_vignette = 1-vignette;

        //vignette chromatic aberration (g
        vec2 shift = screen_res * offset * vignette_chromatic_aberration * inv_vignette;
        float g = texture2DRect(tex0,vary_texcoord0-shift).g;
        float b = texture2DRect(tex0,vary_texcoord0-2*shift).b;
        color.gb = vec2(g,b);

        //vignette 'black' overlay.
        color = mix(color * vignette, color, 1-vignette_darkness);

        //vignette desaturation
        color = mix(vec3(luminance(color)), color, clamp(1-inv_vignette*vignette_desaturation,0,1));

        frag_color = vec4(color,1.0);
}

GLSL shader 120 failed to compile.
GLSL shader 120 info log:
0:22(1): error: syntax error, unexpected EXTENSION, expecting $end


GLSL source for fragment shader 95:
#version 130
precision mediump int;
precision highp float;
#define DEFINE_GL_FRAGCOLOR 1
#define FXAA_GLSL_130 1
#define ATTRIBUTE in
#define VARYING in
#define VARYING_FLAT flat in
#define texture2D texture
#define textureCube texture
#define texture2DLod textureLod
#define shadow2D(a,b) vec2(texture(a,b))
#define NUM_TEX_UNITS 16
#define samples 0
/** 
 * @file glowExtractF.glsl
 *
 * $LicenseInfo:firstyear=2007&license=viewerlgpl$
 * Second Life Viewer Source Code
 * Copyright (C) 2007, Linden Research, Inc.
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation;
 * version 2.1 of the License only.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 * 
 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 * $/LicenseInfo$
 */
 
#extension GL_ARB_texture_rectangle : enable

#ifdef DEFINE_GL_FRAGCOLOR
out vec4 frag_color;
#else
#define frag_color gl_FragColor
#endif

uniform sampler2DRect diffuseMap;
uniform float minLuminance;
uniform float maxExtractAlpha;
uniform vec3 lumWeights;
uniform vec3 warmthWeights;
uniform float warmthAmount;

VARYING vec2 vary_texcoord0;

void main()
{
        vec4 col = texture2DRect(diffuseMap, vary_texcoord0.xy);
        /// CALCULATING LUMINANCE (Using NTSC lum weights)
        /// http://en.wikipedia.org/wiki/Luma_%28video%29
        float lum = smoothstep(minLuminance, minLuminance+1.0, dot(col.rgb, lumWeights ) );
        float warmth = smoothstep(minLuminance, minLuminance+1.0, max(col.r * warmthWeights.r, max(col.g * warmthWeights.g, col.b * warmthWeights.b)) ); 

        frag_color.rgb = col.rgb; 
        frag_color.a = max(col.a, mix(lum, warmth, warmthAmount) * maxExtractAlpha);

}

GLSL shader 95 failed to compile.
GLSL shader 95 info log:
0:40(1): error: syntax error, unexpected EXTENSION, expecting $end

etc..
Comment 6 Ian Romanick 2013-09-12 15:28:34 UTC
I would have sworn that #extension lines had to occur before non-preprocessor lines, but I cannot find anything in the spec to support that. :(

In the mean time, GL_ARB_texture_rectangle predates the #extension mechanism, so you don't actually need to enable it.  It's sort of a special case in that respect.
Comment 7 Ian Romanick 2013-09-12 16:03:05 UTC
(In reply to comment #6)
> I would have sworn that #extension lines had to occur before
> non-preprocessor lines, but I cannot find anything in the spec to support
> that. :(

Scratch that.  I found it.  Page 12 (page 18 of the PDF) in section 3.3 (Preprocessor) of the GLSL 1.40 spec (and other versions) says:

    "If nothing is said, the granularity is a shader (that is, a
    single compilation unit), and the extension directives must
    occur before any non-preprocessor tokens."

In this case, "precision mediump int; precision highp float;" are non-preprocessor tokens.

I dug through old e-mail because I was also pretty sure that this had come up once before.  The advice I gave in the previous situation was to emit a "#extension ...: enable" line for each extension that the application might use from the same place that the #version line is dynamically generated.

I'm also a little confused / concerned about the precision lines.  mediump is already the ES2 and ES3 default for int, and highp is only valid (in ES2) for float when GL_FRAGMENT_PRECISION_HIGH is defined.

The most portable way for this shader to be coded is:

#version 130
#extension GL_ARB_texture_rectangle : enable

#if defined GL_ES
#  if defined GL_FRAGMENT_PRECISION_HIGH || __VERSION__ >= 300
precision highp float;
#  else
precision mediump float;
#  endif
#endif

#define DEFINE_GL_FRAGCOLOR 1
#define FXAA_GLSL_130 1
#define ATTRIBUTE in
#define VARYING in
#define VARYING_FLAT flat in
#define texture2D texture
#define textureCube texture
#define texture2DLod textureLod
#define shadow2D(a,b) vec2(texture(a,b))
#define NUM_TEX_UNITS 16
#define samples 0

> In the mean time, GL_ARB_texture_rectangle predates the #extension
> mechanism, so you don't actually need to enable it.  It's sort of a special
> case in that respect.
Comment 8 Shawn Starr 2013-09-12 16:12:11 UTC
So what to do? If games don't follow GLSL spec fully/properly, we can't just fail?  It's not like I'd rewrite all the shader programs for them nor would know how to.
Comment 9 Shawn Starr 2013-09-12 16:14:50 UTC
if it's only adjusting those lines, well you did the work and I could patch my copies accordingly. That said though, I'm sure other games don't follow the spec fully?
Comment 10 Ian Romanick 2013-09-12 20:12:34 UTC
The developers of the other application that ran into this fix their bug.  I suggest that the Second Life developers do the same.  I really not sure what else to say.
Comment 11 Ian Romanick 2013-09-12 20:16:22 UTC
For most other applications that don't follow the spec, we generally either disable functionality or disable error checks based on config variables.  We do that because disabling an error check requires one or two lines of code change.  Working around this would require a bunch of effort in the GLSL parser... which I'd prefer to only monkey with when I absolutely have to.
Comment 12 Shawn Starr 2013-09-14 06:06:27 UTC
The new GLSL code doesn't work, is the example ported code you listed correct?

Mesa debug output:

GLSL shader 61 failed to compile.
GLSL shader 61 info log:
0:44(35): preprocessor warning: extra tokens at end of directive
0:40(1): error: syntax error, unexpected EXTENSION, expecting $end

GLSL source for fragment shader 64:
#version 130
precision mediump int;
precision highp float;
#define DEFINE_GL_FRAGCOLOR 1
#define FXAA_GLSL_130 1
#define ATTRIBUTE in
#define VARYING in
#define VARYING_FLAT flat in
#define texture2D texture
#define textureCube texture
#define texture2DLod textureLod
#define shadow2D(a,b) vec2(texture(a,b))
#define NUM_TEX_UNITS 16
#define samples 0
/**
 * @file colorFilterF.glsl
 *
 * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
 * $License$
 */

#extension GL_ARB_texture_rectangle : enable

#ifdef GL_ES
#ifdef GL_FRAGMENT_PRECISION_HIGH || __VERSION__ >= 300
precision highp float;
#else
precision mediump float;
#endif
#endif

#ifdef DEFINE_GL_FRAGCOLOR
out vec4 frag_color;
#else
#define frag_color gl_FragColor
#endif


uniform sampler2DRect tex0;
uniform float brightness;
2013-09-14T05:58:39Z WARNING("ShaderLoading"): LLError::NoClassInfo::loadShaderFile: GLSL Compilation Error: (0) in effects/colorFilterF.glsl
2013-09-14T05:58:39Z WARNING("ShaderLoading"): LLError::NoClassInfo::dumpObjectLog: 0:26(35): preprocessor warning: extra tokens at end of directive
0:22(1): error: syntax error, unexpected EXTENSION, expecting $end


Actual GLSL file:
=-===========


/**
 * @file colorFilterF.glsl
 *
 * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
 * $License$
 */

#extension GL_ARB_texture_rectangle : enable

#ifdef GL_ES
#ifdef GL_FRAGMENT_PRECISION_HIGH || __VERSION__ >= 300
precision highp float;
#else
precision mediump float;
#endif
#endif

#ifdef DEFINE_GL_FRAGCOLOR
out vec4 frag_color;
#else
#define frag_color gl_FragColor
#endif


uniform sampler2DRect tex0;
uniform float brightness;
uniform float contrast;
uniform vec3  contrastBase;
uniform float saturation;
uniform vec3  lumWeights;

uniform float gamma;

VARYING vec2 vary_texcoord0;

float luminance(vec3 color)
{
        /// CALCULATING LUMINANCE (Using NTSC lum weights)
        /// http://en.wikipedia.org/wiki/Luma_%28video%29
        return dot(color, vec3(0.299, 0.587, 0.114));
}

void main(void)
{
        vec3 color = vec3(texture2DRect(tex0, vary_texcoord0.st));

        /// Apply gamma
        color = pow(color, vec3(1.0/gamma));

        /// Modulate brightness
        color *= brightness;

        /// Modulate contrast
        color = mix(contrastBase, color, contrast);

        /// Modulate saturation
        color = mix(vec3(luminance(color)), color, saturation);

        frag_color = vec4(color, 1.0);
}
Comment 13 Shawn Starr 2013-09-14 07:14:50 UTC
ok, I can fix the shaders by disabling:

#extension GL_ARB_texture_rectangle : enable

we seem to not handle #extension for some reason the game works with all the shaders now but I guess GL_ARB_texture_rectangle is disabled.
Comment 14 Shawn Starr 2013-09-16 14:05:32 UTC
So with this in mind, is this a GLSL compiler issue or the game's GLSL program?
Comment 15 Ian Romanick 2013-09-18 13:44:41 UTC
(In reply to comment #14)
> So with this in mind, is this a GLSL compiler issue or the game's GLSL
> program?

It is the game's issue.  Page 12 (page 18 of the PDF) in section 3.3 (Preprocessor) of the GLSL 1.40 spec (and other versions) says:

    "If nothing is said, the granularity is a shader (that is, a
    single compilation unit), and the extension directives must
    occur before any non-preprocessor tokens."

Their #extension occurs after non-preprocessor tokens.
Comment 16 Ian Romanick 2013-09-18 13:48:58 UTC
(In reply to comment #12)
> The new GLSL code doesn't work, is the example ported code you listed
> correct?
> 
> Mesa debug output:
> 
> GLSL shader 61 failed to compile.
> GLSL shader 61 info log:
> 0:44(35): preprocessor warning: extra tokens at end of directive
> 0:40(1): error: syntax error, unexpected EXTENSION, expecting $end
> 
> GLSL source for fragment shader 64:
> #version 130
> precision mediump int;
> precision highp float;

These are the lines of code that are causing the problem.  The have to occur after the #extension line.  The code I supplied in comment #7 works around a different issue that this code will have on other compilers (namely that not all OpenGL ES 2.0 implementations support 'highp float' in the fragment shader).

> #define DEFINE_GL_FRAGCOLOR 1
> #define FXAA_GLSL_130 1
> #define ATTRIBUTE in
> #define VARYING in
> #define VARYING_FLAT flat in
> #define texture2D texture
> #define textureCube texture
> #define texture2DLod textureLod
> #define shadow2D(a,b) vec2(texture(a,b))
> #define NUM_TEX_UNITS 16
> #define samples 0
> /**
>  * @file colorFilterF.glsl
>  *
>  * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
>  * $License$
>  */
> 
> #extension GL_ARB_texture_rectangle : enable
> 
> #ifdef GL_ES
> #ifdef GL_FRAGMENT_PRECISION_HIGH || __VERSION__ >= 300
> precision highp float;
> #else
> precision mediump float;
> #endif
> #endif
> 
> #ifdef DEFINE_GL_FRAGCOLOR
> out vec4 frag_color;
> #else
> #define frag_color gl_FragColor
> #endif
> 
> 
> uniform sampler2DRect tex0;
> uniform float brightness;
> 2013-09-14T05:58:39Z WARNING("ShaderLoading"):
> LLError::NoClassInfo::loadShaderFile: GLSL Compilation Error: (0) in
> effects/colorFilterF.glsl
> 2013-09-14T05:58:39Z WARNING("ShaderLoading"):
> LLError::NoClassInfo::dumpObjectLog: 0:26(35): preprocessor warning: extra
> tokens at end of directive
> 0:22(1): error: syntax error, unexpected EXTENSION, expecting $end
> 
> 
> Actual GLSL file:
> =-===========
> 
> 
> /**
>  * @file colorFilterF.glsl
>  *
>  * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
>  * $License$
>  */
> 
> #extension GL_ARB_texture_rectangle : enable
> 
> #ifdef GL_ES
> #ifdef GL_FRAGMENT_PRECISION_HIGH || __VERSION__ >= 300
> precision highp float;
> #else
> precision mediump float;
> #endif
> #endif
> 
> #ifdef DEFINE_GL_FRAGCOLOR
> out vec4 frag_color;
> #else
> #define frag_color gl_FragColor
> #endif
> 
> 
> uniform sampler2DRect tex0;
> uniform float brightness;
> uniform float contrast;
> uniform vec3  contrastBase;
> uniform float saturation;
> uniform vec3  lumWeights;
> 
> uniform float gamma;
> 
> VARYING vec2 vary_texcoord0;
> 
> float luminance(vec3 color)
> {
>         /// CALCULATING LUMINANCE (Using NTSC lum weights)
>         /// http://en.wikipedia.org/wiki/Luma_%28video%29
>         return dot(color, vec3(0.299, 0.587, 0.114));
> }
> 
> void main(void)
> {
>         vec3 color = vec3(texture2DRect(tex0, vary_texcoord0.st));
> 
>         /// Apply gamma
>         color = pow(color, vec3(1.0/gamma));
> 
>         /// Modulate brightness
>         color *= brightness;
> 
>         /// Modulate contrast
>         color = mix(contrastBase, color, contrast);
> 
>         /// Modulate saturation
>         color = mix(vec3(luminance(color)), color, saturation);
> 
>         frag_color = vec4(color, 1.0);
> }


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.