Jamie Madill | 8daaba1 | 2014-06-13 10:04:33 -0400 | [diff] [blame] | 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 | |
Geoff Lang | 0a73dd8 | 2014-11-19 16:18:08 -0500 | [diff] [blame] | 10 | #ifndef COMPILER_TRANSLATOR_STRUCTUREHLSL_H_ |
| 11 | #define COMPILER_TRANSLATOR_STRUCTUREHLSL_H_ |
Jamie Madill | 8daaba1 | 2014-06-13 10:04:33 -0400 | [diff] [blame] | 12 | |
| 13 | #include "compiler/translator/Common.h" |
Jamie Madill | b1a85f4 | 2014-08-19 15:23:24 -0400 | [diff] [blame] | 14 | #include "compiler/translator/IntermNode.h" |
Jamie Madill | 8daaba1 | 2014-06-13 10:04:33 -0400 | [diff] [blame] | 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: |
Jamie Madill | 33a74bd | 2014-08-18 15:47:59 -0400 | [diff] [blame] | 29 | explicit Std140PaddingHelper(const std::map<TString, int> &structElementIndexes, |
Jamie Madill | 80d934b | 2015-02-19 10:16:12 -0500 | [diff] [blame] | 30 | unsigned int *uniqueCounter); |
| 31 | Std140PaddingHelper(const Std140PaddingHelper &other); |
| 32 | Std140PaddingHelper &operator=(const Std140PaddingHelper &other); |
Jamie Madill | 8daaba1 | 2014-06-13 10:04:33 -0400 | [diff] [blame] | 33 | |
| 34 | int elementIndex() const { return mElementIndex; } |
| 35 | int prePadding(const TType &type); |
| 36 | TString prePaddingString(const TType &type); |
| 37 | TString postPaddingString(const TType &type, bool useHLSLRowMajorPacking); |
| 38 | |
| 39 | private: |
Jamie Madill | 33a74bd | 2014-08-18 15:47:59 -0400 | [diff] [blame] | 40 | TString next(); |
| 41 | |
| 42 | unsigned *mPaddingCounter; |
Jamie Madill | 8daaba1 | 2014-06-13 10:04:33 -0400 | [diff] [blame] | 43 | int mElementIndex; |
Jamie Madill | 80d934b | 2015-02-19 10:16:12 -0500 | [diff] [blame] | 44 | const std::map<TString, int> *mStructElementIndexes; |
Jamie Madill | 8daaba1 | 2014-06-13 10:04:33 -0400 | [diff] [blame] | 45 | }; |
| 46 | |
Jamie Madill | f0d10f8 | 2015-03-31 12:56:52 -0400 | [diff] [blame] | 47 | class StructureHLSL : angle::NonCopyable |
Jamie Madill | 8daaba1 | 2014-06-13 10:04:33 -0400 | [diff] [blame] | 48 | { |
| 49 | public: |
| 50 | StructureHLSL(); |
| 51 | |
| 52 | void addConstructor(const TType &type, const TString &name, const TIntermSequence *parameters); |
| 53 | std::string structsHeader() const; |
| 54 | |
| 55 | TString defineQualified(const TStructure &structure, bool useHLSLRowMajorPacking, bool useStd140Packing); |
| 56 | static TString defineNameless(const TStructure &structure); |
| 57 | |
Jamie Madill | 33a74bd | 2014-08-18 15:47:59 -0400 | [diff] [blame] | 58 | Std140PaddingHelper getPaddingHelper(); |
Jamie Madill | 8daaba1 | 2014-06-13 10:04:33 -0400 | [diff] [blame] | 59 | |
| 60 | private: |
Jamie Madill | 33a74bd | 2014-08-18 15:47:59 -0400 | [diff] [blame] | 61 | unsigned mUniquePaddingCounter; |
| 62 | |
Jamie Madill | 8daaba1 | 2014-06-13 10:04:33 -0400 | [diff] [blame] | 63 | std::map<TString, int> mStd140StructElementIndexes; |
| 64 | |
| 65 | typedef std::set<TString> StructNames; |
| 66 | StructNames mStructNames; |
| 67 | |
| 68 | typedef std::set<TString> Constructors; |
| 69 | Constructors mConstructors; |
| 70 | |
| 71 | typedef std::vector<TString> StructDeclarations; |
| 72 | StructDeclarations mStructDeclarations; |
| 73 | |
| 74 | void storeStd140ElementIndex(const TStructure &structure, bool useHLSLRowMajorPacking); |
| 75 | static TString define(const TStructure &structure, bool useHLSLRowMajorPacking, |
| 76 | bool useStd140Packing, Std140PaddingHelper *padHelper); |
| 77 | }; |
| 78 | |
| 79 | } |
| 80 | |
Geoff Lang | 0a73dd8 | 2014-11-19 16:18:08 -0500 | [diff] [blame] | 81 | #endif // COMPILER_TRANSLATOR_STRUCTUREHLSL_H_ |