1Name 2 3 EXT_shader_non_constant_global_initializers 4 5Name Strings 6 7 GL_EXT_shader_non_constant_global_initializers 8 9Contact 10 11 Daniel Koch, NVIDIA (dkoch 'at' nvidia.com) 12 13Contributors 14 15 Sahil Parmar, NVIDIA 16 Weiwan Liu, NVIDIA 17 John Kessenich, Google 18 Jeff Leger, Qualcomm 19 20Status 21 22 Complete 23 24Version 25 26 Last Modified Date: July 4, 2016 27 Revision: 2 28 29Number 30 31 OpenGL ES Extension #264 32 33Dependencies 34 35 OpenGL ES Shading Language 1.00 is required. 36 37 This extension is written against the OpenGL ES 3.20 38 Shading Language (August 6, 2015) specification, but 39 can apply to earlier versions. 40 41Overview 42 43 This extension adds the ability to use non-constant initializers for 44 global variables in the OpenGL ES Shading Language specifications. 45 This functionality is already present in the OpenGL Shading language 46 specification. 47 48New Procedures and Functions 49 50 None. 51 52New Tokens 53 54 None. 55 56Additions to the OpenGL ES 3.2 Specification 57 58 None 59 60Additions to the OpenGL ES Shading Language 3.20 Specification 61 62 Including the following line in a shader can be used to control the 63 language features described in this extension: 64 65 #extension GL_EXT_shader_non_constant_global_initializers : <behavior> 66 67 where <behavior> is as specified in section 3.4. 68 69 A new preprocessor #define is added to the OpenGL ES Shading Language: 70 71 #define GL_EXT_shader_non_constant_global_initializers 1 72 73 Modifications to Section 4.3 (Storage Qualifiers): 74 75 Replace the last paragraph: 76 77 "In declarations of global variables with no storage qualifier or 78 with a const qualifier, any initializer must be a constant expression. 79 Declarations of global variables with other storage qualifiers may not 80 contain initializers. Global variables without storage qualifiers that 81 are not initialized in their declaration or by the application will not 82 be initialized by OpenGL ES, but rather will enter main() with undefined 83 values." 84 85 with the following paragraph: 86 87 "Initializers in global declarations may only be used in declarations 88 of global variables with either no storage qualifier, or a "const" 89 qualifier. All such initializers will have been executed before, or 90 on entry to, main(). Global variables without storage qualifiers that 91 are not initialized in their declaration or by the application will not 92 be initialized by OpenGL ES, but rather will enter main() with undefined 93 values." 94 95Issues 96 97 (1) How does this differ from OpenGL Shader Language support? 98 99 RESOLVED. This is based on the language from the OpenGL Shading 100 Language 4.50 specification. The only difference is that GLSL 101 allows initializers on uniform variables, whereas ESSL does not. 102 Also have added the statement clarifying that "All such initializers 103 will have been executed before, or on entry to, main()". 104 105 (2) How should these global non-constant initializers be implemented? 106 107 RESOLVED. They operate as if they are executed at the beginning of 108 the main() block before any other statements. That is: 109 110 vec4 v = ...; // "..." is a valid non-const initializer at this point 111 112 void main() 113 { 114 statement1; 115 statement2; 116 } 117 118 means 119 120 vec4 v; 121 122 void main() 123 { 124 v = ...; 125 statement1; 126 statement2; 127 } 128 129 For a more complex example: 130 131 uniform int i; 132 int a = i; 133 134 void foo(); 135 void main() { foo(); } 136 137 int b = 2 * a; 138 139 void foo() { /* what's b? */ } 140 141 the same rule applies. The point in time 'b' gets it's value 142 is at the beginning of main(). There is no problem like "b isn't 143 visible in main()". Rather, 'b' exists and is initialized on entry 144 to main(), but is just not visible (per normal language rules). 145 The full semantics of this are implemented in the glslang reference 146 compiler. 147 148Revision History 149 Rev. Date Author Changes 150 ---- ----------- ------------ --------------------------------- 151 1 10-Jun-2016 dkoch Initial draft based on GLSL 4.50 152 2 04-Jul-2016 dkoch Final edits before publishing 153 154