blob: ea247663776be8e2fc4cd746d07cb17e665a21a4 [file] [log] [blame]
Qiankun Miao705a9192016-08-29 10:05:27 +08001//
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
11namespace sh
12{
13
14namespace
15{
16
17// An AST traverser that removes invariant declaration for input in fragment shader
18// when GLSL >= 4.20.
19class 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 for (TIntermNode *&child : *node->getSequence())
30 {
31 TIntermTyped *typed = child->getAsTyped();
32 if (typed && typed->getQualifier() == EvqVaryingIn)
33 {
34 TIntermSequence emptyReplacement;
35 mMultiReplacements.push_back(NodeReplaceWithMultipleEntry(
36 getParentNode()->getAsBlock(), node, emptyReplacement));
37 return false;
38 }
39 }
40 }
41 return true;
42 }
43};
44
45} // anonymous namespace
46
47void RemoveInvariantDeclaration(TIntermNode *root)
48{
49 RemoveInvariantDeclarationTraverser traverser;
50 root->traverse(&traverser);
51 traverser.updateTree();
52}
53
54} // namespace sh