epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 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 | */ |
bsalomon@google.com | 971d0c8 | 2011-08-19 17:22:05 +0000 | [diff] [blame] | 7 | |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 8 | #include "BenchTimer.h" |
commit-bot@chromium.org | e3bb3bc | 2013-12-03 18:16:48 +0000 | [diff] [blame] | 9 | #include "ResultsWriter.h" |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 10 | #include "SkBenchLogger.h" |
bsalomon@google.com | 971d0c8 | 2011-08-19 17:22:05 +0000 | [diff] [blame] | 11 | #include "SkBenchmark.h" |
robertphillips@google.com | 7367225 | 2013-08-29 12:40:26 +0000 | [diff] [blame] | 12 | #include "SkBitmapDevice.h" |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 13 | #include "SkCanvas.h" |
mtklein@google.com | 78d0379 | 2013-09-10 19:42:07 +0000 | [diff] [blame] | 14 | #include "SkColorPriv.h" |
sglez@google.com | 586db93 | 2013-07-24 17:24:23 +0000 | [diff] [blame] | 15 | #include "SkCommandLineFlags.h" |
reed@google.com | 1bc6c6a | 2014-02-04 14:02:44 +0000 | [diff] [blame] | 16 | #include "SkData.h" |
bsalomon@google.com | 82a7bfc | 2012-04-16 19:11:17 +0000 | [diff] [blame] | 17 | #include "SkDeferredCanvas.h" |
commit-bot@chromium.org | 6adce67 | 2014-02-03 14:48:17 +0000 | [diff] [blame] | 18 | #include "SkGMBench.h" |
reed@android.com | 3a859a0 | 2009-01-28 00:56:29 +0000 | [diff] [blame] | 19 | #include "SkGraphics.h" |
reed@android.com | b398fe8 | 2009-01-07 11:47:57 +0000 | [diff] [blame] | 20 | #include "SkImageEncoder.h" |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 21 | #include "SkOSFile.h" |
reed@android.com | 6c924ad | 2009-03-31 03:48:49 +0000 | [diff] [blame] | 22 | #include "SkPicture.h" |
robertphillips@google.com | 770963f | 2014-04-18 18:04:41 +0000 | [diff] [blame] | 23 | #include "SkPictureRecorder.h" |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 24 | #include "SkString.h" |
reed@google.com | 1bc6c6a | 2014-02-04 14:02:44 +0000 | [diff] [blame] | 25 | #include "SkSurface.h" |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 26 | |
djsollen@google.com | db490e9 | 2013-11-20 13:15:40 +0000 | [diff] [blame] | 27 | #if SK_SUPPORT_GPU |
| 28 | #include "GrContext.h" |
| 29 | #include "GrContextFactory.h" |
| 30 | #include "GrRenderTarget.h" |
| 31 | #include "SkGpuDevice.h" |
| 32 | #include "gl/GrGLDefines.h" |
| 33 | #else |
| 34 | class GrContext; |
| 35 | #endif // SK_SUPPORT_GPU |
| 36 | |
mtklein@google.com | 9ef1d21 | 2013-09-13 20:39:50 +0000 | [diff] [blame] | 37 | #include <limits> |
| 38 | |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 39 | enum BenchMode { |
| 40 | kNormal_BenchMode, |
| 41 | kDeferred_BenchMode, |
| 42 | kDeferredSilent_BenchMode, |
| 43 | kRecord_BenchMode, |
| 44 | kPictureRecord_BenchMode |
keyar@chromium.org | fdd909c | 2012-07-20 23:03:42 +0000 | [diff] [blame] | 45 | }; |
mtklein@google.com | dbd41c8 | 2013-09-13 20:11:09 +0000 | [diff] [blame] | 46 | const char* BenchMode_Name[] = { |
| 47 | "normal", "deferred", "deferredSilent", "record", "picturerecord" |
| 48 | }; |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 49 | |
borenet@google.com | 4e061d3 | 2013-09-16 19:12:19 +0000 | [diff] [blame] | 50 | static const char kDefaultsConfigStr[] = "defaults"; |
| 51 | |
keyar@chromium.org | fdd909c | 2012-07-20 23:03:42 +0000 | [diff] [blame] | 52 | /////////////////////////////////////////////////////////////////////////////// |
| 53 | |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 54 | class Iter { |
| 55 | public: |
commit-bot@chromium.org | 575d9cd | 2014-02-24 23:25:49 +0000 | [diff] [blame] | 56 | Iter() : fBenches(BenchRegistry::Head()), fGMs(skiagm::GMRegistry::Head()) {} |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 57 | |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 58 | SkBenchmark* next() { |
commit-bot@chromium.org | 575d9cd | 2014-02-24 23:25:49 +0000 | [diff] [blame] | 59 | if (fBenches) { |
| 60 | BenchRegistry::Factory f = fBenches->factory(); |
| 61 | fBenches = fBenches->next(); |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 62 | return (*f)(NULL); |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 63 | } |
commit-bot@chromium.org | 575d9cd | 2014-02-24 23:25:49 +0000 | [diff] [blame] | 64 | |
| 65 | while (fGMs) { |
| 66 | SkAutoTDelete<skiagm::GM> gm(fGMs->factory()(NULL)); |
| 67 | fGMs = fGMs->next(); |
| 68 | if (gm->getFlags() & skiagm::GM::kAsBench_Flag) { |
| 69 | return SkNEW_ARGS(SkGMBench, (gm.detach())); |
| 70 | } |
| 71 | } |
| 72 | |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 73 | return NULL; |
| 74 | } |
bungeman@google.com | d1a416a | 2011-05-18 18:37:07 +0000 | [diff] [blame] | 75 | |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 76 | private: |
commit-bot@chromium.org | 575d9cd | 2014-02-24 23:25:49 +0000 | [diff] [blame] | 77 | const BenchRegistry* fBenches; |
| 78 | const skiagm::GMRegistry* fGMs; |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 79 | }; |
| 80 | |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 81 | class AutoPrePostDraw { |
| 82 | public: |
| 83 | AutoPrePostDraw(SkBenchmark* bench) : fBench(bench) { |
| 84 | fBench->preDraw(); |
| 85 | } |
| 86 | ~AutoPrePostDraw() { |
| 87 | fBench->postDraw(); |
| 88 | } |
| 89 | private: |
| 90 | SkBenchmark* fBench; |
| 91 | }; |
| 92 | |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 93 | static void make_filename(const char name[], SkString* path) { |
| 94 | path->set(name); |
| 95 | for (int i = 0; name[i]; i++) { |
| 96 | switch (name[i]) { |
| 97 | case '/': |
| 98 | case '\\': |
| 99 | case ' ': |
| 100 | case ':': |
| 101 | path->writable_str()[i] = '-'; |
| 102 | break; |
| 103 | default: |
| 104 | break; |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 | |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 109 | static void saveFile(const char name[], const char config[], const char dir[], |
reed@google.com | 1bc6c6a | 2014-02-04 14:02:44 +0000 | [diff] [blame] | 110 | const SkImage* image) { |
| 111 | SkAutoTUnref<SkData> data(image->encode(SkImageEncoder::kPNG_Type, 100)); |
| 112 | if (NULL == data.get()) { |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 113 | return; |
| 114 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 115 | |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 116 | SkString filename; |
| 117 | make_filename(name, &filename); |
| 118 | filename.appendf("_%s.png", config); |
| 119 | SkString path = SkOSPath::SkPathJoin(dir, filename.c_str()); |
| 120 | ::remove(path.c_str()); |
reed@google.com | 1bc6c6a | 2014-02-04 14:02:44 +0000 | [diff] [blame] | 121 | |
reed@google.com | ace1354 | 2014-02-06 22:00:58 +0000 | [diff] [blame] | 122 | SkFILEWStream stream(path.c_str()); |
reed@google.com | 1bc6c6a | 2014-02-04 14:02:44 +0000 | [diff] [blame] | 123 | stream.write(data->data(), data->size()); |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 124 | } |
| 125 | |
robertphillips@google.com | 84b18c7 | 2014-04-13 19:09:42 +0000 | [diff] [blame] | 126 | static void perform_clip(SkCanvas* canvas, int w, int h) { |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 127 | SkRect r; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 128 | |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 129 | r.set(SkIntToScalar(10), SkIntToScalar(10), |
| 130 | SkIntToScalar(w*2/3), SkIntToScalar(h*2/3)); |
| 131 | canvas->clipRect(r, SkRegion::kIntersect_Op); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 132 | |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 133 | r.set(SkIntToScalar(w/3), SkIntToScalar(h/3), |
| 134 | SkIntToScalar(w-10), SkIntToScalar(h-10)); |
| 135 | canvas->clipRect(r, SkRegion::kXOR_Op); |
| 136 | } |
| 137 | |
robertphillips@google.com | 84b18c7 | 2014-04-13 19:09:42 +0000 | [diff] [blame] | 138 | static void perform_rotate(SkCanvas* canvas, int w, int h) { |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 139 | const SkScalar x = SkIntToScalar(w) / 2; |
| 140 | const SkScalar y = SkIntToScalar(h) / 2; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 141 | |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 142 | canvas->translate(x, y); |
| 143 | canvas->rotate(SkIntToScalar(35)); |
| 144 | canvas->translate(-x, -y); |
| 145 | } |
| 146 | |
robertphillips@google.com | 84b18c7 | 2014-04-13 19:09:42 +0000 | [diff] [blame] | 147 | static void perform_scale(SkCanvas* canvas, int w, int h) { |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 148 | const SkScalar x = SkIntToScalar(w) / 2; |
| 149 | const SkScalar y = SkIntToScalar(h) / 2; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 150 | |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 151 | canvas->translate(x, y); |
| 152 | // just enough so we can't take the sprite case |
| 153 | canvas->scale(SK_Scalar1 * 99/100, SK_Scalar1 * 99/100); |
| 154 | canvas->translate(-x, -y); |
| 155 | } |
| 156 | |
reed@google.com | 1bc6c6a | 2014-02-04 14:02:44 +0000 | [diff] [blame] | 157 | static SkSurface* make_surface(SkColorType colorType, const SkIPoint& size, |
| 158 | SkBenchmark::Backend backend, int sampleCount, |
| 159 | GrContext* context) { |
| 160 | SkSurface* surface = NULL; |
| 161 | SkImageInfo info = SkImageInfo::Make(size.fX, size.fY, colorType, |
| 162 | kPremul_SkAlphaType); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 163 | |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 164 | switch (backend) { |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 165 | case SkBenchmark::kRaster_Backend: |
reed@google.com | 1bc6c6a | 2014-02-04 14:02:44 +0000 | [diff] [blame] | 166 | surface = SkSurface::NewRaster(info); |
| 167 | surface->getCanvas()->clear(SK_ColorWHITE); |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 168 | break; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 169 | #if SK_SUPPORT_GPU |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 170 | case SkBenchmark::kGPU_Backend: { |
reed@google.com | 1bc6c6a | 2014-02-04 14:02:44 +0000 | [diff] [blame] | 171 | surface = SkSurface::NewRenderTarget(context, info, sampleCount); |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 172 | break; |
bsalomon@google.com | cb26535 | 2013-02-22 16:13:16 +0000 | [diff] [blame] | 173 | } |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 174 | #endif |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 175 | case SkBenchmark::kPDF_Backend: |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 176 | default: |
mtklein@google.com | 330313a | 2013-08-22 15:37:26 +0000 | [diff] [blame] | 177 | SkDEBUGFAIL("unsupported"); |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 178 | } |
reed@google.com | 1bc6c6a | 2014-02-04 14:02:44 +0000 | [diff] [blame] | 179 | return surface; |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 180 | } |
| 181 | |
bsalomon@google.com | cb26535 | 2013-02-22 16:13:16 +0000 | [diff] [blame] | 182 | #if SK_SUPPORT_GPU |
| 183 | GrContextFactory gContextFactory; |
| 184 | typedef GrContextFactory::GLContextType GLContextType; |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 185 | static const GLContextType kNative = GrContextFactory::kNative_GLContextType; |
commit-bot@chromium.org | e898957 | 2014-01-26 20:51:00 +0000 | [diff] [blame] | 186 | static const GLContextType kNVPR = GrContextFactory::kNVPR_GLContextType; |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 187 | #if SK_ANGLE |
| 188 | static const GLContextType kANGLE = GrContextFactory::kANGLE_GLContextType; |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 189 | #endif |
| 190 | static const GLContextType kDebug = GrContextFactory::kDebug_GLContextType; |
| 191 | static const GLContextType kNull = GrContextFactory::kNull_GLContextType; |
bsalomon@google.com | cb26535 | 2013-02-22 16:13:16 +0000 | [diff] [blame] | 192 | #else |
| 193 | typedef int GLContextType; |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 194 | static const GLContextType kNative = 0, kANGLE = 0, kDebug = 0, kNull = 0; |
bsalomon@google.com | cb26535 | 2013-02-22 16:13:16 +0000 | [diff] [blame] | 195 | #endif |
| 196 | |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 197 | #ifdef SK_DEBUG |
| 198 | static const bool kIsDebug = true; |
| 199 | #else |
| 200 | static const bool kIsDebug = false; |
| 201 | #endif |
| 202 | |
| 203 | static const struct Config { |
reed@google.com | 1bc6c6a | 2014-02-04 14:02:44 +0000 | [diff] [blame] | 204 | SkColorType fColorType; |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 205 | const char* name; |
| 206 | int sampleCount; |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 207 | SkBenchmark::Backend backend; |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 208 | GLContextType contextType; |
| 209 | bool runByDefault; |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 210 | } gConfigs[] = { |
commit-bot@chromium.org | 28fcae2 | 2014-04-11 17:15:40 +0000 | [diff] [blame] | 211 | { kN32_SkColorType, "NONRENDERING", 0, SkBenchmark::kNonRendering_Backend, kNative, true}, |
| 212 | { kN32_SkColorType, "8888", 0, SkBenchmark::kRaster_Backend, kNative, true}, |
reed@google.com | 1bc6c6a | 2014-02-04 14:02:44 +0000 | [diff] [blame] | 213 | { kRGB_565_SkColorType, "565", 0, SkBenchmark::kRaster_Backend, kNative, true}, |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 214 | #if SK_SUPPORT_GPU |
commit-bot@chromium.org | 28fcae2 | 2014-04-11 17:15:40 +0000 | [diff] [blame] | 215 | { kN32_SkColorType, "GPU", 0, SkBenchmark::kGPU_Backend, kNative, true}, |
| 216 | { kN32_SkColorType, "MSAA4", 4, SkBenchmark::kGPU_Backend, kNative, false}, |
| 217 | { kN32_SkColorType, "MSAA16", 16, SkBenchmark::kGPU_Backend, kNative, false}, |
| 218 | { kN32_SkColorType, "NVPRMSAA4", 4, SkBenchmark::kGPU_Backend, kNVPR, true}, |
| 219 | { kN32_SkColorType, "NVPRMSAA16", 16, SkBenchmark::kGPU_Backend, kNVPR, false}, |
robertphillips@google.com | d3b9fbb | 2012-03-28 16:19:11 +0000 | [diff] [blame] | 220 | #if SK_ANGLE |
commit-bot@chromium.org | 28fcae2 | 2014-04-11 17:15:40 +0000 | [diff] [blame] | 221 | { kN32_SkColorType, "ANGLE", 0, SkBenchmark::kGPU_Backend, kANGLE, true}, |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 222 | #endif // SK_ANGLE |
commit-bot@chromium.org | 28fcae2 | 2014-04-11 17:15:40 +0000 | [diff] [blame] | 223 | { kN32_SkColorType, "Debug", 0, SkBenchmark::kGPU_Backend, kDebug, kIsDebug}, |
| 224 | { kN32_SkColorType, "NULLGPU", 0, SkBenchmark::kGPU_Backend, kNull, true}, |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 225 | #endif // SK_SUPPORT_GPU |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 226 | }; |
| 227 | |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 228 | DEFINE_string(outDir, "", "If given, image of each bench will be put in outDir."); |
| 229 | DEFINE_string(timers, "cg", "Timers to display. " |
| 230 | "Options: w(all) W(all, truncated) c(pu) C(pu, truncated) g(pu)"); |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 231 | |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 232 | DEFINE_bool(rotate, false, "Rotate canvas before bench run?"); |
| 233 | DEFINE_bool(scale, false, "Scale canvas before bench run?"); |
| 234 | DEFINE_bool(clip, false, "Clip canvas before bench run?"); |
bsalomon@google.com | 8a70eef | 2013-03-19 13:58:55 +0000 | [diff] [blame] | 235 | |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 236 | DEFINE_bool(forceAA, true, "Force anti-aliasing?"); |
| 237 | DEFINE_bool(forceFilter, false, "Force bitmap filtering?"); |
| 238 | DEFINE_string(forceDither, "default", "Force dithering: true, false, or default?"); |
| 239 | DEFINE_bool(forceBlend, false, "Force alpha blending?"); |
| 240 | |
| 241 | DEFINE_int32(gpuCacheBytes, -1, "GPU cache size limit in bytes. 0 to disable cache."); |
| 242 | DEFINE_int32(gpuCacheCount, -1, "GPU cache size limit in object count. 0 to disable cache."); |
| 243 | |
commit-bot@chromium.org | 6dda827 | 2014-01-23 17:21:19 +0000 | [diff] [blame] | 244 | DEFINE_bool2(leaks, l, false, "show leaked ref cnt'd objects."); |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 245 | DEFINE_string(match, "", "[~][^]substring[$] [...] of test name to run.\n" |
| 246 | "Multiple matches may be separated by spaces.\n" |
| 247 | "~ causes a matching test to always be skipped\n" |
| 248 | "^ requires the start of the test to match\n" |
| 249 | "$ requires the end of the test to match\n" |
| 250 | "^ and $ requires an exact match\n" |
| 251 | "If a test does not match any list entry,\n" |
| 252 | "it is skipped unless some list entry starts with ~\n"); |
| 253 | DEFINE_string(mode, "normal", |
| 254 | "normal: draw to a normal canvas;\n" |
| 255 | "deferred: draw to a deferred canvas;\n" |
| 256 | "deferredSilent: deferred with silent playback;\n" |
| 257 | "record: draw to an SkPicture;\n" |
| 258 | "picturerecord: draw from an SkPicture to an SkPicture.\n"); |
borenet@google.com | 4e061d3 | 2013-09-16 19:12:19 +0000 | [diff] [blame] | 259 | DEFINE_string(config, kDefaultsConfigStr, |
| 260 | "Run configs given. By default, runs the configs marked \"runByDefault\" in gConfigs."); |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 261 | DEFINE_string(logFile, "", "Also write stdout here."); |
mtklein@google.com | dbd41c8 | 2013-09-13 20:11:09 +0000 | [diff] [blame] | 262 | DEFINE_int32(minMs, 20, "Shortest time we'll allow a benchmark to run."); |
| 263 | DEFINE_int32(maxMs, 4000, "Longest time we'll allow a benchmark to run."); |
commit-bot@chromium.org | 4bbe2e5 | 2014-04-21 21:12:32 +0000 | [diff] [blame] | 264 | DEFINE_bool(runOnce, kIsDebug, "Run each bench exactly once and don't report timings."); |
mtklein@google.com | dbd41c8 | 2013-09-13 20:11:09 +0000 | [diff] [blame] | 265 | DEFINE_double(error, 0.01, |
| 266 | "Ratio of subsequent bench measurements must drop within 1±error to converge."); |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 267 | DEFINE_string(timeFormat, "%9.2f", "Format to print results, in milliseconds per 1000 loops."); |
mtklein@google.com | dbd41c8 | 2013-09-13 20:11:09 +0000 | [diff] [blame] | 268 | DEFINE_bool2(verbose, v, false, "Print more."); |
tfarina@chromium.org | 725a64c | 2013-12-31 14:29:52 +0000 | [diff] [blame] | 269 | DEFINE_string2(resourcePath, i, "resources", "directory for test resources."); |
commit-bot@chromium.org | 61744ec | 2014-05-16 13:15:41 +0000 | [diff] [blame] | 270 | #ifdef SK_BUILD_JSON_WRITER |
commit-bot@chromium.org | e3bb3bc | 2013-12-03 18:16:48 +0000 | [diff] [blame] | 271 | DEFINE_string(outResultsFile, "", "If given, the results will be written to the file in JSON format."); |
commit-bot@chromium.org | 61744ec | 2014-05-16 13:15:41 +0000 | [diff] [blame] | 272 | #endif |
commit-bot@chromium.org | 56b7a6d | 2014-03-13 16:22:00 +0000 | [diff] [blame] | 273 | DEFINE_bool(dryRun, false, "Don't actually run the tests, just print what would have been done."); |
| 274 | |
mtklein@google.com | dbd41c8 | 2013-09-13 20:11:09 +0000 | [diff] [blame] | 275 | // Has this bench converged? First arguments are milliseconds / loop iteration, |
| 276 | // last is overall runtime in milliseconds. |
| 277 | static bool HasConverged(double prevPerLoop, double currPerLoop, double currRaw) { |
| 278 | if (currRaw < FLAGS_minMs) { |
| 279 | return false; |
| 280 | } |
| 281 | const double low = 1 - FLAGS_error, high = 1 + FLAGS_error; |
| 282 | const double ratio = currPerLoop / prevPerLoop; |
| 283 | return low < ratio && ratio < high; |
| 284 | } |
tomhudson@google.com | 86bb9b7 | 2012-04-03 13:28:57 +0000 | [diff] [blame] | 285 | |
caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 286 | int tool_main(int argc, char** argv); |
| 287 | int tool_main(int argc, char** argv) { |
commit-bot@chromium.org | 6dda827 | 2014-01-23 17:21:19 +0000 | [diff] [blame] | 288 | SkCommandLineFlags::Parse(argc, argv); |
bsalomon@google.com | 4e23068 | 2013-01-15 20:37:04 +0000 | [diff] [blame] | 289 | #if SK_ENABLE_INST_COUNT |
commit-bot@chromium.org | 6dda827 | 2014-01-23 17:21:19 +0000 | [diff] [blame] | 290 | if (FLAGS_leaks) { |
| 291 | gPrintInstCount = true; |
| 292 | } |
bsalomon@google.com | 65a87cc | 2012-08-14 13:15:44 +0000 | [diff] [blame] | 293 | #endif |
reed@android.com | 3a859a0 | 2009-01-28 00:56:29 +0000 | [diff] [blame] | 294 | SkAutoGraphics ag; |
bsalomon@google.com | 65a87cc | 2012-08-14 13:15:44 +0000 | [diff] [blame] | 295 | |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 296 | // First, parse some flags. |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 297 | SkBenchLogger logger; |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 298 | if (FLAGS_logFile.count()) { |
| 299 | logger.SetLogFile(FLAGS_logFile[0]); |
| 300 | } |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 301 | |
commit-bot@chromium.org | e3bb3bc | 2013-12-03 18:16:48 +0000 | [diff] [blame] | 302 | LoggerResultsWriter logWriter(logger, FLAGS_timeFormat[0]); |
| 303 | MultiResultsWriter writer; |
| 304 | writer.add(&logWriter); |
commit-bot@chromium.org | 61744ec | 2014-05-16 13:15:41 +0000 | [diff] [blame] | 305 | |
| 306 | #ifdef SK_BUILD_JSON_WRITER |
commit-bot@chromium.org | e3bb3bc | 2013-12-03 18:16:48 +0000 | [diff] [blame] | 307 | SkAutoTDelete<JSONResultsWriter> jsonWriter; |
| 308 | if (FLAGS_outResultsFile.count()) { |
| 309 | jsonWriter.reset(SkNEW(JSONResultsWriter(FLAGS_outResultsFile[0]))); |
| 310 | writer.add(jsonWriter.get()); |
| 311 | } |
commit-bot@chromium.org | 61744ec | 2014-05-16 13:15:41 +0000 | [diff] [blame] | 312 | #endif |
| 313 | |
commit-bot@chromium.org | e3bb3bc | 2013-12-03 18:16:48 +0000 | [diff] [blame] | 314 | // Instantiate after all the writers have been added to writer so that we |
| 315 | // call close() before their destructors are called on the way out. |
| 316 | CallEnd<MultiResultsWriter> ender(writer); |
| 317 | |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 318 | const uint8_t alpha = FLAGS_forceBlend ? 0x80 : 0xFF; |
| 319 | SkTriState::State dither = SkTriState::kDefault; |
| 320 | for (size_t i = 0; i < 3; i++) { |
| 321 | if (strcmp(SkTriState::Name[i], FLAGS_forceDither[0]) == 0) { |
| 322 | dither = static_cast<SkTriState::State>(i); |
reed@android.com | b398fe8 | 2009-01-07 11:47:57 +0000 | [diff] [blame] | 323 | } |
| 324 | } |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 325 | |
| 326 | BenchMode benchMode = kNormal_BenchMode; |
| 327 | for (size_t i = 0; i < SK_ARRAY_COUNT(BenchMode_Name); i++) { |
| 328 | if (strcmp(FLAGS_mode[0], BenchMode_Name[i]) == 0) { |
| 329 | benchMode = static_cast<BenchMode>(i); |
| 330 | } |
keyar@chromium.org | fdd909c | 2012-07-20 23:03:42 +0000 | [diff] [blame] | 331 | } |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 332 | |
| 333 | SkTDArray<int> configs; |
borenet@google.com | 4e061d3 | 2013-09-16 19:12:19 +0000 | [diff] [blame] | 334 | bool runDefaultConfigs = false; |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 335 | // Try user-given configs first. |
| 336 | for (int i = 0; i < FLAGS_config.count(); i++) { |
robertphillips@google.com | e9cd27d | 2013-10-16 17:48:11 +0000 | [diff] [blame] | 337 | for (int j = 0; j < static_cast<int>(SK_ARRAY_COUNT(gConfigs)); ++j) { |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 338 | if (0 == strcmp(FLAGS_config[i], gConfigs[j].name)) { |
| 339 | *configs.append() = j; |
borenet@google.com | 4e061d3 | 2013-09-16 19:12:19 +0000 | [diff] [blame] | 340 | } else if (0 == strcmp(FLAGS_config[i], kDefaultsConfigStr)) { |
| 341 | runDefaultConfigs = true; |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 342 | } |
| 343 | } |
keyar@chromium.org | fdd909c | 2012-07-20 23:03:42 +0000 | [diff] [blame] | 344 | } |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 345 | // If there weren't any, fill in with defaults. |
borenet@google.com | 4e061d3 | 2013-09-16 19:12:19 +0000 | [diff] [blame] | 346 | if (runDefaultConfigs) { |
robertphillips@google.com | e9cd27d | 2013-10-16 17:48:11 +0000 | [diff] [blame] | 347 | for (int i = 0; i < static_cast<int>(SK_ARRAY_COUNT(gConfigs)); ++i) { |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 348 | if (gConfigs[i].runByDefault) { |
bsalomon@google.com | 8a70eef | 2013-03-19 13:58:55 +0000 | [diff] [blame] | 349 | *configs.append() = i; |
| 350 | } |
tomhudson@google.com | 13eaaaa | 2012-04-16 18:00:40 +0000 | [diff] [blame] | 351 | } |
| 352 | } |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 353 | // Filter out things we can't run. |
| 354 | if (kNormal_BenchMode != benchMode) { |
bsalomon@google.com | 604a56a | 2013-03-15 15:42:15 +0000 | [diff] [blame] | 355 | // Non-rendering configs only run in normal mode |
| 356 | for (int i = 0; i < configs.count(); ++i) { |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 357 | const Config& config = gConfigs[configs[i]]; |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 358 | if (SkBenchmark::kNonRendering_Backend == config.backend) { |
bsalomon@google.com | 604a56a | 2013-03-15 15:42:15 +0000 | [diff] [blame] | 359 | configs.remove(i, 1); |
| 360 | --i; |
| 361 | } |
| 362 | } |
| 363 | } |
scroggo@google.com | 111fd11 | 2013-09-25 21:42:12 +0000 | [diff] [blame] | 364 | // Set the resource path. |
| 365 | if (!FLAGS_resourcePath.isEmpty()) { |
| 366 | SkBenchmark::SetResourcePath(FLAGS_resourcePath[0]); |
| 367 | } |
| 368 | |
bsalomon@google.com | 8a70eef | 2013-03-19 13:58:55 +0000 | [diff] [blame] | 369 | #if SK_SUPPORT_GPU |
| 370 | for (int i = 0; i < configs.count(); ++i) { |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 371 | const Config& config = gConfigs[configs[i]]; |
bsalomon@google.com | 8a70eef | 2013-03-19 13:58:55 +0000 | [diff] [blame] | 372 | |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 373 | if (SkBenchmark::kGPU_Backend == config.backend) { |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 374 | GrContext* context = gContextFactory.get(config.contextType); |
bsalomon@google.com | 8a70eef | 2013-03-19 13:58:55 +0000 | [diff] [blame] | 375 | if (NULL == context) { |
commit-bot@chromium.org | 0f298cc | 2014-04-30 15:54:29 +0000 | [diff] [blame] | 376 | SkDebugf("GrContext could not be created for config %s. Config will be skipped.\n", |
| 377 | config.name); |
bsalomon@google.com | 8a70eef | 2013-03-19 13:58:55 +0000 | [diff] [blame] | 378 | configs.remove(i); |
| 379 | --i; |
| 380 | continue; |
| 381 | } |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 382 | if (config.sampleCount > context->getMaxSampleCount()){ |
commit-bot@chromium.org | 0f298cc | 2014-04-30 15:54:29 +0000 | [diff] [blame] | 383 | SkDebugf( |
| 384 | "Sample count (%d) for config %s is not supported. Config will be skipped.\n", |
| 385 | config.sampleCount, config.name); |
bsalomon@google.com | 8a70eef | 2013-03-19 13:58:55 +0000 | [diff] [blame] | 386 | configs.remove(i); |
| 387 | --i; |
| 388 | continue; |
| 389 | } |
| 390 | } |
| 391 | } |
| 392 | #endif |
| 393 | |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 394 | // All flags should be parsed now. Report our settings. |
commit-bot@chromium.org | 4bbe2e5 | 2014-04-21 21:12:32 +0000 | [diff] [blame] | 395 | if (FLAGS_runOnce) { |
| 396 | logger.logError("bench was run with --runOnce, so we're going to hide the times." |
| 397 | " It's for your own good!\n"); |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 398 | } |
commit-bot@chromium.org | e3bb3bc | 2013-12-03 18:16:48 +0000 | [diff] [blame] | 399 | writer.option("mode", FLAGS_mode[0]); |
| 400 | writer.option("alpha", SkStringPrintf("0x%02X", alpha).c_str()); |
| 401 | writer.option("antialias", SkStringPrintf("%d", FLAGS_forceAA).c_str()); |
| 402 | writer.option("filter", SkStringPrintf("%d", FLAGS_forceFilter).c_str()); |
| 403 | writer.option("dither", SkTriState::Name[dither]); |
| 404 | |
| 405 | writer.option("rotate", SkStringPrintf("%d", FLAGS_rotate).c_str()); |
| 406 | writer.option("scale", SkStringPrintf("%d", FLAGS_scale).c_str()); |
| 407 | writer.option("clip", SkStringPrintf("%d", FLAGS_clip).c_str()); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 408 | |
bungeman@google.com | a5d4841 | 2011-06-15 17:25:46 +0000 | [diff] [blame] | 409 | #if defined(SK_BUILD_FOR_WIN32) |
commit-bot@chromium.org | e3bb3bc | 2013-12-03 18:16:48 +0000 | [diff] [blame] | 410 | writer.option("system", "WIN32"); |
bungeman@google.com | a5d4841 | 2011-06-15 17:25:46 +0000 | [diff] [blame] | 411 | #elif defined(SK_BUILD_FOR_MAC) |
commit-bot@chromium.org | e3bb3bc | 2013-12-03 18:16:48 +0000 | [diff] [blame] | 412 | writer.option("system", "MAC"); |
bungeman@google.com | a5d4841 | 2011-06-15 17:25:46 +0000 | [diff] [blame] | 413 | #elif defined(SK_BUILD_FOR_ANDROID) |
commit-bot@chromium.org | e3bb3bc | 2013-12-03 18:16:48 +0000 | [diff] [blame] | 414 | writer.option("system", "ANDROID"); |
bungeman@google.com | a5d4841 | 2011-06-15 17:25:46 +0000 | [diff] [blame] | 415 | #elif defined(SK_BUILD_FOR_UNIX) |
commit-bot@chromium.org | e3bb3bc | 2013-12-03 18:16:48 +0000 | [diff] [blame] | 416 | writer.option("system", "UNIX"); |
bungeman@google.com | a5d4841 | 2011-06-15 17:25:46 +0000 | [diff] [blame] | 417 | #else |
commit-bot@chromium.org | e3bb3bc | 2013-12-03 18:16:48 +0000 | [diff] [blame] | 418 | writer.option("system", "other"); |
bungeman@google.com | a5d4841 | 2011-06-15 17:25:46 +0000 | [diff] [blame] | 419 | #endif |
| 420 | |
| 421 | #if defined(SK_DEBUG) |
commit-bot@chromium.org | e3bb3bc | 2013-12-03 18:16:48 +0000 | [diff] [blame] | 422 | writer.option("build", "DEBUG"); |
| 423 | #else |
| 424 | writer.option("build", "RELEASE"); |
bungeman@google.com | a5d4841 | 2011-06-15 17:25:46 +0000 | [diff] [blame] | 425 | #endif |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 426 | |
| 427 | // Set texture cache limits if non-default. |
bsalomon@google.com | 5c90e29 | 2013-02-22 19:17:13 +0000 | [diff] [blame] | 428 | for (size_t i = 0; i < SK_ARRAY_COUNT(gConfigs); ++i) { |
bsalomon@google.com | cb26535 | 2013-02-22 16:13:16 +0000 | [diff] [blame] | 429 | #if SK_SUPPORT_GPU |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 430 | const Config& config = gConfigs[i]; |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 431 | if (SkBenchmark::kGPU_Backend != config.backend) { |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 432 | continue; |
bsalomon@google.com | cb26535 | 2013-02-22 16:13:16 +0000 | [diff] [blame] | 433 | } |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 434 | GrContext* context = gContextFactory.get(config.contextType); |
| 435 | if (NULL == context) { |
| 436 | continue; |
| 437 | } |
| 438 | |
| 439 | size_t bytes; |
| 440 | int count; |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 441 | context->getResourceCacheLimits(&count, &bytes); |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 442 | if (-1 != FLAGS_gpuCacheBytes) { |
| 443 | bytes = static_cast<size_t>(FLAGS_gpuCacheBytes); |
| 444 | } |
| 445 | if (-1 != FLAGS_gpuCacheCount) { |
| 446 | count = FLAGS_gpuCacheCount; |
| 447 | } |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 448 | context->setResourceCacheLimits(count, bytes); |
bsalomon@google.com | cb26535 | 2013-02-22 16:13:16 +0000 | [diff] [blame] | 449 | #endif |
| 450 | } |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 451 | |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 452 | // Run each bench in each configuration it supports and we asked for. |
| 453 | Iter iter; |
commit-bot@chromium.org | e3bb3bc | 2013-12-03 18:16:48 +0000 | [diff] [blame] | 454 | SkBenchmark* bench; |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 455 | while ((bench = iter.next()) != NULL) { |
bsalomon@google.com | 7fbc604 | 2012-08-13 22:10:05 +0000 | [diff] [blame] | 456 | SkAutoTUnref<SkBenchmark> benchUnref(bench); |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 457 | if (SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getName())) { |
reed@android.com | b398fe8 | 2009-01-07 11:47:57 +0000 | [diff] [blame] | 458 | continue; |
| 459 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 460 | |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 461 | bench->setForceAlpha(alpha); |
| 462 | bench->setForceAA(FLAGS_forceAA); |
| 463 | bench->setForceFilter(FLAGS_forceFilter); |
| 464 | bench->setDither(dither); |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 465 | AutoPrePostDraw appd(bench); |
| 466 | |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 467 | bool loggedBenchName = false; |
| 468 | for (int i = 0; i < configs.count(); ++i) { |
| 469 | const int configIndex = configs[i]; |
| 470 | const Config& config = gConfigs[configIndex]; |
tomhudson@google.com | 13eaaaa | 2012-04-16 18:00:40 +0000 | [diff] [blame] | 471 | |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 472 | if (!bench->isSuitableFor(config.backend)) { |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 473 | continue; |
bsalomon@google.com | 604a56a | 2013-03-15 15:42:15 +0000 | [diff] [blame] | 474 | } |
| 475 | |
bsalomon@google.com | cb26535 | 2013-02-22 16:13:16 +0000 | [diff] [blame] | 476 | GrContext* context = NULL; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 477 | #if SK_SUPPORT_GPU |
sugoi@google.com | 9c55f80 | 2013-03-07 20:52:59 +0000 | [diff] [blame] | 478 | SkGLContextHelper* glContext = NULL; |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 479 | if (SkBenchmark::kGPU_Backend == config.backend) { |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 480 | context = gContextFactory.get(config.contextType); |
bsalomon@google.com | cb26535 | 2013-02-22 16:13:16 +0000 | [diff] [blame] | 481 | if (NULL == context) { |
| 482 | continue; |
| 483 | } |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 484 | glContext = gContextFactory.getGLContext(config.contextType); |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 485 | } |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 486 | #endif |
reed@google.com | 1bc6c6a | 2014-02-04 14:02:44 +0000 | [diff] [blame] | 487 | |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 488 | SkAutoTUnref<SkCanvas> canvas; |
robertphillips@google.com | 84b18c7 | 2014-04-13 19:09:42 +0000 | [diff] [blame] | 489 | SkAutoTUnref<SkPicture> recordFrom; |
| 490 | SkPictureRecorder recorderTo; |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 491 | const SkIPoint dim = bench->getSize(); |
bsalomon@google.com | 604a56a | 2013-03-15 15:42:15 +0000 | [diff] [blame] | 492 | |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 493 | const SkPicture::RecordingFlags kRecordFlags = |
| 494 | SkPicture::kUsePathBoundsForClip_RecordingFlag; |
| 495 | |
reed@google.com | 1bc6c6a | 2014-02-04 14:02:44 +0000 | [diff] [blame] | 496 | SkAutoTUnref<SkSurface> surface; |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 497 | if (SkBenchmark::kNonRendering_Backend != config.backend) { |
reed@google.com | 1bc6c6a | 2014-02-04 14:02:44 +0000 | [diff] [blame] | 498 | surface.reset(make_surface(config.fColorType, |
| 499 | dim, |
| 500 | config.backend, |
| 501 | config.sampleCount, |
| 502 | context)); |
| 503 | if (!surface.get()) { |
mtklein@google.com | dbd41c8 | 2013-09-13 20:11:09 +0000 | [diff] [blame] | 504 | logger.logError(SkStringPrintf( |
| 505 | "Device creation failure for config %s. Will skip.\n", config.name)); |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 506 | continue; |
keyar@chromium.org | fdd909c | 2012-07-20 23:03:42 +0000 | [diff] [blame] | 507 | } |
junov@chromium.org | fb10389 | 2012-09-20 19:35:43 +0000 | [diff] [blame] | 508 | |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 509 | switch(benchMode) { |
| 510 | case kDeferredSilent_BenchMode: |
| 511 | case kDeferred_BenchMode: |
reed@google.com | 1bc6c6a | 2014-02-04 14:02:44 +0000 | [diff] [blame] | 512 | canvas.reset(SkDeferredCanvas::Create(surface.get())); |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 513 | break; |
| 514 | case kRecord_BenchMode: |
skia.committer@gmail.com | 60bd751 | 2014-04-18 03:03:54 +0000 | [diff] [blame] | 515 | canvas.reset(SkRef(recorderTo.beginRecording(dim.fX, dim.fY, |
commit-bot@chromium.org | 5fb2ce3 | 2014-04-17 23:35:06 +0000 | [diff] [blame] | 516 | NULL, kRecordFlags))); |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 517 | break; |
robertphillips@google.com | 84b18c7 | 2014-04-13 19:09:42 +0000 | [diff] [blame] | 518 | case kPictureRecord_BenchMode: { |
| 519 | SkPictureRecorder recorderFrom; |
skia.committer@gmail.com | 60bd751 | 2014-04-18 03:03:54 +0000 | [diff] [blame] | 520 | bench->draw(1, recorderFrom.beginRecording(dim.fX, dim.fY, |
commit-bot@chromium.org | 5fb2ce3 | 2014-04-17 23:35:06 +0000 | [diff] [blame] | 521 | NULL, kRecordFlags)); |
robertphillips@google.com | 84b18c7 | 2014-04-13 19:09:42 +0000 | [diff] [blame] | 522 | recordFrom.reset(recorderFrom.endRecording()); |
skia.committer@gmail.com | 60bd751 | 2014-04-18 03:03:54 +0000 | [diff] [blame] | 523 | canvas.reset(SkRef(recorderTo.beginRecording(dim.fX, dim.fY, |
commit-bot@chromium.org | 5fb2ce3 | 2014-04-17 23:35:06 +0000 | [diff] [blame] | 524 | NULL, kRecordFlags))); |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 525 | break; |
robertphillips@google.com | 84b18c7 | 2014-04-13 19:09:42 +0000 | [diff] [blame] | 526 | } |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 527 | case kNormal_BenchMode: |
reed@google.com | 1bc6c6a | 2014-02-04 14:02:44 +0000 | [diff] [blame] | 528 | canvas.reset(SkRef(surface->getCanvas())); |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 529 | break; |
| 530 | default: |
| 531 | SkASSERT(false); |
| 532 | } |
| 533 | } |
| 534 | |
| 535 | if (NULL != canvas) { |
| 536 | canvas->clear(SK_ColorWHITE); |
skia.committer@gmail.com | 5199701 | 2014-04-14 03:04:57 +0000 | [diff] [blame] | 537 | if (FLAGS_clip) { |
| 538 | perform_clip(canvas, dim.fX, dim.fY); |
robertphillips@google.com | 84b18c7 | 2014-04-13 19:09:42 +0000 | [diff] [blame] | 539 | } |
skia.committer@gmail.com | 5199701 | 2014-04-14 03:04:57 +0000 | [diff] [blame] | 540 | if (FLAGS_scale) { |
| 541 | perform_scale(canvas, dim.fX, dim.fY); |
robertphillips@google.com | 84b18c7 | 2014-04-13 19:09:42 +0000 | [diff] [blame] | 542 | } |
skia.committer@gmail.com | 5199701 | 2014-04-14 03:04:57 +0000 | [diff] [blame] | 543 | if (FLAGS_rotate) { |
| 544 | perform_rotate(canvas, dim.fX, dim.fY); |
robertphillips@google.com | 84b18c7 | 2014-04-13 19:09:42 +0000 | [diff] [blame] | 545 | } |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | if (!loggedBenchName) { |
| 549 | loggedBenchName = true; |
commit-bot@chromium.org | e3bb3bc | 2013-12-03 18:16:48 +0000 | [diff] [blame] | 550 | writer.bench(bench->getName(), dim.fX, dim.fY); |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | #if SK_SUPPORT_GPU |
| 554 | SkGLContextHelper* contextHelper = NULL; |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 555 | if (SkBenchmark::kGPU_Backend == config.backend) { |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 556 | contextHelper = gContextFactory.getGLContext(config.contextType); |
| 557 | } |
| 558 | BenchTimer timer(contextHelper); |
| 559 | #else |
| 560 | BenchTimer timer; |
| 561 | #endif |
| 562 | |
mtklein@google.com | 9ef1d21 | 2013-09-13 20:39:50 +0000 | [diff] [blame] | 563 | double previous = std::numeric_limits<double>::infinity(); |
mtklein@google.com | dbd41c8 | 2013-09-13 20:11:09 +0000 | [diff] [blame] | 564 | bool converged = false; |
djsollen@google.com | 70de4da | 2013-10-10 17:33:39 +0000 | [diff] [blame] | 565 | |
| 566 | // variables used to compute loopsPerFrame |
| 567 | double frameIntervalTime = 0.0f; |
| 568 | int frameIntervalTotalLoops = 0; |
| 569 | |
| 570 | bool frameIntervalComputed = false; |
| 571 | int loopsPerFrame = 0; |
| 572 | int loopsPerIter = 0; |
mtklein@google.com | dbd41c8 | 2013-09-13 20:11:09 +0000 | [diff] [blame] | 573 | if (FLAGS_verbose) { SkDebugf("%s %s: ", bench->getName(), config.name); } |
commit-bot@chromium.org | 56b7a6d | 2014-03-13 16:22:00 +0000 | [diff] [blame] | 574 | if (!FLAGS_dryRun) { |
| 575 | do { |
| 576 | // Ramp up 1 -> 2 -> 4 -> 8 -> 16 -> ... -> ~1 billion. |
| 577 | loopsPerIter = (loopsPerIter == 0) ? 1 : loopsPerIter * 2; |
| 578 | if (loopsPerIter >= (1<<30) || timer.fWall > FLAGS_maxMs) { |
| 579 | // If you find it takes more than a billion loops to get up to 20ms of runtime, |
| 580 | // you've got a computer clocked at several THz or have a broken benchmark. ;) |
| 581 | // "1B ought to be enough for anybody." |
| 582 | logger.logError(SkStringPrintf( |
| 583 | "\nCan't get %s %s to converge in %dms (%d loops)", |
| 584 | bench->getName(), config.name, FLAGS_maxMs, loopsPerIter)); |
| 585 | break; |
djsollen@google.com | 70de4da | 2013-10-10 17:33:39 +0000 | [diff] [blame] | 586 | } |
| 587 | |
commit-bot@chromium.org | 56b7a6d | 2014-03-13 16:22:00 +0000 | [diff] [blame] | 588 | if ((benchMode == kRecord_BenchMode || benchMode == kPictureRecord_BenchMode)) { |
| 589 | // Clear the recorded commands so that they do not accumulate. |
skia.committer@gmail.com | 60bd751 | 2014-04-18 03:03:54 +0000 | [diff] [blame] | 590 | canvas.reset(SkRef(recorderTo.beginRecording(dim.fX, dim.fY, |
commit-bot@chromium.org | 5fb2ce3 | 2014-04-17 23:35:06 +0000 | [diff] [blame] | 591 | NULL, kRecordFlags))); |
djsollen@google.com | 70de4da | 2013-10-10 17:33:39 +0000 | [diff] [blame] | 592 | } |
| 593 | |
commit-bot@chromium.org | 56b7a6d | 2014-03-13 16:22:00 +0000 | [diff] [blame] | 594 | timer.start(); |
| 595 | // Inner loop that allows us to break the run into smaller |
| 596 | // chunks (e.g. frames). This is especially useful for the GPU |
| 597 | // as we can flush and/or swap buffers to keep the GPU from |
| 598 | // queuing up too much work. |
| 599 | for (int loopCount = loopsPerIter; loopCount > 0; ) { |
| 600 | // Save and restore around each call to draw() to guarantee a pristine canvas. |
| 601 | SkAutoCanvasRestore saveRestore(canvas, true/*also save*/); |
djsollen@google.com | 70de4da | 2013-10-10 17:33:39 +0000 | [diff] [blame] | 602 | |
commit-bot@chromium.org | 56b7a6d | 2014-03-13 16:22:00 +0000 | [diff] [blame] | 603 | int loops; |
| 604 | if (frameIntervalComputed && loopCount > loopsPerFrame) { |
| 605 | loops = loopsPerFrame; |
| 606 | loopCount -= loopsPerFrame; |
| 607 | } else { |
| 608 | loops = loopCount; |
| 609 | loopCount = 0; |
djsollen@google.com | 70de4da | 2013-10-10 17:33:39 +0000 | [diff] [blame] | 610 | } |
djsollen@google.com | dcfed6c | 2013-10-10 18:48:27 +0000 | [diff] [blame] | 611 | |
commit-bot@chromium.org | 56b7a6d | 2014-03-13 16:22:00 +0000 | [diff] [blame] | 612 | if (benchMode == kPictureRecord_BenchMode) { |
robertphillips@google.com | 84b18c7 | 2014-04-13 19:09:42 +0000 | [diff] [blame] | 613 | recordFrom->draw(canvas); |
commit-bot@chromium.org | 56b7a6d | 2014-03-13 16:22:00 +0000 | [diff] [blame] | 614 | } else { |
| 615 | bench->draw(loops, canvas); |
| 616 | } |
| 617 | |
| 618 | if (kDeferredSilent_BenchMode == benchMode) { |
| 619 | static_cast<SkDeferredCanvas*>(canvas.get())->silentFlush(); |
| 620 | } else if (NULL != canvas) { |
| 621 | canvas->flush(); |
| 622 | } |
| 623 | |
| 624 | #if SK_SUPPORT_GPU |
| 625 | // swap drawing buffers on each frame to prevent the GPU |
| 626 | // from queuing up too much work |
| 627 | if (NULL != glContext) { |
| 628 | glContext->swapBuffers(); |
| 629 | } |
| 630 | #endif |
| 631 | } |
| 632 | |
| 633 | |
| 634 | |
| 635 | // Stop truncated timers before GL calls complete, and stop the full timers after. |
| 636 | timer.truncatedEnd(); |
| 637 | #if SK_SUPPORT_GPU |
| 638 | if (NULL != glContext) { |
| 639 | context->flush(); |
| 640 | SK_GL(*glContext, Finish()); |
| 641 | } |
| 642 | #endif |
| 643 | timer.end(); |
| 644 | |
| 645 | // setup the frame interval for subsequent iterations |
| 646 | if (!frameIntervalComputed) { |
| 647 | frameIntervalTime += timer.fWall; |
| 648 | frameIntervalTotalLoops += loopsPerIter; |
| 649 | if (frameIntervalTime >= FLAGS_minMs) { |
| 650 | frameIntervalComputed = true; |
| 651 | loopsPerFrame = |
| 652 | (int)(((double)frameIntervalTotalLoops / frameIntervalTime) * FLAGS_minMs); |
| 653 | if (loopsPerFrame < 1) { |
| 654 | loopsPerFrame = 1; |
| 655 | } |
| 656 | // SkDebugf(" %s has %d loops in %f ms (normalized to %d)\n", |
| 657 | // bench->getName(), frameIntervalTotalLoops, |
| 658 | // timer.fWall, loopsPerFrame); |
| 659 | } |
| 660 | } |
| 661 | |
| 662 | const double current = timer.fWall / loopsPerIter; |
| 663 | if (FLAGS_verbose && current > previous) { SkDebugf("↑"); } |
| 664 | if (FLAGS_verbose) { SkDebugf("%.3g ", current); } |
| 665 | converged = HasConverged(previous, current, timer.fWall); |
| 666 | previous = current; |
commit-bot@chromium.org | 4bbe2e5 | 2014-04-21 21:12:32 +0000 | [diff] [blame] | 667 | } while (!FLAGS_runOnce && !converged); |
commit-bot@chromium.org | 56b7a6d | 2014-03-13 16:22:00 +0000 | [diff] [blame] | 668 | } |
mtklein@google.com | dbd41c8 | 2013-09-13 20:11:09 +0000 | [diff] [blame] | 669 | if (FLAGS_verbose) { SkDebugf("\n"); } |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 670 | |
commit-bot@chromium.org | 56b7a6d | 2014-03-13 16:22:00 +0000 | [diff] [blame] | 671 | if (!FLAGS_dryRun && FLAGS_outDir.count() && SkBenchmark::kNonRendering_Backend != config.backend) { |
reed@google.com | 1bc6c6a | 2014-02-04 14:02:44 +0000 | [diff] [blame] | 672 | SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); |
| 673 | if (image.get()) { |
| 674 | saveFile(bench->getName(), config.name, FLAGS_outDir[0], |
| 675 | image); |
| 676 | } |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 677 | } |
| 678 | |
commit-bot@chromium.org | 4bbe2e5 | 2014-04-21 21:12:32 +0000 | [diff] [blame] | 679 | if (FLAGS_runOnce) { |
| 680 | // Let's not mislead ourselves by looking at Debug build or single iteration bench times! |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 681 | continue; |
| 682 | } |
| 683 | |
| 684 | // Normalize to ms per 1000 iterations. |
djsollen@google.com | 70de4da | 2013-10-10 17:33:39 +0000 | [diff] [blame] | 685 | const double normalize = 1000.0 / loopsPerIter; |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 686 | const struct { char shortName; const char* longName; double ms; } times[] = { |
| 687 | {'w', "msecs", normalize * timer.fWall}, |
| 688 | {'W', "Wmsecs", normalize * timer.fTruncatedWall}, |
| 689 | {'c', "cmsecs", normalize * timer.fCpu}, |
| 690 | {'C', "Cmsecs", normalize * timer.fTruncatedCpu}, |
| 691 | {'g', "gmsecs", normalize * timer.fGpu}, |
| 692 | }; |
| 693 | |
commit-bot@chromium.org | e3bb3bc | 2013-12-03 18:16:48 +0000 | [diff] [blame] | 694 | writer.config(config.name); |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 695 | for (size_t i = 0; i < SK_ARRAY_COUNT(times); i++) { |
| 696 | if (strchr(FLAGS_timers[0], times[i].shortName) && times[i].ms > 0) { |
commit-bot@chromium.org | e3bb3bc | 2013-12-03 18:16:48 +0000 | [diff] [blame] | 697 | writer.timer(times[i].longName, times[i].ms); |
commit-bot@chromium.org | 7495f59 | 2013-06-03 19:31:07 +0000 | [diff] [blame] | 698 | } |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 699 | } |
bsalomon@google.com | 604a56a | 2013-03-15 15:42:15 +0000 | [diff] [blame] | 700 | } |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 701 | } |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 702 | #if SK_SUPPORT_GPU |
bsalomon@google.com | cb26535 | 2013-02-22 16:13:16 +0000 | [diff] [blame] | 703 | gContextFactory.destroyContexts(); |
robertphillips@google.com | 9d59420 | 2012-09-13 14:05:00 +0000 | [diff] [blame] | 704 | #endif |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 705 | return 0; |
| 706 | } |
caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 707 | |
borenet@google.com | 7158e6a | 2012-11-01 17:43:44 +0000 | [diff] [blame] | 708 | #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) |
caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 709 | int main(int argc, char * const argv[]) { |
| 710 | return tool_main(argc, (char**) argv); |
| 711 | } |
| 712 | #endif |