Small downsample_3_3 optimization
authorMatt Sarett <msarett@google.com>
Wed, 22 Mar 2017 13:20:02 +0000 (09:20 -0400)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Wed, 22 Mar 2017 14:39:17 +0000 (14:39 +0000)
Just a little less math...

mipmap_build_2047x2047_0_gamma
Before: 15.8ms
After:  13.4ms

Hard to see much difference on the gamma correct
mips, which are more dominated by load time.

BUG=skia:

Change-Id: I978cbc85a7d75cfcca2d5cd3fbc75e93413782f2
Reviewed-on: https://skia-review.googlesource.com/9988
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Matt Sarett <msarett@google.com>

bench/MipMapBench.cpp
src/core/SkMipMap.cpp

index 1ffd624feebd1095dfeca7dc8f84ae5dc1a406c1..cc5c8aefa385678118f0af62674b5da777947b13 100644 (file)
@@ -68,3 +68,6 @@ DEF_BENCH( return new MipMapBench(511, 511, SkDestinationSurfaceColorMode::kLega
 DEF_BENCH( return new MipMapBench(2048, 2048, SkDestinationSurfaceColorMode::kLegacy); )
 DEF_BENCH( return new MipMapBench(2048, 2048,
                                   SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware); )
+DEF_BENCH( return new MipMapBench(2047, 2047, SkDestinationSurfaceColorMode::kLegacy); )
+DEF_BENCH( return new MipMapBench(2047, 2047,
+                                  SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware); )
index 7a6897e1d97d0dfebce0f521cda7e3b0ab66dc1c..03341c60c875df86f6f5cb170e59217fc7a53aa4 100644 (file)
@@ -266,25 +266,34 @@ template <typename F> void downsample_3_3(void* dst, const void* src, size_t src
     auto p2 = (const typename F::Type*)((const char*)p1 + srcRB);
     auto d = static_cast<typename F::Type*>(dst);
 
-    auto c02 = F::Expand(p0[0]);
-    auto c12 = F::Expand(p1[0]);
-    auto c22 = F::Expand(p2[0]);
+    // Given pixels:
+    // a0 b0 c0 d0 e0 ...
+    // a1 b1 c1 d1 e1 ...
+    // a2 b2 c2 d2 e2 ...
+    // We want:
+    // (a0 + 2*b0 + c0 + 2*a1 + 4*b1 + 2*c1 + a2 + 2*b2 + c2) / 16
+    // (c0 + 2*d0 + e0 + 2*c1 + 4*d1 + 2*e1 + c2 + 2*d2 + e2) / 16
+    // ...
+
+    auto c0 = F::Expand(p0[0]);
+    auto c1 = F::Expand(p1[0]);
+    auto c2 = F::Expand(p2[0]);
+    auto c = add_121(c0, c1, c2);
     for (int i = 0; i < count; ++i) {
-        auto c00 = c02;
-        auto c01 = F::Expand(p0[1]);
-             c02 = F::Expand(p0[2]);
-        auto c10 = c12;
-        auto c11 = F::Expand(p1[1]);
-             c12 = F::Expand(p1[2]);
-        auto c20 = c22;
-        auto c21 = F::Expand(p2[1]);
-             c22 = F::Expand(p2[2]);
+        auto a = c;
+
+        auto b0 = F::Expand(p0[1]);
+        auto b1 = F::Expand(p1[1]);
+        auto b2 = F::Expand(p2[1]);
+        auto b = shift_left(add_121(b0, b1, b2), 1);
+
+        c0 = F::Expand(p0[2]);
+        c1 = F::Expand(p1[2]);
+        c2 = F::Expand(p2[2]);
+        c = add_121(c0, c1, c2);
 
-        auto c =
-            add_121(c00, c01, c02) +
-            shift_left(add_121(c10, c11, c12), 1) +
-            add_121(c20, c21, c22);
-        d[i] = F::Compact(shift_right(c, 4));
+        auto sum = a + b + c;
+        d[i] = F::Compact(shift_right(sum, 4));
         p0 += 2;
         p1 += 2;
         p2 += 2;