Alexey Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 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 | |
Alex Vakulenko | 298290d | 2016-01-20 16:07:13 -0800 | [diff] [blame] | 8 | #include "base/macros.h" |
Alexey Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 9 | |
| 10 | #include "main.h" |
| 11 | |
Alexey Marinichev | 01e4be1 | 2010-08-02 15:27:31 -0700 | [diff] [blame] | 12 | #define DISABLE_SOME_TESTS_FOR_INTEL_DRIVER 1 |
Alexey Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 13 | |
Allen Martin | 140559c | 2011-08-12 14:53:38 -0700 | [diff] [blame] | 14 | #define IS_NOT_POWER_OF_2(v) (((v) & ((v) - 1)) && (v)) |
| 15 | |
Alexey Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 16 | namespace glbench { |
| 17 | |
| 18 | class TestBase; |
| 19 | |
Ilja H. Friedel | 439ea14 | 2014-02-21 20:29:10 -0800 | [diff] [blame] | 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); |
Alexey Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 24 | |
| 25 | // Runs Bench on an instance of TestBase and prints out results. |
Alexey Marinichev | b70421f | 2010-07-12 18:11:27 -0700 | [diff] [blame] | 26 | // |
Alexey Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 27 | // coefficient is multiplied (if inverse is false) or divided (if inverse is |
Ilja H. Friedel | 439ea14 | 2014-02-21 20:29:10 -0800 | [diff] [blame] | 28 | // true) by the measured unit runtime and the result is printed. |
Alexey Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 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. |
Ilja H. Friedel | 439ea14 | 2014-02-21 20:29:10 -0800 | [diff] [blame] | 36 | void RunTest(TestBase* test, |
| 37 | const char *name, |
| 38 | double coefficient, |
Ilja Friedel | 3907fd1 | 2014-04-15 14:29:43 -0700 | [diff] [blame] | 39 | const int width, |
| 40 | const int height, |
Ilja H. Friedel | 439ea14 | 2014-02-21 20:29:10 -0800 | [diff] [blame] | 41 | bool inverse); |
Alexey Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 42 | |
| 43 | class TestBase { |
| 44 | public: |
| 45 | virtual ~TestBase() {} |
| 46 | // Runs the test case n times. |
Ilja H. Friedel | 439ea14 | 2014-02-21 20:29:10 -0800 | [diff] [blame] | 47 | virtual bool TestFunc(uint64_t n) = 0; |
Alexey Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 48 | // Main entry point into the test. |
| 49 | virtual bool Run() = 0; |
Daniel Kurtz | bcad4fb | 2014-06-18 12:31:03 +0800 | [diff] [blame] | 50 | // Name of test case group |
Alexey Marinichev | f50ecb1 | 2010-06-14 15:21:41 -0700 | [diff] [blame] | 51 | virtual const char* Name() const = 0; |
Daniel Kurtz | bcad4fb | 2014-06-18 12:31:03 +0800 | [diff] [blame] | 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; |
Daniel Kurtz | aace01b | 2014-06-17 21:05:24 +0800 | [diff] [blame] | 56 | // Name of unit for benchmark score (e.g., mtexel_sec, us, etc.) |
| 57 | virtual const char* Unit() const = 0; |
Alexey Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | // Helper class to time glDrawArrays. |
| 61 | class DrawArraysTestFunc : public TestBase { |
| 62 | public: |
| 63 | virtual ~DrawArraysTestFunc() {} |
Ilja H. Friedel | 439ea14 | 2014-02-21 20:29:10 -0800 | [diff] [blame] | 64 | virtual bool TestFunc(uint64_t); |
Daniel Kurtz | bcad4fb | 2014-06-18 12:31:03 +0800 | [diff] [blame] | 65 | virtual bool IsDrawTest() const { return true; } |
Daniel Kurtz | aace01b | 2014-06-17 21:05:24 +0800 | [diff] [blame] | 66 | virtual const char* Unit() const { return "mpixels_sec"; } |
Alexey Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 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. |
Ilja H. Friedel | 439ea14 | 2014-02-21 20:29:10 -0800 | [diff] [blame] | 73 | void FillRateTestNormalSubWindow(const char* name, |
Ilja Friedel | 3907fd1 | 2014-04-15 14:29:43 -0700 | [diff] [blame] | 74 | const int width, const int height); |
Alexey Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 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); |
Alexey Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | // Helper class to time glDrawElements. |
| 82 | class DrawElementsTestFunc : public TestBase { |
| 83 | public: |
| 84 | DrawElementsTestFunc() : count_(0) {} |
| 85 | virtual ~DrawElementsTestFunc() {} |
Ilja H. Friedel | 439ea14 | 2014-02-21 20:29:10 -0800 | [diff] [blame] | 86 | virtual bool TestFunc(uint64_t); |
Daniel Kurtz | bcad4fb | 2014-06-18 12:31:03 +0800 | [diff] [blame] | 87 | virtual bool IsDrawTest() const { return true; } |
Daniel Kurtz | aace01b | 2014-06-17 21:05:24 +0800 | [diff] [blame] | 88 | virtual const char* Unit() const { return "mtri_sec"; } |
Alexey Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 89 | |
| 90 | protected: |
| 91 | // Passed to glDrawElements. |
| 92 | GLsizei count_; |
| 93 | }; |
| 94 | |
| 95 | } // namespace glbench |
| 96 | |
| 97 | #endif // BENCH_GL_TESTBASE_H_ |