blob: b20b18a10a16a535ec933b357497734d27b690b1 [file] [log] [blame]
Jamie Madillffcc2e62014-08-26 13:16:40 -04001//
2// Copyright (c) 2014 The ANGLE Project Authors. All rights reserved.
3// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7#ifndef SAMPLE_UTIL_SIMPLE_BENCHMARK_H
8#define SAMPLE_UTIL_SIMPLE_BENCHMARK_H
9
10#include <memory>
11#include <vector>
12#include <EGL/egl.h>
13#include <EGL/eglext.h>
14#include <string>
15
16#include "shared_utils.h"
17
18#include "OSWindow.h"
19#include "EGLWindow.h"
20#include "Timer.h"
21
22class Event;
23
24class SimpleBenchmark
25{
26 public:
27 SimpleBenchmark(const std::string &name, size_t width, size_t height,
28 EGLint glesMajorVersion = 2,
29 EGLint requestedRenderer = EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE);
30
31 virtual ~SimpleBenchmark() { };
32
Jamie Madillffcc2e62014-08-26 13:16:40 -040033 virtual bool initializeBenchmark() { return true; }
34 virtual void destroyBenchmark() { }
35
36 virtual void stepBenchmark(float dt, double totalTime) { }
37
38 virtual void beginDrawBenchmark() { }
39 virtual void drawBenchmark() = 0;
40 virtual void endDrawBenchmark() { }
41
42 int run();
43 bool popEvent(Event *event);
44
45 OSWindow *getWindow();
46
Jamie Madill33ea2f92014-08-29 15:15:01 -040047 protected:
48 unsigned int mDrawIterations;
49 double mRunTimeSeconds;
Jamie Madill82cceb22014-09-09 13:21:33 -040050 int mNumFrames;
Jamie Madill33ea2f92014-08-29 15:15:01 -040051
Jamie Madillffcc2e62014-08-26 13:16:40 -040052 private:
53 DISALLOW_COPY_AND_ASSIGN(SimpleBenchmark);
54
55 bool initialize();
56 void destroy();
57
58 void step(float dt, double totalTime);
59 void draw();
60
Jamie Madillffcc2e62014-08-26 13:16:40 -040061 std::string mName;
62 bool mRunning;
63
64 std::unique_ptr<EGLWindow> mEGLWindow;
65 std::unique_ptr<OSWindow> mOSWindow;
66 std::unique_ptr<Timer> mTimer;
67};
68
69// Base class
70struct BenchmarkParams
71{
Jamie Madillbbffd552014-09-10 10:12:49 -040072 EGLint requestedRenderer;
73
74 virtual std::string name() const
75 {
76 switch (requestedRenderer)
77 {
78 case EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE: return "D3D11";
79 case EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE: return "D3D9";
80 default: return "Unknown Renderer";
81 }
82 }
Jamie Madillffcc2e62014-08-26 13:16:40 -040083};
84
85template <typename BenchmarkT, typename ParamsT>
86inline int RunBenchmarks(const std::vector<ParamsT> &benchmarks)
87{
88 int result;
89
90 for (size_t benchIndex = 0; benchIndex < benchmarks.size(); benchIndex++)
91 {
92 BenchmarkT benchmark(benchmarks[benchIndex]);
93 result = benchmark.run();
94 if (result != 0) { return result; }
95 }
96
97 return 0;
98}
99
100#endif // SAMPLE_UTIL_SIMPLE_BENCHMARK_H