| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 | 8 |
| 9 #ifndef VisualBench_DEFINED | 9 #ifndef VisualBench_DEFINED |
| 10 #define VisualBench_DEFINED | 10 #define VisualBench_DEFINED |
| 11 | 11 |
| 12 #include "SkWindow.h" | 12 #include "SkWindow.h" |
| 13 | 13 |
| 14 #include "ResultsWriter.h" | |
| 15 #include "SkPicture.h" | 14 #include "SkPicture.h" |
| 16 #include "SkString.h" | 15 #include "SkString.h" |
| 17 #include "SkSurface.h" | 16 #include "SkSurface.h" |
| 18 #include "Timer.h" | 17 #include "VisualFlags.h" |
| 19 #include "VisualBenchmarkStream.h" | 18 #include "VisualModule.h" |
| 20 #include "gl/SkGLContext.h" | 19 #include "gl/SkGLContext.h" |
| 21 | 20 |
| 22 class GrContext; | 21 class GrContext; |
| 23 struct GrGLInterface; | 22 struct GrGLInterface; |
| 24 class GrRenderTarget; | 23 class GrRenderTarget; |
| 25 class SkCanvas; | 24 class SkCanvas; |
| 26 | 25 |
| 27 /* | 26 /* |
| 28 * A Visual benchmarking tool for gpu benchmarking | 27 * A Visual benchmarking tool for gpu benchmarking |
| 29 */ | 28 */ |
| 30 class VisualBench : public SkOSWindow { | 29 class VisualBench : public SkOSWindow { |
| 31 public: | 30 public: |
| 32 VisualBench(void* hwnd, int argc, char** argv); | 31 VisualBench(void* hwnd, int argc, char** argv); |
| 33 ~VisualBench() override; | 32 ~VisualBench() override; |
| 34 | 33 |
| 34 void reset() { this->resetContext(); } |
| 35 |
| 35 protected: | 36 protected: |
| 36 SkSurface* createSurface() override; | 37 SkSurface* createSurface() override; |
| 37 | 38 |
| 38 void draw(SkCanvas* canvas) override; | 39 void draw(SkCanvas* canvas) override; |
| 39 | 40 |
| 40 void onSizeChange() override; | 41 void onSizeChange() override; |
| 41 | 42 |
| 42 private: | 43 private: |
| 43 /* | |
| 44 * The heart of visual bench is an event driven timing loop. | |
| 45 * kPreWarmLoopsPerCanvasPreDraw_State: Before we begin timing, Benchmarks
have a hook to | |
| 46 * access the canvas. Then we prewarm
before the autotune | |
| 47 * loops step. | |
| 48 * kPreWarmLoops_State: We prewarm the gpu before auto tuni
ng to enter a steady | |
| 49 * work state | |
| 50 * kTuneLoops_State: Then we tune the loops of the bench
mark to ensure we | |
| 51 * are doing a measurable amount of wo
rk | |
| 52 * kPreWarmTimingPerCanvasPreDraw_State: Because reset the context after tun
ing loops to ensure | |
| 53 * coherent state, we need to give the
benchmark | |
| 54 * another hook | |
| 55 * kPreWarmTiming_State: We prewarm the gpu again to enter a
steady state | |
| 56 * kTiming_State: Finally we time the benchmark. Whe
n finished timing | |
| 57 * if we have enough samples then we'l
l start the next | |
| 58 * benchmark in the kPreWarmLoopsPerCa
nvasPreDraw_State. | |
| 59 * otherwise, we enter the | |
| 60 * kPreWarmTimingPerCanvasPreDraw_Stat
e for another sample | |
| 61 * In either case we reset the context
. | |
| 62 */ | |
| 63 enum State { | |
| 64 kPreWarmLoopsPerCanvasPreDraw_State, | |
| 65 kPreWarmLoops_State, | |
| 66 kTuneLoops_State, | |
| 67 kPreWarmTimingPerCanvasPreDraw_State, | |
| 68 kPreWarmTiming_State, | |
| 69 kTiming_State, | |
| 70 }; | |
| 71 void setTitle(); | 44 void setTitle(); |
| 72 bool setupBackend(); | 45 bool setupBackend(); |
| 73 void resetContext(); | 46 void resetContext(); |
| 74 void setupRenderTarget(); | 47 void setupRenderTarget(); |
| 75 bool onHandleChar(SkUnichar unichar) override; | 48 bool onHandleChar(SkUnichar unichar) override; |
| 76 void printStats(); | |
| 77 bool advanceRecordIfNecessary(SkCanvas*); | |
| 78 inline void renderFrame(SkCanvas*); | |
| 79 inline void nextState(State); | |
| 80 void perCanvasPreDraw(SkCanvas*, State); | |
| 81 void preWarm(State nextState); | |
| 82 void scaleLoops(double elapsedMs); | |
| 83 inline void tuneLoops(); | |
| 84 inline void timing(SkCanvas*); | |
| 85 inline double elapsed(); | |
| 86 void resetTimingState(); | |
| 87 void postDraw(SkCanvas*); | |
| 88 void recordMeasurement(); | |
| 89 | |
| 90 struct Record { | |
| 91 SkTArray<double> fMeasurements; | |
| 92 }; | |
| 93 | |
| 94 int fCurrentSample; | |
| 95 int fCurrentFrame; | |
| 96 int fLoops; | |
| 97 SkTArray<Record> fRecords; | |
| 98 WallTimer fTimer; | |
| 99 State fState; | |
| 100 SkAutoTDelete<VisualBenchmarkStream> fBenchmarkStream; | |
| 101 SkAutoTUnref<Benchmark> fBenchmark; | |
| 102 | 49 |
| 103 // support framework | 50 // support framework |
| 51 SkAutoTDelete<VisualModule> fModule; |
| 104 SkAutoTUnref<SkSurface> fSurface; | 52 SkAutoTUnref<SkSurface> fSurface; |
| 105 SkAutoTUnref<GrContext> fContext; | 53 SkAutoTUnref<GrContext> fContext; |
| 106 SkAutoTUnref<GrRenderTarget> fRenderTarget; | 54 SkAutoTUnref<GrRenderTarget> fRenderTarget; |
| 107 AttachmentInfo fAttachmentInfo; | 55 AttachmentInfo fAttachmentInfo; |
| 108 SkAutoTUnref<const GrGLInterface> fInterface; | 56 SkAutoTUnref<const GrGLInterface> fInterface; |
| 109 SkAutoTDelete<ResultsWriter> fResults; | |
| 110 | 57 |
| 111 typedef SkOSWindow INHERITED; | 58 typedef SkOSWindow INHERITED; |
| 112 }; | 59 }; |
| 113 | 60 |
| 114 #endif | 61 #endif |
| OLD | NEW |