blob: c5217ea319bd6046490b885315affb0059e5481c [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.com4f39fd92010-03-08 20:26:45 +000049 void outputTriplet(Visit visit, const char *preString, const char *inString, const char *postString);
daniel@transgaming.com005c7392010-04-15 20:45:27 +000050 TString argumentString(const TIntermSymbol *symbol);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000051
daniel@transgaming.com950f9932010-04-13 03:26:14 +000052 TParseContext &mContext;
daniel@transgaming.comb5875982010-04-15 20:44:53 +000053 UnfoldSelect *mUnfoldSelect;
daniel@transgaming.comf9ef1072010-04-22 13:35:16 +000054 bool mInsideFunction;
daniel@transgaming.com950f9932010-04-13 03:26:14 +000055
56 // Output streams
57 TInfoSinkBase mHeader;
58 TInfoSinkBase mBody;
59 TInfoSinkBase mFooter;
daniel@transgaming.comd91cfe72010-04-13 03:26:17 +000060
daniel@transgaming.com86f7c9d2010-04-20 18:52:06 +000061 std::set<std::string> mReferencedUniforms;
62 std::set<std::string> mReferencedAttributes;
63 std::set<std::string> mReferencedVaryings;
64
daniel@transgaming.comd91cfe72010-04-13 03:26:17 +000065 // Parameters determining what goes in the header output
daniel@transgaming.com5024cc42010-04-20 18:52:04 +000066 bool mUsesTexture2D;
67 bool mUsesTexture2D_bias;
68 bool mUsesTexture2DProj;
69 bool mUsesTexture2DProj_bias;
70 bool mUsesTextureCube;
71 bool mUsesTextureCube_bias;
daniel@transgaming.com0bbb0312010-04-26 15:33:39 +000072 bool mUsesFaceforward1;
73 bool mUsesFaceforward2;
74 bool mUsesFaceforward3;
75 bool mUsesFaceforward4;
daniel@transgaming.comd91cfe72010-04-13 03:26:17 +000076 bool mUsesEqualMat2;
77 bool mUsesEqualMat3;
78 bool mUsesEqualMat4;
79 bool mUsesEqualVec2;
80 bool mUsesEqualVec3;
81 bool mUsesEqualVec4;
82 bool mUsesEqualIVec2;
83 bool mUsesEqualIVec3;
84 bool mUsesEqualIVec4;
85 bool mUsesEqualBVec2;
86 bool mUsesEqualBVec3;
87 bool mUsesEqualBVec4;
daniel@transgaming.com005c7392010-04-15 20:45:27 +000088
89 int mArgumentIndex; // For creating unique argument names
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000090};
91}
92
93#endif // COMPILER_OUTPUTHLSL_H_