aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/effects/gradients/SkSweepGradient.cpp11
-rw-r--r--src/gpu/gl/builders/GrGLShaderStringBuilder.cpp1
-rw-r--r--src/sksl/SkSLGLSLCodeGenerator.cpp12
-rw-r--r--src/sksl/SkSLGLSLCodeGenerator.h4
-rw-r--r--src/sksl/SkSLMain.cpp3
-rw-r--r--tests/SkSLGLSLTest.cpp24
6 files changed, 44 insertions, 11 deletions
diff --git a/src/effects/gradients/SkSweepGradient.cpp b/src/effects/gradients/SkSweepGradient.cpp
index f4ef8ab41f..d62e2e55f2 100644
--- a/src/effects/gradients/SkSweepGradient.cpp
+++ b/src/effects/gradients/SkSweepGradient.cpp
@@ -210,15 +210,8 @@ void GrSweepGradient::GLSLSweepProcessor::emitCode(EmitArgs& args) {
SkString coords2D = args.fFragBuilder->ensureCoords2D(args.fTransformedCoords[0]);
SkString t;
// 0.1591549430918 is 1/(2*pi), used since atan returns values [-pi, pi]
- // On Intel GPU there is an issue where it reads the second arguement to atan "- %s.x" as an int
- // thus must us -1.0 * %s.x to work correctly
- if (args.fGLSLCaps->mustForceNegatedAtanParamToFloat()){
- t.printf("(atan(- %s.y, -1.0 * %s.x) * 0.1591549430918 + 0.5)",
- coords2D.c_str(), coords2D.c_str());
- } else {
- t.printf("(atan(- %s.y, - %s.x) * 0.1591549430918 + 0.5)",
- coords2D.c_str(), coords2D.c_str());
- }
+ t.printf("(atan(- %s.y, - %s.x) * 0.1591549430918 + 0.5)",
+ coords2D.c_str(), coords2D.c_str());
this->emitColor(args.fFragBuilder,
args.fUniformHandler,
args.fGLSLCaps,
diff --git a/src/gpu/gl/builders/GrGLShaderStringBuilder.cpp b/src/gpu/gl/builders/GrGLShaderStringBuilder.cpp
index b26ce894f0..8e8bb9a0fc 100644
--- a/src/gpu/gl/builders/GrGLShaderStringBuilder.cpp
+++ b/src/gpu/gl/builders/GrGLShaderStringBuilder.cpp
@@ -86,6 +86,7 @@ SkSL::GLCaps GrGLSkSLCapsForContext(const GrGLContext& context) {
result.fUsesPrecisionModifiers = glslCaps->usesPrecisionModifiers();
result.fMustDeclareFragmentShaderOutput = glslCaps->mustDeclareFragmentShaderOutput();
result.fCanUseMinAndAbsTogether = glslCaps->canUseMinAndAbsTogether();
+ result.fMustForceNegatedAtanParamToFloat = glslCaps->mustForceNegatedAtanParamToFloat();
return result;
}
diff --git a/src/sksl/SkSLGLSLCodeGenerator.cpp b/src/sksl/SkSLGLSLCodeGenerator.cpp
index 58cf7d3c36..45644e8cd1 100644
--- a/src/sksl/SkSLGLSLCodeGenerator.cpp
+++ b/src/sksl/SkSLGLSLCodeGenerator.cpp
@@ -163,6 +163,18 @@ void GLSLCodeGenerator::writeFunctionCall(const FunctionCall& c) {
return;
}
}
+ if (fCaps.fMustForceNegatedAtanParamToFloat && c.fFunction.fName == "atan" &&
+ 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(");
+ this->writeExpression(*c.fArguments[0], kSequence_Precedence);
+ this->write(", -1.0 * ");
+ this->writeExpression(*p.fOperand, kMultiplicative_Precedence);
+ this->write(")");
+ return;
+ }
+ }
this->write(c.fFunction.fName + "(");
const char* separator = "";
for (const auto& arg : c.fArguments) {
diff --git a/src/sksl/SkSLGLSLCodeGenerator.h b/src/sksl/SkSLGLSLCodeGenerator.h
index 965721eb31..17ac90ea23 100644
--- a/src/sksl/SkSLGLSLCodeGenerator.h
+++ b/src/sksl/SkSLGLSLCodeGenerator.h
@@ -55,6 +55,10 @@ struct GLCaps {
bool fMustDeclareFragmentShaderOutput;
// The Tegra3 compiler will sometimes never return if we have min(abs(x), y)
bool fCanUseMinAndAbsTogether;
+ // On Intel GPU there is an issue where it misinterprets an atan argument (second argument only,
+ // apparently) of the form "-<expr>" as an int, so we rewrite it as "-1.0 * <expr>" to avoid
+ // this problem
+ bool fMustForceNegatedAtanParamToFloat;
};
/**
diff --git a/src/sksl/SkSLMain.cpp b/src/sksl/SkSLMain.cpp
index de1b9819d5..fe925e0c6e 100644
--- a/src/sksl/SkSLMain.cpp
+++ b/src/sksl/SkSLMain.cpp
@@ -23,7 +23,8 @@ static SkSL::GLCaps default_caps() {
false, // isCoreProfile
false, // usesPrecisionModifiers;
false, // mustDeclareFragmentShaderOutput
- true // canUseMinAndAbsTogether
+ true, // canUseMinAndAbsTogether
+ false // mustForceNegatedAtanParamToFloat
};
}
diff --git a/tests/SkSLGLSLTest.cpp b/tests/SkSLGLSLTest.cpp
index dedddad1f8..b615f67814 100644
--- a/tests/SkSLGLSLTest.cpp
+++ b/tests/SkSLGLSLTest.cpp
@@ -33,7 +33,8 @@ static SkSL::GLCaps default_caps() {
false, // isCoreProfile
false, // usesPrecisionModifiers;
false, // mustDeclareFragmentShaderOutput
- true // canUseMinAndAbsTogether
+ true, // canUseMinAndAbsTogether
+ false // mustForceNegatedAtanParamToFloat
};
}
@@ -315,6 +316,27 @@ DEF_TEST(SkSLMinAbs, r) {
"}\n");
}
+DEF_TEST(SkSLNegatedAtan, r) {
+ test(r,
+ "void main() { vec2 x = vec2(1, 2); float y = atan(x.x, -(2 * x.y)); }",
+ default_caps(),
+ "#version 400\n"
+ "void main() {\n"
+ " vec2 x = vec2(1.0, 2.0);\n"
+ " float y = atan(x.x, -(2.0 * x.y));\n"
+ "}\n");
+ SkSL::GLCaps caps = default_caps();
+ caps.fMustForceNegatedAtanParamToFloat = true;
+ test(r,
+ "void main() { vec2 x = vec2(1, 2); float y = atan(x.x, -(2 * x.y)); }",
+ caps,
+ "#version 400\n"
+ "void main() {\n"
+ " vec2 x = vec2(1.0, 2.0);\n"
+ " float y = atan(x.x, -1.0 * (2.0 * x.y));\n"
+ "}\n");
+}
+
DEF_TEST(SkSLModifiersDeclaration, r) {
test(r,
"layout(blend_support_all_equations) out;"