1 // 2 // Copyright (c) 2014 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 // StructureHLSL.h: 7 // Interfaces of methods for HLSL translation of GLSL structures. 8 // 9 10 #ifndef TRANSLATOR_STRUCTUREHLSL_H_ 11 #define TRANSLATOR_STRUCTUREHLSL_H_ 12 13 #include "compiler/translator/Common.h" 14 #include "compiler/translator/IntermNode.h" 15 16 #include <set> 17 18 class TInfoSinkBase; 19 class TScopeBracket; 20 21 namespace sh 22 { 23 24 // This helper class assists structure and interface block definitions in determining 25 // how to pack std140 structs within HLSL's packing rules. 26 class Std140PaddingHelper 27 { 28 public: 29 explicit Std140PaddingHelper(const std::map<TString, int> &structElementIndexes, 30 unsigned *uniqueCounter); 31 32 int elementIndex() const { return mElementIndex; } 33 int prePadding(const TType &type); 34 TString prePaddingString(const TType &type); 35 TString postPaddingString(const TType &type, bool useHLSLRowMajorPacking); 36 37 private: 38 TString next(); 39 40 unsigned *mPaddingCounter; 41 int mElementIndex; 42 const std::map<TString, int> &mStructElementIndexes; 43 }; 44 45 class StructureHLSL 46 { 47 public: 48 StructureHLSL(); 49 50 void addConstructor(const TType &type, const TString &name, const TIntermSequence *parameters); 51 std::string structsHeader() const; 52 53 TString defineQualified(const TStructure &structure, bool useHLSLRowMajorPacking, bool useStd140Packing); 54 static TString defineNameless(const TStructure &structure); 55 56 Std140PaddingHelper getPaddingHelper(); 57 58 private: 59 unsigned mUniquePaddingCounter; 60 61 std::map<TString, int> mStd140StructElementIndexes; 62 63 typedef std::set<TString> StructNames; 64 StructNames mStructNames; 65 66 typedef std::set<TString> Constructors; 67 Constructors mConstructors; 68 69 typedef std::vector<TString> StructDeclarations; 70 StructDeclarations mStructDeclarations; 71 72 void storeStd140ElementIndex(const TStructure &structure, bool useHLSLRowMajorPacking); 73 static TString define(const TStructure &structure, bool useHLSLRowMajorPacking, 74 bool useStd140Packing, Std140PaddingHelper *padHelper); 75 }; 76 77 } 78 79 #endif // COMPILER_STRUCTUREHLSL_H_ 80