1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
|
/*
* Copyright 2012 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "Timer.h"
#include "PictureBenchmark.h"
#include "SkCanvas.h"
#include "SkPicture.h"
#include "SkString.h"
#include "picture_utils.h"
namespace sk_tools {
PictureBenchmark::PictureBenchmark()
: fRepeats(1)
, fRenderer(NULL)
, fTimerResult(TimerData::kAvg_Result)
, fTimerTypes(0)
, fTimeIndividualTiles(false)
, fPurgeDecodedTex(false)
, fWriter(NULL) {
}
PictureBenchmark::~PictureBenchmark() {
SkSafeUnref(fRenderer);
}
void PictureBenchmark::setTimersToShow(bool wall,
bool truncatedWall,
bool cpu,
bool truncatedCpu,
bool gpu) {
fTimerTypes = 0;
fTimerTypes |= wall ? TimerData::kWall_Flag : 0;
fTimerTypes |= truncatedWall ? TimerData::kTruncatedWall_Flag : 0;
fTimerTypes |= cpu ? TimerData::kCpu_Flag : 0;
fTimerTypes |= truncatedCpu ? TimerData::kTruncatedCpu_Flag : 0;
fTimerTypes |= gpu ? TimerData::kGpu_Flag : 0;
}
Timer* PictureBenchmark::setupTimer(bool useGLTimer) {
#if SK_SUPPORT_GPU
if (useGLTimer && fRenderer != NULL && fRenderer->isUsingGpuDevice()) {
return SkNEW_ARGS(Timer, (fRenderer->getGLContext()));
}
#endif
return SkNEW_ARGS(Timer, (NULL));
}
PictureRenderer* PictureBenchmark::setRenderer(sk_tools::PictureRenderer* renderer) {
SkRefCnt_SafeAssign(fRenderer, renderer);
return renderer;
}
void PictureBenchmark::run(SkPicture* pict, bool useMultiPictureDraw) {
SkASSERT(pict);
if (NULL == pict) {
return;
}
SkASSERT(fRenderer != NULL);
if (NULL == fRenderer) {
return;
}
fRenderer->init(pict, NULL, NULL, NULL, false, useMultiPictureDraw);
// We throw this away to remove first time effects (such as paging in this program)
fRenderer->setup();
fRenderer->render(NULL);
fRenderer->resetState(true); // flush, swapBuffers and Finish
if (fPurgeDecodedTex) {
fRenderer->purgeTextures();
}
bool usingGpu = false;
#if SK_SUPPORT_GPU
usingGpu = fRenderer->isUsingGpuDevice();
#endif
uint32_t timerTypes = fTimerTypes;
if (!usingGpu) {
timerTypes &= ~TimerData::kGpu_Flag;
}
SkString timeFormat;
if (TimerData::kPerIter_Result == fTimerResult) {
timeFormat = fRenderer->getPerIterTimeFormat();
} else {
timeFormat = fRenderer->getNormalTimeFormat();
}
static const int kNumInnerLoops = 10;
int numOuterLoops = 1;
int numInnerLoops = fRepeats;
if (TimerData::kPerIter_Result == fTimerResult && fRepeats > 1) {
// interpret this flag combination to mean: generate 'fRepeats'
// numbers by averaging each rendering 'kNumInnerLoops' times
numOuterLoops = fRepeats;
numInnerLoops = kNumInnerLoops;
}
if (fTimeIndividualTiles) {
TiledPictureRenderer* tiledRenderer = fRenderer->getTiledRenderer();
SkASSERT(tiledRenderer && tiledRenderer->supportsTimingIndividualTiles());
if (NULL == tiledRenderer || !tiledRenderer->supportsTimingIndividualTiles()) {
return;
}
int xTiles, yTiles;
if (!tiledRenderer->tileDimensions(xTiles, yTiles)) {
return;
}
int x, y;
while (tiledRenderer->nextTile(x, y)) {
// There are two timers, which will behave slightly differently:
// 1) longRunningTimer, along with perTileTimerData, will time how long it takes to draw
// one tile fRepeats times, and take the average. As such, it will not respect the
// logPerIter or printMin options, since it does not know the time per iteration. It
// will also be unable to call flush() for each tile.
// The goal of this timer is to make up for a system timer that is not precise enough to
// measure the small amount of time it takes to draw one tile once.
//
// 2) perTileTimer, along with perTileTimerData, will record each run separately, and
// then take the average. As such, it supports logPerIter and printMin options.
//
// Although "legal", having two gpu timers running at the same time
// seems to cause problems (i.e., INVALID_OPERATIONs) on several
// platforms. To work around this, we disable the gpu timer on the
// long running timer.
SkAutoTDelete<Timer> longRunningTimer(this->setupTimer());
TimerData longRunningTimerData(numOuterLoops);
for (int outer = 0; outer < numOuterLoops; ++outer) {
SkAutoTDelete<Timer> perTileTimer(this->setupTimer(false));
TimerData perTileTimerData(numInnerLoops);
longRunningTimer->start();
for (int inner = 0; inner < numInnerLoops; ++inner) {
perTileTimer->start();
tiledRenderer->drawCurrentTile();
perTileTimer->truncatedEnd();
tiledRenderer->resetState(false); // flush & swapBuffers, but don't Finish
perTileTimer->end();
SkAssertResult(perTileTimerData.appendTimes(perTileTimer.get()));
if (fPurgeDecodedTex) {
fRenderer->purgeTextures();
}
}
longRunningTimer->truncatedEnd();
tiledRenderer->resetState(true); // flush, swapBuffers and Finish
longRunningTimer->end();
SkAssertResult(longRunningTimerData.appendTimes(longRunningTimer.get()));
}
fWriter->logRenderer(tiledRenderer);
fWriter->tileMeta(x, y, xTiles, yTiles);
// TODO(borenet): Turn off per-iteration tile time reporting for now.
// Avoiding logging the time for every iteration for each tile cuts
// down on data file size by a significant amount. Re-enable this once
// we're loading the bench data directly into a data store and are no
// longer generating SVG graphs.
#if 0
fWriter->tileData(
&perTileTimerData,
timeFormat.c_str(),
fTimerResult,
timerTypes);
#endif
if (fPurgeDecodedTex) {
fWriter->addTileFlag(PictureResultsWriter::kPurging);
}
fWriter->addTileFlag(PictureResultsWriter::kAvg);
fWriter->tileData(
&longRunningTimerData,
tiledRenderer->getNormalTimeFormat().c_str(),
TimerData::kAvg_Result,
timerTypes,
numInnerLoops);
}
} else {
SkAutoTDelete<Timer> longRunningTimer(this->setupTimer());
TimerData longRunningTimerData(numOuterLoops);
for (int outer = 0; outer < numOuterLoops; ++outer) {
SkAutoTDelete<Timer> perRunTimer(this->setupTimer(false));
TimerData perRunTimerData(numInnerLoops);
longRunningTimer->start();
for (int inner = 0; inner < numInnerLoops; ++inner) {
fRenderer->setup();
perRunTimer->start();
fRenderer->render(NULL);
perRunTimer->truncatedEnd();
fRenderer->resetState(false); // flush & swapBuffers, but don't Finish
perRunTimer->end();
SkAssertResult(perRunTimerData.appendTimes(perRunTimer.get()));
if (fPurgeDecodedTex) {
fRenderer->purgeTextures();
}
}
longRunningTimer->truncatedEnd();
fRenderer->resetState(true); // flush, swapBuffers and Finish
longRunningTimer->end();
SkAssertResult(longRunningTimerData.appendTimes(longRunningTimer.get()));
}
fWriter->logRenderer(fRenderer);
if (fPurgeDecodedTex) {
fWriter->addTileFlag(PictureResultsWriter::kPurging);
}
// Beware - since the per-run-timer doesn't ever include a glFinish it can
// report a lower time then the long-running-timer
#if 0
fWriter->tileData(
&perRunTimerData,
timeFormat.c_str(),
fTimerResult,
timerTypes);
#else
fWriter->tileData(
&longRunningTimerData,
timeFormat.c_str(),
fTimerResult,
timerTypes,
numInnerLoops);
#endif
}
fRenderer->end();
}
}
|