added SkSL support for mustForceNegatedAtanParamToFloat cap

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2413363002

Review-Url: https://codereview.chromium.org/2413363002
This commit is contained in:
ethannicholas 2016-10-14 06:40:02 -07:00 committed by Commit bot
parent 2dbbfa5d37
commit ad146f6ef5
6 changed files with 44 additions and 11 deletions

View File

@ -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,

View File

@ -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;
}

View File

@ -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) {

View File

@ -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;
};
/**

View File

@ -23,7 +23,8 @@ static SkSL::GLCaps default_caps() {
false, // isCoreProfile
false, // usesPrecisionModifiers;
false, // mustDeclareFragmentShaderOutput
true // canUseMinAndAbsTogether
true, // canUseMinAndAbsTogether
false // mustForceNegatedAtanParamToFloat
};
}

View File

@ -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;"