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 VisualLightweightBenchModule_DEFINED | 9 #ifndef VisualLightweightBenchModule_DEFINED |
10 #define VisualLightweightBenchModule_DEFINED | 10 #define VisualLightweightBenchModule_DEFINED |
11 | 11 |
12 #include "VisualModule.h" | 12 #include "VisualModule.h" |
13 | 13 |
14 #include "ResultsWriter.h" | 14 #include "ResultsWriter.h" |
15 #include "SkPicture.h" | 15 #include "SkPicture.h" |
16 #include "Timer.h" | 16 #include "TimingStateMachine.h" |
17 #include "VisualBench.h" | 17 #include "VisualBench.h" |
18 #include "VisualBenchmarkStream.h" | 18 #include "VisualBenchmarkStream.h" |
19 | 19 |
20 class SkCanvas; | 20 class SkCanvas; |
21 | 21 |
22 /* | 22 /* |
23 * This module is designed to be a minimal overhead timing module for VisualBenc
h | 23 * This module is designed to be a minimal overhead timing module for VisualBenc
h |
24 */ | 24 */ |
25 class VisualLightweightBenchModule : public VisualModule { | 25 class VisualLightweightBenchModule : public VisualModule { |
26 public: | 26 public: |
27 // TODO get rid of backpointer | 27 // TODO get rid of backpointer |
28 VisualLightweightBenchModule(VisualBench* owner); | 28 VisualLightweightBenchModule(VisualBench* owner); |
29 | 29 |
30 void draw(SkCanvas* canvas) override; | 30 void draw(SkCanvas* canvas) override; |
31 | 31 |
32 bool onHandleChar(SkUnichar c) override; | 32 bool onHandleChar(SkUnichar c) override; |
33 | 33 |
34 private: | 34 private: |
35 /* | |
36 * The heart of visual bench is an event driven timing loop. | |
37 * kWarmup_State: We run a dummy bench to let things
settle on startup | |
38 * kPreWarmLoopsPerCanvasPreDraw_State: Before we begin timing, Benchmarks
have a hook to | |
39 * access the canvas. Then we prewarm
before the autotune | |
40 * loops step. | |
41 * kPreWarmLoops_State: We prewarm the gpu before auto tuni
ng to enter a steady | |
42 * work state | |
43 * kTuneLoops_State: Then we tune the loops of the bench
mark to ensure we | |
44 * are doing a measurable amount of wo
rk | |
45 * kPreWarmTimingPerCanvasPreDraw_State: Because reset the context after tun
ing loops to ensure | |
46 * coherent state, we need to give the
benchmark | |
47 * another hook | |
48 * kPreWarmTiming_State: We prewarm the gpu again to enter a
steady state | |
49 * kTiming_State: Finally we time the benchmark. Whe
n finished timing | |
50 * if we have enough samples then we'l
l start the next | |
51 * benchmark in the kPreWarmLoopsPerCa
nvasPreDraw_State. | |
52 * otherwise, we enter the | |
53 * kPreWarmTimingPerCanvasPreDraw_Stat
e for another sample | |
54 * In either case we reset the context
. | |
55 */ | |
56 enum State { | |
57 kWarmup_State, | |
58 kPreWarmLoopsPerCanvasPreDraw_State, | |
59 kPreWarmLoops_State, | |
60 kTuneLoops_State, | |
61 kPreWarmTimingPerCanvasPreDraw_State, | |
62 kPreWarmTiming_State, | |
63 kTiming_State, | |
64 }; | |
65 void setTitle(); | 35 void setTitle(); |
66 bool setupBackend(); | 36 bool setupBackend(); |
67 void setupRenderTarget(); | 37 void setupRenderTarget(); |
68 void printStats(); | 38 void printStats(); |
69 bool advanceRecordIfNecessary(SkCanvas*); | 39 bool advanceRecordIfNecessary(SkCanvas*); |
70 inline void renderFrame(SkCanvas*); | 40 inline void renderFrame(SkCanvas*); |
71 inline void nextState(State); | |
72 void perCanvasPreDraw(SkCanvas*, State); | |
73 void preWarm(State nextState); | |
74 inline void tuneLoops(); | |
75 inline void timing(SkCanvas*); | |
76 inline double elapsed(); | |
77 void resetTimingState(); | |
78 void postDraw(SkCanvas*); | |
79 void recordMeasurement(); | |
80 void warmup(SkCanvas* canvas); | |
81 | 41 |
82 struct Record { | 42 struct Record { |
83 SkTArray<double> fMeasurements; | 43 SkTArray<double> fMeasurements; |
84 }; | 44 }; |
85 | |
86 int fCurrentSample; | 45 int fCurrentSample; |
87 int fCurrentFrame; | |
88 int fLoops; | |
89 SkTArray<Record> fRecords; | 46 SkTArray<Record> fRecords; |
90 WallTimer fTimer; | |
91 State fState; | |
92 SkAutoTDelete<VisualBenchmarkStream> fBenchmarkStream; | 47 SkAutoTDelete<VisualBenchmarkStream> fBenchmarkStream; |
93 SkAutoTUnref<Benchmark> fBenchmark; | 48 SkAutoTUnref<Benchmark> fBenchmark; |
| 49 TimingStateMachine fTSM; |
94 | 50 |
95 // support framework | 51 // support framework |
96 SkAutoTUnref<VisualBench> fOwner; | 52 SkAutoTUnref<VisualBench> fOwner; |
97 SkAutoTDelete<ResultsWriter> fResults; | 53 SkAutoTDelete<ResultsWriter> fResults; |
98 | 54 |
99 typedef VisualModule INHERITED; | 55 typedef VisualModule INHERITED; |
100 }; | 56 }; |
101 | 57 |
102 #endif | 58 #endif |
OLD | NEW |