Path: blob/main_old/src/compiler/translator/FlagStd140Structs.cpp
1693 views
//1// Copyright 2013 The ANGLE Project Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4//5// FlagStd140Structs.cpp: Find structs in std140 blocks, where the padding added in the translator6// conflicts with the "natural" unpadded type.78#include "compiler/translator/FlagStd140Structs.h"910#include "compiler/translator/SymbolTable.h"11#include "compiler/translator/tree_util/IntermTraverse.h"1213namespace sh14{1516namespace17{1819class FlagStd140StructsTraverser : public TIntermTraverser20{21public:22FlagStd140StructsTraverser() : TIntermTraverser(true, false, false) {}2324const std::vector<MappedStruct> getMappedStructs() const { return mMappedStructs; }2526protected:27bool visitDeclaration(Visit visit, TIntermDeclaration *node) override;2829private:30void mapBlockStructMembers(TIntermSymbol *blockDeclarator, const TInterfaceBlock *block);3132std::vector<MappedStruct> mMappedStructs;33};3435void FlagStd140StructsTraverser::mapBlockStructMembers(TIntermSymbol *blockDeclarator,36const TInterfaceBlock *block)37{38for (auto *field : block->fields())39{40if (field->type()->getBasicType() == EbtStruct)41{42MappedStruct mappedStruct;43mappedStruct.blockDeclarator = blockDeclarator;44mappedStruct.field = field;45mMappedStructs.push_back(mappedStruct);46}47}48}4950bool FlagStd140StructsTraverser::visitDeclaration(Visit visit, TIntermDeclaration *node)51{52TIntermTyped *declarator = node->getSequence()->back()->getAsTyped();53if (declarator->getBasicType() == EbtInterfaceBlock)54{55const TInterfaceBlock *block = declarator->getType().getInterfaceBlock();56if (block->blockStorage() == EbsStd140)57{58mapBlockStructMembers(declarator->getAsSymbolNode(), block);59}60}61return false;62}6364} // anonymous namespace6566std::vector<MappedStruct> FlagStd140Structs(TIntermNode *node)67{68FlagStd140StructsTraverser flaggingTraversal;6970node->traverse(&flaggingTraversal);7172return flaggingTraversal.getMappedStructs();73}7475} // namespace sh767778