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

Side by Side Diff: bench/nanobench.cpp

Issue 731973005: Add MultiPictureDraw to nanobench (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix threading issue in SkColorTable Created 6 years, 1 month 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
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 "Benchmark.h" 10 #include "Benchmark.h"
11 #include "CrashHandler.h" 11 #include "CrashHandler.h"
12 #include "GMBench.h" 12 #include "GMBench.h"
13 #include "ProcStats.h" 13 #include "ProcStats.h"
14 #include "ResultsWriter.h" 14 #include "ResultsWriter.h"
15 #include "RecordingBench.h" 15 #include "RecordingBench.h"
16 #include "SKPBench.h" 16 #include "SKPBench.h"
17 #include "Stats.h" 17 #include "Stats.h"
18 #include "Timer.h" 18 #include "Timer.h"
19 19
20 #include "SkBBoxHierarchy.h" 20 #include "SkBBoxHierarchy.h"
21 #include "SkCanvas.h" 21 #include "SkCanvas.h"
22 #include "SkCommonFlags.h" 22 #include "SkCommonFlags.h"
23 #include "SkForceLinking.h" 23 #include "SkForceLinking.h"
24 #include "SkGraphics.h" 24 #include "SkGraphics.h"
25 #include "SkOSFile.h" 25 #include "SkOSFile.h"
26 #include "SkPictureRecorder.h" 26 #include "SkPictureRecorder.h"
27 #include "SkString.h" 27 #include "SkString.h"
28 #include "SkSurface.h" 28 #include "SkSurface.h"
29 #include "SkTaskGroup.h"
29 30
30 #if SK_SUPPORT_GPU 31 #if SK_SUPPORT_GPU
31 #include "gl/GrGLDefines.h" 32 #include "gl/GrGLDefines.h"
32 #include "GrContextFactory.h" 33 #include "GrContextFactory.h"
33 SkAutoTDelete<GrContextFactory> gGrFactory; 34 SkAutoTDelete<GrContextFactory> gGrFactory;
34 #endif 35 #endif
35 36
36 __SK_FORCE_IMAGE_DECODER_LINKING; 37 __SK_FORCE_IMAGE_DECODER_LINKING;
37 38
38 static const int kAutoTuneLoops = 0; 39 static const int kAutoTuneLoops = 0;
(...skipping 24 matching lines...) Expand all
63 DEFINE_bool(gpuCompressAlphaMasks, false, "Compress masks generated from falling back to " 64 DEFINE_bool(gpuCompressAlphaMasks, false, "Compress masks generated from falling back to "
64 "software path rendering."); 65 "software path rendering.");
65 66
66 DEFINE_string(outResultsFile, "", "If given, write results here as JSON."); 67 DEFINE_string(outResultsFile, "", "If given, write results here as JSON.");
67 DEFINE_int32(maxCalibrationAttempts, 3, 68 DEFINE_int32(maxCalibrationAttempts, 3,
68 "Try up to this many times to guess loops for a bench, or skip the bench."); 69 "Try up to this many times to guess loops for a bench, or skip the bench.");
69 DEFINE_int32(maxLoops, 1000000, "Never run a bench more times than this."); 70 DEFINE_int32(maxLoops, 1000000, "Never run a bench more times than this.");
70 DEFINE_string(clip, "0,0,1000,1000", "Clip for SKPs."); 71 DEFINE_string(clip, "0,0,1000,1000", "Clip for SKPs.");
71 DEFINE_string(scales, "1.0", "Space-separated scales for SKPs."); 72 DEFINE_string(scales, "1.0", "Space-separated scales for SKPs.");
72 DEFINE_bool(bbh, true, "Build a BBH for SKPs?"); 73 DEFINE_bool(bbh, true, "Build a BBH for SKPs?");
74 DEFINE_bool(mpd, true, "Use MultiPictureDraw for the SKPs?");
73 DEFINE_int32(flushEvery, 10, "Flush --outResultsFile every Nth run."); 75 DEFINE_int32(flushEvery, 10, "Flush --outResultsFile every Nth run.");
74 76
75 static SkString humanize(double ms) { 77 static SkString humanize(double ms) {
76 if (FLAGS_verbose) return SkStringPrintf("%llu", (uint64_t)(ms*1e6)); 78 if (FLAGS_verbose) return SkStringPrintf("%llu", (uint64_t)(ms*1e6));
77 if (ms > 1e+3) return SkStringPrintf("%.3gs", ms/1e3); 79 if (ms > 1e+3) return SkStringPrintf("%.3gs", ms/1e3);
78 if (ms < 1e-3) return SkStringPrintf("%.3gns", ms*1e6); 80 if (ms < 1e-3) return SkStringPrintf("%.3gns", ms*1e6);
79 #ifdef SK_BUILD_FOR_WIN 81 #ifdef SK_BUILD_FOR_WIN
80 if (ms < 1) return SkStringPrintf("%.3gus", ms*1e3); 82 if (ms < 1) return SkStringPrintf("%.3gus", ms*1e3);
81 #else 83 #else
82 if (ms < 1) return SkStringPrintf("%.3gµs", ms*1e3); 84 if (ms < 1) return SkStringPrintf("%.3gµs", ms*1e3);
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 log->configOption("GL_SHADING_LANGUAGE_VERSION", (const char*) version); 432 log->configOption("GL_SHADING_LANGUAGE_VERSION", (const char*) version);
431 } 433 }
432 #endif 434 #endif
433 435
434 class BenchmarkStream { 436 class BenchmarkStream {
435 public: 437 public:
436 BenchmarkStream() : fBenches(BenchRegistry::Head()) 438 BenchmarkStream() : fBenches(BenchRegistry::Head())
437 , fGMs(skiagm::GMRegistry::Head()) 439 , fGMs(skiagm::GMRegistry::Head())
438 , fCurrentRecording(0) 440 , fCurrentRecording(0)
439 , fCurrentScale(0) 441 , fCurrentScale(0)
440 , fCurrentSKP(0) { 442 , fCurrentSKP(0)
443 , fCurrentUseMPD(0) {
441 for (int i = 0; i < FLAGS_skps.count(); i++) { 444 for (int i = 0; i < FLAGS_skps.count(); i++) {
442 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) { 445 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) {
443 fSKPs.push_back() = FLAGS_skps[i]; 446 fSKPs.push_back() = FLAGS_skps[i];
444 } else { 447 } else {
445 SkOSFile::Iter it(FLAGS_skps[i], ".skp"); 448 SkOSFile::Iter it(FLAGS_skps[i], ".skp");
446 SkString path; 449 SkString path;
447 while (it.next(&path)) { 450 while (it.next(&path)) {
448 fSKPs.push_back() = SkOSPath::Join(FLAGS_skps[0], path.c_str ()); 451 fSKPs.push_back() = SkOSPath::Join(FLAGS_skps[0], path.c_str ());
449 } 452 }
450 } 453 }
451 } 454 }
452 455
453 if (4 != sscanf(FLAGS_clip[0], "%d,%d,%d,%d", 456 if (4 != sscanf(FLAGS_clip[0], "%d,%d,%d,%d",
454 &fClip.fLeft, &fClip.fTop, &fClip.fRight, &fClip.fBottom )) { 457 &fClip.fLeft, &fClip.fTop, &fClip.fRight, &fClip.fBottom )) {
455 SkDebugf("Can't parse %s from --clip as an SkIRect.\n", FLAGS_clip[0 ]); 458 SkDebugf("Can't parse %s from --clip as an SkIRect.\n", FLAGS_clip[0 ]);
456 exit(1); 459 exit(1);
457 } 460 }
458 461
459 for (int i = 0; i < FLAGS_scales.count(); i++) { 462 for (int i = 0; i < FLAGS_scales.count(); i++) {
460 if (1 != sscanf(FLAGS_scales[i], "%f", &fScales.push_back())) { 463 if (1 != sscanf(FLAGS_scales[i], "%f", &fScales.push_back())) {
461 SkDebugf("Can't parse %s from --scales as an SkScalar.\n", FLAGS _scales[i]); 464 SkDebugf("Can't parse %s from --scales as an SkScalar.\n", FLAGS _scales[i]);
462 exit(1); 465 exit(1);
463 } 466 }
464 } 467 }
468
469 fUseMPDs.push_back() = false;
470 if (FLAGS_mpd) {
471 fUseMPDs.push_back() = true;
472 }
465 } 473 }
466 474
467 static bool ReadPicture(const char* path, SkAutoTUnref<SkPicture>* pic) { 475 static bool ReadPicture(const char* path, SkAutoTUnref<SkPicture>* pic) {
468 // Not strictly necessary, as it will be checked again later, 476 // Not strictly necessary, as it will be checked again later,
469 // but helps to avoid a lot of pointless work if we're going to skip it. 477 // but helps to avoid a lot of pointless work if we're going to skip it.
470 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path)) { 478 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path)) {
471 return false; 479 return false;
472 } 480 }
473 481
474 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path)); 482 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path));
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 } 521 }
514 SkString name = SkOSPath::Basename(path.c_str()); 522 SkString name = SkOSPath::Basename(path.c_str());
515 fSourceType = "skp"; 523 fSourceType = "skp";
516 fBenchType = "recording"; 524 fBenchType = "recording";
517 return SkNEW_ARGS(RecordingBench, (name.c_str(), pic.get(), FLAGS_bb h)); 525 return SkNEW_ARGS(RecordingBench, (name.c_str(), pic.get(), FLAGS_bb h));
518 } 526 }
519 527
520 // Then once each for each scale as SKPBenches (playback). 528 // Then once each for each scale as SKPBenches (playback).
521 while (fCurrentScale < fScales.count()) { 529 while (fCurrentScale < fScales.count()) {
522 while (fCurrentSKP < fSKPs.count()) { 530 while (fCurrentSKP < fSKPs.count()) {
523 const SkString& path = fSKPs[fCurrentSKP++]; 531 const SkString& path = fSKPs[fCurrentSKP];
524 SkAutoTUnref<SkPicture> pic; 532 SkAutoTUnref<SkPicture> pic;
525 if (!ReadPicture(path.c_str(), &pic)) { 533 if (!ReadPicture(path.c_str(), &pic)) {
534 fCurrentSKP++;
526 continue; 535 continue;
527 } 536 }
528 if (FLAGS_bbh) { 537
529 // The SKP we read off disk doesn't have a BBH. Re-record s o it grows one. 538 while (fCurrentUseMPD < fUseMPDs.count()) {
530 SkRTreeFactory factory; 539 if (FLAGS_bbh) {
531 SkPictureRecorder recorder; 540 // The SKP we read off disk doesn't have a BBH. Re-reco rd so it grows one.
532 pic->playback(recorder.beginRecording(pic->cullRect().width( ), 541 SkRTreeFactory factory;
533 pic->cullRect().height (), 542 SkPictureRecorder recorder;
534 &factory)); 543 static const int kFlags = SkPictureRecorder::kComputeSav eLayerInfo_RecordFlag;
535 pic.reset(recorder.endRecording()); 544 pic->playback(recorder.beginRecording(pic->cullRect().wi dth(),
545 pic->cullRect().he ight(),
546 &factory, kFlags)) ;
547 pic.reset(recorder.endRecording());
548 }
549 SkString name = SkOSPath::Basename(path.c_str());
550 fSourceType = "skp";
551 fBenchType = "playback";
552 return SkNEW_ARGS(SKPBench,
553 (name.c_str(), pic.get(), fClip,
554 fScales[fCurrentScale], fUseMPDs[fCurrentUseMPD++]) );
536 } 555 }
537 SkString name = SkOSPath::Basename(path.c_str()); 556 fCurrentUseMPD = 0;
538 fSourceType = "skp"; 557 fCurrentSKP++;
539 fBenchType = "playback";
540 return SkNEW_ARGS(SKPBench,
541 (name.c_str(), pic.get(), fClip, fScales[fCurrentScale]) );
542 } 558 }
543 fCurrentSKP = 0; 559 fCurrentSKP = 0;
544 fCurrentScale++; 560 fCurrentScale++;
545 } 561 }
546 562
547 return NULL; 563 return NULL;
548 } 564 }
549 565
550 void fillCurrentOptions(ResultsWriter* log) const { 566 void fillCurrentOptions(ResultsWriter* log) const {
551 log->configOption("source_type", fSourceType); 567 log->configOption("source_type", fSourceType);
552 log->configOption("bench_type", fBenchType); 568 log->configOption("bench_type", fBenchType);
553 if (0 == strcmp(fSourceType, "skp")) { 569 if (0 == strcmp(fSourceType, "skp")) {
554 log->configOption("clip", 570 log->configOption("clip",
555 SkStringPrintf("%d %d %d %d", fClip.fLeft, fClip.fTop, 571 SkStringPrintf("%d %d %d %d", fClip.fLeft, fClip.fTop,
556 fClip.fRight, fClip.fBottom).c _str()); 572 fClip.fRight, fClip.fBottom).c _str());
557 log->configOption("scale", SkStringPrintf("%.2g", fScales[fCurrentSc ale]).c_str()); 573 log->configOption("scale", SkStringPrintf("%.2g", fScales[fCurrentSc ale]).c_str());
574 if (fCurrentUseMPD > 0) {
575 SkASSERT(1 == fCurrentUseMPD || 2 == fCurrentUseMPD);
576 log->configOption("multi_picture_draw", fUseMPDs[fCurrentUseMPD- 1] ? "true" : "false");
577 }
558 } 578 }
559 } 579 }
560 580
561 private: 581 private:
562 const BenchRegistry* fBenches; 582 const BenchRegistry* fBenches;
563 const skiagm::GMRegistry* fGMs; 583 const skiagm::GMRegistry* fGMs;
564 SkIRect fClip; 584 SkIRect fClip;
565 SkTArray<SkScalar> fScales; 585 SkTArray<SkScalar> fScales;
566 SkTArray<SkString> fSKPs; 586 SkTArray<SkString> fSKPs;
587 SkTArray<bool> fUseMPDs;
567 588
568 const char* fSourceType; // What we're benching: bench, GM, SKP, ... 589 const char* fSourceType; // What we're benching: bench, GM, SKP, ...
569 const char* fBenchType; // How we bench it: micro, recording, playback, .. . 590 const char* fBenchType; // How we bench it: micro, recording, playback, .. .
570 int fCurrentRecording; 591 int fCurrentRecording;
571 int fCurrentScale; 592 int fCurrentScale;
572 int fCurrentSKP; 593 int fCurrentSKP;
594 int fCurrentUseMPD;
573 }; 595 };
574 596
575 int nanobench_main(); 597 int nanobench_main();
576 int nanobench_main() { 598 int nanobench_main() {
577 SetupCrashHandler(); 599 SetupCrashHandler();
578 SkAutoGraphics ag; 600 SkAutoGraphics ag;
601 SkTaskGroup::Enabler enabled;
579 602
580 #if SK_SUPPORT_GPU 603 #if SK_SUPPORT_GPU
581 GrContext::Options grContextOpts; 604 GrContext::Options grContextOpts;
582 grContextOpts.fDrawPathToCompressedTexture = FLAGS_gpuCompressAlphaMasks; 605 grContextOpts.fDrawPathToCompressedTexture = FLAGS_gpuCompressAlphaMasks;
583 gGrFactory.reset(SkNEW_ARGS(GrContextFactory, (grContextOpts))); 606 gGrFactory.reset(SkNEW_ARGS(GrContextFactory, (grContextOpts)));
584 #endif 607 #endif
585 608
586 if (FLAGS_veryVerbose) { 609 if (FLAGS_veryVerbose) {
587 FLAGS_verbose = true; 610 FLAGS_verbose = true;
588 } 611 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 create_targets(&targets, bench.get(), configs); 675 create_targets(&targets, bench.get(), configs);
653 676
654 if (!targets.isEmpty()) { 677 if (!targets.isEmpty()) {
655 log->bench(bench->getUniqueName(), bench->getSize().fX, bench->getSi ze().fY); 678 log->bench(bench->getUniqueName(), bench->getSize().fX, bench->getSi ze().fY);
656 bench->preDraw(); 679 bench->preDraw();
657 } 680 }
658 for (int j = 0; j < targets.count(); j++) { 681 for (int j = 0; j < targets.count(); j++) {
659 SkCanvas* canvas = targets[j]->surface.get() ? targets[j]->surface-> getCanvas() : NULL; 682 SkCanvas* canvas = targets[j]->surface.get() ? targets[j]->surface-> getCanvas() : NULL;
660 const char* config = targets[j]->config.name; 683 const char* config = targets[j]->config.name;
661 684
685 bench->perCanvasPreDraw(canvas);
686
662 const int loops = 687 const int loops =
663 #if SK_SUPPORT_GPU 688 #if SK_SUPPORT_GPU
664 Benchmark::kGPU_Backend == targets[j]->config.backend 689 Benchmark::kGPU_Backend == targets[j]->config.backend
665 ? gpu_bench(targets[j]->gl, bench.get(), canvas, samples.get()) 690 ? gpu_bench(targets[j]->gl, bench.get(), canvas, samples.get())
666 : 691 :
667 #endif 692 #endif
668 cpu_bench( overhead, bench.get(), canvas, samples.get()); 693 cpu_bench( overhead, bench.get(), canvas, samples.get());
669 694
695 bench->perCanvasPostDraw(canvas);
696
670 if (canvas && !FLAGS_writePath.isEmpty() && FLAGS_writePath[0]) { 697 if (canvas && !FLAGS_writePath.isEmpty() && FLAGS_writePath[0]) {
671 SkString pngFilename = SkOSPath::Join(FLAGS_writePath[0], config ); 698 SkString pngFilename = SkOSPath::Join(FLAGS_writePath[0], config );
672 pngFilename = SkOSPath::Join(pngFilename.c_str(), bench->getUniq ueName()); 699 pngFilename = SkOSPath::Join(pngFilename.c_str(), bench->getUniq ueName());
673 pngFilename.append(".png"); 700 pngFilename.append(".png");
674 write_canvas_png(canvas, pngFilename); 701 write_canvas_png(canvas, pngFilename);
675 } 702 }
676 703
677 if (kFailedLoops == loops) { 704 if (kFailedLoops == loops) {
678 // Can't be timed. A warning note has already been printed. 705 // Can't be timed. A warning note has already been printed.
679 continue; 706 continue;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 778
752 return 0; 779 return 0;
753 } 780 }
754 781
755 #if !defined SK_BUILD_FOR_IOS 782 #if !defined SK_BUILD_FOR_IOS
756 int main(int argc, char** argv) { 783 int main(int argc, char** argv) {
757 SkCommandLineFlags::Parse(argc, argv); 784 SkCommandLineFlags::Parse(argc, argv);
758 return nanobench_main(); 785 return nanobench_main();
759 } 786 }
760 #endif 787 #endif
OLDNEW
« no previous file with comments | « bench/SKPBench.cpp ('k') | include/core/SkColorTable.h » ('j') | include/core/SkColorTable.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698