Add support for atan() to DSL.

Change-Id: I00cc1e89fd85fdc0ce0860fcb35ececd0eaec50a
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/400540
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
This commit is contained in:
John Stiles 2021-04-26 09:36:07 -04:00 committed by Skia Commit-Bot
parent b9fc6e45c2
commit e3fa745a5a
6 changed files with 21 additions and 0 deletions

View File

@ -175,6 +175,12 @@ DSLExpression All(DSLExpression x, PositionInfo pos = PositionInfo());
*/
DSLExpression Any(DSLExpression x, PositionInfo pos = PositionInfo());
/**
* Returns the arctangent of y over x. Operates componentwise on vectors.
*/
DSLExpression Atan(DSLExpression y_over_x, PositionInfo pos = PositionInfo());
DSLExpression Atan(DSLExpression y, DSLExpression x, PositionInfo pos = PositionInfo());
/**
* Returns x rounded towards positive infinity. If x is a vector, operates componentwise.
*/

View File

@ -6,6 +6,8 @@ half4 main() {
n.x = abs(n.x);
b.z = all(b.xy);
b.w = any(b.xyz);
n.xy = atan(n.xy);
n.zwx = atan(n.yyy, n.zzz);
n.xyzw = ceil(n.xyzw);
n.x = clamp(n.y, n.z, n.w);
n.y = cos(n.y);

View File

@ -343,6 +343,7 @@ void DSLCPPCodeGenerator::writeFunctionCall(const FunctionCall& c) {
{"abs", "Abs"},
{"all", "All"},
{"any", "Any"},
{"atan", "Atan"},
{"ceil", "Ceil"},
{"clamp", "Clamp"},
{"cos", "Cos"},

View File

@ -230,6 +230,14 @@ DSLExpression Any(DSLExpression x, PositionInfo pos) {
return DSLExpression(DSLCore::Call("any", std::move(x)), pos);
}
DSLExpression Atan(DSLExpression y_over_x, PositionInfo pos) {
return DSLExpression(DSLCore::Call("atan", std::move(y_over_x)), pos);
}
DSLExpression Atan(DSLExpression y, DSLExpression x, PositionInfo pos) {
return DSLExpression(DSLCore::Call("atan", std::move(y), std::move(x)), pos);
}
DSLExpression Ceil(DSLExpression x, PositionInfo pos) {
return DSLExpression(DSLCore::Call("ceil", std::move(x)), pos);
}

View File

@ -1435,6 +1435,8 @@ DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLBuiltins, r, ctxInfo) {
EXPECT_EQUAL(Abs(a), "abs(a)");
EXPECT_EQUAL(All(b4), "all(b4)");
EXPECT_EQUAL(Any(b4), "any(b4)");
EXPECT_EQUAL(Atan(a), "atan(a)");
EXPECT_EQUAL(Atan(a, b), "atan(a, b)");
EXPECT_EQUAL(Ceil(a), "ceil(a)");
EXPECT_EQUAL(Clamp(a, 0, 1), "clamp(a, 0.0, 1.0)");
EXPECT_EQUAL(Cos(a), "cos(a)");

View File

@ -38,6 +38,8 @@ Declare(_b);
_n.x() = Abs(_n.x());
_b.z() = All(Swizzle(_b, X, Y));
_b.w() = Any(Swizzle(_b, X, Y, Z));
Swizzle(_n, X, Y) = Atan(Swizzle(_n, X, Y));
Swizzle(_n, Z, W, X) = Atan(Swizzle(_n, Y, Y, Y), Swizzle(_n, Z, Z, Z));
_n = Ceil(_n);
_n.x() = Clamp(_n.y(), _n.z(), _n.w());
_n.y() = Cos(_n.y());