diff --git a/Test/100.frag b/Test/100.frag index ce6a6eec5550777584ca03d505040bec5af41e0c..4f0c69b5ddbc8a77d78141c2e776eccfe448b338 100644 --- a/Test/100.frag +++ b/Test/100.frag @@ -213,6 +213,12 @@ float fooinit() int init1 = gl_FrontFacing ? 1 : 2; // ERROR, non-const initializer +#ifdef GL_EXT_shader_non_constant_global_initializers +#extension GL_EXT_shader_non_constant_global_initializers : enable +#endif + +int init2 = gl_FrontFacing ? 1 : 2; + #pragma STDGL invariant(all) #line 3000 diff --git a/Test/baseResults/100.frag.out b/Test/baseResults/100.frag.out index 7af716d84b70af804e9e3a072bf32bf37821088b..70b893494f039e0265387aa7c65bae90fe99572a 100644 --- a/Test/baseResults/100.frag.out +++ b/Test/baseResults/100.frag.out @@ -82,7 +82,7 @@ ERROR: 0:192: '.' : cannot apply to an array: nothing ERROR: 0:193: '.length' : not supported for this version or the enabled extensions ERROR: 0:194: '.' : cannot apply to an array: method ERROR: 0:194: 'a' : can't use function syntax on variable -ERROR: 0:214: 'non-constant global initializer' : not supported with this profile: es +ERROR: 0:214: 'non-constant global initializer (needs GL_EXT_shader_non_constant_global_initializers)' : not supported for this version or the enabled extensions ERROR: 0:3000: '#error' : line of this error should be 3000 ERROR: 0:3002: '' : syntax error ERROR: 77 compilation errors. No code generated. @@ -90,6 +90,7 @@ ERROR: 77 compilation errors. No code generated. Shader version: 100 Requested GL_EXT_frag_depth +Requested GL_EXT_shader_non_constant_global_initializers Requested GL_EXT_shader_texture_lod Requested GL_OES_EGL_image_external Requested GL_OES_standard_derivatives @@ -376,6 +377,18 @@ ERROR: node is still EOpNull! 0:214 false case 0:214 Constant: 0:214 2 (const int) +0:220 Sequence +0:220 move second child to first child (temp mediump int) +0:220 'init2' (global mediump int) +0:220 Test condition and select (temp mediump int) +0:220 Condition +0:220 'gl_FrontFacing' (gl_FrontFacing bool Face) +0:220 true case +0:220 Constant: +0:220 1 (const int) +0:220 false case +0:220 Constant: +0:220 2 (const int) 0:? Linker Objects 0:? 'a' (global 3-element array of mediump int) 0:? 'uint' (global mediump int) @@ -407,6 +420,7 @@ ERROR: node is still EOpNull! 0:? 'fi3' (const mediump float) 0:? 5.000000 0:? 'init1' (global mediump int) +0:? 'init2' (global mediump int) Linked fragment stage: @@ -414,6 +428,7 @@ Linked fragment stage: Shader version: 100 Requested GL_EXT_frag_depth +Requested GL_EXT_shader_non_constant_global_initializers Requested GL_EXT_shader_texture_lod Requested GL_OES_EGL_image_external Requested GL_OES_standard_derivatives @@ -700,6 +715,18 @@ ERROR: node is still EOpNull! 0:214 false case 0:214 Constant: 0:214 2 (const int) +0:220 Sequence +0:220 move second child to first child (temp mediump int) +0:220 'init2' (global mediump int) +0:220 Test condition and select (temp mediump int) +0:220 Condition +0:220 'gl_FrontFacing' (gl_FrontFacing bool Face) +0:220 true case +0:220 Constant: +0:220 1 (const int) +0:220 false case +0:220 Constant: +0:220 2 (const int) 0:? Linker Objects 0:? 'a' (global 3-element array of mediump int) 0:? 'uint' (global mediump int) @@ -731,4 +758,5 @@ ERROR: node is still EOpNull! 0:? 'fi3' (const mediump float) 0:? 5.000000 0:? 'init1' (global mediump int) +0:? 'init2' (global mediump int) diff --git a/glslang/MachineIndependent/ParseHelper.cpp b/glslang/MachineIndependent/ParseHelper.cpp index 35085af627426718394545c37712826834504e7b..8d7ecdec568dd3448ff0f637fd2c69e9d2b4cf4b 100644 --- a/glslang/MachineIndependent/ParseHelper.cpp +++ b/glslang/MachineIndependent/ParseHelper.cpp @@ -5083,11 +5083,13 @@ TIntermNode* TParseContext::executeInitializer(const TSourceLoc& loc, TIntermTyp // "In declarations of global variables with no storage qualifier or with a const // qualifier any initializer must be a constant expression." if (symbolTable.atGlobalLevel() && ! initializer->getType().getQualifier().isConstant()) { - const char* initFeature = "non-constant global initializer"; - if (relaxedErrors()) - warn(loc, "not allowed in this version", initFeature, ""); - else - requireProfile(loc, ~EEsProfile, initFeature); + const char* initFeature = "non-constant global initializer (needs GL_EXT_shader_non_constant_global_initializers)"; + if (profile == EEsProfile) { + if (relaxedErrors() && ! extensionTurnedOn(E_GL_EXT_shader_non_constant_global_initializers)) + warn(loc, "not allowed in this version", initFeature, ""); + else + profileRequires(loc, EEsProfile, 0, E_GL_EXT_shader_non_constant_global_initializers, initFeature); + } } } diff --git a/glslang/MachineIndependent/Versions.cpp b/glslang/MachineIndependent/Versions.cpp index ec418ddddef67c45dd1aca29d0ac3ccea823a651..7d5a81e72efc5ad96db7b244e8c31089e50c277d 100644 --- a/glslang/MachineIndependent/Versions.cpp +++ b/glslang/MachineIndependent/Versions.cpp @@ -182,6 +182,8 @@ void TParseVersions::initializeExtensionBehavior() extensionBehavior[E_GL_ARB_sparse_texture_clamp] = EBhDisable; // extensionBehavior[E_GL_ARB_cull_distance] = EBhDisable; // present for 4.5, but need extension control over block members + extensionBehavior[E_GL_EXT_shader_non_constant_global_initializers] = EBhDisable; + // #line and #include extensionBehavior[E_GL_GOOGLE_cpp_style_line_directive] = EBhDisable; extensionBehavior[E_GL_GOOGLE_include_directive] = EBhDisable; @@ -256,6 +258,7 @@ void TParseVersions::getPreamble(std::string& preamble) "#define GL_OES_tessellation_point_size 1\n" "#define GL_OES_texture_buffer 1\n" "#define GL_OES_texture_cube_map_array 1\n" + "#define GL_EXT_shader_non_constant_global_initializers 1\n" ; } else { preamble = @@ -284,6 +287,7 @@ void TParseVersions::getPreamble(std::string& preamble) "#define GL_ARB_sparse_texture2 1\n" "#define GL_ARB_sparse_texture_clamp 1\n" // "#define GL_ARB_cull_distance 1\n" // present for 4.5, but need extension control over block members + "#define GL_EXT_shader_non_constant_global_initializers 1\n" ; } diff --git a/glslang/MachineIndependent/Versions.h b/glslang/MachineIndependent/Versions.h index 98da0e6307f8f75a6e6c09f99c262e65998bcf31..3a212a00b8a80cfedfe3dcab0425c33c2e6cb119 100644 --- a/glslang/MachineIndependent/Versions.h +++ b/glslang/MachineIndependent/Versions.h @@ -130,6 +130,8 @@ const char* const E_GL_ARB_sparse_texture2 = "GL_ARB_sparse_texture const char* const E_GL_ARB_sparse_texture_clamp = "GL_ARB_sparse_texture_clamp"; //const char* const E_GL_ARB_cull_distance = "GL_ARB_cull_distance"; // present for 4.5, but need extension control over block members +const char* const E_GL_EXT_shader_non_constant_global_initializers = "GL_EXT_shader_non_constant_global_initializers"; + // #line and #include const char* const E_GL_GOOGLE_cpp_style_line_directive = "GL_GOOGLE_cpp_style_line_directive"; const char* const E_GL_GOOGLE_include_directive = "GL_GOOGLE_include_directive";