1 //
2 // Copyright (c) 2016 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 
7 #include "compiler/translator/RemoveInvariantDeclaration.h"
8 
9 #include "compiler/translator/IntermTraverse.h"
10 
11 namespace sh
12 {
13 
14 namespace
15 {
16 
17 // An AST traverser that removes invariant declaration for input in fragment shader
18 // when GLSL >= 4.20 and for output in vertex shader when GLSL < 4.2.
19 class RemoveInvariantDeclarationTraverser : public TIntermTraverser
20 {
21   public:
RemoveInvariantDeclarationTraverser()22     RemoveInvariantDeclarationTraverser() : TIntermTraverser(true, false, false) {}
23 
24   private:
visitInvariantDeclaration(Visit visit,TIntermInvariantDeclaration * node)25     bool visitInvariantDeclaration(Visit visit, TIntermInvariantDeclaration *node) override
26     {
27         TIntermSequence emptyReplacement;
28         mMultiReplacements.push_back(
29             NodeReplaceWithMultipleEntry(getParentNode()->getAsBlock(), node, emptyReplacement));
30         return false;
31     }
32 };
33 
34 }  // anonymous namespace
35 
RemoveInvariantDeclaration(TIntermNode * root)36 void RemoveInvariantDeclaration(TIntermNode *root)
37 {
38     RemoveInvariantDeclarationTraverser traverser;
39     root->traverse(&traverser);
40     traverser.updateTree();
41 }
42 
43 }  // namespace sh
44