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

Side by Side Diff: bench/nanobench.cpp

Issue 1603063005: Adding support for parsing extended gpu config parameters in nanobench. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « bench/nanobench.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include <ctype.h> 8 #include <ctype.h>
9 9
10 #include "nanobench.h" 10 #include "nanobench.h"
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 this->con fig.ctxOptions), 178 this->con fig.ctxOptions),
179 SkSurface::kNo_Budgeted , info, 179 SkSurface::kNo_Budgeted , info,
180 this->config.samples, & props)); 180 this->config.samples, & props));
181 this->gl = gGrFactory->getContextInfo(this->config.ctxType, 181 this->gl = gGrFactory->getContextInfo(this->config.ctxType,
182 this->config.ctxOptions).fGLContex t; 182 this->config.ctxOptions).fGLContex t;
183 if (!this->surface.get()) { 183 if (!this->surface.get()) {
184 return false; 184 return false;
185 } 185 }
186 if (!this->gl->fenceSyncSupport()) { 186 if (!this->gl->fenceSyncSupport()) {
187 SkDebugf("WARNING: GL context for config \"%s\" does not support fen ce sync. " 187 SkDebugf("WARNING: GL context for config \"%s\" does not support fen ce sync. "
188 "Timings might not be accurate.\n", this->config.name); 188 "Timings might not be accurate.\n", this->config.name.c_str ());
189 } 189 }
190 return true; 190 return true;
191 } 191 }
192 void fillOptions(ResultsWriter* log) override { 192 void fillOptions(ResultsWriter* log) override {
193 const GrGLubyte* version; 193 const GrGLubyte* version;
194 SK_GL_RET(*this->gl, version, GetString(GR_GL_VERSION)); 194 SK_GL_RET(*this->gl, version, GetString(GR_GL_VERSION));
195 log->configOption("GL_VERSION", (const char*)(version)); 195 log->configOption("GL_VERSION", (const char*)(version));
196 196
197 SK_GL_RET(*this->gl, version, GetString(GR_GL_RENDERER)); 197 SK_GL_RET(*this->gl, version, GetString(GR_GL_RENDERER));
198 log->configOption("GL_RENDERER", (const char*) version); 198 log->configOption("GL_RENDERER", (const char*) version);
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 } 373 }
374 374
375 static SkString to_lower(const char* str) { 375 static SkString to_lower(const char* str) {
376 SkString lower(str); 376 SkString lower(str);
377 for (size_t i = 0; i < lower.size(); i++) { 377 for (size_t i = 0; i < lower.size(); i++) {
378 lower[i] = tolower(lower[i]); 378 lower[i] = tolower(lower[i]);
379 } 379 }
380 return lower; 380 return lower;
381 } 381 }
382 382
383 static bool is_cpu_config_allowed(const char* name) { 383 static bool is_cpu_config_allowed(const char* name) {
Kimmo Kinnunen 2016/01/20 18:25:55 this would be static bool is_cpu_config_allowed(co
Sami Väisänen 2016/01/21 12:42:32 Done.
384 for (int i = 0; i < FLAGS_config.count(); i++) { 384 for (int i = 0; i < FLAGS_config.count(); i++) {
385 if (to_lower(FLAGS_config[i]).equals(name)) { 385 if (to_lower(FLAGS_config[i]).equals(name)) {
386 return true; 386 return true;
387 } 387 }
388 } 388 }
389 return false; 389 return false;
390 } 390 }
391 391
392 #if SK_SUPPORT_GPU 392 #if SK_SUPPORT_GPU
393 static bool is_gpu_config_allowed(const char* name, GrContextFactory::GLContextT ype ctxType, 393 static bool is_gpu_config_allowed(const char* name, GrContextFactory::GLContextT ype ctxType,
Kimmo Kinnunen 2016/01/20 18:25:56 likewise here.
Sami Väisänen 2016/01/21 12:42:32 Done.
394 GrContextFactory::GLContextOptions ctxOptions, 394 GrContextFactory::GLContextOptions ctxOptions,
395 int sampleCnt) { 395 int sampleCnt) {
396 if (!is_cpu_config_allowed(name)) { 396 if (!is_cpu_config_allowed(name)) {
397 return false; 397 return false;
398 } 398 }
399 if (const GrContext* ctx = gGrFactory->get(ctxType, ctxOptions)) { 399 if (const GrContext* ctx = gGrFactory->get(ctxType, ctxOptions)) {
400 return sampleCnt <= ctx->caps()->maxSampleCount(); 400 return sampleCnt <= ctx->caps()->maxSampleCount();
401 } 401 }
402 return false; 402 return false;
403 } 403 }
404 #endif 404 #endif
405 405
406 #if SK_SUPPORT_GPU 406 #if SK_SUPPORT_GPU
407 #define kBogusGLContextType GrContextFactory::kNative_GLContextType 407 #define kBogusGLContextType GrContextFactory::kNative_GLContextType
408 #define kBogusGLContextOptions GrContextFactory::kNone_GLContextOptions 408 #define kBogusGLContextOptions GrContextFactory::kNone_GLContextOptions
409 #else 409 #else
410 #define kBogusGLContextType 0 410 #define kBogusGLContextType 0
411 #define kBogusGLContextOptions 0 411 #define kBogusGLContextOptions 0
412 #endif 412 #endif
413 413
414 // create a config from a specific 'gpu(...)' parameter pack.
Kimmo Kinnunen 2016/01/20 18:25:55 This comment does not add any information, if you
Sami Väisänen 2016/01/21 12:42:32 Done.
415 static void create_commandline_config(SkTArray<Config, false>& nanoConfigs, cons t SkCommandLineConfig& conf) {
Kimmo Kinnunen 2016/01/20 18:25:55 So this function could be called static void creat
Sami Väisänen 2016/01/21 12:42:32 Done.
416 if (!FLAGS_gpu)
417 return;
Kimmo Kinnunen 2016/01/20 18:25:55 this would be removed. Instead, you actually need
Sami Väisänen 2016/01/21 12:42:32 Done.
418
419 // only interested in gpu configs.
420 const auto* gpuConf = conf.asConfigGpu();
Kimmo Kinnunen 2016/01/20 18:25:55 This would go to the parent function.
421 if (!gpuConf)
422 return;
423
424 // if tag is empty the config was not specified with parameters,
425 // i.e. it was just simple config.
426 const auto& tag = gpuConf->getTag();
427 if (tag.isEmpty())
Kimmo Kinnunen 2016/01/20 18:25:55 This is wrong. The intention is that you check con
428 return;
429
Kimmo Kinnunen 2016/01/20 18:25:55 you would need to call also the is_gpu_config_allo
Sami Väisänen 2016/01/21 12:42:32 Done.
430 Config target;
Kimmo Kinnunen 2016/01/20 18:25:55 So here you handle all GPU related configs. Thus y
Sami Väisänen 2016/01/21 12:42:32 Done.
431 target.name = tag;
Kimmo Kinnunen 2016/01/20 18:25:56 Since the original used object initializer syntax,
Sami Väisänen 2016/01/21 12:42:32 Done.
432 target.backend = Benchmark::kGPU_Backend;
433 target.color = kN32_SkColorType;
434 target.alpha = kPremul_SkAlphaType;
435 target.ctxOptions = gpuConf->getUseNVPR() ? GrContextFactory::kEnableNVPR_GL ContextOptions :
436 GrContextFactory::kNone_GLContextOptions;
437 target.samples = gpuConf->getSamples();
438 target.ctxType = gpuConf->getContextType();
439 target.useDFText = false;
440 nanoConfigs.push_back(target);
441 }
442
443
444
445 // create configs from specific command line parameters
446 // that were specified using --config 'gpu(foo=bar,...)' parameters
Kimmo Kinnunen 2016/01/20 18:25:55 The comment doesn't add that much value. It's rath
Sami Väisänen 2016/01/21 12:42:32 Done.
447 static void gather_commandline_configs(SkTArray<Config, false>& nanoConfigs) {
Kimmo Kinnunen 2016/01/20 18:25:55 So this could be called static void create_config
Sami Väisänen 2016/01/21 12:42:32 Done.
448 SkCommandLineConfigArray configs;
449 ParseConfigs(FLAGS_config, &configs);
450 for (int i=0; i<configs.count(); ++i) {
Kimmo Kinnunen 2016/01/20 18:25:55 Here whitespace between operators.
Sami Väisänen 2016/01/21 12:42:32 Done.
451 const auto& config = *configs[i];
Kimmo Kinnunen 2016/01/20 18:25:55 so here you should have code like #if SK_SUPPORT_G
Sami Väisänen 2016/01/21 12:42:32 Done.
452 create_commandline_config(nanoConfigs, config);
453 }
454 }
455
414 // Append all configs that are enabled and supported. 456 // Append all configs that are enabled and supported.
415 static void create_configs(SkTDArray<Config>* configs) { 457 static void create_configs(SkTArray<Config, false>* configs) {
Kimmo Kinnunen 2016/01/20 18:25:55 This would be called: static void create_config(co
Sami Väisänen 2016/01/21 12:42:32 Done.
416 #define CPU_CONFIG(name, backend, color, alpha) \ 458 #define CPU_CONFIG(name, backend, color, alpha) \
417 if (is_cpu_config_allowed(#name)) { \ 459 if (is_cpu_config_allowed(#name)) { \
Kimmo Kinnunen 2016/01/20 18:25:56 here you would have if (is_cpu_config_allowed(#nam
Kimmo Kinnunen 2016/01/20 18:25:55 so this would call if (is_cpu_config_allowed(#nam
Sami Väisänen 2016/01/21 12:42:32 Done.
418 Config config = { #name, Benchmark::backend, color, alpha, 0, \ 460 Config config = { SkString(#name), Benchmark::backend, color, alpha, 0, \
419 kBogusGLContextType, kBogusGLContextOptions, \ 461 kBogusGLContextType, kBogusGLContextOptions, \
420 false }; \ 462 false }; \
421 configs->push(config); \ 463 configs->push_back(config); \
Kimmo Kinnunen 2016/01/20 18:25:55 in the macro, you would add "return", so that the
422 } 464 }
423 465
424 if (FLAGS_cpu) { 466 if (FLAGS_cpu) {
425 CPU_CONFIG(nonrendering, kNonRendering_Backend, kUnknown_SkColorType, kU npremul_SkAlphaType) 467 CPU_CONFIG(nonrendering, kNonRendering_Backend, kUnknown_SkColorType, kU npremul_SkAlphaType)
426 CPU_CONFIG(8888, kRaster_Backend, kN32_SkColorType, kPremul_SkAlphaType) 468 CPU_CONFIG(8888, kRaster_Backend, kN32_SkColorType, kPremul_SkAlphaType)
427 CPU_CONFIG(565, kRaster_Backend, kRGB_565_SkColorType, kOpaque_SkAlphaTy pe) 469 CPU_CONFIG(565, kRaster_Backend, kRGB_565_SkColorType, kOpaque_SkAlphaTy pe)
428 } 470 }
429 471
430 #if SK_SUPPORT_GPU 472 #if SK_SUPPORT_GPU
431 #define GPU_CONFIG(name, ctxType, ctxOptions, samples, useDFText) \ 473 #define GPU_CONFIG(name, ctxType, ctxOptions, samples, useDFText) \
432 if (is_gpu_config_allowed(#name, GrContextFactory::ctxType, \ 474 if (is_gpu_config_allowed(#name, GrContextFactory::ctxType, \
Kimmo Kinnunen 2016/01/20 18:25:55 (1) GPU configs are already handled in the functio
Sami Väisänen 2016/01/21 12:42:32 Done.
433 GrContextFactory::ctxOptions, samples)) { \ 475 GrContextFactory::ctxOptions, samples)) { \
434 Config config = { \ 476 Config config = { \
435 #name, \ 477 SkString(#name), \
436 Benchmark::kGPU_Backend, \ 478 Benchmark::kGPU_Backend, \
437 kN32_SkColorType, \ 479 kN32_SkColorType, \
438 kPremul_SkAlphaType, \ 480 kPremul_SkAlphaType, \
439 samples, \ 481 samples, \
440 GrContextFactory::ctxType, \ 482 GrContextFactory::ctxType, \
441 GrContextFactory::ctxOptions, \ 483 GrContextFactory::ctxOptions, \
442 useDFText }; \ 484 useDFText }; \
443 configs->push(config); \ 485 configs->push_back(config); \
Kimmo Kinnunen 2016/01/20 18:30:46 Also make sure that macro line continuations match
Sami Väisänen 2016/01/21 12:42:32 Done.
444 } 486 }
445 487
446 if (FLAGS_gpu) { 488 if (FLAGS_gpu) {
447 GPU_CONFIG(gpu, kNative_GLContextType, kNone_GLContextOptions, 0, false) 489 GPU_CONFIG(gpu, kNative_GLContextType, kNone_GLContextOptions, 0, false)
448 GPU_CONFIG(msaa4, kNative_GLContextType, kNone_GLContextOptions, 4, fals e) 490 GPU_CONFIG(msaa4, kNative_GLContextType, kNone_GLContextOptions, 4, fals e)
449 GPU_CONFIG(msaa16, kNative_GLContextType, kNone_GLContextOptions, 16, fa lse) 491 GPU_CONFIG(msaa16, kNative_GLContextType, kNone_GLContextOptions, 16, fa lse)
450 GPU_CONFIG(nvprmsaa4, kNative_GLContextType, kEnableNVPR_GLContextOption s, 4, false) 492 GPU_CONFIG(nvprmsaa4, kNative_GLContextType, kEnableNVPR_GLContextOption s, 4, false)
451 GPU_CONFIG(nvprmsaa16, kNative_GLContextType, kEnableNVPR_GLContextOptio ns, 16, false) 493 GPU_CONFIG(nvprmsaa16, kNative_GLContextType, kEnableNVPR_GLContextOptio ns, 16, false)
452 GPU_CONFIG(gpudft, kNative_GLContextType, kNone_GLContextOptions, 0, tru e) 494 GPU_CONFIG(gpudft, kNative_GLContextType, kNone_GLContextOptions, 0, tru e)
453 GPU_CONFIG(debug, kDebug_GLContextType, kNone_GLContextOptions, 0, false ) 495 GPU_CONFIG(debug, kDebug_GLContextType, kNone_GLContextOptions, 0, false )
(...skipping 11 matching lines...) Expand all
465 GPU_CONFIG(mesa, kMESA_GLContextType, kNone_GLContextOptions, 0, false) 507 GPU_CONFIG(mesa, kMESA_GLContextType, kNone_GLContextOptions, 0, false)
466 #endif 508 #endif
467 } 509 }
468 #endif 510 #endif
469 511
470 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK 512 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
471 if (is_cpu_config_allowed("hwui")) { 513 if (is_cpu_config_allowed("hwui")) {
472 Config config = { "hwui", Benchmark::kHWUI_Backend, kRGBA_8888_SkColorTy pe, 514 Config config = { "hwui", Benchmark::kHWUI_Backend, kRGBA_8888_SkColorTy pe,
473 kPremul_SkAlphaType, 0, kBogusGLContextType, kBogusGLC ontextOptions, 515 kPremul_SkAlphaType, 0, kBogusGLContextType, kBogusGLC ontextOptions,
474 false }; 516 false };
475 configs->push(config); 517 configs->push_back(config);
476 } 518 }
477 #endif 519 #endif
Kimmo Kinnunen 2016/01/20 18:25:55 Not sure about this, but here you could propose to
Sami Väisänen 2016/01/21 12:42:32 Done.
478 } 520 }
479 521
480 // If bench is enabled for config, returns a Target* for it, otherwise nullptr. 522 // If bench is enabled for config, returns a Target* for it, otherwise nullptr.
481 static Target* is_enabled(Benchmark* bench, const Config& config) { 523 static Target* is_enabled(Benchmark* bench, const Config& config) {
482 if (!bench->isSuitableFor(config.backend)) { 524 if (!bench->isSuitableFor(config.backend)) {
483 return nullptr; 525 return nullptr;
484 } 526 }
485 527
486 SkImageInfo info = SkImageInfo::Make(bench->getSize().fX, bench->getSize().f Y, 528 SkImageInfo info = SkImageInfo::Make(bench->getSize().fX, bench->getSize().f Y,
487 config.color, config.alpha); 529 config.color, config.alpha);
(...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after
1083 } else if (FLAGS_quiet) { 1125 } else if (FLAGS_quiet) {
1084 SkDebugf("! -> high variance, ? -> moderate variance\n"); 1126 SkDebugf("! -> high variance, ? -> moderate variance\n");
1085 SkDebugf(" micros \tbench\n"); 1127 SkDebugf(" micros \tbench\n");
1086 } else if (FLAGS_ms) { 1128 } else if (FLAGS_ms) {
1087 SkDebugf("curr/maxrss\tloops\tmin\tmedian\tmean\tmax\tstddev\tsamples\tc onfig\tbench\n"); 1129 SkDebugf("curr/maxrss\tloops\tmin\tmedian\tmean\tmax\tstddev\tsamples\tc onfig\tbench\n");
1088 } else { 1130 } else {
1089 SkDebugf("curr/maxrss\tloops\tmin\tmedian\tmean\tmax\tstddev\t%-*s\tconf ig\tbench\n", 1131 SkDebugf("curr/maxrss\tloops\tmin\tmedian\tmean\tmax\tstddev\t%-*s\tconf ig\tbench\n",
1090 FLAGS_samples, "samples"); 1132 FLAGS_samples, "samples");
1091 } 1133 }
1092 1134
1093 SkTDArray<Config> configs; 1135 SkTArray<Config, false> configs;
Kimmo Kinnunen 2016/01/20 18:25:55 TArray MEM_COPY defaults to false, so it's maybe c
Sami Väisänen 2016/01/21 12:42:32 Done.
1094 create_configs(&configs); 1136 create_configs(&configs);
1137 gather_commandline_configs(configs);
Kimmo Kinnunen 2016/01/20 18:25:55 and since create_configs would be your toplevel it
Sami Väisänen 2016/01/21 12:42:32 Done.
1095 1138
1096 if (FLAGS_keepAlive) { 1139 if (FLAGS_keepAlive) {
1097 start_keepalive(); 1140 start_keepalive();
1098 } 1141 }
1099 1142
1100 int runs = 0; 1143 int runs = 0;
1101 BenchmarkStream benchStream; 1144 BenchmarkStream benchStream;
1102 while (Benchmark* b = benchStream.next()) { 1145 while (Benchmark* b = benchStream.next()) {
1103 SkAutoTDelete<Benchmark> bench(b); 1146 SkAutoTDelete<Benchmark> bench(b);
1104 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getUniqueName())) { 1147 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getUniqueName())) {
1105 continue; 1148 continue;
1106 } 1149 }
1107 1150
1108 if (!configs.isEmpty()) { 1151 if (!configs.empty()) {
1109 log->bench(bench->getUniqueName(), bench->getSize().fX, bench->getSi ze().fY); 1152 log->bench(bench->getUniqueName(), bench->getSize().fX, bench->getSi ze().fY);
1110 bench->delayedSetup(); 1153 bench->delayedSetup();
1111 } 1154 }
1112 for (int i = 0; i < configs.count(); ++i) { 1155 for (int i = 0; i < configs.count(); ++i) {
1113 Target* target = is_enabled(b, configs[i]); 1156 Target* target = is_enabled(b, configs[i]);
1114 if (!target) { 1157 if (!target) {
1115 continue; 1158 continue;
1116 } 1159 }
1117 1160
1118 // During HWUI output this canvas may be nullptr. 1161 // During HWUI output this canvas may be nullptr.
1119 SkCanvas* canvas = target->getCanvas(); 1162 SkCanvas* canvas = target->getCanvas();
1120 const char* config = target->config.name; 1163 const char* config = target->config.name.c_str();
1121 1164
1122 target->setup(); 1165 target->setup();
1123 bench->perCanvasPreDraw(canvas); 1166 bench->perCanvasPreDraw(canvas);
1124 1167
1125 int maxFrameLag; 1168 int maxFrameLag;
1126 int loops = target->needsFrameTiming(&maxFrameLag) 1169 int loops = target->needsFrameTiming(&maxFrameLag)
1127 ? setup_gpu_bench(target, bench.get(), maxFrameLag) 1170 ? setup_gpu_bench(target, bench.get(), maxFrameLag)
1128 : setup_cpu_bench(overhead, target, bench.get()); 1171 : setup_cpu_bench(overhead, target, bench.get());
1129 1172
1130 if (FLAGS_ms) { 1173 if (FLAGS_ms) {
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
1253 1296
1254 return 0; 1297 return 0;
1255 } 1298 }
1256 1299
1257 #if !defined SK_BUILD_FOR_IOS 1300 #if !defined SK_BUILD_FOR_IOS
1258 int main(int argc, char** argv) { 1301 int main(int argc, char** argv) {
1259 SkCommandLineFlags::Parse(argc, argv); 1302 SkCommandLineFlags::Parse(argc, argv);
1260 return nanobench_main(); 1303 return nanobench_main();
1261 } 1304 }
1262 #endif 1305 #endif
OLDNEW
« no previous file with comments | « bench/nanobench.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698