blob: 6a026c86b6daeeef491e384ae065181a0275b8fe [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
Olli Etuahoc26214d2018-03-16 10:43:11 +02009#include "compiler/translator/tree_util/IntermTraverse.h"
Qiankun Miao705a9192016-08-29 10:05:27 +080010
11namespace sh
12{
13
14namespace
15{
16
17// An AST traverser that removes invariant declaration for input in fragment shader
Qiankun Miao89dd8f32016-11-09 12:59:30 +000018// when GLSL >= 4.20 and for output in vertex shader when GLSL < 4.2.
Qiankun Miao705a9192016-08-29 10:05:27 +080019class RemoveInvariantDeclarationTraverser : public TIntermTraverser
20{
21 public:
22 RemoveInvariantDeclarationTraverser() : TIntermTraverser(true, false, false) {}
23
24 private:
Olli Etuahobf4e1b72016-12-09 11:30:15 +000025 bool visitInvariantDeclaration(Visit visit, TIntermInvariantDeclaration *node) override
Qiankun Miao705a9192016-08-29 10:05:27 +080026 {
Olli Etuahobf4e1b72016-12-09 11:30:15 +000027 TIntermSequence emptyReplacement;
28 mMultiReplacements.push_back(
29 NodeReplaceWithMultipleEntry(getParentNode()->getAsBlock(), node, emptyReplacement));
30 return false;
Qiankun Miao705a9192016-08-29 10:05:27 +080031 }
32};
33
34} // anonymous namespace
35
36void RemoveInvariantDeclaration(TIntermNode *root)
37{
38 RemoveInvariantDeclarationTraverser traverser;
39 root->traverse(&traverser);
40 traverser.updateTree();
41}
42
43} // namespace sh