blob: 92c762e40d436a1824965e9f614a5ea8cca4a727 [file] [log] [blame]
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001//
Nicolas Capensb1f45b72013-12-19 17:37:19 -05002// Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
Geoff Lang0a73dd82014-11-19 16:18:08 -05007#ifndef COMPILER_TRANSLATOR_OUTPUTHLSL_H_
8#define COMPILER_TRANSLATOR_OUTPUTHLSL_H_
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00009
alokp@chromium.org4e89d232010-05-14 19:37:21 +000010#include <list>
11#include <set>
daniel@transgaming.com652468c2012-12-20 21:11:57 +000012#include <map>
13
Jamie Madillf51639a2014-06-25 16:04:57 -040014#include "angle_gl.h"
Jamie Madill13cfd272014-07-17 14:16:28 -040015
Jamie Madillb1a85f42014-08-19 15:23:24 -040016#include "compiler/translator/IntermNode.h"
Jamie Madill6b9cb252013-10-17 10:45:47 -040017#include "compiler/translator/ParseContext.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000018
19namespace sh
20{
daniel@transgaming.comf8f8f362012-04-28 00:35:00 +000021class UnfoldShortCircuit;
Jamie Madill8daaba12014-06-13 10:04:33 -040022class StructureHLSL;
Jamie Madillf91ce812014-06-13 10:04:34 -040023class UniformHLSL;
24
25typedef std::map<TString, TIntermSymbol*> ReferencedSymbols;
daniel@transgaming.comb5875982010-04-15 20:44:53 +000026
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000027class OutputHLSL : public TIntermTraverser
28{
29 public:
Jamie Madill54ad4f82014-09-03 09:40:46 -040030 OutputHLSL(TParseContext &context, TranslatorHLSL *parentTranslator);
daniel@transgaming.comb5875982010-04-15 20:44:53 +000031 ~OutputHLSL();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000032
daniel@transgaming.com950f9932010-04-13 03:26:14 +000033 void output();
34
daniel@transgaming.comb5875982010-04-15 20:44:53 +000035 TInfoSinkBase &getBodyStream();
36
Jamie Madill4e1fd412014-07-10 17:50:10 -040037 const std::map<std::string, unsigned int> &getInterfaceBlockRegisterMap() const;
Jamie Madill9fe25e92014-07-18 10:33:08 -040038 const std::map<std::string, unsigned int> &getUniformRegisterMap() const;
Jamie Madill4e1fd412014-07-10 17:50:10 -040039
daniel@transgaming.comb5875982010-04-15 20:44:53 +000040 static TString initializer(const TType &type);
daniel@transgaming.comb5875982010-04-15 20:44:53 +000041
daniel@transgaming.com950f9932010-04-13 03:26:14 +000042 protected:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000043 void header();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000044
daniel@transgaming.com950f9932010-04-13 03:26:14 +000045 // Visit AST nodes and output their code to the body stream
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000046 void visitSymbol(TIntermSymbol*);
Jamie Madill4cfb1e82014-07-07 12:49:23 -040047 void visitRaw(TIntermRaw*);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000048 void visitConstantUnion(TIntermConstantUnion*);
49 bool visitBinary(Visit visit, TIntermBinary*);
50 bool visitUnary(Visit visit, TIntermUnary*);
51 bool visitSelection(Visit visit, TIntermSelection*);
52 bool visitAggregate(Visit visit, TIntermAggregate*);
53 bool visitLoop(Visit visit, TIntermLoop*);
54 bool visitBranch(Visit visit, TIntermBranch*);
55
daniel@transgaming.com44fffee2012-04-28 00:34:20 +000056 void traverseStatements(TIntermNode *node);
daniel@transgaming.comb5875982010-04-15 20:44:53 +000057 bool isSingleStatement(TIntermNode *node);
daniel@transgaming.com4a35ef22010-04-08 03:51:06 +000058 bool handleExcessiveLoop(TIntermLoop *node);
daniel@transgaming.com67de6d62010-04-29 03:35:30 +000059 void outputTriplet(Visit visit, const TString &preString, const TString &inString, const TString &postString);
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000060 void outputLineDirective(int line);
daniel@transgaming.com005c7392010-04-15 20:45:27 +000061 TString argumentString(const TIntermSymbol *symbol);
daniel@transgaming.com0b6b8342010-04-26 15:33:45 +000062 int vectorSize(const TType &type) const;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000063
Nicolas Capens1af18dc2014-06-11 11:07:32 -040064 void outputConstructor(Visit visit, const TType &type, const TString &name, const TIntermSequence *parameters);
daniel@transgaming.coma54da4e2010-05-07 13:03:28 +000065 const ConstantUnion *writeConstantUnion(const TType &type, const ConstantUnion *constUnion);
daniel@transgaming.com63691862010-04-29 03:32:42 +000066
daniel@transgaming.com950f9932010-04-13 03:26:14 +000067 TParseContext &mContext;
shannon.woods@transgaming.comb73964e2013-01-25 21:49:14 +000068 const ShShaderOutput mOutputType;
daniel@transgaming.comf8f8f362012-04-28 00:35:00 +000069 UnfoldShortCircuit *mUnfoldShortCircuit;
daniel@transgaming.comf9ef1072010-04-22 13:35:16 +000070 bool mInsideFunction;
daniel@transgaming.com950f9932010-04-13 03:26:14 +000071
72 // Output streams
73 TInfoSinkBase mHeader;
74 TInfoSinkBase mBody;
75 TInfoSinkBase mFooter;
daniel@transgaming.comd91cfe72010-04-13 03:26:17 +000076
daniel@transgaming.com8803b852012-12-20 21:11:47 +000077 ReferencedSymbols mReferencedUniforms;
shannonwoods@chromium.org4a643ae2013-05-30 00:12:27 +000078 ReferencedSymbols mReferencedInterfaceBlocks;
daniel@transgaming.com8803b852012-12-20 21:11:47 +000079 ReferencedSymbols mReferencedAttributes;
80 ReferencedSymbols mReferencedVaryings;
Jamie Madill46131a32013-06-20 11:55:50 -040081 ReferencedSymbols mReferencedOutputVariables;
daniel@transgaming.com86f7c9d2010-04-20 18:52:06 +000082
Jamie Madill8daaba12014-06-13 10:04:33 -040083 StructureHLSL *mStructureHLSL;
Jamie Madillf91ce812014-06-13 10:04:34 -040084 UniformHLSL *mUniformHLSL;
Jamie Madill8daaba12014-06-13 10:04:33 -040085
Nicolas Capense0ba27a2013-06-24 16:10:52 -040086 struct TextureFunction
87 {
Nicolas Capens75fb4752013-07-10 15:14:47 -040088 enum Method
Nicolas Capense0ba27a2013-06-24 16:10:52 -040089 {
Nicolas Capens75fb4752013-07-10 15:14:47 -040090 IMPLICIT, // Mipmap LOD determined implicitly (standard lookup)
Nicolas Capense0ba27a2013-06-24 16:10:52 -040091 BIAS,
92 LOD,
Nicolas Capens75fb4752013-07-10 15:14:47 -040093 LOD0,
Nicolas Capens84cfa122014-04-14 13:48:45 -040094 LOD0BIAS,
Nicolas Capensfc014542014-02-18 14:47:13 -050095 SIZE, // textureSize()
Nicolas Capensd11d5492014-02-19 17:06:10 -050096 FETCH,
97 GRAD
Nicolas Capense0ba27a2013-06-24 16:10:52 -040098 };
99
100 TBasicType sampler;
101 int coords;
102 bool proj;
Nicolas Capensb1f45b72013-12-19 17:37:19 -0500103 bool offset;
Nicolas Capens75fb4752013-07-10 15:14:47 -0400104 Method method;
Nicolas Capense0ba27a2013-06-24 16:10:52 -0400105
106 TString name() const;
107
108 bool operator<(const TextureFunction &rhs) const;
109 };
110
111 typedef std::set<TextureFunction> TextureFunctionSet;
112
daniel@transgaming.comd91cfe72010-04-13 03:26:17 +0000113 // Parameters determining what goes in the header output
Nicolas Capense0ba27a2013-06-24 16:10:52 -0400114 TextureFunctionSet mUsesTexture;
shannon.woods%transgaming.com@gtempaccount.comaa8b5cf2013-04-13 03:31:55 +0000115 bool mUsesFragColor;
116 bool mUsesFragData;
daniel@transgaming.comd7c98102010-05-14 17:30:48 +0000117 bool mUsesDepthRange;
daniel@transgaming.com4af7acc2010-05-14 17:30:53 +0000118 bool mUsesFragCoord;
119 bool mUsesPointCoord;
120 bool mUsesFrontFacing;
121 bool mUsesPointSize;
Jamie Madill2aeb26a2013-07-08 14:02:55 -0400122 bool mUsesFragDepth;
daniel@transgaming.comd7c98102010-05-14 17:30:48 +0000123 bool mUsesXor;
124 bool mUsesMod1;
daniel@transgaming.com4229f592011-11-24 22:34:04 +0000125 bool mUsesMod2v;
126 bool mUsesMod2f;
127 bool mUsesMod3v;
128 bool mUsesMod3f;
129 bool mUsesMod4v;
130 bool mUsesMod4f;
daniel@transgaming.com0bbb0312010-04-26 15:33:39 +0000131 bool mUsesFaceforward1;
132 bool mUsesFaceforward2;
133 bool mUsesFaceforward3;
134 bool mUsesFaceforward4;
daniel@transgaming.com35342dc2012-02-28 02:01:22 +0000135 bool mUsesAtan2_1;
136 bool mUsesAtan2_2;
137 bool mUsesAtan2_3;
138 bool mUsesAtan2_4;
Jamie Madill3c9eeb92013-11-04 11:09:26 -0500139 bool mUsesDiscardRewriting;
Nicolas Capens655fe362014-04-11 13:12:34 -0400140 bool mUsesNestedBreak;
daniel@transgaming.com005c7392010-04-15 20:45:27 +0000141
shannon.woods%transgaming.com@gtempaccount.comaa8b5cf2013-04-13 03:31:55 +0000142 int mNumRenderTargets;
143
daniel@transgaming.comb6ef8f12010-11-15 16:41:14 +0000144 int mUniqueIndex; // For creating unique names
daniel@transgaming.com89431aa2012-05-31 01:20:29 +0000145
146 bool mContainsLoopDiscontinuity;
Corentin Wallez80bacde2014-11-10 12:07:37 -0800147 bool mContainsAnyLoop;
daniel@transgaming.com89431aa2012-05-31 01:20:29 +0000148 bool mOutputLod0Function;
daniel@transgaming.come11100c2012-05-31 01:20:32 +0000149 bool mInsideDiscontinuousLoop;
Nicolas Capens655fe362014-04-11 13:12:34 -0400150 int mNestedLoopDepth;
daniel@transgaming.come9b3f602012-07-11 20:37:31 +0000151
152 TIntermSymbol *mExcessiveLoopIndex;
daniel@transgaming.com652468c2012-12-20 21:11:57 +0000153
Jamie Madill98493dd2013-07-08 14:39:03 -0400154 TString structInitializerString(int indent, const TStructure &structure, const TString &rhsStructName);
daniel@transgaming.comf4d9fef2012-12-20 21:12:13 +0000155
Jamie Madill570e04d2013-06-21 09:15:33 -0400156 std::map<TIntermTyped*, TString> mFlaggedStructMappedNames;
157 std::map<TIntermTyped*, TString> mFlaggedStructOriginalNames;
158
159 void makeFlaggedStructMaps(const std::vector<TIntermTyped *> &flaggedStructs);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000160};
Jamie Madill8daaba12014-06-13 10:04:33 -0400161
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000162}
163
Geoff Lang0a73dd82014-11-19 16:18:08 -0500164#endif // COMPILER_TRANSLATOR_OUTPUTHLSL_H_