| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef SKSL_GLSLCODEGENERATOR | 8 #ifndef SKSL_GLSLCODEGENERATOR |
| 9 #define SKSL_GLSLCODEGENERATOR | 9 #define SKSL_GLSLCODEGENERATOR |
| 10 | 10 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 namespace SkSL { | 43 namespace SkSL { |
| 44 | 44 |
| 45 #define kLast_Capability SpvCapabilityMultiViewport | 45 #define kLast_Capability SpvCapabilityMultiViewport |
| 46 | 46 |
| 47 struct GLCaps { | 47 struct GLCaps { |
| 48 int fVersion; | 48 int fVersion; |
| 49 enum { | 49 enum { |
| 50 kGL_Standard, | 50 kGL_Standard, |
| 51 kGLES_Standard | 51 kGLES_Standard |
| 52 } fStandard; | 52 } fStandard; |
| 53 bool fIsCoreProfile; |
| 54 bool fUsesPrecisionModifiers; |
| 55 bool fMustDeclareFragmentShaderOutput; |
| 56 // The Tegra3 compiler will sometimes never return if we have min(abs(x), y) |
| 57 bool fCanUseMinAndAbsTogether; |
| 53 }; | 58 }; |
| 54 | 59 |
| 55 /** | 60 /** |
| 56 * Converts a Program into GLSL code. | 61 * Converts a Program into GLSL code. |
| 57 */ | 62 */ |
| 58 class GLSLCodeGenerator : public CodeGenerator { | 63 class GLSLCodeGenerator : public CodeGenerator { |
| 59 public: | 64 public: |
| 60 enum Precedence { | 65 enum Precedence { |
| 61 kParentheses_Precedence = 1, | 66 kParentheses_Precedence = 1, |
| 62 kPostfix_Precedence = 2, | 67 kPostfix_Precedence = 2, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 void writeInterfaceBlock(const InterfaceBlock& intf); | 109 void writeInterfaceBlock(const InterfaceBlock& intf); |
| 105 | 110 |
| 106 void writeFunctionStart(const FunctionDeclaration& f); | 111 void writeFunctionStart(const FunctionDeclaration& f); |
| 107 | 112 |
| 108 void writeFunctionDeclaration(const FunctionDeclaration& f); | 113 void writeFunctionDeclaration(const FunctionDeclaration& f); |
| 109 | 114 |
| 110 void writeFunction(const FunctionDefinition& f); | 115 void writeFunction(const FunctionDefinition& f); |
| 111 | 116 |
| 112 void writeLayout(const Layout& layout); | 117 void writeLayout(const Layout& layout); |
| 113 | 118 |
| 114 void writeModifiers(const Modifiers& modifiers); | 119 void writeModifiers(const Modifiers& modifiers, bool globalContext); |
| 115 | 120 |
| 116 void writeGlobalVars(const VarDeclaration& vs); | 121 void writeGlobalVars(const VarDeclaration& vs); |
| 117 | 122 |
| 118 void writeVarDeclarations(const VarDeclarations& decl); | 123 void writeVarDeclarations(const VarDeclarations& decl, bool global); |
| 119 | 124 |
| 120 void writeVariableReference(const VariableReference& ref); | 125 void writeVariableReference(const VariableReference& ref); |
| 121 | 126 |
| 122 void writeExpression(const Expression& expr, Precedence parentPrecedence); | 127 void writeExpression(const Expression& expr, Precedence parentPrecedence); |
| 123 | 128 |
| 124 void writeIntrinsicCall(const FunctionCall& c); | 129 void writeIntrinsicCall(const FunctionCall& c); |
| 125 | 130 |
| 131 void writeMinAbsHack(Expression& absExpr, Expression& otherExpr); |
| 132 |
| 126 void writeFunctionCall(const FunctionCall& c); | 133 void writeFunctionCall(const FunctionCall& c); |
| 127 | 134 |
| 128 void writeConstructor(const Constructor& c); | 135 void writeConstructor(const Constructor& c); |
| 129 | 136 |
| 130 void writeFieldAccess(const FieldAccess& f); | 137 void writeFieldAccess(const FieldAccess& f); |
| 131 | 138 |
| 132 void writeSwizzle(const Swizzle& swizzle); | 139 void writeSwizzle(const Swizzle& swizzle); |
| 133 | 140 |
| 134 void writeBinaryExpression(const BinaryExpression& b, Precedence parentPrece
dence); | 141 void writeBinaryExpression(const BinaryExpression& b, Precedence parentPrece
dence); |
| 135 | 142 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 157 | 164 |
| 158 void writeWhileStatement(const WhileStatement& w); | 165 void writeWhileStatement(const WhileStatement& w); |
| 159 | 166 |
| 160 void writeDoStatement(const DoStatement& d); | 167 void writeDoStatement(const DoStatement& d); |
| 161 | 168 |
| 162 void writeReturnStatement(const ReturnStatement& r); | 169 void writeReturnStatement(const ReturnStatement& r); |
| 163 | 170 |
| 164 const Context& fContext; | 171 const Context& fContext; |
| 165 const GLCaps fCaps; | 172 const GLCaps fCaps; |
| 166 std::ostream* fOut; | 173 std::ostream* fOut; |
| 174 Program::Kind fProgramKind; |
| 167 int fIndentation; | 175 int fIndentation; |
| 168 bool fAtLineStart; | 176 bool fAtLineStart; |
| 169 // Keeps track of which struct types we have written. Given that we are unli
kely to ever write | 177 // Keeps track of which struct types we have written. Given that we are unli
kely to ever write |
| 170 // more than one or two structs per shader, a simple linear search will be f
aster than anything | 178 // more than one or two structs per shader, a simple linear search will be f
aster than anything |
| 171 // fancier. | 179 // fancier. |
| 172 std::vector<const Type*> fWrittenStructs; | 180 std::vector<const Type*> fWrittenStructs; |
| 173 }; | 181 }; |
| 174 | 182 |
| 175 } | 183 } |
| 176 | 184 |
| 177 #endif | 185 #endif |
| OLD | NEW |