1 // 2 // Copyright 2002 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_TRANSLATOR_OUTPUTGLSLBASE_H_ 8 #define COMPILER_TRANSLATOR_OUTPUTGLSLBASE_H_ 9 10 #include <set> 11 12 #include "compiler/translator/HashNames.h" 13 #include "compiler/translator/InfoSink.h" 14 #include "compiler/translator/tree_util/IntermTraverse.h" 15 16 namespace sh 17 { 18 19 class TOutputGLSLBase : public TIntermTraverser 20 { 21 public: 22 TOutputGLSLBase(TInfoSinkBase &objSink, 23 ShArrayIndexClampingStrategy clampingStrategy, 24 ShHashFunction64 hashFunction, 25 NameMap &nameMap, 26 TSymbolTable *symbolTable, 27 sh::GLenum shaderType, 28 int shaderVersion, 29 ShShaderOutput output, 30 ShCompileOptions compileOptions); 31 getShaderOutput()32 ShShaderOutput getShaderOutput() const { return mOutput; } 33 34 // Return the original name if hash function pointer is NULL; 35 // otherwise return the hashed name. Has special handling for internal names and built-ins, 36 // which are not hashed. 37 ImmutableString hashName(const TSymbol *symbol); 38 39 protected: objSink()40 TInfoSinkBase &objSink() { return mObjSink; } 41 void writeFloat(TInfoSinkBase &out, float f); 42 void writeTriplet(Visit visit, const char *preStr, const char *inStr, const char *postStr); 43 std::string getCommonLayoutQualifiers(TIntermTyped *variable); 44 std::string getMemoryQualifiers(const TType &type); 45 virtual void writeLayoutQualifier(TIntermTyped *variable); 46 void writeFieldLayoutQualifier(const TField *field); 47 void writeInvariantQualifier(const TType &type); 48 void writePreciseQualifier(const TType &type); 49 virtual void writeVariableType(const TType &type, 50 const TSymbol *symbol, 51 bool isFunctionArgument); 52 virtual bool writeVariablePrecision(TPrecision precision) = 0; 53 void writeFunctionParameters(const TFunction *func); 54 const TConstantUnion *writeConstantUnion(const TType &type, const TConstantUnion *pConstUnion); 55 void writeConstructorTriplet(Visit visit, const TType &type); 56 ImmutableString getTypeName(const TType &type); 57 58 void visitSymbol(TIntermSymbol *node) override; 59 void visitConstantUnion(TIntermConstantUnion *node) override; 60 bool visitSwizzle(Visit visit, TIntermSwizzle *node) override; 61 bool visitBinary(Visit visit, TIntermBinary *node) override; 62 bool visitUnary(Visit visit, TIntermUnary *node) override; 63 bool visitTernary(Visit visit, TIntermTernary *node) override; 64 bool visitIfElse(Visit visit, TIntermIfElse *node) override; 65 bool visitSwitch(Visit visit, TIntermSwitch *node) override; 66 bool visitCase(Visit visit, TIntermCase *node) override; 67 void visitFunctionPrototype(TIntermFunctionPrototype *node) override; 68 bool visitFunctionDefinition(Visit visit, TIntermFunctionDefinition *node) override; 69 bool visitAggregate(Visit visit, TIntermAggregate *node) override; 70 bool visitBlock(Visit visit, TIntermBlock *node) override; 71 bool visitGlobalQualifierDeclaration(Visit visit, 72 TIntermGlobalQualifierDeclaration *node) override; 73 bool visitDeclaration(Visit visit, TIntermDeclaration *node) override; 74 bool visitLoop(Visit visit, TIntermLoop *node) override; 75 bool visitBranch(Visit visit, TIntermBranch *node) override; 76 void visitPreprocessorDirective(TIntermPreprocessorDirective *node) override; 77 78 void visitCodeBlock(TIntermBlock *node); 79 80 ImmutableString hashFieldName(const TField *field); 81 // Same as hashName(), but without hashing "main". 82 ImmutableString hashFunctionNameIfNeeded(const TFunction *func); 83 // Used to translate function names for differences between ESSL and GLSL translateTextureFunction(const ImmutableString & name,const ShCompileOptions & option)84 virtual ImmutableString translateTextureFunction(const ImmutableString &name, 85 const ShCompileOptions &option) 86 { 87 return name; 88 } 89 90 void declareStruct(const TStructure *structure); 91 void writeQualifier(TQualifier qualifier, const TType &type, const TSymbol *symbol); 92 93 const char *mapQualifierToString(TQualifier qualifier); 94 getShaderType()95 sh::GLenum getShaderType() { return mShaderType; } 96 97 private: 98 void declareInterfaceBlockLayout(const TType &type); 99 void declareInterfaceBlock(const TType &type); 100 101 void writeBuiltInFunctionTriplet(Visit visit, TOperator op, bool useEmulatedFunction); 102 103 TInfoSinkBase &mObjSink; 104 bool mDeclaringVariable; 105 106 ShArrayIndexClampingStrategy mClampingStrategy; 107 108 // name hashing. 109 ShHashFunction64 mHashFunction; 110 111 NameMap &mNameMap; 112 113 sh::GLenum mShaderType; 114 115 const int mShaderVersion; 116 117 ShShaderOutput mOutput; 118 119 ShCompileOptions mCompileOptions; 120 }; 121 122 void WriteGeometryShaderLayoutQualifiers(TInfoSinkBase &out, 123 sh::TLayoutPrimitiveType inputPrimitive, 124 int invocations, 125 sh::TLayoutPrimitiveType outputPrimitive, 126 int maxVertices); 127 128 void WriteTessControlShaderLayoutQualifiers(TInfoSinkBase &out, int inputVertices); 129 130 void WriteTessEvaluationShaderLayoutQualifiers(TInfoSinkBase &out, 131 sh::TLayoutTessEvaluationType inputPrimitive, 132 sh::TLayoutTessEvaluationType inputVertexSpacing, 133 sh::TLayoutTessEvaluationType inputOrdering, 134 sh::TLayoutTessEvaluationType inputPoint); 135 136 bool NeedsToWriteLayoutQualifier(const TType &type); 137 138 } // namespace sh 139 140 #endif // COMPILER_TRANSLATOR_OUTPUTGLSLBASE_H_ 141