Edit

kc3-lang/angle/src/compiler/translator/tree_ops/RemoveInvariantDeclaration.cpp

Branch :

  • Show log

    Commit

  • Author : Shahbaz Youssefi
    Date : 2021-01-19 12:48:15
    Hash : 9f4b159b
    Message : Translator: Avoid vector copies with multi-replacement Turns push_backs into emplace_backs and changes the TIntermSequence constructor argument to &&. Bug: angleproject:5535 Change-Id: I640ce879b6ade48a28dea6385ebb7a95cb8304ff Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2636680 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Tim Van Patten <timvp@google.com>

  • src/compiler/translator/tree_ops/RemoveInvariantDeclaration.cpp
  • //
    // Copyright 2016 The ANGLE Project Authors. All rights reserved.
    // Use of this source code is governed by a BSD-style license that can be
    // found in the LICENSE file.
    //
    
    #include "compiler/translator/tree_ops/RemoveInvariantDeclaration.h"
    
    #include "compiler/translator/tree_util/IntermTraverse.h"
    
    namespace sh
    {
    
    namespace
    {
    
    // An AST traverser that removes invariant declaration for input in fragment shader
    // when GLSL >= 4.20 and for output in vertex shader when GLSL < 4.2.
    class RemoveInvariantDeclarationTraverser : public TIntermTraverser
    {
      public:
        RemoveInvariantDeclarationTraverser() : TIntermTraverser(true, false, false) {}
    
      private:
        bool visitGlobalQualifierDeclaration(Visit visit,
                                             TIntermGlobalQualifierDeclaration *node) override
        {
            if (node->isInvariant())
            {
                TIntermSequence emptyReplacement;
                mMultiReplacements.emplace_back(getParentNode()->getAsBlock(), node,
                                                std::move(emptyReplacement));
            }
            return false;
        }
    };
    
    }  // anonymous namespace
    
    bool RemoveInvariantDeclaration(TCompiler *compiler, TIntermNode *root)
    {
        RemoveInvariantDeclarationTraverser traverser;
        root->traverse(&traverser);
        return traverser.updateTree(compiler, root);
    }
    
    }  // namespace sh