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