OSDN Git Service

Restrict GLSL globals to be initialized with constant expressions.
authorNicolas Capens <capn@google.com>
Thu, 7 Apr 2016 05:03:14 +0000 (01:03 -0400)
committerNicolas Capens <nicolascapens@google.com>
Thu, 10 Aug 2017 15:38:04 +0000 (15:38 +0000)
This follows the GLSL ES 1.0 and 3.0 specs more strictly.

Change-Id: I323e90ef0a1588109e2cb7988136a9520e501a6d
Reviewed-on: https://swiftshader-review.googlesource.com/5065
Tested-by: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
src/OpenGL/compiler/Android.mk
src/OpenGL/compiler/BUILD.gn
src/OpenGL/compiler/Compiler.vcxproj
src/OpenGL/compiler/Compiler.vcxproj.filters
src/OpenGL/compiler/ParseHelper.cpp
src/OpenGL/compiler/ValidateGlobalInitializer.cpp [deleted file]
src/OpenGL/compiler/ValidateGlobalInitializer.h [deleted file]

index 5bca1fe..da35aa0 100644 (file)
@@ -69,7 +69,6 @@ COMMON_SRC_FILES := \
        SymbolTable.cpp \
        TranslatorASM.cpp \
        util.cpp \
-       ValidateGlobalInitializer.cpp \
        ValidateLimitations.cpp \
        ValidateSwitch.cpp \
 
index 3341e1e..3759f1c 100644 (file)
@@ -57,7 +57,6 @@ swiftshader_source_set("swiftshader_opengl_compiler") {
     "PoolAlloc.cpp",
     "SymbolTable.cpp",
     "TranslatorASM.cpp",
-    "ValidateGlobalInitializer.cpp",
     "ValidateLimitations.cpp",
     "ValidateSwitch.cpp",
     "debug.cpp",
index 58a0e5a..c4f56bf 100644 (file)
     <ClCompile Include="SymbolTable.cpp" />\r
     <ClCompile Include="TranslatorASM.cpp" />\r
     <ClCompile Include="util.cpp" />\r
-    <ClCompile Include="ValidateGlobalInitializer.cpp" />\r
     <ClCompile Include="ValidateLimitations.cpp" />\r
     <ClCompile Include="glslang_lex.cpp" />\r
     <ClCompile Include="glslang_tab.cpp" />\r
     <ClInclude Include="TranslatorASM.h" />\r
     <ClInclude Include="Types.h" />\r
     <ClInclude Include="util.h" />\r
-    <ClInclude Include="ValidateGlobalInitializer.h" />\r
     <ClInclude Include="ValidateLimitations.h" />\r
     <ClInclude Include="glslang_tab.h" />\r
     <ClInclude Include="ValidateSwitch.h" />\r
index a4435bc..91d0749 100644 (file)
@@ -86,9 +86,6 @@
     <ClCompile Include="ValidateSwitch.cpp">\r
       <Filter>Source Files</Filter>\r
     </ClCompile>\r
-    <ClCompile Include="ValidateGlobalInitializer.cpp">\r
-      <Filter>Source Files</Filter>\r
-    </ClCompile>\r
   </ItemGroup>\r
   <ItemGroup>\r
     <ClInclude Include="BaseTypes.h">\r
     <ClInclude Include="ValidateSwitch.h">\r
       <Filter>Header Files</Filter>\r
     </ClInclude>\r
-    <ClInclude Include="ValidateGlobalInitializer.h">\r
-      <Filter>Header Files</Filter>\r
-    </ClInclude>\r
   </ItemGroup>\r
   <ItemGroup>\r
     <CustomBuild Include="glslang.l">\r
index 7cca42c..3fea084 100644 (file)
@@ -19,7 +19,6 @@
 
 #include "glslang.h"
 #include "preprocessor/SourceLocation.h"
-#include "ValidateGlobalInitializer.h"
 #include "ValidateSwitch.h"
 
 ///////////////////////////////////////////////////////////////////////
@@ -1300,19 +1299,11 @@ bool TParseContext::executeInitializer(const TSourceLoc& line, const TString& id
                return true;
        }
 
-       bool globalInitWarning = false;
-       if(symbolTable.atGlobalLevel() && !ValidateGlobalInitializer(initializer, this, &globalInitWarning))
+       if(symbolTable.atGlobalLevel() && initializer->getQualifier() != EvqConstExpr)
        {
-               // Error message does not completely match behavior with ESSL 1.00, but
-               // we want to steer developers towards only using constant expressions.
                error(line, "global variable initializers must be constant expressions", "=");
                return true;
        }
-       if(globalInitWarning)
-       {
-               warning(line, "global variable initializers should be constant expressions "
-                       "(uniforms and globals are allowed in global initializers for legacy compatibility)", "=");
-       }
 
        //
        // identifier must be of type constant, a global, or a temporary
diff --git a/src/OpenGL/compiler/ValidateGlobalInitializer.cpp b/src/OpenGL/compiler/ValidateGlobalInitializer.cpp
deleted file mode 100644 (file)
index 6c5fa86..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//    http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#include "ValidateGlobalInitializer.h"
-
-#include "ParseHelper.h"
-
-namespace
-{
-
-class ValidateGlobalInitializerTraverser : public TIntermTraverser
-{
-public:
-       ValidateGlobalInitializerTraverser(const TParseContext *context);
-
-       void visitSymbol(TIntermSymbol *node) override;
-
-       bool isValid() const { return mIsValid; }
-       bool issueWarning() const { return mIssueWarning; }
-
-private:
-       const TParseContext *mContext;
-       bool mIsValid;
-       bool mIssueWarning;
-};
-
-void ValidateGlobalInitializerTraverser::visitSymbol(TIntermSymbol *node)
-{
-       const TSymbol *sym = mContext->symbolTable.find(node->getSymbol(), mContext->getShaderVersion());
-       if (sym->isVariable())
-       {
-               // ESSL 1.00 section 4.3 (or ESSL 3.00 section 4.3):
-               // Global initializers must be constant expressions.
-               const TVariable *var = static_cast<const TVariable *>(sym);
-               switch (var->getType().getQualifier())
-               {
-               case EvqConstExpr:
-                       break;
-               case EvqGlobal:
-               case EvqTemporary:
-               case EvqUniform:
-                       // We allow these cases to be compatible with legacy ESSL 1.00 content.
-                       // Implement stricter rules for ESSL 3.00 since there's no legacy content to deal with.
-                       if (mContext->getShaderVersion() >= 300)
-                       {
-                               mIsValid = false;
-                       }
-                       else
-                       {
-                               mIssueWarning = true;
-                       }
-                       break;
-               default:
-                       mIsValid = false;
-               }
-       }
-}
-
-ValidateGlobalInitializerTraverser::ValidateGlobalInitializerTraverser(const TParseContext *context)
-       : TIntermTraverser(true, false, false),
-         mContext(context),
-         mIsValid(true),
-         mIssueWarning(false)
-{
-}
-
-} // namespace
-
-bool ValidateGlobalInitializer(TIntermTyped *initializer, const TParseContext *context, bool *warning)
-{
-       ValidateGlobalInitializerTraverser validate(context);
-       initializer->traverse(&validate);
-       ASSERT(warning != nullptr);
-       *warning = validate.issueWarning();
-       return validate.isValid();
-}
-
diff --git a/src/OpenGL/compiler/ValidateGlobalInitializer.h b/src/OpenGL/compiler/ValidateGlobalInitializer.h
deleted file mode 100644 (file)
index 28c1293..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//    http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#ifndef COMPILER_TRANSLATOR_VALIDATEGLOBALINITIALIZER_H_
-#define COMPILER_TRANSLATOR_VALIDATEGLOBALINITIALIZER_H_
-
-class TIntermTyped;
-class TParseContext;
-
-// Returns true if the initializer is valid.
-bool ValidateGlobalInitializer(TIntermTyped *initializer, const TParseContext *context, bool *warning);
-
-#endif // COMPILER_TRANSLATOR_VALIDATEGLOBALINITIALIZER_H_