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

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: Adding support for parsing gpu config parameters in nanobench 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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 365
366 // Pretty much the same deal as the calibration: do some warmup to make 366 // Pretty much the same deal as the calibration: do some warmup to make
367 // sure we're timing steady-state pipelined frames. 367 // sure we're timing steady-state pipelined frames.
368 for (int i = 0; i < maxGpuFrameLag - 1; i++) { 368 for (int i = 0; i < maxGpuFrameLag - 1; i++) {
369 time(loops, bench, target); 369 time(loops, bench, target);
370 } 370 }
371 371
372 return loops; 372 return loops;
373 } 373 }
374 374
375 static SkString to_lower(const char* str) {
376 SkString lower(str);
377 for (size_t i = 0; i < lower.size(); i++) {
378 lower[i] = tolower(lower[i]);
379 }
380 return lower;
381 }
382
383 static bool is_cpu_config_allowed(const char* name) {
384 for (int i = 0; i < FLAGS_config.count(); i++) {
385 if (to_lower(FLAGS_config[i]).equals(name)) {
386 return true;
387 }
388 }
389 return false;
390 }
391
392 #if SK_SUPPORT_GPU
393 static bool is_gpu_config_allowed(const char* name, GrContextFactory::GLContextT ype ctxType,
394 GrContextFactory::GLContextOptions ctxOptions,
395 int sampleCnt) {
396 if (!is_cpu_config_allowed(name)) {
397 return false;
398 }
399 if (const GrContext* ctx = gGrFactory->get(ctxType, ctxOptions)) {
400 return sampleCnt <= ctx->caps()->maxSampleCount();
401 }
402 return false;
403 }
404 #endif
405
406 #if SK_SUPPORT_GPU 375 #if SK_SUPPORT_GPU
407 #define kBogusGLContextType GrContextFactory::kNative_GLContextType 376 #define kBogusGLContextType GrContextFactory::kNative_GLContextType
408 #define kBogusGLContextOptions GrContextFactory::kNone_GLContextOptions 377 #define kBogusGLContextOptions GrContextFactory::kNone_GLContextOptions
409 #else 378 #else
410 #define kBogusGLContextType 0 379 #define kBogusGLContextType 0
411 #define kBogusGLContextOptions 0 380 #define kBogusGLContextOptions 0
412 #endif 381 #endif
413 382
414 // Append all configs that are enabled and supported. 383 static void create_config(const SkCommandLineConfig* config, SkTArray<Config>* c onfigs) {
415 static void create_configs(SkTDArray<Config>* configs) { 384
416 #define CPU_CONFIG(name, backend, color, alpha) \ 385 #if SK_SUPPORT_GPU
417 if (is_cpu_config_allowed(#name)) { \ 386 if (const auto* gpuConfig = config->asConfigGpu()) {
418 Config config = { #name, Benchmark::backend, color, alpha, 0, \ 387 if (!FLAGS_gpu)
419 kBogusGLContextType, kBogusGLContextOptions, \ 388 return;
420 false }; \ 389
421 configs->push(config); \ 390 const auto ctxOptions = gpuConfig->getUseNVPR() ? GrContextFactory::kEna bleNVPR_GLContextOptions
391 : GrContextFactory::kNon e_GLContextOptions;
392 const auto ctxType = gpuConfig->getContextType();
393 const auto sampleCount = gpuConfig->getSamples();
394
395 if (const GrContext* ctx = gGrFactory->get(ctxType, ctxOptions)) {
396 const auto maxSampleCount = ctx->caps()->maxSampleCount();
397 if (sampleCount > ctx->caps()->maxSampleCount()) {
398 SkDebugf("Configuration sample count %d exceeds maximum %d.\n",
399 sampleCount, maxSampleCount);
400 return;
401 }
402 } else {
403 SkDebugf("No context was available matching config type and options. \n");
404 return;
405 }
406
407 Config target = {
408 config->getTag(),
409 Benchmark::kGPU_Backend,
410 kN32_SkColorType,
411 kPremul_SkAlphaType,
412 sampleCount,
413 ctxType,
414 ctxOptions,
415 false };
416
417 configs->push_back(target);
418 return;
419 }
420 #endif
421
422 #define CPU_CONFIG(name, backend, color, alpha) \
423 if (config->getTag().equals(#name)) { \
424 Config config = { SkString(#name), Benchmark::backend, color, alpha, 0, \
425 kBogusGLContextType, kBogusGLContextOptions, \
426 false }; \
427 configs->push_back(config); \
428 return; \
422 } 429 }
423 430
424 if (FLAGS_cpu) { 431 if (FLAGS_cpu) {
425 CPU_CONFIG(nonrendering, kNonRendering_Backend, kUnknown_SkColorType, kU npremul_SkAlphaType) 432 CPU_CONFIG(nonrendering, kNonRendering_Backend, kUnknown_SkColorType, kU npremul_SkAlphaType)
426 CPU_CONFIG(8888, kRaster_Backend, kN32_SkColorType, kPremul_SkAlphaType) 433 CPU_CONFIG(8888, kRaster_Backend, kN32_SkColorType, kPremul_SkAlphaType)
427 CPU_CONFIG(565, kRaster_Backend, kRGB_565_SkColorType, kOpaque_SkAlphaTy pe) 434 CPU_CONFIG(565, kRaster_Backend, kRGB_565_SkColorType, kOpaque_SkAlphaTy pe)
428 } 435 }
429 436
430 #if SK_SUPPORT_GPU 437 #undef CPU_CONFIG
431 #define GPU_CONFIG(name, ctxType, ctxOptions, samples, useDFText) \
432 if (is_gpu_config_allowed(#name, GrContextFactory::ctxType, \
433 GrContextFactory::ctxOptions, samples)) { \
434 Config config = { \
435 #name, \
436 Benchmark::kGPU_Backend, \
437 kN32_SkColorType, \
438 kPremul_SkAlphaType, \
439 samples, \
440 GrContextFactory::ctxType, \
441 GrContextFactory::ctxOptions, \
442 useDFText }; \
443 configs->push(config); \
444 }
445
446 if (FLAGS_gpu) {
447 GPU_CONFIG(gpu, kNative_GLContextType, kNone_GLContextOptions, 0, false)
448 GPU_CONFIG(msaa4, kNative_GLContextType, kNone_GLContextOptions, 4, fals e)
449 GPU_CONFIG(msaa16, kNative_GLContextType, kNone_GLContextOptions, 16, fa lse)
450 GPU_CONFIG(nvprmsaa4, kNative_GLContextType, kEnableNVPR_GLContextOption s, 4, false)
451 GPU_CONFIG(nvprmsaa16, kNative_GLContextType, kEnableNVPR_GLContextOptio ns, 16, false)
452 GPU_CONFIG(gpudft, kNative_GLContextType, kNone_GLContextOptions, 0, tru e)
453 GPU_CONFIG(debug, kDebug_GLContextType, kNone_GLContextOptions, 0, false )
454 GPU_CONFIG(nullgpu, kNull_GLContextType, kNone_GLContextOptions, 0, fals e)
455 #if SK_ANGLE
456 #ifdef SK_BUILD_FOR_WIN
457 GPU_CONFIG(angle, kANGLE_GLContextType, kNone_GLContextOptions, 0, false )
458 #endif
459 GPU_CONFIG(angle-gl, kANGLE_GL_GLContextType, kNone_GLContextOptions, 0, false)
460 #endif
461 #if SK_COMMAND_BUFFER
462 GPU_CONFIG(commandbuffer, kCommandBuffer_GLContextType, kNone_GLContextO ptions, 0, false)
463 #endif
464 #if SK_MESA
465 GPU_CONFIG(mesa, kMESA_GLContextType, kNone_GLContextOptions, 0, false)
466 #endif
467 }
468 #endif
469 438
470 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK 439 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
471 if (is_cpu_config_allowed("hwui")) { 440 if (is_cpu_config_allowed("hwui", config)) {
472 Config config = { "hwui", Benchmark::kHWUI_Backend, kRGBA_8888_SkColorTy pe, 441 Config config = { "hwui", Benchmark::kHWUI_Backend, kRGBA_8888_SkColorTy pe,
473 kPremul_SkAlphaType, 0, kBogusGLContextType, kBogusGLC ontextOptions, 442 kPremul_SkAlphaType, 0, kBogusGLContextType, kBogusGLC ontextOptions,
474 false }; 443 false };
475 configs->push(config); 444 configs->push_back(config);
445 return;
476 } 446 }
477 #endif 447 #endif
478 } 448 }
479 449
450 // Append all configs that are enabled and supported.
451 void create_configs(SkTArray<Config>* configs) {
452 SkCommandLineConfigArray array;
453 ParseConfigs(FLAGS_config, &array);
454 for (int i = 0; i < array.count(); ++i) {
455 create_config(array[i], configs);
456 }
457 }
458
480 // If bench is enabled for config, returns a Target* for it, otherwise nullptr. 459 // If bench is enabled for config, returns a Target* for it, otherwise nullptr.
481 static Target* is_enabled(Benchmark* bench, const Config& config) { 460 static Target* is_enabled(Benchmark* bench, const Config& config) {
482 if (!bench->isSuitableFor(config.backend)) { 461 if (!bench->isSuitableFor(config.backend)) {
483 return nullptr; 462 return nullptr;
484 } 463 }
485 464
486 SkImageInfo info = SkImageInfo::Make(bench->getSize().fX, bench->getSize().f Y, 465 SkImageInfo info = SkImageInfo::Make(bench->getSize().fX, bench->getSize().f Y,
487 config.color, config.alpha); 466 config.color, config.alpha);
488 467
489 Target* target = nullptr; 468 Target* target = nullptr;
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after
1083 } else if (FLAGS_quiet) { 1062 } else if (FLAGS_quiet) {
1084 SkDebugf("! -> high variance, ? -> moderate variance\n"); 1063 SkDebugf("! -> high variance, ? -> moderate variance\n");
1085 SkDebugf(" micros \tbench\n"); 1064 SkDebugf(" micros \tbench\n");
1086 } else if (FLAGS_ms) { 1065 } else if (FLAGS_ms) {
1087 SkDebugf("curr/maxrss\tloops\tmin\tmedian\tmean\tmax\tstddev\tsamples\tc onfig\tbench\n"); 1066 SkDebugf("curr/maxrss\tloops\tmin\tmedian\tmean\tmax\tstddev\tsamples\tc onfig\tbench\n");
1088 } else { 1067 } else {
1089 SkDebugf("curr/maxrss\tloops\tmin\tmedian\tmean\tmax\tstddev\t%-*s\tconf ig\tbench\n", 1068 SkDebugf("curr/maxrss\tloops\tmin\tmedian\tmean\tmax\tstddev\t%-*s\tconf ig\tbench\n",
1090 FLAGS_samples, "samples"); 1069 FLAGS_samples, "samples");
1091 } 1070 }
1092 1071
1093 SkTDArray<Config> configs; 1072 SkTArray<Config> configs;
1094 create_configs(&configs); 1073 create_configs(&configs);
1095 1074
1096 if (FLAGS_keepAlive) { 1075 if (FLAGS_keepAlive) {
1097 start_keepalive(); 1076 start_keepalive();
1098 } 1077 }
1099 1078
1100 int runs = 0; 1079 int runs = 0;
1101 BenchmarkStream benchStream; 1080 BenchmarkStream benchStream;
1102 while (Benchmark* b = benchStream.next()) { 1081 while (Benchmark* b = benchStream.next()) {
1103 SkAutoTDelete<Benchmark> bench(b); 1082 SkAutoTDelete<Benchmark> bench(b);
1104 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getUniqueName())) { 1083 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getUniqueName())) {
1105 continue; 1084 continue;
1106 } 1085 }
1107 1086
1108 if (!configs.isEmpty()) { 1087 if (!configs.empty()) {
1109 log->bench(bench->getUniqueName(), bench->getSize().fX, bench->getSi ze().fY); 1088 log->bench(bench->getUniqueName(), bench->getSize().fX, bench->getSi ze().fY);
1110 bench->delayedSetup(); 1089 bench->delayedSetup();
1111 } 1090 }
1112 for (int i = 0; i < configs.count(); ++i) { 1091 for (int i = 0; i < configs.count(); ++i) {
1113 Target* target = is_enabled(b, configs[i]); 1092 Target* target = is_enabled(b, configs[i]);
1114 if (!target) { 1093 if (!target) {
1115 continue; 1094 continue;
1116 } 1095 }
1117 1096
1118 // During HWUI output this canvas may be nullptr. 1097 // During HWUI output this canvas may be nullptr.
1119 SkCanvas* canvas = target->getCanvas(); 1098 SkCanvas* canvas = target->getCanvas();
1120 const char* config = target->config.name; 1099 const char* config = target->config.name.c_str();
1121 1100
1122 target->setup(); 1101 target->setup();
1123 bench->perCanvasPreDraw(canvas); 1102 bench->perCanvasPreDraw(canvas);
1124 1103
1125 int maxFrameLag; 1104 int maxFrameLag;
1126 int loops = target->needsFrameTiming(&maxFrameLag) 1105 int loops = target->needsFrameTiming(&maxFrameLag)
1127 ? setup_gpu_bench(target, bench.get(), maxFrameLag) 1106 ? setup_gpu_bench(target, bench.get(), maxFrameLag)
1128 : setup_cpu_bench(overhead, target, bench.get()); 1107 : setup_cpu_bench(overhead, target, bench.get());
1129 1108
1130 if (FLAGS_ms) { 1109 if (FLAGS_ms) {
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
1253 1232
1254 return 0; 1233 return 0;
1255 } 1234 }
1256 1235
1257 #if !defined SK_BUILD_FOR_IOS 1236 #if !defined SK_BUILD_FOR_IOS
1258 int main(int argc, char** argv) { 1237 int main(int argc, char** argv) {
1259 SkCommandLineFlags::Parse(argc, argv); 1238 SkCommandLineFlags::Parse(argc, argv);
1260 return nanobench_main(); 1239 return nanobench_main();
1261 } 1240 }
1262 #endif 1241 #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