Bug 25830 - [GLSL] allowing non-constant-expression as const declaration initializer
Summary: [GLSL] allowing non-constant-expression as const declaration initializer
Alias: None
Product: Mesa
Classification: Unclassified
Component: Mesa core (show other bugs)
Version: git
Hardware: All All
: medium normal
Assignee: Ian Romanick
QA Contact:
Depends on:
Blocks: 29044
  Show dependency treegraph
Reported: 2009-12-30 01:09 UTC by Gordon Jin
Modified: 2010-08-18 19:37 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


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.