| Index: src/sksl/SkSLGLSLCodeGenerator.cpp
|
| diff --git a/src/sksl/SkSLGLSLCodeGenerator.cpp b/src/sksl/SkSLGLSLCodeGenerator.cpp
|
| index 45644e8cd10032c12a824826a0073d4505d703af..8a26f6a71362ae825dd6432bc621f1196b2053ed 100644
|
| --- a/src/sksl/SkSLGLSLCodeGenerator.cpp
|
| +++ b/src/sksl/SkSLGLSLCodeGenerator.cpp
|
| @@ -150,7 +150,7 @@ void GLSLCodeGenerator::writeMinAbsHack(Expression& absExpr, Expression& otherEx
|
| }
|
|
|
| void GLSLCodeGenerator::writeFunctionCall(const FunctionCall& c) {
|
| - if (!fCaps.fCanUseMinAndAbsTogether && c.fFunction.fName == "min") {
|
| + if (!fCaps.fCanUseMinAndAbsTogether && c.fFunction.fName == "min" && c.fFunction.fBuiltin) {
|
| ASSERT(c.fArguments.size() == 2);
|
| if (is_abs(*c.fArguments[0])) {
|
| this->writeMinAbsHack(*c.fArguments[0], *c.fArguments[1]);
|
| @@ -164,7 +164,8 @@ void GLSLCodeGenerator::writeFunctionCall(const FunctionCall& c) {
|
| }
|
| }
|
| if (fCaps.fMustForceNegatedAtanParamToFloat && c.fFunction.fName == "atan" &&
|
| - c.fArguments.size() == 2 && c.fArguments[1]->fKind == Expression::kPrefix_Kind) {
|
| + c.fFunction.fBuiltin && c.fArguments.size() == 2 &&
|
| + c.fArguments[1]->fKind == Expression::kPrefix_Kind) {
|
| const PrefixExpression& p = (PrefixExpression&) *c.fArguments[1];
|
| if (p.fOperator == Token::MINUS) {
|
| this->write("atan(");
|
| @@ -175,6 +176,12 @@ void GLSLCodeGenerator::writeFunctionCall(const FunctionCall& c) {
|
| return;
|
| }
|
| }
|
| + if (!fFoundDerivatives && fCaps.fShaderDerivativeExtensionString != "" &&
|
| + (c.fFunction.fName == "dFdx" || c.fFunction.fName == "dFdy") && c.fFunction.fBuiltin) {
|
| + ASSERT(fCaps.fShaderDerivativeSupport);
|
| + fHeader << "#extension " << fCaps.fShaderDerivativeExtensionString << " : require\n";
|
| + fFoundDerivatives = true;
|
| + }
|
| this->write(c.fFunction.fName + "(");
|
| const char* separator = "";
|
| for (const auto& arg : c.fArguments) {
|
| @@ -578,7 +585,7 @@ void GLSLCodeGenerator::writeReturnStatement(const ReturnStatement& r) {
|
|
|
| void GLSLCodeGenerator::generateCode(const Program& program, std::ostream& out) {
|
| ASSERT(fOut == nullptr);
|
| - fOut = &out;
|
| + fOut = &fHeader;
|
| fProgramKind = program.fKind;
|
| this->write("#version " + to_string(fCaps.fVersion));
|
| if (fCaps.fStandard == GLCaps::kGLES_Standard && fCaps.fVersion >= 300) {
|
| @@ -592,6 +599,8 @@ void GLSLCodeGenerator::generateCode(const Program& program, std::ostream& out)
|
| this->writeExtension((Extension&) *e);
|
| }
|
| }
|
| + std::stringstream body;
|
| + fOut = &body;
|
| if (fCaps.fStandard == GLCaps::kGLES_Standard) {
|
| this->write("precision ");
|
| switch (program.fDefaultPrecision) {
|
| @@ -649,6 +658,9 @@ void GLSLCodeGenerator::generateCode(const Program& program, std::ostream& out)
|
| }
|
| }
|
| fOut = nullptr;
|
| +
|
| + out << fHeader.str();
|
| + out << body.str();
|
| }
|
|
|
| }
|
|
|