Bug 25830

Summary: [GLSL] allowing non-constant-expression as const declaration initializer
Product: Mesa Reporter: Gordon Jin <gordon.jin>
Component: Mesa coreAssignee: Ian Romanick <idr>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: medium CC: brianp
Version: git   
Hardware: All   
OS: All   
i915 platform: i915 features:
Bug Depends on:    
Bug Blocks: 29044    

Description Gordon Jin 2009-12-30 01:09:16 UTC
GLSL spec section 4.3.2 says "Initializers for const declarations must be constant expressions".

Apparently below 2 examples are not constant expressions, so should not be allowed:
    const vec3 v = vec3(1.0, func()); // user defined functions do not return const value

    float f = 1.0;
    const vec4 v2 = vec4(float(vec4(1,2,3,f))); // f is not constant

And below example is not allowed in GLSL v1.10, but allowed starting from GLSL v1.20 (allowing built-in function call whose arguments are all constant expressions):
    const vec4 v = vec4(normalize(vec4(1))); // builtIn functions do not return const
    const vec4 v1 = vec4(clamp(1.0, .20, 3.0)); // builtIn functions do not return const

All of above examples are allowed in current mesa.
Comment 1 Eric Anholt 2010-08-17 08:46:12 UTC
Fixed with glsl2 merge
Comment 2 Gordon Jin 2010-08-18 19:37:21 UTC
verified with mesa master d442a01ac14382d83cdaac87d2832315ceb3e963.

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.