blob: aeec800af56d9297b4911cd89f0edf25b58a93b8 [file] [log] [blame]
Alexey Marinichev9f9b8732010-05-20 19:33:44 -07001// 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/basictypes.h"
9
10#include "main.h"
11
Alexey Marinichev01e4be12010-08-02 15:27:31 -070012#define DISABLE_SOME_TESTS_FOR_INTEL_DRIVER 1
Alexey Marinichev9f9b8732010-05-20 19:33:44 -070013
Allen Martin140559c2011-08-12 14:53:38 -070014#define IS_NOT_POWER_OF_2(v) (((v) & ((v) - 1)) && (v))
15
Alexey Marinichev9f9b8732010-05-20 19:33:44 -070016namespace glbench {
17
18class TestBase;
19
Ilja H. Friedel439ea142014-02-21 20:29:10 -080020// 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.
23double Bench(TestBase* test);
Alexey Marinichev9f9b8732010-05-20 19:33:44 -070024
25// Runs Bench on an instance of TestBase and prints out results.
Alexey Marinichevb70421f2010-07-12 18:11:27 -070026//
Alexey Marinichev9f9b8732010-05-20 19:33:44 -070027// coefficient is multiplied (if inverse is false) or divided (if inverse is
Ilja H. Friedel439ea142014-02-21 20:29:10 -080028// true) by the measured unit runtime and the result is printed.
Alexey Marinichev9f9b8732010-05-20 19:33:44 -070029//
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.
Ilja H. Friedel439ea142014-02-21 20:29:10 -080036void RunTest(TestBase* test,
37 const char *name,
38 double coefficient,
Ilja Friedel3907fd12014-04-15 14:29:43 -070039 const int width,
40 const int height,
Ilja H. Friedel439ea142014-02-21 20:29:10 -080041 bool inverse);
Alexey Marinichev9f9b8732010-05-20 19:33:44 -070042
43class TestBase {
44 public:
45 virtual ~TestBase() {}
46 // Runs the test case n times.
Ilja H. Friedel439ea142014-02-21 20:29:10 -080047 virtual bool TestFunc(uint64_t n) = 0;
Alexey Marinichev9f9b8732010-05-20 19:33:44 -070048 // Main entry point into the test.
49 virtual bool Run() = 0;
Daniel Kurtzbcad4fb2014-06-18 12:31:03 +080050 // Name of test case group
Alexey Marinichevf50ecb12010-06-14 15:21:41 -070051 virtual const char* Name() const = 0;
Daniel Kurtzbcad4fb2014-06-18 12:31:03 +080052 // 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;
Alexey Marinichev9f9b8732010-05-20 19:33:44 -070056};
57
58// Helper class to time glDrawArrays.
59class DrawArraysTestFunc : public TestBase {
60 public:
61 virtual ~DrawArraysTestFunc() {}
Ilja H. Friedel439ea142014-02-21 20:29:10 -080062 virtual bool TestFunc(uint64_t);
Daniel Kurtzbcad4fb2014-06-18 12:31:03 +080063 virtual bool IsDrawTest() const { return true; }
Alexey Marinichev9f9b8732010-05-20 19:33:44 -070064
65 // Runs the test and reports results in mpixels per second, assuming each
66 // iteration updates the whole window (its size is g_width by g_height).
67 void FillRateTestNormal(const char* name);
68 // Runs the test and reports results in mpixels per second, assuming each
69 // iteration updates a window of width by height pixels.
Ilja H. Friedel439ea142014-02-21 20:29:10 -080070 void FillRateTestNormalSubWindow(const char* name,
Ilja Friedel3907fd12014-04-15 14:29:43 -070071 const int width, const int height);
Alexey Marinichev9f9b8732010-05-20 19:33:44 -070072 // Runs the test three times: with blending on; with depth test enabled and
73 // depth function of GL_NOTEQUAL; with depth function GL_NEVER. Results are
74 // reported as in FillRateTestNormal.
75 void FillRateTestBlendDepth(const char *name);
Alexey Marinichev9f9b8732010-05-20 19:33:44 -070076};
77
78// Helper class to time glDrawElements.
79class DrawElementsTestFunc : public TestBase {
80 public:
81 DrawElementsTestFunc() : count_(0) {}
82 virtual ~DrawElementsTestFunc() {}
Ilja H. Friedel439ea142014-02-21 20:29:10 -080083 virtual bool TestFunc(uint64_t);
Daniel Kurtzbcad4fb2014-06-18 12:31:03 +080084 virtual bool IsDrawTest() const { return true; }
Alexey Marinichev9f9b8732010-05-20 19:33:44 -070085
86 protected:
87 // Passed to glDrawElements.
88 GLsizei count_;
89};
90
91} // namespace glbench
92
93#endif // BENCH_GL_TESTBASE_H_