blob: 9d64d3cab94cc02dc76f903371ad6b9c7aef202c [file] [log] [blame]
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001//
2// Copyright (c) 2002-2010 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
7#ifndef COMPILER_OUTPUTHLSL_H_
8#define COMPILER_OUTPUTHLSL_H_
9
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000010#include "compiler/intermediate.h"
11#include "compiler/ParseHelper.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000012
13namespace sh
14{
daniel@transgaming.comb5875982010-04-15 20:44:53 +000015class UnfoldSelect;
16
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000017class OutputHLSL : public TIntermTraverser
18{
19 public:
daniel@transgaming.comb5875982010-04-15 20:44:53 +000020 explicit OutputHLSL(TParseContext &context);
21 ~OutputHLSL();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000022
daniel@transgaming.com950f9932010-04-13 03:26:14 +000023 void output();
24
daniel@transgaming.comb5875982010-04-15 20:44:53 +000025 TInfoSinkBase &getBodyStream();
26
daniel@transgaming.comb5875982010-04-15 20:44:53 +000027 static TString qualifierString(TQualifier qualifier);
28 static TString typeString(const TType &type);
29 static TString arrayString(const TType &type);
30 static TString initializer(const TType &type);
31 static TString decorate(const TString &string); // Prepend an underscore to avoid naming clashes
32
daniel@transgaming.com950f9932010-04-13 03:26:14 +000033 protected:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000034 void header();
daniel@transgaming.come78c0c92010-03-28 19:36:06 +000035 void footer();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000036
daniel@transgaming.com950f9932010-04-13 03:26:14 +000037 // Visit AST nodes and output their code to the body stream
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000038 void visitSymbol(TIntermSymbol*);
39 void visitConstantUnion(TIntermConstantUnion*);
40 bool visitBinary(Visit visit, TIntermBinary*);
41 bool visitUnary(Visit visit, TIntermUnary*);
42 bool visitSelection(Visit visit, TIntermSelection*);
43 bool visitAggregate(Visit visit, TIntermAggregate*);
44 bool visitLoop(Visit visit, TIntermLoop*);
45 bool visitBranch(Visit visit, TIntermBranch*);
46
daniel@transgaming.comb5875982010-04-15 20:44:53 +000047 bool isSingleStatement(TIntermNode *node);
daniel@transgaming.com4a35ef22010-04-08 03:51:06 +000048 bool handleExcessiveLoop(TIntermLoop *node);
daniel@transgaming.com67de6d62010-04-29 03:35:30 +000049 void outputTriplet(Visit visit, const TString &preString, const TString &inString, const TString &postString);
daniel@transgaming.com005c7392010-04-15 20:45:27 +000050 TString argumentString(const TIntermSymbol *symbol);
daniel@transgaming.com0b6b8342010-04-26 15:33:45 +000051 int vectorSize(const TType &type) const;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000052
daniel@transgaming.com67de6d62010-04-29 03:35:30 +000053 void addConstructor(const TType &type, const TString &name, const TIntermSequence *parameters);
daniel@transgaming.coma54da4e2010-05-07 13:03:28 +000054 const ConstantUnion *writeConstantUnion(const TType &type, const ConstantUnion *constUnion);
daniel@transgaming.com63691862010-04-29 03:32:42 +000055
daniel@transgaming.com950f9932010-04-13 03:26:14 +000056 TParseContext &mContext;
daniel@transgaming.comb5875982010-04-15 20:44:53 +000057 UnfoldSelect *mUnfoldSelect;
daniel@transgaming.comf9ef1072010-04-22 13:35:16 +000058 bool mInsideFunction;
daniel@transgaming.com950f9932010-04-13 03:26:14 +000059
60 // Output streams
61 TInfoSinkBase mHeader;
62 TInfoSinkBase mBody;
63 TInfoSinkBase mFooter;
daniel@transgaming.comd91cfe72010-04-13 03:26:17 +000064
daniel@transgaming.com86f7c9d2010-04-20 18:52:06 +000065 std::set<std::string> mReferencedUniforms;
66 std::set<std::string> mReferencedAttributes;
67 std::set<std::string> mReferencedVaryings;
68
daniel@transgaming.comd91cfe72010-04-13 03:26:17 +000069 // Parameters determining what goes in the header output
daniel@transgaming.com5024cc42010-04-20 18:52:04 +000070 bool mUsesTexture2D;
71 bool mUsesTexture2D_bias;
72 bool mUsesTexture2DProj;
73 bool mUsesTexture2DProj_bias;
74 bool mUsesTextureCube;
75 bool mUsesTextureCube_bias;
daniel@transgaming.comd7c98102010-05-14 17:30:48 +000076 bool mUsesDepthRange;
77 bool mUsesXor;
78 bool mUsesMod1;
79 bool mUsesMod2;
80 bool mUsesMod3;
81 bool mUsesMod4;
daniel@transgaming.com0bbb0312010-04-26 15:33:39 +000082 bool mUsesFaceforward1;
83 bool mUsesFaceforward2;
84 bool mUsesFaceforward3;
85 bool mUsesFaceforward4;
daniel@transgaming.comd91cfe72010-04-13 03:26:17 +000086 bool mUsesEqualMat2;
87 bool mUsesEqualMat3;
88 bool mUsesEqualMat4;
89 bool mUsesEqualVec2;
90 bool mUsesEqualVec3;
91 bool mUsesEqualVec4;
92 bool mUsesEqualIVec2;
93 bool mUsesEqualIVec3;
94 bool mUsesEqualIVec4;
95 bool mUsesEqualBVec2;
96 bool mUsesEqualBVec3;
97 bool mUsesEqualBVec4;
daniel@transgaming.com0f189612010-05-07 13:03:36 +000098 bool mUsesAtan2;
daniel@transgaming.com005c7392010-04-15 20:45:27 +000099
daniel@transgaming.com63691862010-04-29 03:32:42 +0000100 struct Constructor // Describes a constructor signature
101 {
102 TType type;
103 TString name;
104
105 typedef std::vector<TType> ParameterArray;
106 ParameterArray parameters;
107 };
108
109 struct CompareConstructor
110 {
111 bool operator()(const Constructor &x, const Constructor &y) const;
112 };
113
114 typedef std::set<Constructor, CompareConstructor> ConstructorSet;
115 ConstructorSet mConstructors;
116
daniel@transgaming.com7a7003c2010-04-29 03:35:33 +0000117 typedef std::list<TType> StructureArray;
118 StructureArray mStructures;
119
daniel@transgaming.com005c7392010-04-15 20:45:27 +0000120 int mArgumentIndex; // For creating unique argument names
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000121};
122}
123
124#endif // COMPILER_OUTPUTHLSL_H_