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