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

Side by Side Diff: tools/kilobench/kilobench.cpp

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

Powered by Google App Engine
This is Rietveld 408576698