blob: dd2389ce2e71a8e53d6ec7d6890d558056547f49 [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.com0bbb0312010-04-26 15:33:39 +000076 bool mUsesFaceforward1;
77 bool mUsesFaceforward2;
78 bool mUsesFaceforward3;
79 bool mUsesFaceforward4;
daniel@transgaming.comd91cfe72010-04-13 03:26:17 +000080 bool mUsesEqualMat2;
81 bool mUsesEqualMat3;
82 bool mUsesEqualMat4;
83 bool mUsesEqualVec2;
84 bool mUsesEqualVec3;
85 bool mUsesEqualVec4;
86 bool mUsesEqualIVec2;
87 bool mUsesEqualIVec3;
88 bool mUsesEqualIVec4;
89 bool mUsesEqualBVec2;
90 bool mUsesEqualBVec3;
91 bool mUsesEqualBVec4;
daniel@transgaming.com005c7392010-04-15 20:45:27 +000092
daniel@transgaming.com63691862010-04-29 03:32:42 +000093 struct Constructor // Describes a constructor signature
94 {
95 TType type;
96 TString name;
97
98 typedef std::vector<TType> ParameterArray;
99 ParameterArray parameters;
100 };
101
102 struct CompareConstructor
103 {
104 bool operator()(const Constructor &x, const Constructor &y) const;
105 };
106
107 typedef std::set<Constructor, CompareConstructor> ConstructorSet;
108 ConstructorSet mConstructors;
109
daniel@transgaming.com7a7003c2010-04-29 03:35:33 +0000110 typedef std::list<TType> StructureArray;
111 StructureArray mStructures;
112
daniel@transgaming.com005c7392010-04-15 20:45:27 +0000113 int mArgumentIndex; // For creating unique argument names
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000114};
115}
116
117#endif // COMPILER_OUTPUTHLSL_H_