Minor cleanup in the intrinsics GMs

- Renamed do_unary() to plot(). Originally intended to do higher
  dimension functions differently, but the 1D plot by varying some
  parameters is easier to look at and reason about, so all plots will
  follow this model.
- Added an optional label for the expressions that are getting really
  long. "smoothstep" was already overflowing, and the final wave of
  intrinsics (geometry and vector comparison) are going to all be long.

Bug: skia:10913
Change-Id: I69086152718c43e602755ddc9017b2a73fec5038
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/335583
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
This commit is contained in:
Brian Osman 2020-11-17 09:53:54 -05:00 committed by Skia Commit-Bot
parent 1d75778cbf
commit 5035b8f92a

View File

@ -49,16 +49,24 @@ static SkString make_unary_sksl_1d(const char* fn) {
}
// Draws one row of boxes, then advances the canvas translation vertically
static void do_unary(
SkCanvas* canvas, const char* fn, float xMin, float xMax, float yMin, float yMax) {
static void plot(SkCanvas* canvas,
const char* fn,
float xMin,
float xMax,
float yMin,
float yMax,
const char* label = nullptr) {
canvas->save();
SkFont font(ToolUtils::create_portable_typeface());
SkPaint p(SkColors::kBlack);
SkRect bounds;
font.measureText(fn, strlen(fn), SkTextEncoding::kUTF8, &bounds);
if (!label) {
label = fn;
}
font.measureText(label, strlen(label), SkTextEncoding::kUTF8, &bounds);
canvas->drawSimpleText(fn, strlen(fn), SkTextEncoding::kUTF8,
canvas->drawSimpleText(label, strlen(label), SkTextEncoding::kUTF8,
(kBoxSize - bounds.width()) * 0.5f,
(kLabelHeight + bounds.height()) * 0.5f, font, p);
canvas->translate(0, kLabelHeight);
@ -140,22 +148,22 @@ DEF_SIMPLE_GM_BG(
canvas->translate(kPadding, kPadding);
canvas->save();
do_unary(canvas, "radians(x)", 0.0f, 360.0f, 0.0f, kTwoPI); col(canvas);
do_unary(canvas, "degrees(x)", 0.0f, kTwoPI, 0.0f, 360.0f); row(canvas);
plot(canvas, "radians(x)", 0.0f, 360.0f, 0.0f, kTwoPI); col(canvas);
plot(canvas, "degrees(x)", 0.0f, kTwoPI, 0.0f, 360.0f); row(canvas);
do_unary(canvas, "sin(x)", 0.0f, kTwoPI, -1.0f, 1.0f); col(canvas);
do_unary(canvas, "cos(x)", 0.0f, kTwoPI, -1.0f, 1.0f); col(canvas);
do_unary(canvas, "tan(x)", 0.0f, kPI, -10.0f, 10.0f); row(canvas);
plot(canvas, "sin(x)", 0.0f, kTwoPI, -1.0f, 1.0f); col(canvas);
plot(canvas, "cos(x)", 0.0f, kTwoPI, -1.0f, 1.0f); col(canvas);
plot(canvas, "tan(x)", 0.0f, kPI, -10.0f, 10.0f); row(canvas);
do_unary(canvas, "asin(x)", -1.0f, 1.0f, -kPIOverTwo, kPIOverTwo); col(canvas);
do_unary(canvas, "acos(x)", -1.0f, 1.0f, 0.0f, kPI); col(canvas);
do_unary(canvas, "atan(x)", -10.0f, 10.0f, -kPIOverTwo, kPIOverTwo); row(canvas);
plot(canvas, "asin(x)", -1.0f, 1.0f, -kPIOverTwo, kPIOverTwo); col(canvas);
plot(canvas, "acos(x)", -1.0f, 1.0f, 0.0f, kPI); col(canvas);
plot(canvas, "atan(x)", -10.0f, 10.0f, -kPIOverTwo, kPIOverTwo); row(canvas);
do_unary(canvas, "atan(0.1, x)", -1.0f, 1.0f, 0.0f, kPI); col(canvas);
do_unary(canvas, "atan(-0.1, x)", -1.0f, 1.0f, -kPI, 0.0f); row(canvas);
plot(canvas, "atan(0.1, x)", -1.0f, 1.0f, 0.0f, kPI); col(canvas);
plot(canvas, "atan(-0.1, x)", -1.0f, 1.0f, -kPI, 0.0f); row(canvas);
do_unary(canvas, "atan(x, 0.1)", -1.0f, 1.0f, -kPIOverTwo, kPIOverTwo); col(canvas);
do_unary(canvas, "atan(x, -0.1)", -1.0f, 1.0f, -kPI, kPI); row(canvas);
plot(canvas, "atan(x, 0.1)", -1.0f, 1.0f, -kPIOverTwo, kPIOverTwo); col(canvas);
plot(canvas, "atan(x, -0.1)", -1.0f, 1.0f, -kPI, kPI); row(canvas);
}
// The OpenGL ES Shading Language, Version 1.00, Section 8.2
@ -167,20 +175,20 @@ DEF_SIMPLE_GM_BG(runtime_intrinsics_exponential,
canvas->translate(kPadding, kPadding);
canvas->save();
do_unary(canvas, "pow(x, 3)", 0.0f, 8.0f, 0.0f, 500.0f); col(canvas);
do_unary(canvas, "pow(x, -3)", 0.0f, 4.0f, 0.0f, 10.0f); row(canvas);
plot(canvas, "pow(x, 3)", 0.0f, 8.0f, 0.0f, 500.0f); col(canvas);
plot(canvas, "pow(x, -3)", 0.0f, 4.0f, 0.0f, 10.0f); row(canvas);
do_unary(canvas, "pow(0.9, x)", -10.0f, 10.0f, 0.0f, 3.0f); col(canvas);
do_unary(canvas, "pow(1.1, x)", -10.0f, 10.0f, 0.0f, 3.0f); row(canvas);
plot(canvas, "pow(0.9, x)", -10.0f, 10.0f, 0.0f, 3.0f); col(canvas);
plot(canvas, "pow(1.1, x)", -10.0f, 10.0f, 0.0f, 3.0f); row(canvas);
do_unary(canvas, "exp(x)", -1.0f, 7.0f, 0.0f, 1000.0f); col(canvas);
do_unary(canvas, "log(x)", 0.0f, 2.5f, -4.0f, 1.0f); row(canvas);
plot(canvas, "exp(x)", -1.0f, 7.0f, 0.0f, 1000.0f); col(canvas);
plot(canvas, "log(x)", 0.0f, 2.5f, -4.0f, 1.0f); row(canvas);
do_unary(canvas, "exp2(x)", -1.0f, 7.0f, 0.0f, 130.0f); col(canvas);
do_unary(canvas, "log2(x)", 0.0f, 4.0f, -4.0f, 2.0f); row(canvas);
plot(canvas, "exp2(x)", -1.0f, 7.0f, 0.0f, 130.0f); col(canvas);
plot(canvas, "log2(x)", 0.0f, 4.0f, -4.0f, 2.0f); row(canvas);
do_unary(canvas, "sqrt(x)", 0.0f, 25.0f, 0.0f, 5.0f); col(canvas);
do_unary(canvas, "inversesqrt(x)", 0.0f, 25.0f, 0.2f, 4.0f); row(canvas);
plot(canvas, "sqrt(x)", 0.0f, 25.0f, 0.0f, 5.0f); col(canvas);
plot(canvas, "inversesqrt(x)", 0.0f, 25.0f, 0.2f, 4.0f); row(canvas);
}
// The OpenGL ES Shading Language, Version 1.00, Section 8.3
@ -192,36 +200,36 @@ DEF_SIMPLE_GM_BG(runtime_intrinsics_common,
canvas->translate(kPadding, kPadding);
canvas->save();
do_unary(canvas, "abs(x)", -10.0f, 10.0f, 0.0f, 10.0f); col(canvas);
do_unary(canvas, "sign(x)", -1.0f, 1.0f, -1.5f, 1.5f); row(canvas);
plot(canvas, "abs(x)", -10.0f, 10.0f, 0.0f, 10.0f); col(canvas);
plot(canvas, "sign(x)", -1.0f, 1.0f, -1.5f, 1.5f); row(canvas);
do_unary(canvas, "floor(x)", -3.0f, 3.0f, -4.0f, 4.0f); col(canvas);
do_unary(canvas, "ceil(x)", -3.0f, 3.0f, -4.0f, 4.0f); col(canvas);
do_unary(canvas, "fract(x)", -3.0f, 3.0f, 0.0f, 1.0f); col(canvas);
do_unary(canvas, "mod(x, 2)", -4.0f, 4.0f, -2.0f, 2.0f); col(canvas);
do_unary(canvas, "mod(p, -2).x", -4.0f, 4.0f, -2.0f, 2.0f); col(canvas);
do_unary(canvas, "mod(p, v2).x", -4.0f, 4.0f, -2.0f, 2.0f); row(canvas);
plot(canvas, "floor(x)", -3.0f, 3.0f, -4.0f, 4.0f); col(canvas);
plot(canvas, "ceil(x)", -3.0f, 3.0f, -4.0f, 4.0f); col(canvas);
plot(canvas, "fract(x)", -3.0f, 3.0f, 0.0f, 1.0f); col(canvas);
plot(canvas, "mod(x, 2)", -4.0f, 4.0f, -2.0f, 2.0f, "mod(scalar)"); col(canvas);
plot(canvas, "mod(p, -2).x", -4.0f, 4.0f, -2.0f, 2.0f, "mod(mixed)" ); col(canvas);
plot(canvas, "mod(p, v2).x", -4.0f, 4.0f, -2.0f, 2.0f, "mod(vector)"); row(canvas);
do_unary(canvas, "min(x, 1)", 0.0f, 2.0f, 0.0f, 2.0f); col(canvas);
do_unary(canvas, "min(p, 1).x", 0.0f, 2.0f, 0.0f, 2.0f); col(canvas);
do_unary(canvas, "min(p, v1).x", 0.0f, 2.0f, 0.0f, 2.0f); col(canvas);
do_unary(canvas, "max(x, 1)", 0.0f, 2.0f, 0.0f, 2.0f); col(canvas);
do_unary(canvas, "max(p, 1).x", 0.0f, 2.0f, 0.0f, 2.0f); col(canvas);
do_unary(canvas, "max(p, v1).x", 0.0f, 2.0f, 0.0f, 2.0f); row(canvas);
plot(canvas, "min(x, 1)", 0.0f, 2.0f, 0.0f, 2.0f, "min(scalar)"); col(canvas);
plot(canvas, "min(p, 1).x", 0.0f, 2.0f, 0.0f, 2.0f, "min(mixed)" ); col(canvas);
plot(canvas, "min(p, v1).x", 0.0f, 2.0f, 0.0f, 2.0f, "min(vector)"); col(canvas);
plot(canvas, "max(x, 1)", 0.0f, 2.0f, 0.0f, 2.0f, "max(scalar)"); col(canvas);
plot(canvas, "max(p, 1).x", 0.0f, 2.0f, 0.0f, 2.0f, "max(mixed)" ); col(canvas);
plot(canvas, "max(p, v1).x", 0.0f, 2.0f, 0.0f, 2.0f, "max(vector)"); row(canvas);
do_unary(canvas, "clamp(x, 1, 2)", 0.0f, 3.0f, 0.0f, 3.0f); col(canvas);
do_unary(canvas, "clamp(p, 1, 2).x", 0.0f, 3.0f, 0.0f, 3.0f); col(canvas);
do_unary(canvas, "clamp(p, v1, v2).x", 0.0f, 3.0f, 0.0f, 3.0f); col(canvas);
do_unary(canvas, "saturate(x)", -1.0f, 2.0f, -0.5f, 1.5f); row(canvas);
plot(canvas, "clamp(x, 1, 2)", 0.0f, 3.0f, 0.0f, 3.0f, "clamp(scalar)"); col(canvas);
plot(canvas, "clamp(p, 1, 2).x", 0.0f, 3.0f, 0.0f, 3.0f, "clamp(mixed)" ); col(canvas);
plot(canvas, "clamp(p, v1, v2).x", 0.0f, 3.0f, 0.0f, 3.0f, "clamp(vector)"); col(canvas);
plot(canvas, "saturate(x)", -1.0f, 2.0f, -0.5f, 1.5f); row(canvas);
do_unary(canvas, "mix(1, 2, x)", -1.0f, 2.0f, 0.0f, 3.0f); col(canvas);
do_unary(canvas, "mix(v1, v2, x).x", -1.0f, 2.0f, 0.0f, 3.0f); col(canvas);
do_unary(canvas, "mix(v1, v2, p).x", -1.0f, 2.0f, 0.0f, 3.0f); row(canvas);
plot(canvas, "mix(1, 2, x)", -1.0f, 2.0f, 0.0f, 3.0f, "mix(scalar)"); col(canvas);
plot(canvas, "mix(v1, v2, x).x", -1.0f, 2.0f, 0.0f, 3.0f, "mix(mixed)" ); col(canvas);
plot(canvas, "mix(v1, v2, p).x", -1.0f, 2.0f, 0.0f, 3.0f, "mix(vector)"); row(canvas);
do_unary(canvas, "step(1, x)", 0.0f, 2.0f, -0.5f, 1.5f); col(canvas);
do_unary(canvas, "step(1, p).x", 0.0f, 2.0f, -0.5f, 1.5f); col(canvas);
do_unary(canvas, "step(v1, p).x", 0.0f, 2.0f, -0.5f, 1.5f); col(canvas);
do_unary(canvas, "smoothstep(1, 2, x)", 0.5f, 2.5f, -0.5f, 1.5f); col(canvas);
do_unary(canvas, "smoothstep(1, 2, p).x", 0.5f, 2.5f, -0.5f, 1.5f); col(canvas);
do_unary(canvas, "smoothstep(v1, v2, p).x", 0.5f, 2.5f, -0.5f, 1.5f); row(canvas);
plot(canvas, "step(1, x)", 0.0f, 2.0f, -0.5f, 1.5f, "step(scalar)"); col(canvas);
plot(canvas, "step(1, p).x", 0.0f, 2.0f, -0.5f, 1.5f, "step(mixed)" ); col(canvas);
plot(canvas, "step(v1, p).x", 0.0f, 2.0f, -0.5f, 1.5f, "step(vector)"); col(canvas);
plot(canvas, "smoothstep(1, 2, x)", 0.5f, 2.5f, -0.5f, 1.5f, "smooth(scalar)"); col(canvas);
plot(canvas, "smoothstep(1, 2, p).x", 0.5f, 2.5f, -0.5f, 1.5f, "smooth(mixed)" ); col(canvas);
plot(canvas, "smoothstep(v1, v2, p).x", 0.5f, 2.5f, -0.5f, 1.5f, "smooth(vector)"); row(canvas);
}