Line data Source code
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 COMPILER_TRANSLATOR_STRUCTUREHLSL_H_
11 : #define COMPILER_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 int *uniqueCounter);
31 : Std140PaddingHelper(const Std140PaddingHelper &other);
32 : Std140PaddingHelper &operator=(const Std140PaddingHelper &other);
33 :
34 0 : 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:
40 : TString next();
41 :
42 : unsigned *mPaddingCounter;
43 : int mElementIndex;
44 : const std::map<TString, int> *mStructElementIndexes;
45 : };
46 :
47 0 : class StructureHLSL : angle::NonCopyable
48 : {
49 : public:
50 : StructureHLSL();
51 :
52 : // Returns the name of the constructor function. "name" parameter is the name of the type being
53 : // constructed.
54 : TString addConstructor(const TType &type,
55 : const TString &name,
56 : const TIntermSequence *parameters);
57 : std::string structsHeader() const;
58 :
59 : TString defineQualified(const TStructure &structure, bool useHLSLRowMajorPacking, bool useStd140Packing);
60 : static TString defineNameless(const TStructure &structure);
61 :
62 : Std140PaddingHelper getPaddingHelper();
63 :
64 : private:
65 : unsigned mUniquePaddingCounter;
66 :
67 : std::map<TString, int> mStd140StructElementIndexes;
68 :
69 : typedef std::set<TString> StructNames;
70 : StructNames mStructNames;
71 :
72 : typedef std::set<TString> Constructors;
73 : Constructors mConstructors;
74 :
75 : typedef std::vector<TString> StructDeclarations;
76 : StructDeclarations mStructDeclarations;
77 :
78 : void storeStd140ElementIndex(const TStructure &structure, bool useHLSLRowMajorPacking);
79 : static TString define(const TStructure &structure, bool useHLSLRowMajorPacking,
80 : bool useStd140Packing, Std140PaddingHelper *padHelper);
81 : };
82 :
83 : }
84 :
85 : #endif // COMPILER_TRANSLATOR_STRUCTUREHLSL_H_
|