Qiankun Miao | d842a6b | 2016-08-29 10:05:27 +0800 | [diff] [blame^] | 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/IntermNode.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. |
| 19 | class RemoveInvariantDeclarationTraverser : public TIntermTraverser |
| 20 | { |
| 21 | public: |
| 22 | RemoveInvariantDeclarationTraverser() : TIntermTraverser(true, false, false) {} |
| 23 | |
| 24 | private: |
| 25 | bool visitAggregate(Visit visit, TIntermAggregate *node) override |
| 26 | { |
| 27 | if (node->getOp() == EOpInvariantDeclaration) |
| 28 | { |
| 29 | TIntermSequence emptyReplacement; |
| 30 | mMultiReplacements.push_back( |
| 31 | NodeReplaceWithMultipleEntry(getParentNode()->getAsBlock(), node, emptyReplacement)); |
| 32 | return false; |
| 33 | } |
| 34 | return true; |
| 35 | } |
| 36 | }; |
| 37 | |
| 38 | } // anonymous namespace |
| 39 | |
| 40 | void RemoveInvariantDeclaration(TIntermNode *root) |
| 41 | { |
| 42 | RemoveInvariantDeclarationTraverser traverser; |
| 43 | root->traverse(&traverser); |
| 44 | traverser.updateTree(); |
| 45 | } |
| 46 | |
| 47 | } // namespace sh |