blob: d9ee013436cd9bb1d9ed768d0708f07d097087e6 [file] [log] [blame]
zmo@google.com5601ea02011-06-10 18:23:25 +00001//
Jamie Madill02f20dd2013-09-12 12:07:42 -04002// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
zmo@google.com5601ea02011-06-10 18:23:25 +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_OUTPUTGLSLBASE_H_
8#define COMPILER_TRANSLATOR_OUTPUTGLSLBASE_H_
zmo@google.com5601ea02011-06-10 18:23:25 +00009
Jamie Madill01f85ac2014-06-06 11:55:04 -040010#include <set>
zmo@google.com5601ea02011-06-10 18:23:25 +000011
Jamie Madillb1a85f42014-08-19 15:23:24 -040012#include "compiler/translator/IntermNode.h"
Jamie Madill6b9cb252013-10-17 10:45:47 -040013#include "compiler/translator/ParseContext.h"
zmo@google.com5601ea02011-06-10 18:23:25 +000014
Jamie Madill45bcc782016-11-07 13:58:48 -050015namespace sh
16{
17
zmo@google.com5601ea02011-06-10 18:23:25 +000018class TOutputGLSLBase : public TIntermTraverser
19{
Zhenyao Mo9eedea02014-05-12 16:02:35 -070020 public:
21 TOutputGLSLBase(TInfoSinkBase &objSink,
shannon.woods@transgaming.com1d432bb2013-01-25 21:57:28 +000022 ShArrayIndexClampingStrategy clampingStrategy,
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +000023 ShHashFunction64 hashFunction,
Zhenyao Mo9eedea02014-05-12 16:02:35 -070024 NameMap &nameMap,
Qiankun Miao89dd8f32016-11-09 12:59:30 +000025 TSymbolTable &symbolTable,
26 sh::GLenum shaderType,
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080027 int shaderVersion,
Qiankun Miao705a9192016-08-29 10:05:27 +080028 ShShaderOutput output,
29 ShCompileOptions compileOptions);
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080030
Jamie Madilld7b1ab52016-12-12 14:42:19 -050031 ShShaderOutput getShaderOutput() const { return mOutput; }
zmo@google.com5601ea02011-06-10 18:23:25 +000032
Zhenyao Mo9eedea02014-05-12 16:02:35 -070033 protected:
34 TInfoSinkBase &objSink() { return mObjSink; }
Olli Etuaho56a2f952016-12-08 12:16:27 +000035 void writeFloat(TInfoSinkBase &out, float f);
Zhenyao Mo9eedea02014-05-12 16:02:35 -070036 void writeTriplet(Visit visit, const char *preStr, const char *inStr, const char *postStr);
Olli Etuahoae69d7e2015-10-07 17:19:50 +030037 void writeLayoutQualifier(const TType &type);
Zhenyao Mob7bf7422016-11-08 14:44:05 -080038 void writeInvariantQualifier(const TType &type);
Zhenyao Mo9eedea02014-05-12 16:02:35 -070039 void writeVariableType(const TType &type);
zmo@google.com5601ea02011-06-10 18:23:25 +000040 virtual bool writeVariablePrecision(TPrecision precision) = 0;
Zhenyao Mo9eedea02014-05-12 16:02:35 -070041 void writeFunctionParameters(const TIntermSequence &args);
Jamie Madill6ba6ead2015-05-04 14:21:21 -040042 const TConstantUnion *writeConstantUnion(const TType &type, const TConstantUnion *pConstUnion);
Olli Etuahoe92507b2016-07-04 11:20:10 +030043 void writeConstructorTriplet(Visit visit, const TType &type);
Zhenyao Mo9eedea02014-05-12 16:02:35 -070044 TString getTypeName(const TType &type);
zmo@google.com5601ea02011-06-10 18:23:25 +000045
Corentin Walleze5a1f272015-08-21 02:58:25 +020046 void visitSymbol(TIntermSymbol *node) override;
47 void visitConstantUnion(TIntermConstantUnion *node) override;
Olli Etuahob6fa0432016-09-28 16:28:05 +010048 bool visitSwizzle(Visit visit, TIntermSwizzle *node) override;
Corentin Walleze5a1f272015-08-21 02:58:25 +020049 bool visitBinary(Visit visit, TIntermBinary *node) override;
50 bool visitUnary(Visit visit, TIntermUnary *node) override;
Olli Etuahod0bad2c2016-09-09 18:01:16 +030051 bool visitTernary(Visit visit, TIntermTernary *node) override;
Olli Etuaho57961272016-09-14 13:57:46 +030052 bool visitIfElse(Visit visit, TIntermIfElse *node) override;
Corentin Walleze5a1f272015-08-21 02:58:25 +020053 bool visitSwitch(Visit visit, TIntermSwitch *node) override;
54 bool visitCase(Visit visit, TIntermCase *node) override;
Olli Etuaho336b1472016-10-05 16:37:55 +010055 bool visitFunctionDefinition(Visit visit, TIntermFunctionDefinition *node) override;
Corentin Walleze5a1f272015-08-21 02:58:25 +020056 bool visitAggregate(Visit visit, TIntermAggregate *node) override;
Olli Etuaho6d40bbd2016-09-30 13:49:38 +010057 bool visitBlock(Visit visit, TIntermBlock *node) override;
Olli Etuahobf4e1b72016-12-09 11:30:15 +000058 bool visitInvariantDeclaration(Visit visit, TIntermInvariantDeclaration *node) override;
Olli Etuaho13389b62016-10-16 11:48:18 +010059 bool visitDeclaration(Visit visit, TIntermDeclaration *node) override;
Corentin Walleze5a1f272015-08-21 02:58:25 +020060 bool visitLoop(Visit visit, TIntermLoop *node) override;
61 bool visitBranch(Visit visit, TIntermBranch *node) override;
zmo@google.com5601ea02011-06-10 18:23:25 +000062
Olli Etuaho6d40bbd2016-09-30 13:49:38 +010063 void visitCodeBlock(TIntermBlock *node);
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +000064
65 // Return the original name if hash function pointer is NULL;
66 // otherwise return the hashed name.
Olli Etuaho0982a2b2016-11-01 15:13:46 +000067 TString hashName(const TName &name);
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +000068 // Same as hashName(), but without hashing built-in variables.
Olli Etuaho0982a2b2016-11-01 15:13:46 +000069 TString hashVariableName(const TName &name);
Olli Etuaho59f9a642015-08-06 20:38:26 +030070 // Same as hashName(), but without hashing built-in functions and with unmangling.
71 TString hashFunctionNameIfNeeded(const TName &mangledName);
Nicolas Capens46485082014-04-15 13:12:50 -040072 // Used to translate function names for differences between ESSL and GLSL
Zhenyao Mo9eedea02014-05-12 16:02:35 -070073 virtual TString translateTextureFunction(TString &name) { return name; }
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +000074
Zhenyao Mo9eedea02014-05-12 16:02:35 -070075 private:
76 bool structDeclared(const TStructure *structure) const;
77 void declareStruct(const TStructure *structure);
Jamie Madill98493dd2013-07-08 14:39:03 -040078
Geoff Langbdcc54a2015-09-02 13:09:48 -040079 void declareInterfaceBlockLayout(const TInterfaceBlock *interfaceBlock);
80 void declareInterfaceBlock(const TInterfaceBlock *interfaceBlock);
81
Zhenyao Mo9eedea02014-05-12 16:02:35 -070082 void writeBuiltInFunctionTriplet(Visit visit, const char *preStr, bool useEmulatedFunction);
83
Zhenyao Mob7bf7422016-11-08 14:44:05 -080084 const char *mapQualifierToString(TQualifier qialifier);
85
Zhenyao Mo9eedea02014-05-12 16:02:35 -070086 TInfoSinkBase &mObjSink;
zmo@google.com5601ea02011-06-10 18:23:25 +000087 bool mDeclaringVariables;
88
Jamie Madill01f85ac2014-06-06 11:55:04 -040089 // This set contains all the ids of the structs from every scope.
90 std::set<int> mDeclaredStructs;
zmo@google.com5601ea02011-06-10 18:23:25 +000091
shannon.woods@transgaming.com1d432bb2013-01-25 21:57:28 +000092 ShArrayIndexClampingStrategy mClampingStrategy;
93
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +000094 // name hashing.
95 ShHashFunction64 mHashFunction;
shannon.woods@transgaming.com1d432bb2013-01-25 21:57:28 +000096
Zhenyao Mo9eedea02014-05-12 16:02:35 -070097 NameMap &mNameMap;
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +000098
Zhenyao Mo9eedea02014-05-12 16:02:35 -070099 TSymbolTable &mSymbolTable;
Jamie Madill02f20dd2013-09-12 12:07:42 -0400100
Qiankun Miao89dd8f32016-11-09 12:59:30 +0000101 sh::GLenum mShaderType;
102
Jamie Madill02f20dd2013-09-12 12:07:42 -0400103 const int mShaderVersion;
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -0800104
105 ShShaderOutput mOutput;
Qiankun Miao705a9192016-08-29 10:05:27 +0800106
107 ShCompileOptions mCompileOptions;
zmo@google.com5601ea02011-06-10 18:23:25 +0000108};
109
Jamie Madill45bcc782016-11-07 13:58:48 -0500110} // namespace sh
111
Geoff Lang0a73dd82014-11-19 16:18:08 -0500112#endif // COMPILER_TRANSLATOR_OUTPUTGLSLBASE_H_