2015-05-27 16:19:03 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef VisualBench_DEFINED
|
|
|
|
#define VisualBench_DEFINED
|
|
|
|
|
|
|
|
#include "SkWindow.h"
|
|
|
|
|
2015-08-18 19:13:34 +00:00
|
|
|
#include "ResultsWriter.h"
|
2015-05-27 16:19:03 +00:00
|
|
|
#include "SkPicture.h"
|
2015-06-16 20:52:18 +00:00
|
|
|
#include "SkString.h"
|
2015-05-27 16:19:03 +00:00
|
|
|
#include "SkSurface.h"
|
2015-06-01 17:03:54 +00:00
|
|
|
#include "Timer.h"
|
2015-06-30 14:43:14 +00:00
|
|
|
#include "VisualBenchmarkStream.h"
|
2015-05-27 16:19:03 +00:00
|
|
|
#include "gl/SkGLContext.h"
|
|
|
|
|
|
|
|
class GrContext;
|
|
|
|
struct GrGLInterface;
|
|
|
|
class GrRenderTarget;
|
|
|
|
class SkCanvas;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A Visual benchmarking tool for gpu benchmarking
|
|
|
|
*/
|
|
|
|
class VisualBench : public SkOSWindow {
|
|
|
|
public:
|
|
|
|
VisualBench(void* hwnd, int argc, char** argv);
|
|
|
|
~VisualBench() override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
SkSurface* createSurface() override;
|
|
|
|
|
|
|
|
void draw(SkCanvas* canvas) override;
|
|
|
|
|
|
|
|
void onSizeChange() override;
|
|
|
|
|
|
|
|
private:
|
2015-07-17 16:09:23 +00:00
|
|
|
/*
|
|
|
|
* The heart of visual bench is an event driven timing loop.
|
|
|
|
* kPreWarmLoopsPerCanvasPreDraw_State: Before we begin timing, Benchmarks have a hook to
|
|
|
|
* access the canvas. Then we prewarm before the autotune
|
|
|
|
* loops step.
|
|
|
|
* kPreWarmLoops_State: We prewarm the gpu before auto tuning to enter a steady
|
|
|
|
* work state
|
|
|
|
* kTuneLoops_State: Then we tune the loops of the benchmark to ensure we
|
|
|
|
* are doing a measurable amount of work
|
|
|
|
* kPreWarmTimingPerCanvasPreDraw_State: Because reset the context after tuning loops to ensure
|
|
|
|
* coherent state, we need to give the benchmark
|
|
|
|
* another hook
|
|
|
|
* kPreWarmTiming_State: We prewarm the gpu again to enter a steady state
|
|
|
|
* kTiming_State: Finally we time the benchmark. When finished timing
|
|
|
|
* if we have enough samples then we'll start the next
|
|
|
|
* benchmark in the kPreWarmLoopsPerCanvasPreDraw_State.
|
|
|
|
* otherwise, we enter the
|
|
|
|
* kPreWarmTimingPerCanvasPreDraw_State for another sample
|
|
|
|
* In either case we reset the context.
|
|
|
|
*/
|
|
|
|
enum State {
|
|
|
|
kPreWarmLoopsPerCanvasPreDraw_State,
|
|
|
|
kPreWarmLoops_State,
|
|
|
|
kTuneLoops_State,
|
|
|
|
kPreWarmTimingPerCanvasPreDraw_State,
|
|
|
|
kPreWarmTiming_State,
|
|
|
|
kTiming_State,
|
|
|
|
};
|
2015-05-27 16:19:03 +00:00
|
|
|
void setTitle();
|
|
|
|
bool setupBackend();
|
2015-06-01 17:03:54 +00:00
|
|
|
void resetContext();
|
2015-05-27 16:19:03 +00:00
|
|
|
void setupRenderTarget();
|
|
|
|
bool onHandleChar(SkUnichar unichar) override;
|
2015-06-01 17:03:54 +00:00
|
|
|
void printStats();
|
2015-06-30 14:43:14 +00:00
|
|
|
bool advanceRecordIfNecessary(SkCanvas*);
|
2015-06-01 17:03:54 +00:00
|
|
|
inline void renderFrame(SkCanvas*);
|
2015-07-17 16:09:23 +00:00
|
|
|
inline void nextState(State);
|
|
|
|
void perCanvasPreDraw(SkCanvas*, State);
|
|
|
|
void preWarm(State nextState);
|
|
|
|
void scaleLoops(double elapsedMs);
|
|
|
|
inline void tuneLoops();
|
|
|
|
inline void timing(SkCanvas*);
|
|
|
|
inline double elapsed();
|
|
|
|
void resetTimingState();
|
|
|
|
void postDraw(SkCanvas*);
|
|
|
|
void recordMeasurement();
|
2015-05-27 16:19:03 +00:00
|
|
|
|
2015-06-16 20:52:18 +00:00
|
|
|
struct Record {
|
2015-06-01 17:03:54 +00:00
|
|
|
SkTArray<double> fMeasurements;
|
|
|
|
};
|
|
|
|
|
|
|
|
int fCurrentSample;
|
2015-06-23 14:10:59 +00:00
|
|
|
int fCurrentFrame;
|
|
|
|
int fLoops;
|
2015-06-16 20:52:18 +00:00
|
|
|
SkTArray<Record> fRecords;
|
2015-06-01 17:03:54 +00:00
|
|
|
WallTimer fTimer;
|
|
|
|
State fState;
|
2015-06-30 14:43:14 +00:00
|
|
|
SkAutoTDelete<VisualBenchmarkStream> fBenchmarkStream;
|
2015-07-16 21:23:22 +00:00
|
|
|
SkAutoTUnref<Benchmark> fBenchmark;
|
2015-05-27 16:19:03 +00:00
|
|
|
|
|
|
|
// support framework
|
|
|
|
SkAutoTUnref<SkSurface> fSurface;
|
|
|
|
SkAutoTUnref<GrContext> fContext;
|
|
|
|
SkAutoTUnref<GrRenderTarget> fRenderTarget;
|
|
|
|
AttachmentInfo fAttachmentInfo;
|
|
|
|
SkAutoTUnref<const GrGLInterface> fInterface;
|
2015-08-18 19:13:34 +00:00
|
|
|
SkAutoTDelete<ResultsWriter> fResults;
|
2015-05-27 16:19:03 +00:00
|
|
|
|
|
|
|
typedef SkOSWindow INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|