| 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 27 matching lines...) Expand all Loading... |
| 38 #include "ir/SkSLVarDeclarations.h" | 38 #include "ir/SkSLVarDeclarations.h" |
| 39 #include "ir/SkSLVarDeclarationsStatement.h" | 39 #include "ir/SkSLVarDeclarationsStatement.h" |
| 40 #include "ir/SkSLVariableReference.h" | 40 #include "ir/SkSLVariableReference.h" |
| 41 #include "ir/SkSLWhileStatement.h" | 41 #include "ir/SkSLWhileStatement.h" |
| 42 | 42 |
| 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 GLCaps() {} |
| 49 |
| 50 int fVersion = 400; |
| 49 enum { | 51 enum { |
| 50 kGL_Standard, | 52 kGL_Standard, |
| 51 kGLES_Standard | 53 kGLES_Standard |
| 52 } fStandard; | 54 } fStandard = kGL_Standard; |
| 53 bool fIsCoreProfile; | 55 bool fIsCoreProfile = false; |
| 54 bool fUsesPrecisionModifiers; | 56 bool fUsesPrecisionModifiers = false; |
| 55 bool fMustDeclareFragmentShaderOutput; | 57 bool fMustDeclareFragmentShaderOutput = false; |
| 58 bool fShaderDerivativeSupport = true; |
| 59 // extension string to enable derivative support, or null if unnecessary |
| 60 std::string fShaderDerivativeExtensionString; |
| 56 // The Tegra3 compiler will sometimes never return if we have min(abs(x), y) | 61 // The Tegra3 compiler will sometimes never return if we have min(abs(x), y) |
| 57 bool fCanUseMinAndAbsTogether; | 62 bool fCanUseMinAndAbsTogether = true; |
| 58 // On Intel GPU there is an issue where it misinterprets an atan argument (s
econd argument only, | 63 // On Intel GPU there is an issue where it misinterprets an atan argument (s
econd argument only, |
| 59 // apparently) of the form "-<expr>" as an int, so we rewrite it as "-1.0 *
<expr>" to avoid | 64 // apparently) of the form "-<expr>" as an int, so we rewrite it as "-1.0 *
<expr>" to avoid |
| 60 // this problem | 65 // this problem |
| 61 bool fMustForceNegatedAtanParamToFloat; | 66 bool fMustForceNegatedAtanParamToFloat = false; |
| 62 }; | 67 }; |
| 63 | 68 |
| 64 /** | 69 /** |
| 65 * Converts a Program into GLSL code. | 70 * Converts a Program into GLSL code. |
| 66 */ | 71 */ |
| 67 class GLSLCodeGenerator : public CodeGenerator { | 72 class GLSLCodeGenerator : public CodeGenerator { |
| 68 public: | 73 public: |
| 69 enum Precedence { | 74 enum Precedence { |
| 70 kParentheses_Precedence = 1, | 75 kParentheses_Precedence = 1, |
| 71 kPostfix_Precedence = 2, | 76 kPostfix_Precedence = 2, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 82 kLogicalXor_Precedence = 13, | 87 kLogicalXor_Precedence = 13, |
| 83 kLogicalOr_Precedence = 14, | 88 kLogicalOr_Precedence = 14, |
| 84 kTernary_Precedence = 15, | 89 kTernary_Precedence = 15, |
| 85 kAssignment_Precedence = 16, | 90 kAssignment_Precedence = 16, |
| 86 kSequence_Precedence = 17, | 91 kSequence_Precedence = 17, |
| 87 kTopLevel_Precedence = 18 | 92 kTopLevel_Precedence = 18 |
| 88 }; | 93 }; |
| 89 | 94 |
| 90 GLSLCodeGenerator(const Context* context, GLCaps caps) | 95 GLSLCodeGenerator(const Context* context, GLCaps caps) |
| 91 : fContext(*context) | 96 : fContext(*context) |
| 92 , fCaps(caps) | 97 , fCaps(caps) {} |
| 93 , fOut(nullptr) | |
| 94 , fVarCount(0) | |
| 95 , fIndentation(0) | |
| 96 , fAtLineStart(true) {} | |
| 97 | 98 |
| 98 void generateCode(const Program& program, std::ostream& out) override; | 99 void generateCode(const Program& program, std::ostream& out) override; |
| 99 | 100 |
| 100 private: | 101 private: |
| 101 void write(const char* s); | 102 void write(const char* s); |
| 102 | 103 |
| 103 void writeLine(); | 104 void writeLine(); |
| 104 | 105 |
| 105 void writeLine(const char* s); | 106 void writeLine(const char* s); |
| 106 | 107 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 void writeForStatement(const ForStatement& f); | 170 void writeForStatement(const ForStatement& f); |
| 170 | 171 |
| 171 void writeWhileStatement(const WhileStatement& w); | 172 void writeWhileStatement(const WhileStatement& w); |
| 172 | 173 |
| 173 void writeDoStatement(const DoStatement& d); | 174 void writeDoStatement(const DoStatement& d); |
| 174 | 175 |
| 175 void writeReturnStatement(const ReturnStatement& r); | 176 void writeReturnStatement(const ReturnStatement& r); |
| 176 | 177 |
| 177 const Context& fContext; | 178 const Context& fContext; |
| 178 const GLCaps fCaps; | 179 const GLCaps fCaps; |
| 179 std::ostream* fOut; | 180 std::ostream* fOut = nullptr; |
| 181 std::stringstream fHeader; |
| 180 std::string fFunctionHeader; | 182 std::string fFunctionHeader; |
| 181 Program::Kind fProgramKind; | 183 Program::Kind fProgramKind; |
| 182 int fVarCount; | 184 int fVarCount = 0; |
| 183 int fIndentation; | 185 int fIndentation = 0; |
| 184 bool fAtLineStart; | 186 bool fAtLineStart = false; |
| 185 // Keeps track of which struct types we have written. Given that we are unli
kely to ever write | 187 // Keeps track of which struct types we have written. Given that we are unli
kely to ever write |
| 186 // more than one or two structs per shader, a simple linear search will be f
aster than anything | 188 // more than one or two structs per shader, a simple linear search will be f
aster than anything |
| 187 // fancier. | 189 // fancier. |
| 188 std::vector<const Type*> fWrittenStructs; | 190 std::vector<const Type*> fWrittenStructs; |
| 191 // true if we have run into usages of dFdx / dFdy |
| 192 bool fFoundDerivatives = false; |
| 189 }; | 193 }; |
| 190 | 194 |
| 191 } | 195 } |
| 192 | 196 |
| 193 #endif | 197 #endif |
| OLD | NEW |