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:
parent
2dbbfa5d37
commit
ad146f6ef5
@ -210,15 +210,8 @@ void GrSweepGradient::GLSLSweepProcessor::emitCode(EmitArgs& args) {
|
|||||||
SkString coords2D = args.fFragBuilder->ensureCoords2D(args.fTransformedCoords[0]);
|
SkString coords2D = args.fFragBuilder->ensureCoords2D(args.fTransformedCoords[0]);
|
||||||
SkString t;
|
SkString t;
|
||||||
// 0.1591549430918 is 1/(2*pi), used since atan returns values [-pi, pi]
|
// 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
|
t.printf("(atan(- %s.y, - %s.x) * 0.1591549430918 + 0.5)",
|
||||||
// thus must us -1.0 * %s.x to work correctly
|
coords2D.c_str(), coords2D.c_str());
|
||||||
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());
|
|
||||||
}
|
|
||||||
this->emitColor(args.fFragBuilder,
|
this->emitColor(args.fFragBuilder,
|
||||||
args.fUniformHandler,
|
args.fUniformHandler,
|
||||||
args.fGLSLCaps,
|
args.fGLSLCaps,
|
||||||
|
@ -86,6 +86,7 @@ SkSL::GLCaps GrGLSkSLCapsForContext(const GrGLContext& context) {
|
|||||||
result.fUsesPrecisionModifiers = glslCaps->usesPrecisionModifiers();
|
result.fUsesPrecisionModifiers = glslCaps->usesPrecisionModifiers();
|
||||||
result.fMustDeclareFragmentShaderOutput = glslCaps->mustDeclareFragmentShaderOutput();
|
result.fMustDeclareFragmentShaderOutput = glslCaps->mustDeclareFragmentShaderOutput();
|
||||||
result.fCanUseMinAndAbsTogether = glslCaps->canUseMinAndAbsTogether();
|
result.fCanUseMinAndAbsTogether = glslCaps->canUseMinAndAbsTogether();
|
||||||
|
result.fMustForceNegatedAtanParamToFloat = glslCaps->mustForceNegatedAtanParamToFloat();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,6 +163,18 @@ void GLSLCodeGenerator::writeFunctionCall(const FunctionCall& c) {
|
|||||||
return;
|
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 + "(");
|
this->write(c.fFunction.fName + "(");
|
||||||
const char* separator = "";
|
const char* separator = "";
|
||||||
for (const auto& arg : c.fArguments) {
|
for (const auto& arg : c.fArguments) {
|
||||||
|
@ -55,6 +55,10 @@ struct GLCaps {
|
|||||||
bool fMustDeclareFragmentShaderOutput;
|
bool fMustDeclareFragmentShaderOutput;
|
||||||
// The Tegra3 compiler will sometimes never return if we have min(abs(x), y)
|
// The Tegra3 compiler will sometimes never return if we have min(abs(x), y)
|
||||||
bool fCanUseMinAndAbsTogether;
|
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;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -23,7 +23,8 @@ static SkSL::GLCaps default_caps() {
|
|||||||
false, // isCoreProfile
|
false, // isCoreProfile
|
||||||
false, // usesPrecisionModifiers;
|
false, // usesPrecisionModifiers;
|
||||||
false, // mustDeclareFragmentShaderOutput
|
false, // mustDeclareFragmentShaderOutput
|
||||||
true // canUseMinAndAbsTogether
|
true, // canUseMinAndAbsTogether
|
||||||
|
false // mustForceNegatedAtanParamToFloat
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +33,8 @@ static SkSL::GLCaps default_caps() {
|
|||||||
false, // isCoreProfile
|
false, // isCoreProfile
|
||||||
false, // usesPrecisionModifiers;
|
false, // usesPrecisionModifiers;
|
||||||
false, // mustDeclareFragmentShaderOutput
|
false, // mustDeclareFragmentShaderOutput
|
||||||
true // canUseMinAndAbsTogether
|
true, // canUseMinAndAbsTogether
|
||||||
|
false // mustForceNegatedAtanParamToFloat
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -315,6 +316,27 @@ DEF_TEST(SkSLMinAbs, r) {
|
|||||||
"}\n");
|
"}\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) {
|
DEF_TEST(SkSLModifiersDeclaration, r) {
|
||||||
test(r,
|
test(r,
|
||||||
"layout(blend_support_all_equations) out;"
|
"layout(blend_support_all_equations) out;"
|
||||||
|
Loading…
Reference in New Issue
Block a user