Bug 29607 - Global scope re-declarations regression after GLSL2 merge
Summary: Global scope re-declarations regression after GLSL2 merge
Status: RESOLVED FIXED
Alias: None
Product: Mesa
Classification: Unclassified
Component: Mesa core (show other bugs)
Version: git
Hardware: x86 (IA32) Linux (All)
: high normal
Assignee: Kenneth Graunke
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-08-17 03:01 UTC by Cedric Vivier
Modified: 2010-08-26 09:44 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments

Description Cedric Vivier 2010-08-17 03:01:56 UTC
Compiling the following testcase fail after GLSL2 merge :

--
const float exp = 1.0; // !!! error: `exp' redeclared

void main()
{
    const float exp = 1.0; // works (as usual)
    gl_Position = vec4(0.0);
}

--

This works if `exp' was redeclared as a function.

However this should work with a re-declaration as variable as well as it used to be before the merge, the built-in functions scope (where 'exp' is declared) being the outermost scope, distinct from the shader's global scope, and that "All variable names, structure type names, and function names in a given scope share the same name space." (GLSL spec section 4.2).


Other than this small issue, GLSL2 is awesome! :)
Comment 1 Eric Anholt 2010-08-17 09:45:01 UTC
Note that the 1.20 wording you quoted is different from 1.10.  We do need to support the 1.20 stuff.  I'm not entirely clear from reading 1.10 on whether it allows what you've done there.
Comment 2 Ian Romanick 2010-08-17 10:29:52 UTC
The language is different in the 1.20 spec, but it was supposed to be just a clarification of the intent of the 1.10 spec.  Either way, this test passes on Nvidia, so we should make it pass too.  Since we already have some special handling of the built-in scope, this should be easy enough to fix.

I'm adding a couple glslparsertests as redeclaration-??.vert to probe a couple of these corner cases.
Comment 3 Ian Romanick 2010-08-26 09:44:39 UTC
These tests should be fixed by this patch sequence:

commit a044285e25615f2d97636fe3ba47d580c3537bc4
Author: Kenneth Graunke <kenneth@whitecape.org>
Date:   Mon Aug 23 14:52:06 2010 -0700

    glsl: Move built-ins to live beyond the global scope.
    
    Per the GLSL 1.20 specification (presumably a clarification of 1.10).
    
    Also, when creating user functions, make a new ir_function that shadows the
    built-in ir_function, rather than adding new signatures.  User functions
    are supposed to hide built-ins, not overload them.
    
    Fixes piglit tests redeclaration-{04, 12, 14}.vert.

commit b6f15869b324ae64a00d0fe46fa3c8c62c1edb6c
Author: Kenneth Graunke <kenneth@whitecape.org>
Date:   Fri Aug 20 20:04:39 2010 -0700

    glsl: Move is_built_in flag from ir_function_signature to ir_function.
    
    Also rename it to "is_builtin" for consistency.
    
    Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>

commit 5d25746640ee27882b69a962459727cf924443db
Author: Kenneth Graunke <kenneth@whitecape.org>
Date:   Tue Aug 24 01:45:49 2010 -0700

    glsl: Refactor variable declaration handling.
    
    Moving the check for an earlier variable declaration helps cleanly
    separate out the re-declaration vs. new declaration code a bit.  With
    that in place, conflicts between variable names and structure types or
    function names aren't caught by the earlier "redeclaration" error
    message, so check the return type on glsl_symbol_table::add_variable
    and issue an error there.  If one occurs, don't emit the initializer.
    
    Fixes redeclaration-01.vert and redeclaration-09.vert.
    
    Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>

commit ac2376e6f51677ab321930b0200a79d1683cfbba
Author: Kenneth Graunke <kenneth@whitecape.org>
Date:   Wed Aug 25 17:10:16 2010 -0700

    glsl: Don't add overloads to existing structure constructors.
    
    Instead, make a new ir_function and try to add it to the symbol table.
    
    Fixes piglit test redeclaration-08.vert.

commit e09591317b2470fe9c104606577d4e10255727c0
Author: Kenneth Graunke <kenneth@whitecape.org>
Date:   Wed Aug 25 16:37:46 2010 -0700

    glsl: Remove name_declared_this_scope check when adding functions.
    
    Instead, rely on the symbol table's rules.
    
    Fixes redeclaration-02.vert.

commit e9c7ceed27f6811ad1cae46c93ce9bc3fb3668d8
Author: Kenneth Graunke <kenneth@whitecape.org>
Date:   Sat Aug 21 20:23:18 2010 -0700

    glsl: Use a single shared namespace in the symbol table.
    
    As of 1.20, variable names, function names, and structure type names all
    share a single namespace, and should conflict with one another in the
    same scope, or hide each other in nested scopes.
    
    However, in 1.10, variables and functions can share the same name in the
    same scope.  Structure types, however, conflict with/hide both.
    
    Fixes piglit tests redeclaration-06.vert, redeclaration-11.vert,
    redeclaration-19.vert, and struct-05.vert.


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.