Home | History | Annotate | Download | only in src
      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 "base/macros.h"
      9 
     10 #include "main.h"
     11 
     12 #define DISABLE_SOME_TESTS_FOR_INTEL_DRIVER 1
     13 
     14 #define IS_NOT_POWER_OF_2(v) (((v) & ((v) - 1)) && (v))
     15 
     16 namespace glbench {
     17 
     18 class TestBase;
     19 
     20 // Runs test->TestFunc() passing it sequential powers of two recording time it
     21 // took until reaching a minimum amount of testing time. The last two runs are
     22 // then averaged.
     23 double Bench(TestBase* test);
     24 
     25 // Runs Bench on an instance of TestBase and prints out results.
     26 //
     27 // coefficient is multiplied (if inverse is false) or divided (if inverse is
     28 // true) by the measured unit runtime and the result is printed.
     29 //
     30 // Examples:
     31 //   coefficient = width * height (measured in pixels), inverse = true
     32 //       returns the throughput in megapixels per second;
     33 //
     34 //   coefficient = 1, inverse = false
     35 //       returns number of operations per second.
     36 void RunTest(TestBase* test,
     37              const char *name,
     38              double coefficient,
     39              const int width,
     40              const int height,
     41              bool inverse);
     42 
     43 class TestBase {
     44  public:
     45   virtual ~TestBase() {}
     46   // Runs the test case n times.
     47   virtual bool TestFunc(uint64_t n) = 0;
     48   // Main entry point into the test.
     49   virtual bool Run() = 0;
     50   // Name of test case group
     51   virtual const char* Name() const = 0;
     52   // Returns true if a test draws some output.
     53   // If so, testbase will read back pixels, compute its MD5 hash and optionally
     54   // save them to a file on disk.
     55   virtual bool IsDrawTest() const = 0;
     56   // Name of unit for benchmark score (e.g., mtexel_sec, us, etc.)
     57   virtual const char* Unit() const = 0;
     58 };
     59 
     60 // Helper class to time glDrawArrays.
     61 class DrawArraysTestFunc : public TestBase {
     62  public:
     63   virtual ~DrawArraysTestFunc() {}
     64   virtual bool TestFunc(uint64_t);
     65   virtual bool IsDrawTest() const { return true; }
     66   virtual const char* Unit() const { return "mpixels_sec"; }
     67 
     68   // Runs the test and reports results in mpixels per second, assuming each
     69   // iteration updates the whole window (its size is g_width by g_height).
     70   void FillRateTestNormal(const char* name);
     71   // Runs the test and reports results in mpixels per second, assuming each
     72   // iteration updates a window of width by height pixels.
     73   void FillRateTestNormalSubWindow(const char* name,
     74                                    const int width, 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:
     84   DrawElementsTestFunc() : count_(0) {}
     85   virtual ~DrawElementsTestFunc() {}
     86   virtual bool TestFunc(uint64_t);
     87   virtual bool IsDrawTest() const { return true; }
     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