blob: 2a3b0608e0e24844ebe3094443390757e9a47881 [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
14namespace glbench {
15
16class TestBase;
17
18// Runs test->TestFunc() passing it sequential powers of two (8, 16, 32,...)
19// recording time it took. The data is then fitted linearly, obtaining slope
20// and bias such that:
21// time it took to run x iterations = slope * x + bias
22// Returns false if one iteration of the test takes longer than
23// MAX_ITERATION_LENGTH_MS. The test is then assumed too slow to provide
24// meaningful results.
25bool Bench(TestBase* test, float *slope, int64_t *bias);
26
27// Runs Bench on an instance of TestBase and prints out results.
Alexey Marinichevb70421f2010-07-12 18:11:27 -070028//
Alexey Marinichev9f9b8732010-05-20 19:33:44 -070029// coefficient is multiplied (if inverse is false) or divided (if inverse is
30// true) by the slope and the result is printed.
31//
32// Examples:
33// coefficient = width * height (measured in pixels), inverse = true
34// returns the throughput in megapixels per second;
35//
36// coefficient = 1, inverse = false
37// returns number of operations per second.
38void RunTest(TestBase* test, const char *name, float coefficient, bool inverse);
39
40
41class TestBase {
42 public:
43 virtual ~TestBase() {}
44 // Runs the test case n times.
45 virtual bool TestFunc(int n) = 0;
46 // Main entry point into the test.
47 virtual bool Run() = 0;
Alexey Marinichevf50ecb12010-06-14 15:21:41 -070048 virtual const char* Name() const = 0;
Alexey Marinichev9f9b8732010-05-20 19:33:44 -070049};
50
51// Helper class to time glDrawArrays.
52class DrawArraysTestFunc : public TestBase {
53 public:
54 virtual ~DrawArraysTestFunc() {}
55 virtual bool TestFunc(int);
56
57 // Runs the test and reports results in mpixels per second, assuming each
58 // iteration updates the whole window (its size is g_width by g_height).
59 void FillRateTestNormal(const char* name);
60 // Runs the test and reports results in mpixels per second, assuming each
61 // iteration updates a window of width by height pixels.
62 void FillRateTestNormalSubWindow(const char* name, float width, float height);
Alexey Marinichev9f9b8732010-05-20 19:33:44 -070063 // Runs the test three times: with blending on; with depth test enabled and
64 // depth function of GL_NOTEQUAL; with depth function GL_NEVER. Results are
65 // reported as in FillRateTestNormal.
66 void FillRateTestBlendDepth(const char *name);
Alexey Marinichev9f9b8732010-05-20 19:33:44 -070067};
68
69// Helper class to time glDrawElements.
70class DrawElementsTestFunc : public TestBase {
71 public:
72 DrawElementsTestFunc() : count_(0) {}
73 virtual ~DrawElementsTestFunc() {}
74 virtual bool TestFunc(int);
75
76 protected:
77 // Passed to glDrawElements.
78 GLsizei count_;
79};
80
81} // namespace glbench
82
83#endif // BENCH_GL_TESTBASE_H_