From 21f1286f57a05b39fbc45a7dfbaf899ede04317b Mon Sep 17 00:00:00 2001 From: John Kessenich <cepheus@frii.com> Date: Fri, 17 Jun 2016 12:43:31 -0600 Subject: [PATCH] Front-end: Implement GL_EXT_shader_non_constant_global_initializers. This lets ES shaders use non-constant initializers for non-constant globals. --- Test/100.frag | 6 +++++ Test/baseResults/100.frag.out | 30 +++++++++++++++++++++- glslang/MachineIndependent/ParseHelper.cpp | 12 +++++---- glslang/MachineIndependent/Versions.cpp | 4 +++ glslang/MachineIndependent/Versions.h | 2 ++ 5 files changed, 48 insertions(+), 6 deletions(-) diff --git a/Test/100.frag b/Test/100.frag index ce6a6eec5..4f0c69b5d 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 7af716d84..70b893494 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 35085af62..8d7ecdec5 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 ec418dddd..7d5a81e72 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 98da0e630..3a212a00b 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"; -- GitLab