[Mesa-dev] [PATCH V2 2/4] glsl: Compile error if fs uses gl_FragCoord before first redeclaration

Anuj Phogat anuj.phogat at gmail.com
Tue Feb 25 13:15:25 PST 2014


On Tue, Feb 25, 2014 at 7:47 AM, Ian Romanick <idr at freedesktop.org> wrote:
>
> On 02/24/2014 05:34 PM, Anuj Phogat wrote:
>>
>> Section 4.3.8.1, page 39 of GLSL 1.50 spec says:
>>    "Within any shader, the first redeclarations of gl_FragCoord
>>     must appear before any use of gl_FragCoord."
>>
>> GLSL compiler should generate an error in following case:
>>
>> vec4 p = gl_FragCoord;
>> layout(origin_upper_left) in vec4 gl_FragCoord;
>>
>> void main()
>> {
>> }
>>
>> Signed-off-by: Anuj Phogat <anuj.phogat at gmail.com>
>> Cc: <mesa-stable at lists.freedesktop.org>
>> ---
>>   src/glsl/ast_to_hir.cpp | 16 ++++++++++++++++
>>   1 file changed, 16 insertions(+)
>>
>> diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
>> index 9fe3095..f5dacfd 100644
>> --- a/src/glsl/ast_to_hir.cpp
>> +++ b/src/glsl/ast_to_hir.cpp
>> @@ -2490,6 +2490,22 @@ apply_type_qualifier_to_variable(const struct ast_type_qualifier *qual,
>>      }
>>
>>      if (strcmp(var->name, "gl_FragCoord") == 0) {
>> +      /* Section 4.3.8.1, page 39 of GLSL 1.50 spec says:
>> +       *
>> +       *    "Within any shader, the first redeclarations of gl_FragCoord
>> +       *     must appear before any use of gl_FragCoord."
>> +       *
>> +       * Generate a compiler error if above condition is not met by the
>> +       * fragment shader.
>> +       */
>> +      ir_variable *earlier = state->symbols->get_variable("gl_FragCoord");
>> +      if (earlier != NULL &&
>> +          earlier->data.used &&
>> +          !state->fs_redeclares_gl_fragcoord) {
>
>
> I don't think '!state->fs_redeclares_gl_fragcoord' should be there. What about a shader like:
>
>     layout(origin_upper_left) in vec4 gl_FragCoord;
>
>     vec4 p = gl_FragCoord;
>     layout(origin_upper_left) in vec4 gl_FragCoord;
>
>     void main()
>     {
>     }
>
This shader compiles successfully as I expected. Only the first re-declaration
must appear before gl_FragCoord usage. Do you interpret the spec differently?
I've added new piglit tests which cover this case as well:
http://patchwork.freedesktop.org/project/piglit/list/?submitter=Anuj+Phogat&q=glsl-1.50

>> +         _mesa_glsl_error(loc, state,
>> +                          "gl_FragCoord used before its first redeclaration "
>> +                          "in fragment shader");
>> +      }
>>
>>         /* Make sure all gl_FragCoord redeclarations specify the same layout
>>          * qualifiers.
>>
>


More information about the mesa-dev mailing list