OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 "GrCaps.h" | 8 #include "GrCaps.h" |
9 #include "GrContextFactory.h" | 9 #include "GrContextFactory.h" |
10 #include "Benchmark.h" | 10 #include "Benchmark.h" |
11 #include "ResultsWriter.h" | 11 #include "ResultsWriter.h" |
12 #include "SkCommandLineFlags.h" | 12 #include "SkCommandLineFlags.h" |
13 #include "SkOSFile.h" | 13 #include "SkOSFile.h" |
14 #include "SkStream.h" | 14 #include "SkStream.h" |
15 #include "SkSurface.h" | 15 #include "SkSurface.h" |
16 #include "SkTime.h" | 16 #include "SkTime.h" |
17 #include "SkTLList.h" | 17 #include "SkTLList.h" |
18 #include "SkThreadUtils.h" | 18 #include "SkThreadUtils.h" |
19 #include "Stats.h" | 19 #include "Stats.h" |
20 #include "Timer.h" | 20 #include "Timer.h" |
21 #include "VisualSKPBench.h" | 21 #include "VisualSKPBench.h" |
22 #include "gl/GrGLDefines.h" | 22 #include "gl/GrGLDefines.h" |
| 23 #include "gl/GrGLUtil.h" |
23 #include "../private/SkMutex.h" | 24 #include "../private/SkMutex.h" |
24 #include "../private/SkSemaphore.h" | 25 #include "../private/SkSemaphore.h" |
25 #include "../private/SkGpuFenceSync.h" | 26 #include "../private/SkGpuFenceSync.h" |
26 | 27 |
27 // posix only for now | 28 // posix only for now |
28 #include <unistd.h> | 29 #include <unistd.h> |
29 #include <sys/types.h> | 30 #include <sys/types.h> |
30 #include <sys/wait.h> | 31 #include <sys/wait.h> |
31 | 32 |
| 33 using namespace sk_gpu_test; |
| 34 |
32 /* | 35 /* |
33 * This is an experimental GPU only benchmarking program. The initial implement
ation will only | 36 * This is an experimental GPU only benchmarking program. The initial implement
ation will only |
34 * support SKPs. | 37 * support SKPs. |
35 */ | 38 */ |
36 | 39 |
37 static const int kAutoTuneLoops = 0; | 40 static const int kAutoTuneLoops = 0; |
38 | 41 |
39 static const int kDefaultLoops = | 42 static const int kDefaultLoops = |
40 #ifdef SK_DEBUG | 43 #ifdef SK_DEBUG |
41 1; | 44 1; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 } | 140 } |
138 | 141 |
139 SkTArray<SkString> fSKPs; | 142 SkTArray<SkString> fSKPs; |
140 int fCurrentSKP; | 143 int fCurrentSKP; |
141 }; | 144 }; |
142 | 145 |
143 struct GPUTarget { | 146 struct GPUTarget { |
144 void setup() { | 147 void setup() { |
145 fGL->makeCurrent(); | 148 fGL->makeCurrent(); |
146 // Make sure we're done with whatever came before. | 149 // Make sure we're done with whatever came before. |
147 SK_GL(*fGL, Finish()); | 150 GR_GL_CALL(fGL->gl(), Finish()); |
148 } | 151 } |
149 | 152 |
150 SkCanvas* beginTiming(SkCanvas* canvas) { return canvas; } | 153 SkCanvas* beginTiming(SkCanvas* canvas) { return canvas; } |
151 | 154 |
152 void endTiming(bool usePlatformSwapBuffers) { | 155 void endTiming(bool usePlatformSwapBuffers) { |
153 if (fGL) { | 156 if (fGL) { |
154 SK_GL(*fGL, Flush()); | 157 GR_GL_CALL(fGL->gl(), Flush()); |
155 if (usePlatformSwapBuffers) { | 158 if (usePlatformSwapBuffers) { |
156 fGL->swapBuffers(); | 159 fGL->swapBuffers(); |
157 } else { | 160 } else { |
158 fGL->waitOnSyncOrSwap(); | 161 fGL->waitOnSyncOrSwap(); |
159 } | 162 } |
160 } | 163 } |
161 } | 164 } |
162 void finish() { | 165 void finish() { |
163 SK_GL(*fGL, Finish()); | 166 GR_GL_CALL(fGL->gl(), Finish()); |
164 } | 167 } |
165 | 168 |
166 bool needsFrameTiming(int* maxFrameLag) const { | 169 bool needsFrameTiming(int* maxFrameLag) const { |
167 if (!fGL->getMaxGpuFrameLag(maxFrameLag)) { | 170 if (!fGL->getMaxGpuFrameLag(maxFrameLag)) { |
168 // Frame lag is unknown. | 171 // Frame lag is unknown. |
169 *maxFrameLag = FLAGS_gpuFrameLag; | 172 *maxFrameLag = FLAGS_gpuFrameLag; |
170 } | 173 } |
171 return true; | 174 return true; |
172 } | 175 } |
173 | 176 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 return false; | 211 return false; |
209 } | 212 } |
210 bmp->setInfo(canvas->imageInfo()); | 213 bmp->setInfo(canvas->imageInfo()); |
211 if (!canvas->readPixels(bmp, 0, 0)) { | 214 if (!canvas->readPixels(bmp, 0, 0)) { |
212 SkDebugf("Can't read canvas pixels.\n"); | 215 SkDebugf("Can't read canvas pixels.\n"); |
213 return false; | 216 return false; |
214 } | 217 } |
215 return true; | 218 return true; |
216 } | 219 } |
217 | 220 |
218 SkGLContext* gl() { return fGL; } | 221 GLContext* gl() { return fGL; } |
219 | 222 |
220 private: | 223 private: |
221 SkGLContext* fGL; | 224 GLContext* fGL; |
222 SkAutoTDelete<SkSurface> fSurface; | 225 SkAutoTDelete<SkSurface> fSurface; |
223 }; | 226 }; |
224 | 227 |
225 static bool write_canvas_png(GPUTarget* target, const SkString& filename) { | 228 static bool write_canvas_png(GPUTarget* target, const SkString& filename) { |
226 | 229 |
227 if (filename.isEmpty()) { | 230 if (filename.isEmpty()) { |
228 return false; | 231 return false; |
229 } | 232 } |
230 if (target->getCanvas() && | 233 if (target->getCanvas() && |
231 kUnknown_SkColorType == target->getCanvas()->imageInfo().colorType()) { | 234 kUnknown_SkColorType == target->getCanvas()->imageInfo().colorType()) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 if (loops > FLAGS_maxLoops) { | 275 if (loops > FLAGS_maxLoops) { |
273 SkDebugf("WARNING: clamping loops from %d to FLAGS_maxLoops, %d.\n", loo
ps, FLAGS_maxLoops); | 276 SkDebugf("WARNING: clamping loops from %d to FLAGS_maxLoops, %d.\n", loo
ps, FLAGS_maxLoops); |
274 return FLAGS_maxLoops; | 277 return FLAGS_maxLoops; |
275 } | 278 } |
276 return loops; | 279 return loops; |
277 } | 280 } |
278 | 281 |
279 static double now_ms() { return SkTime::GetNSecs() * 1e-6; } | 282 static double now_ms() { return SkTime::GetNSecs() * 1e-6; } |
280 | 283 |
281 struct TimingThread { | 284 struct TimingThread { |
282 TimingThread(SkGLContext* mainContext) | 285 TimingThread(GLContext* mainContext) |
283 : fFenceSync(mainContext->fenceSync()) | 286 : fFenceSync(mainContext->fenceSync()) |
284 , fMainContext(mainContext) | 287 , fMainContext(mainContext) |
285 , fDone(false) {} | 288 , fDone(false) {} |
286 | 289 |
287 static void Loop(void* data) { | 290 static void Loop(void* data) { |
288 TimingThread* timingThread = reinterpret_cast<TimingThread*>(data); | 291 TimingThread* timingThread = reinterpret_cast<TimingThread*>(data); |
289 timingThread->timingLoop(); | 292 timingThread->timingLoop(); |
290 } | 293 } |
291 | 294 |
292 // To ensure waiting for the sync actually does something, we check to make
sure the we exceed | 295 // To ensure waiting for the sync actually does something, we check to make
sure the we exceed |
293 // some small value | 296 // some small value |
294 const double kMinElapsed = 1e-6; | 297 const double kMinElapsed = 1e-6; |
295 bool sanity(double start) const { | 298 bool sanity(double start) const { |
296 double elapsed = now_ms() - start; | 299 double elapsed = now_ms() - start; |
297 return elapsed > kMinElapsed; | 300 return elapsed > kMinElapsed; |
298 } | 301 } |
299 | 302 |
300 void waitFence(SkPlatformGpuFence sync) { | 303 void waitFence(SkPlatformGpuFence sync) { |
301 SkDEBUGCODE(double start = now_ms()); | 304 SkDEBUGCODE(double start = now_ms()); |
302 fFenceSync->waitFence(sync, false); | 305 fFenceSync->waitFence(sync, false); |
303 SkASSERT(sanity(start)); | 306 SkASSERT(sanity(start)); |
304 } | 307 } |
305 | 308 |
306 void timingLoop() { | 309 void timingLoop() { |
307 // Create a context which shares display lists with the main thread | 310 // Create a context which shares display lists with the main thread |
308 SkAutoTDelete<SkGLContext> glContext(SkCreatePlatformGLContext(kNone_GrG
LStandard, | 311 SkAutoTDelete<GLContext> glContext(CreatePlatformGLContext(kNone_GrGLSta
ndard, |
309 fMainCont
ext)); | 312 fMainContext)
); |
310 glContext->makeCurrent(); | 313 glContext->makeCurrent(); |
311 | 314 |
312 // Basic timing methodology is: | 315 // Basic timing methodology is: |
313 // 1) Wait on semaphore until main thread indicates its time to start ti
ming the frame | 316 // 1) Wait on semaphore until main thread indicates its time to start ti
ming the frame |
314 // 2) Wait on frame start sync, record time. This is start of the frame
. | 317 // 2) Wait on frame start sync, record time. This is start of the frame
. |
315 // 3) Wait on semaphore until main thread indicates its time to finish t
iming the frame | 318 // 3) Wait on semaphore until main thread indicates its time to finish t
iming the frame |
316 // 4) Wait on frame end sync, record time. FrameEndTime - FrameStartTim
e = frame time | 319 // 4) Wait on frame end sync, record time. FrameEndTime - FrameStartTim
e = frame time |
317 // 5) Wait on semaphore until main thread indicates we should time the n
ext frame or quit | 320 // 5) Wait on semaphore until main thread indicates we should time the n
ext frame or quit |
318 while (true) { | 321 while (true) { |
319 fSemaphore.wait(); | 322 fSemaphore.wait(); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 | 398 |
396 private: | 399 private: |
397 SkGpuFenceSync* fFenceSync; | 400 SkGpuFenceSync* fFenceSync; |
398 SkSemaphore fSemaphore; | 401 SkSemaphore fSemaphore; |
399 SkMutex fFrameStartSyncsMutex; | 402 SkMutex fFrameStartSyncsMutex; |
400 SyncQueue fFrameStartSyncs; | 403 SyncQueue fFrameStartSyncs; |
401 SkMutex fFrameEndSyncsMutex; | 404 SkMutex fFrameEndSyncsMutex; |
402 SyncQueue fFrameEndSyncs; | 405 SyncQueue fFrameEndSyncs; |
403 SkTArray<double> fTimings; | 406 SkTArray<double> fTimings; |
404 SkMutex fDoneMutex; | 407 SkMutex fDoneMutex; |
405 SkGLContext* fMainContext; | 408 GLContext* fMainContext; |
406 bool fDone; | 409 bool fDone; |
407 }; | 410 }; |
408 | 411 |
409 static double time(int loops, Benchmark* bench, GPUTarget* target, TimingThread*
timingThread) { | 412 static double time(int loops, Benchmark* bench, GPUTarget* target, TimingThread*
timingThread) { |
410 SkCanvas* canvas = target->getCanvas(); | 413 SkCanvas* canvas = target->getCanvas(); |
411 canvas->clear(SK_ColorWHITE); | 414 canvas->clear(SK_ColorWHITE); |
412 bench->preDraw(canvas); | 415 bench->preDraw(canvas); |
413 | 416 |
414 if (timingThread) { | 417 if (timingThread) { |
415 timingThread->pushStartSync(); | 418 timingThread->pushStartSync(); |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
645 } | 648 } |
646 return 0; | 649 return 0; |
647 } | 650 } |
648 | 651 |
649 #if !defined SK_BUILD_FOR_IOS | 652 #if !defined SK_BUILD_FOR_IOS |
650 int main(int argc, char** argv) { | 653 int main(int argc, char** argv) { |
651 SkCommandLineFlags::Parse(argc, argv); | 654 SkCommandLineFlags::Parse(argc, argv); |
652 return kilobench_main(); | 655 return kilobench_main(); |
653 } | 656 } |
654 #endif | 657 #endif |
OLD | NEW |