Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(197)

Side by Side Diff: bench/SkBlend_optsBench.cpp

Issue 1939513002: Add specialized sRGB blitter for SkOpts (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Sync and remove unneeded. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | resources/iconstrip.png » ('j') | src/opts/SkBlend_opts.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include <tuple>
9
10 #include "Benchmark.h"
11 #include "Resources.h"
12 #include "SkCpu.h"
13 #include "SkImage.h"
14 #include "SkImage_Base.h"
15 #include "SkNx.h"
16 #include "SkOpts.h"
17 #include "SkString.h"
18
19 #define INNER_LOOPS 10
20
21 namespace sk_default {
22 extern void brute_force_srcover_srgb_srgb(
23 uint32_t* dst, const uint32_t* const srcStart, int ndst, const int nsrc);
24 }
25
26 class SrcOverVSkOptsBruteForce {
27 public:
28 static SkString Name() { return SkString{"VSkOptsBruteForce"}; }
29 static bool WorksOnCpu() { return true; }
30 static void BlendN(uint32_t* dst, int count, const uint32_t* src) {
31 sk_default::brute_force_srcover_srgb_srgb(dst, src, count, count);
32 }
33 };
34
35 namespace sk_default {
36 extern void trivial_srcover_srgb_srgb(
37 uint32_t* dst, const uint32_t* const srcStart, int ndst, const int nsrc);
38 }
39
40 class SrcOverVSkOptsTrivial {
41 public:
42 static SkString Name() { return SkString{"VSkOptsTrivial"}; }
43 static bool WorksOnCpu() { return true; }
44 static void BlendN(uint32_t* dst, int count, const uint32_t* src) {
45 sk_default::trivial_srcover_srgb_srgb(dst, src, count, count);
46 }
47 };
48
49 namespace sk_default {
50 extern void best_non_simd_srcover_srgb_srgb(
51 uint32_t* dst, const uint32_t* const srcStart, int ndst, const int nsrc);
52 }
53
54 class SrcOverVSkOptsNonSimdCore {
55 public:
56 static SkString Name() { return SkString{"VSkOptsNonSimdCore"}; }
57 static bool WorksOnCpu() { return true; }
58 static void BlendN(uint32_t* dst, int count, const uint32_t* src) {
59 sk_default::best_non_simd_srcover_srgb_srgb(dst, src, count, count);
60 }
61 };
62
63 namespace sk_default {
64 extern void srcover_srgb_srgb(
65 uint32_t* dst, const uint32_t* const srcStart, int ndst, const int nsrc);
66 }
67
68 class SrcOverVSkOptsDefault {
69 public:
70 static SkString Name() { return SkString{"VSkOptsDefault"}; }
71 static bool WorksOnCpu() { return true; }
72 static void BlendN(uint32_t* dst, int count, const uint32_t* src) {
73 sk_default::srcover_srgb_srgb(dst, src, count, count);
74 }
75 };
76
77 namespace sk_sse41 {
78 extern void srcover_srgb_srgb(
79 uint32_t* dst, const uint32_t* const srcStart, int ndst, const int nsrc);
80 }
81
82 class SrcOverVSkOptsSSE41 {
83 public:
84 static SkString Name() { return SkString{"VSkOptsSSE41"}; }
85 static bool WorksOnCpu() { return SkCpu::Supports(SkCpu::SSE41); }
86 static void BlendN(uint32_t* dst, int count, const uint32_t* src) {
87 sk_sse41::srcover_srgb_srgb(dst, src, count, count);
88 }
89 };
90
91 //////////////////////////////////////////////////////////////////////////////// ///////////////////
92
93 template <typename Blender>
94 class LinearSrcOverBench : public Benchmark {
95 public:
96 LinearSrcOverBench(const char* fileName) {
97 fName = "LinearSrcOver";
98 fName.append(fileName);
99 fName.append(Blender::Name());
100
101 sk_sp<SkImage> image = GetResourceAsImage(fileName);
102 SkBitmap bm;
103 if (!as_IB(image)->getROPixels(&bm)) {
104 SkFAIL("Could not read resource");
105 }
106 bm.peekPixels(&fPixmap);
107 fDst.reset(fPixmap.rowBytesAsPixels());
108 }
109
110 protected:
111 bool isSuitableFor(Backend backend) override { return backend == kNonRenderi ng_Backend; }
112 const char* onGetName() override { return fName.c_str(); }
113 void onDraw(int loops, SkCanvas*) override {
114 if (!Blender::WorksOnCpu()) return;
f(malita) 2016/05/06 17:43:56 mtklein is probably the right person for this ques
herb_g 2016/05/06 20:57:45 Done. Thanks for the insight.
115 SkPixmap& pixels = fPixmap;
f(malita) 2016/05/06 17:43:56 Nit: why alias fPixmap?
herb_g 2016/05/06 20:57:45 Done.
116 SkASSERT(pixels.colorType() == kRGBA_8888_SkColorType);
117
118 const int width = pixels.rowBytesAsPixels();
119 fCount = width;
f(malita) 2016/05/06 17:43:56 Nit: looks like this could live in the ctor?
herb_g 2016/05/06 20:57:45 Done.
120
121 for (int i = 0; i < loops * INNER_LOOPS; ++i) {
122 const uint32_t* src = pixels.addr32();
123 for (int y = 0; y < pixels.height(); y++) {
124 Blender::BlendN(fDst.get(), width, src);
125 src += width;
126 }
127 }
128 }
129
130 void onPostDraw(SkCanvas*) override {
131 // Make sure the compiler does not optimize away the operation.
132 volatile uint32_t v = 0;
133 for (int i = 0; i < fCount; i++) {
134 v ^= fDst[i];
135 }
136 }
137
138 private:
139 int fCount;
140 SkAutoTArray<uint32_t> fDst;
141 SkString fName;
142 SkPixmap fPixmap;
143
144 typedef Benchmark INHERITED;
145 };
146
147 #if defined(SK_CPU_X86) && !defined(SK_BUILD_FOR_IOS)
148 #define BENCHES(fileName) \
149 DEF_BENCH( return new LinearSrcOverBench<SrcOverVSkOptsBruteForce>(fileName); ) \
150 DEF_BENCH( return new LinearSrcOverBench<SrcOverVSkOptsTrivial>(fileName); ) \
151 DEF_BENCH( return new LinearSrcOverBench<SrcOverVSkOptsNonSimdCore>(fileName); ) \
152 DEF_BENCH( return new LinearSrcOverBench<SrcOverVSkOptsDefault>(fileName); ) \
153 DEF_BENCH( return new LinearSrcOverBench<SrcOverVSkOptsSSE41>(fileName); )
154 #else
155 DEF_BENCH( return new LinearSrcOverBench<SrcOverVSkOptsBruteForce>(fileName); ) \
156 DEF_BENCH( return new LinearSrcOverBench<SrcOverVSkOptsTrivial>(fileName); ) \
157 DEF_BENCH( return new LinearSrcOverBench<SrcOverVSkOptsNonSimdCore>(fileName); ) \
158 DEF_BENCH( return new LinearSrcOverBench<SrcOverVSkOptsDefault>(fileName); )
159 #endif
160
161 BENCHES("yellow_rose.png")
162 BENCHES("baby_tux.png")
163 BENCHES("plane.png")
164 BENCHES("mandrill_512.png")
165 BENCHES("iconstrip.png")
OLDNEW
« no previous file with comments | « no previous file | resources/iconstrip.png » ('j') | src/opts/SkBlend_opts.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698