• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef BENCH_GL_TESTBASE_H_
6 #define BENCH_GL_TESTBASE_H_
7 
8 #include <string.h>
9 #include "main.h"
10 
11 #define DISABLE_SOME_TESTS_FOR_INTEL_DRIVER 1
12 
13 #define IS_NOT_POWER_OF_2(v) (((v) & ((v)-1)) && (v))
14 
15 namespace glbench {
16 
17 class TestBase;
18 
19 // Runs test->TestFunc() passing it sequential powers of two recording time it
20 // took until reaching a minimum amount of testing time. The last two runs are
21 // then averaged.
22 double Bench(TestBase* test);
23 
24 // Runs Bench on an instance of TestBase and prints out results.
25 //
26 // coefficient is multiplied (if inverse is false) or divided (if inverse is
27 // true) by the measured unit runtime and the result is printed.
28 //
29 // Examples:
30 //   coefficient = width * height (measured in pixels), inverse = true
31 //       returns the throughput in megapixels per second;
32 //
33 //   coefficient = 1, inverse = false
34 //       returns number of operations per second.
35 void RunTest(TestBase* test,
36              const char* name,
37              double coefficient,
38              const int width,
39              const int height,
40              bool inverse);
41 
42 class TestBase {
43  public:
~TestBase()44   virtual ~TestBase() {}
45   // Runs the test case n times.
46   virtual bool TestFunc(uint64_t n) = 0;
47   // Main entry point into the test.
48   virtual bool Run() = 0;
49   // Name of test case group
50   virtual const char* Name() const = 0;
51   // Returns true if a test draws some output.
52   // If so, testbase will read back pixels, compute its MD5 hash and optionally
53   // save them to a file on disk.
54   virtual bool IsDrawTest() const = 0;
55   // Name of unit for benchmark score (e.g., mtexel_sec, us, etc.)
56   virtual const char* Unit() const = 0;
57 };
58 
59 // Helper class to time glDrawArrays.
60 class DrawArraysTestFunc : public TestBase {
61  public:
~DrawArraysTestFunc()62   virtual ~DrawArraysTestFunc() {}
63   virtual bool TestFunc(uint64_t);
IsDrawTest()64   virtual bool IsDrawTest() const { return true; }
Unit()65   virtual const char* Unit() const { return "mpixels_sec"; }
66 
67   // Runs the test and reports results in mpixels per second, assuming each
68   // iteration updates the whole window (its size is g_width by g_height).
69   void FillRateTestNormal(const char* name);
70   // Runs the test and reports results in mpixels per second, assuming each
71   // iteration updates a window of width by height pixels.
72   void FillRateTestNormalSubWindow(const char* name,
73                                    const int width,
74                                    const int height);
75   // Runs the test three times: with blending on; with depth test enabled and
76   // depth function of GL_NOTEQUAL; with depth function GL_NEVER.  Results are
77   // reported as in FillRateTestNormal.
78   void FillRateTestBlendDepth(const char* name);
79 };
80 
81 // Helper class to time glDrawElements.
82 class DrawElementsTestFunc : public TestBase {
83  public:
DrawElementsTestFunc()84   DrawElementsTestFunc() : count_(0) {}
~DrawElementsTestFunc()85   virtual ~DrawElementsTestFunc() {}
86   virtual bool TestFunc(uint64_t);
IsDrawTest()87   virtual bool IsDrawTest() const { return true; }
Unit()88   virtual const char* Unit() const { return "mtri_sec"; }
89 
90  protected:
91   // Passed to glDrawElements.
92   GLsizei count_;
93 };
94 
95 }  // namespace glbench
96 
97 #endif  // BENCH_GL_TESTBASE_H_
98