Home | History | Annotate | Download | only in perf_tests
      1 //
      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 
     22 class Event;
     23 
     24 class 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 
     33     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 
     47   protected:
     48     unsigned int mDrawIterations;
     49     double mRunTimeSeconds;
     50     int mNumFrames;
     51 
     52   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 
     61     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
     70 struct BenchmarkParams
     71 {
     72     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     }
     83 };
     84 
     85 template <typename BenchmarkT, typename ParamsT>
     86 inline 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
    101