We used to use integer math on sk_FragCoord, when supported, and a
fallback using floating point (on a 4x4 rather than 8x8 grid). Now we
precompute a 8x8 table in a texture because it was shown to be
significantly faster on several devices. Test was done with the following
running in viewer with the stats layer enabled and looking at total
frame time:
SkRandom r;
for (int i = 0; i < N; ++i) {
SkColor c[2] = {r.nextU(), c[1] = r.nextU()};
SkPoint pts[2] = {{r.nextRangeScalar(0, 500), r.nextRangeScalar(0, 500)},
{r.nextRangeScalar(0, 500), r.nextRangeScalar(0, 500)}};
SkPaint p;
p.setDither(true);
p.setShader(SkGradientShader::MakeLinear(pts, c, nullptr, 2, SkTileMode::kRepeat));
canvas->drawPaint(p);
}
Device GPU N no dither int math dither table dither
Linux desktop QuadroP1000 5000 304ms 400ms (1.31x) 383ms (1.26x)
TecnoSpark3Pro PowerVRGE8320 200 299ms 820ms (2.74x) 592ms (1.98x)
Pixel 4 Adreno640 500 110ms 221ms (2.01x) 214ms (1.95x)
Galaxy S20 FE Mali-G77 MP11 600 165ms 360ms (2.18x) 260ms (1.58x)
Bug: b/195281495
Change-Id: I200a2be8e450ab66f7c8ae340a5c83ec6780db09
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/437239
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Michael Ludwig <michaelludwig@google.com>