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