blob: 0d42ca85772a97b0761beaf2f81421ca65de129d [file] [log] [blame]
Alexey Marinichev592b8622010-02-04 15:20:10 -08001// 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
Alexey Marinichev6294a392010-03-02 16:53:36 -08005#include <fcntl.h>
Alexey Marinichev592b8622010-02-04 15:20:10 -08006#include <stdio.h>
7#include <stdlib.h>
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -08008#include <string.h>
Alexey Marinichev6294a392010-03-02 16:53:36 -08009#include <sys/mman.h>
Alexey Marinichev592b8622010-02-04 15:20:10 -080010
Alexey Marinichevaf0b26d2010-02-24 13:03:13 -080011#include "base/logging.h"
12
Alexey Marinichev592b8622010-02-04 15:20:10 -080013#include "main.h"
Alexey Marinichev96e28692010-02-18 16:59:59 -080014#include "shaders.h"
Alexey Marinichev3c199732010-03-11 10:33:35 -080015#include "utils.h"
Alexey Marinichev6294a392010-03-02 16:53:36 -080016#include "yuv2rgb.h"
Alexey Marinichev592b8622010-02-04 15:20:10 -080017
18
Darin Petkovdd314962010-02-18 16:21:29 -080019const int enabled_tests_max = 8;
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -080020const char *enabled_tests[enabled_tests_max+1] = {NULL};
21int seconds_to_run = 0;
22
Alexey Marinicheva991f2b2010-03-11 09:59:51 -080023// Runs Bench on a test function f and prints out results. Bench function
24// returns the slope and bias of a linear model relating the argument passed to
25// f and time it took f to run. Normally the argument of f is assumed to be
26// number of iterations an operation is executed.
27//
28// coefficient is multiplied (if inverse is false) or divided (if inverse is
29// true) by the slope and the result is printed.
30//
31// The test will not run if enabled_tests is nonempty and no string in
32// enabled_tests is contained in name.
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.
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -080040void RunTest(BenchFunc f, const char *name, float coefficient, bool inverse) {
Alexey Marinichev592b8622010-02-04 15:20:10 -080041 float slope;
42 int64_t bias;
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -080043
44 if (enabled_tests[0]) {
45 bool found = false;
46 for (const char **e = enabled_tests; *e; e++)
47 if (strstr(name, *e)) {
48 found = true;
49 break;
50 }
51 if (!found)
52 return;
53 }
54
Alexey Marinichevc24aa232010-02-24 18:15:54 -080055 GLenum err = glGetError();
56 if (err != 0) {
57 printf("# %s failed, glGetError returned 0x%x.\n", name, err);
58 // float() in python will happily parse Nan.
59 printf("%s: Nan\n", name);
60 } else {
Alexey Marinichev8919b6e2010-03-04 16:21:02 -080061 if (Bench(f, &slope, &bias)) {
Alexey Marinicheve5b107a2010-03-10 17:51:04 -080062 printf("%s: %g\n", name, coefficient * (inverse ? 1.f / slope : slope));
Alexey Marinichev8919b6e2010-03-04 16:21:02 -080063 } else {
64 printf("# %s is too slow, returning zero.\n", name);
65 printf("%s: 0\n", name);
66 }
Alexey Marinichevc24aa232010-02-24 18:15:54 -080067 }
Alexey Marinichev592b8622010-02-04 15:20:10 -080068}
69
70static int arg1 = 0;
71static void *arg2 = NULL;
72
Alexey Marinichev592b8622010-02-04 15:20:10 -080073void SwapTestFunc(int iter) {
74 for (int i = 0 ; i < iter; ++i) {
75 SwapBuffers();
76 }
77}
78
79void SwapTest() {
Alexey Marinicheve5b107a2010-03-10 17:51:04 -080080 RunTest(SwapTestFunc, "us_swap_swap", 1.f, false);
Alexey Marinichev592b8622010-02-04 15:20:10 -080081}
82
Alexey Marinichev592b8622010-02-04 15:20:10 -080083void ClearTestFunc(int iter) {
84 GLbitfield mask = arg1;
85 glClear(mask);
86 glFlush(); // Kick GPU as soon as possible
87 for (int i = 0 ; i < iter-1; ++i) {
88 glClear(mask);
89 }
90}
91
92
93void ClearTest() {
94 arg1 = GL_COLOR_BUFFER_BIT;
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -080095 RunTest(ClearTestFunc, "mpixels_sec_clear_color", g_width * g_height, true);
Alexey Marinichev592b8622010-02-04 15:20:10 -080096
97 arg1 = GL_DEPTH_BUFFER_BIT;
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -080098 RunTest(ClearTestFunc, "mpixels_sec_clear_depth", g_width * g_height, true);
Alexey Marinichev592b8622010-02-04 15:20:10 -080099
100 arg1 = GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT;
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -0800101 RunTest(ClearTestFunc, "mpixels_sec_clear_colordepth",
102 g_width * g_height, true);
Alexey Marinichev592b8622010-02-04 15:20:10 -0800103
104 arg1 = GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT;
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -0800105 RunTest(ClearTestFunc, "mpixels_sec_clear_depthstencil",
106 g_width * g_height, true);
Alexey Marinichev592b8622010-02-04 15:20:10 -0800107
108 arg1 = GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT;
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -0800109 RunTest(ClearTestFunc, "mpixels_sec_clear_colordepthstencil",
110 g_width * g_height, true);
Alexey Marinichev592b8622010-02-04 15:20:10 -0800111}
112
113
114GLuint SetupVBO(GLenum target, GLsizeiptr size, const GLvoid *data) {
115 GLuint buf = ~0;
116 glGenBuffers(1, &buf);
117 glBindBuffer(target, buf);
118 glBufferData(target, size, data, GL_STATIC_DRAW);
119
120 return glGetError() == 0 ? buf : 0;
121}
122
123
Alexey Marinichevd4a0f072010-02-09 17:50:12 -0800124GLuint SetupTexture(GLsizei size_log2) {
125 GLsizei size = 1 << size_log2;
Alexey Marinichev592b8622010-02-04 15:20:10 -0800126 GLuint name = ~0;
127 glGenTextures(1, &name);
128 glBindTexture(GL_TEXTURE_2D, name);
129 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
130 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
131
Alexey Marinichevd4a0f072010-02-09 17:50:12 -0800132 unsigned char *pixels = new unsigned char[size * size * 4];
Alexey Marinichev592b8622010-02-04 15:20:10 -0800133 if (!pixels)
134 return 0;
135
Alexey Marinichevd4a0f072010-02-09 17:50:12 -0800136 for (GLint level = 0; size > 0; level++, size /= 2) {
137 unsigned char *p = pixels;
138 for (int i = 0; i < size; i++) {
139 for (int j = 0; j < size; j++) {
140 *p++ = level %3 != 0 ? (i ^ j) << level : 0;
141 *p++ = level %3 != 1 ? (i ^ j) << level : 0;
142 *p++ = level %3 != 2 ? (i ^ j) << level : 0;
143 *p++ = 255;
144 }
Alexey Marinichev592b8622010-02-04 15:20:10 -0800145 }
Alexey Marinichevd4a0f072010-02-09 17:50:12 -0800146 if (size == 1) {
147 unsigned char *p = pixels;
148 *p++ = 255;
149 *p++ = 255;
150 *p++ = 255;
151 *p++ = 255;
152 }
153 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0,
154 GL_RGBA, GL_UNSIGNED_BYTE, pixels);
Alexey Marinichev592b8622010-02-04 15:20:10 -0800155 }
Alexey Marinichev592b8622010-02-04 15:20:10 -0800156 delete[] pixels;
Alexey Marinichev592b8622010-02-04 15:20:10 -0800157 return name;
158}
159
160
Alexey Marinichev96e28692010-02-18 16:59:59 -0800161static void DrawArraysTestFunc(int iter);
Alexey Marinichevd4a0f072010-02-09 17:50:12 -0800162static void FillRateTestNormal(const char *name, float coeff=1.f);
163static void FillRateTestBlendDepth(const char *name);
Alexey Marinichev592b8622010-02-04 15:20:10 -0800164
165void FillRateTest() {
166 glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
167 glDisable(GL_DEPTH_TEST);
168 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
169
Alexey Marinichevd4a0f072010-02-09 17:50:12 -0800170 GLfloat buffer_vertex[8] = {
Alexey Marinichev592b8622010-02-04 15:20:10 -0800171 -1.f, -1.f,
172 1.f, -1.f,
173 -1.f, 1.f,
174 1.f, 1.f,
175 };
Alexey Marinichevd4a0f072010-02-09 17:50:12 -0800176 GLfloat buffer_texture[8] = {
177 0.f, 0.f,
178 1.f, 0.f,
179 0.f, 1.f,
180 1.f, 1.f,
181 };
Alexey Marinichev592b8622010-02-04 15:20:10 -0800182 glEnableClientState(GL_VERTEX_ARRAY);
183
Alexey Marinichevd4a0f072010-02-09 17:50:12 -0800184 GLuint vbo_vertex = SetupVBO(GL_ARRAY_BUFFER,
185 sizeof(buffer_vertex), buffer_vertex);
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -0800186 if (!vbo_vertex)
187 printf("# Not Using VBO!\n");
Alexey Marinichevd4a0f072010-02-09 17:50:12 -0800188 glVertexPointer(2, GL_FLOAT, 0, vbo_vertex ? 0 : buffer_vertex);
189
190 GLuint vbo_texture = SetupVBO(GL_ARRAY_BUFFER,
191 sizeof(buffer_texture), buffer_texture);
192 glTexCoordPointer(2, GL_FLOAT, 0, vbo_texture ? 0 : buffer_texture);
Alexey Marinichev592b8622010-02-04 15:20:10 -0800193
194 glColor4f(1.f, 0.f, 0.f, 1.f);
Alexey Marinichevd4a0f072010-02-09 17:50:12 -0800195 FillRateTestNormal("fill_solid");
196 FillRateTestBlendDepth("fill_solid");
Alexey Marinichev592b8622010-02-04 15:20:10 -0800197
198 glColor4f(1.f, 1.f, 1.f, 1.f);
199 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
200 glEnable(GL_TEXTURE_2D);
201
Alexey Marinichevd4a0f072010-02-09 17:50:12 -0800202 GLuint texture = SetupTexture(9);
203 FillRateTestNormal("fill_tex_nearest");
Alexey Marinichev592b8622010-02-04 15:20:10 -0800204
205 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
206 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
Alexey Marinichevd4a0f072010-02-09 17:50:12 -0800207 FillRateTestNormal("fill_tex_bilinear");
Alexey Marinichev592b8622010-02-04 15:20:10 -0800208
Alexey Marinichevd4a0f072010-02-09 17:50:12 -0800209 // lod = 0.5
210 glScalef(0.7071f, 0.7071f, 1.f);
211 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
212 GL_LINEAR_MIPMAP_NEAREST);
213 FillRateTestNormal("fill_tex_trilinear_nearest_05", 0.7071f * 0.7071f);
214
215 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
216 GL_LINEAR_MIPMAP_LINEAR);
217 FillRateTestNormal("fill_tex_trilinear_linear_05", 0.7071f * 0.7071f);
218
219 // lod = 0.4
220 glLoadIdentity();
221 glScalef(0.758f, 0.758f, 1.f);
222 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
223 GL_LINEAR_MIPMAP_LINEAR);
224 FillRateTestNormal("fill_tex_trilinear_linear_04", 0.758f * 0.758f);
225
226 // lod = 0.1
227 glLoadIdentity();
228 glScalef(0.933f, 0.933f, 1.f);
229 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
230 GL_LINEAR_MIPMAP_LINEAR);
231 FillRateTestNormal("fill_tex_trilinear_linear_01", 0.933f * 0.933f);
232
233 glDeleteBuffers(1, &vbo_vertex);
234 glDeleteBuffers(1, &vbo_texture);
Alexey Marinichev592b8622010-02-04 15:20:10 -0800235 glDeleteTextures(1, &texture);
236}
237
238
Alexey Marinichevd4a0f072010-02-09 17:50:12 -0800239static void FillRateTestNormal(const char *name, float coeff) {
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -0800240 const int buffer_len = 64;
241 char buffer[buffer_len];
242 snprintf(buffer, buffer_len, "mpixels_sec_%s", name);
Alexey Marinichev96e28692010-02-18 16:59:59 -0800243 RunTest(DrawArraysTestFunc, buffer, coeff * g_width * g_height, true);
Alexey Marinichevd4a0f072010-02-09 17:50:12 -0800244}
Alexey Marinichev592b8622010-02-04 15:20:10 -0800245
Alexey Marinichevd4a0f072010-02-09 17:50:12 -0800246static void FillRateTestBlendDepth(const char *name) {
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -0800247 const int buffer_len = 64;
248 char buffer[buffer_len];
249
Alexey Marinichev6d014842010-02-10 19:21:39 -0800250 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
251 glEnable(GL_BLEND);
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -0800252 snprintf(buffer, buffer_len, "mpixels_sec_%s_blended", name);
Alexey Marinichev96e28692010-02-18 16:59:59 -0800253 RunTest(DrawArraysTestFunc, buffer, g_width * g_height, true);
Alexey Marinichev6d014842010-02-10 19:21:39 -0800254 glDisable(GL_BLEND);
Alexey Marinichev592b8622010-02-04 15:20:10 -0800255
Alexey Marinichev6d014842010-02-10 19:21:39 -0800256 glEnable(GL_DEPTH_TEST);
257 glDepthFunc(GL_NOTEQUAL);
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -0800258 snprintf(buffer, buffer_len, "mpixels_sec_%s_depth_neq", name);
Alexey Marinichev96e28692010-02-18 16:59:59 -0800259 RunTest(DrawArraysTestFunc, buffer, g_width * g_height, true);
Alexey Marinichev6d014842010-02-10 19:21:39 -0800260 glDepthFunc(GL_NEVER);
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -0800261 snprintf(buffer, buffer_len, "mpixels_sec_%s_depth_never", name);
Alexey Marinichev96e28692010-02-18 16:59:59 -0800262 RunTest(DrawArraysTestFunc, buffer, g_width * g_height, true);
Alexey Marinichev6d014842010-02-10 19:21:39 -0800263 glDisable(GL_DEPTH_TEST);
Alexey Marinichev592b8622010-02-04 15:20:10 -0800264}
265
266
Alexey Marinichev96e28692010-02-18 16:59:59 -0800267static void DrawArraysTestFunc(int iter) {
Alexey Marinichev592b8622010-02-04 15:20:10 -0800268 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
269 glFlush();
270 for (int i = 0; i < iter-1; ++i) {
271 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
272 }
273}
274
275
Alexey Marinichev96e28692010-02-18 16:59:59 -0800276static void DrawElementsTestFunc(int iter) {
Alexey Marinichev592b8622010-02-04 15:20:10 -0800277 glDrawElements(GL_TRIANGLES, arg1, GL_UNSIGNED_INT, arg2);
278 glFlush();
279 for (int i = 0 ; i < iter-1; ++i) {
280 glDrawElements(GL_TRIANGLES, arg1, GL_UNSIGNED_INT, arg2);
281 }
282}
283
Alexey Marinichev6d014842010-02-10 19:21:39 -0800284// Generates a tautological lattice.
Alexey Marinichevbf88d1f2010-02-12 12:49:16 -0800285static void CreateLattice(GLfloat **vertices, GLsizeiptr *size,
286 GLfloat size_x, GLfloat size_y,
Alexey Marinichev6d014842010-02-10 19:21:39 -0800287 int width, int height)
288{
Alexey Marinichevbf88d1f2010-02-12 12:49:16 -0800289 GLfloat *vptr = *vertices = new GLfloat[2 * (width + 1) * (height + 1)];
Alexey Marinichev6d014842010-02-10 19:21:39 -0800290 for (int j = 0; j <= height; j++) {
291 for (int i = 0; i <= width; i++) {
Alexey Marinichevbf88d1f2010-02-12 12:49:16 -0800292 *vptr++ = i * size_x;
293 *vptr++ = j * size_y;
Alexey Marinichev6d014842010-02-10 19:21:39 -0800294 }
295 }
Alexey Marinichevbf88d1f2010-02-12 12:49:16 -0800296 *size = (vptr - *vertices) * sizeof(GLfloat);
Alexey Marinichev6d014842010-02-10 19:21:39 -0800297}
298
Alexey Marinichev592b8622010-02-04 15:20:10 -0800299// Generates a mesh of 2*width*height triangles. The ratio of front facing to
300// back facing triangles is culled_ratio/RAND_MAX. Returns the number of
301// vertices in the mesh.
Alexey Marinichev6d014842010-02-10 19:21:39 -0800302static int CreateMesh(GLuint **indices, GLsizeiptr *size,
Alexey Marinichev592b8622010-02-04 15:20:10 -0800303 int width, int height, int culled_ratio) {
304 srand(0);
305
Alexey Marinichev6d014842010-02-10 19:21:39 -0800306 GLuint *iptr = *indices = new GLuint[2 * 3 * (width * height)];
Alexey Marinichev592b8622010-02-04 15:20:10 -0800307 const int swath_height = 4;
Alexey Marinichevaf0b26d2010-02-24 13:03:13 -0800308
309 CHECK(width % swath_height == 0 && height % swath_height == 0);
310
Alexey Marinichevbf88d1f2010-02-12 12:49:16 -0800311 for (int j = 0; j < height; j += swath_height) {
Alexey Marinichev592b8622010-02-04 15:20:10 -0800312 for (int i = 0; i < width; i++) {
313 for (int j2 = 0; j2 < swath_height; j2++) {
Alexey Marinichev6d014842010-02-10 19:21:39 -0800314 GLuint first = (j + j2) * (width + 1) + i;
Alexey Marinichev592b8622010-02-04 15:20:10 -0800315 GLuint second = first + 1;
Alexey Marinichev6d014842010-02-10 19:21:39 -0800316 GLuint third = first + (width + 1);
Alexey Marinichev592b8622010-02-04 15:20:10 -0800317 GLuint fourth = third + 1;
318
319 bool flag = rand() < culled_ratio;
320 *iptr++ = first;
321 *iptr++ = flag ? second : third;
322 *iptr++ = flag ? third : second;
323
324 *iptr++ = fourth;
325 *iptr++ = flag ? third : second;
326 *iptr++ = flag ? second : third;
327 }
328 }
329 }
Alexey Marinichev6d014842010-02-10 19:21:39 -0800330 *size = (iptr - *indices) * sizeof(GLuint);
Alexey Marinichev592b8622010-02-04 15:20:10 -0800331
Alexey Marinichev6d014842010-02-10 19:21:39 -0800332 return iptr - *indices;
Alexey Marinichev592b8622010-02-04 15:20:10 -0800333}
334
335void TriangleSetupTest() {
336 glViewport(-g_width, -g_height, g_width*2, g_height*2);
Alexey Marinichev592b8622010-02-04 15:20:10 -0800337
338 // Larger meshes make this test too slow for devices that do 1 mtri/sec.
339 GLint width = 64;
340 GLint height = 64;
341
Alexey Marinichevbf88d1f2010-02-12 12:49:16 -0800342 GLfloat *vertices = NULL;
Alexey Marinichev6d014842010-02-10 19:21:39 -0800343 GLsizeiptr vertex_buffer_size = 0;
Alexey Marinichevbf88d1f2010-02-12 12:49:16 -0800344 CreateLattice(&vertices, &vertex_buffer_size, 1.f / g_width, 1.f / g_height,
345 width, height);
Alexey Marinichev6d014842010-02-10 19:21:39 -0800346 GLuint vertex_buffer = SetupVBO(GL_ARRAY_BUFFER,
347 vertex_buffer_size, vertices);
Alexey Marinichevbf88d1f2010-02-12 12:49:16 -0800348 glVertexPointer(2, GL_FLOAT, 0, vertex_buffer != 0 ? 0 : vertices);
Alexey Marinichev96e28692010-02-18 16:59:59 -0800349 glEnableClientState(GL_VERTEX_ARRAY);
Alexey Marinichev6d014842010-02-10 19:21:39 -0800350
351 GLuint *indices = NULL;
352 GLuint index_buffer = 0;
353 GLsizeiptr index_buffer_size = 0;
354
Alexey Marinichev6d014842010-02-10 19:21:39 -0800355 {
356 arg1 = CreateMesh(&indices, &index_buffer_size, width, height, 0);
357
Alexey Marinichev6d014842010-02-10 19:21:39 -0800358 index_buffer = SetupVBO(GL_ELEMENT_ARRAY_BUFFER,
359 index_buffer_size, indices);
360 arg2 = index_buffer ? 0 : indices;
361
Alexey Marinichev96e28692010-02-18 16:59:59 -0800362 RunTest(DrawElementsTestFunc, "mtri_sec_triangle_setup", arg1 / 3, true);
Alexey Marinichev6d014842010-02-10 19:21:39 -0800363 glEnable(GL_CULL_FACE);
Alexey Marinichev96e28692010-02-18 16:59:59 -0800364 RunTest(DrawElementsTestFunc, "mtri_sec_triangle_setup_all_culled",
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -0800365 arg1 / 3, true);
Alexey Marinichev96e28692010-02-18 16:59:59 -0800366 glDisable(GL_CULL_FACE);
Alexey Marinichev6d014842010-02-10 19:21:39 -0800367
Alexey Marinichev6d014842010-02-10 19:21:39 -0800368 glDeleteBuffers(1, &index_buffer);
Alexey Marinichev96e28692010-02-18 16:59:59 -0800369 delete[] indices;
Alexey Marinichev592b8622010-02-04 15:20:10 -0800370 }
371
Alexey Marinichev6d014842010-02-10 19:21:39 -0800372 {
373 glColor4f(0.f, 1.f, 1.f, 1.f);
374 arg1 = CreateMesh(&indices, &index_buffer_size, width, height,
375 RAND_MAX / 2);
Alexey Marinichev592b8622010-02-04 15:20:10 -0800376
Alexey Marinichev6d014842010-02-10 19:21:39 -0800377 index_buffer = SetupVBO(GL_ELEMENT_ARRAY_BUFFER,
378 index_buffer_size, indices);
379 arg2 = index_buffer ? 0 : indices;
Alexey Marinichev592b8622010-02-04 15:20:10 -0800380
Alexey Marinichev96e28692010-02-18 16:59:59 -0800381 glEnable(GL_CULL_FACE);
382 RunTest(DrawElementsTestFunc, "mtri_sec_triangle_setup_half_culled",
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -0800383 arg1 / 3, true);
Alexey Marinichev592b8622010-02-04 15:20:10 -0800384
Alexey Marinichev6d014842010-02-10 19:21:39 -0800385 glDeleteBuffers(1, &index_buffer);
Alexey Marinichev96e28692010-02-18 16:59:59 -0800386 delete[] indices;
Alexey Marinichev6d014842010-02-10 19:21:39 -0800387 }
Alexey Marinichev592b8622010-02-04 15:20:10 -0800388
Alexey Marinichev6d014842010-02-10 19:21:39 -0800389 glDeleteBuffers(1, &vertex_buffer);
Alexey Marinichev592b8622010-02-04 15:20:10 -0800390 delete[] vertices;
Alexey Marinichev592b8622010-02-04 15:20:10 -0800391}
392
393
Alexey Marinichevaf0b26d2010-02-24 13:03:13 -0800394void AttributeFetchShaderTest() {
Alexey Marinichev96e28692010-02-18 16:59:59 -0800395 GLint width = 64;
396 GLint height = 64;
397
398 glViewport(-g_width, -g_height, g_width*2, g_height*2);
399
400 GLfloat *vertices = NULL;
401 GLsizeiptr vertex_buffer_size = 0;
402 CreateLattice(&vertices, &vertex_buffer_size, 1.f / g_width, 1.f / g_height,
403 width, height);
404 GLuint vertex_buffer = SetupVBO(GL_ARRAY_BUFFER,
405 vertex_buffer_size, vertices);
406
407 GLuint *indices = NULL;
408 GLuint index_buffer = 0;
409 GLsizeiptr index_buffer_size = 0;
410
411 // Everything will be back-face culled.
412 arg1 = CreateMesh(&indices, &index_buffer_size, width, height, 0);
413 index_buffer = SetupVBO(GL_ELEMENT_ARRAY_BUFFER,
414 index_buffer_size, indices);
415
416 glEnable(GL_CULL_FACE);
417
418 GLuint vertex_buffers[8];
419 for (GLuint i = 0; i < sizeof(vertex_buffers)/sizeof(vertex_buffers[0]); i++)
420 vertex_buffers[i] = vertex_buffer;
421
422 ShaderProgram program = AttributeFetchShaderProgram(1, vertex_buffers);
423 RunTest(DrawElementsTestFunc,
424 "mvtx_sec_attribute_fetch_shader", arg1, true);
Alexey Marinichev3c199732010-03-11 10:33:35 -0800425 glDeleteProgram(program);
Alexey Marinichev96e28692010-02-18 16:59:59 -0800426
Alexey Marinichev9b818772010-02-23 12:07:48 -0800427 program = AttributeFetchShaderProgram(2, vertex_buffers);
Alexey Marinichev96e28692010-02-18 16:59:59 -0800428 RunTest(DrawElementsTestFunc,
429 "mvtx_sec_attribute_fetch_shader_2_attr", arg1, true);
Alexey Marinichev3c199732010-03-11 10:33:35 -0800430 glDeleteProgram(program);
Alexey Marinichev96e28692010-02-18 16:59:59 -0800431
Alexey Marinichev9b818772010-02-23 12:07:48 -0800432 program = AttributeFetchShaderProgram(4, vertex_buffers);
Alexey Marinichev96e28692010-02-18 16:59:59 -0800433 RunTest(DrawElementsTestFunc,
434 "mvtx_sec_attribute_fetch_shader_4_attr", arg1, true);
Alexey Marinichev3c199732010-03-11 10:33:35 -0800435 glDeleteProgram(program);
Alexey Marinichev96e28692010-02-18 16:59:59 -0800436
Alexey Marinichev9b818772010-02-23 12:07:48 -0800437 program = AttributeFetchShaderProgram(8, vertex_buffers);
Alexey Marinichev96e28692010-02-18 16:59:59 -0800438 RunTest(DrawElementsTestFunc,
439 "mvtx_sec_attribute_fetch_shader_8_attr", arg1, true);
Alexey Marinichev3c199732010-03-11 10:33:35 -0800440 glDeleteProgram(program);
Alexey Marinichev96e28692010-02-18 16:59:59 -0800441
442 glDeleteBuffers(1, &index_buffer);
443 delete[] indices;
444
445 glDeleteBuffers(1, &vertex_buffer);
446 delete[] vertices;
447}
448
Alexey Marinichevaf0b26d2010-02-24 13:03:13 -0800449
Alexey Marinichevc24aa232010-02-24 18:15:54 -0800450void VaryingsAndDdxyShaderTest() {
Alexey Marinichevaf0b26d2010-02-24 13:03:13 -0800451 glViewport(-g_width, -g_height, g_width*2, g_height*2);
452
453 const int c = 4;
454 GLfloat *vertices = NULL;
455 GLsizeiptr vertex_buffer_size = 0;
456 CreateLattice(&vertices, &vertex_buffer_size, 1.f / c, 1.f / c, c, c);
457 GLuint vertex_buffer = SetupVBO(GL_ARRAY_BUFFER,
458 vertex_buffer_size, vertices);
459
460 GLuint *indices = NULL;
461 GLuint index_buffer = 0;
462 GLsizeiptr index_buffer_size = 0;
463
464 arg1 = CreateMesh(&indices, &index_buffer_size, c, c, 0);
465 index_buffer = SetupVBO(GL_ELEMENT_ARRAY_BUFFER,
466 index_buffer_size, indices);
467
468 ShaderProgram program = VaryingsShaderProgram(1, vertex_buffer);
469 RunTest(DrawElementsTestFunc,
470 "mpixels_sec_varyings_shader_1", g_width * g_height, true);
Alexey Marinichev3c199732010-03-11 10:33:35 -0800471 glDeleteProgram(program);
Alexey Marinichevaf0b26d2010-02-24 13:03:13 -0800472
473 program = VaryingsShaderProgram(2, vertex_buffer);
474 RunTest(DrawElementsTestFunc,
475 "mpixels_sec_varyings_shader_2", g_width * g_height, true);
Alexey Marinichev3c199732010-03-11 10:33:35 -0800476 glDeleteProgram(program);
Alexey Marinichevaf0b26d2010-02-24 13:03:13 -0800477
478 program = VaryingsShaderProgram(4, vertex_buffer);
479 RunTest(DrawElementsTestFunc,
480 "mpixels_sec_varyings_shader_4", g_width * g_height, true);
Alexey Marinichev3c199732010-03-11 10:33:35 -0800481 glDeleteProgram(program);
Alexey Marinichevaf0b26d2010-02-24 13:03:13 -0800482
483 program = VaryingsShaderProgram(8, vertex_buffer);
484 RunTest(DrawElementsTestFunc,
485 "mpixels_sec_varyings_shader_8", g_width * g_height, true);
Alexey Marinichev3c199732010-03-11 10:33:35 -0800486 glDeleteProgram(program);
Alexey Marinichevaf0b26d2010-02-24 13:03:13 -0800487
Alexey Marinichevc24aa232010-02-24 18:15:54 -0800488 program = DdxDdyShaderProgram(true, vertex_buffer);
489 RunTest(DrawElementsTestFunc,
490 "mpixels_sec_ddx_shader", g_width * g_height, true);
Alexey Marinichev3c199732010-03-11 10:33:35 -0800491 glDeleteProgram(program);
Alexey Marinichevc24aa232010-02-24 18:15:54 -0800492
493 program = DdxDdyShaderProgram(false, vertex_buffer);
494 RunTest(DrawElementsTestFunc,
495 "mpixels_sec_ddy_shader", g_width * g_height, true);
Alexey Marinichev3c199732010-03-11 10:33:35 -0800496 glDeleteProgram(program);
Alexey Marinichevc24aa232010-02-24 18:15:54 -0800497
Alexey Marinichevaf0b26d2010-02-24 13:03:13 -0800498 glDeleteBuffers(1, &index_buffer);
499 delete[] indices;
500
501 glDeleteBuffers(1, &vertex_buffer);
502 delete[] vertices;
503}
504
Alexey Marinichev8919b6e2010-03-04 16:21:02 -0800505
506void YuvToRgbShaderTestHelper(int type, const char *name) {
Alexey Marinichev6294a392010-03-02 16:53:36 -0800507 size_t size = 0;
Alexey Marinichev6dfea312010-03-03 14:53:12 -0800508 GLuint texture[2];
Alexey Marinichev6294a392010-03-02 16:53:36 -0800509 ShaderProgram program = 0;
510 GLuint vertex_buffer = 0;
511 GLfloat vertices[8] = {
512 0.f, 0.f,
513 1.f, 0.f,
Alexey Marinicheve5b107a2010-03-10 17:51:04 -0800514 0.f, 1.f,
515 1.f, 1.f,
Alexey Marinichev6294a392010-03-02 16:53:36 -0800516 };
Alexey Marinichev6dfea312010-03-03 14:53:12 -0800517 char evenodd[2] = {0, 255};
Alexey Marinicheve5b107a2010-03-10 17:51:04 -0800518 const int pixel_height = YUV2RGB_HEIGHT * 2 / 3;
Alexey Marinichev6294a392010-03-02 16:53:36 -0800519
520 char *pixels = static_cast<char *>(MmapFile(YUV2RGB_NAME, &size));
521 if (!pixels) {
522 printf("# Could not open image file: %s\n", YUV2RGB_NAME);
523 goto done;
524 }
525 if (size != YUV2RGB_SIZE) {
Alexey Marinichev6dfea312010-03-03 14:53:12 -0800526 printf("# Image file of wrong size, got %d, expected %d\n",
527 static_cast<int>(size), YUV2RGB_SIZE);
Alexey Marinichev6294a392010-03-02 16:53:36 -0800528 goto done;
529 }
530
Alexey Marinichev6dfea312010-03-03 14:53:12 -0800531 glGenTextures(2, texture);
532 glActiveTexture(GL_TEXTURE0);
533 glBindTexture(GL_TEXTURE_2D, texture[0]);
Alexey Marinichev6294a392010-03-02 16:53:36 -0800534 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
535 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
536 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, YUV2RGB_WIDTH, YUV2RGB_HEIGHT,
537 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, pixels);
538
Alexey Marinichev6dfea312010-03-03 14:53:12 -0800539 glActiveTexture(GL_TEXTURE1);
540 glBindTexture(GL_TEXTURE_2D, texture[1]);
541 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
542 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
543 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 2, 1,
544 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, evenodd);
545
Alexey Marinicheve5b107a2010-03-10 17:51:04 -0800546 glViewport(-YUV2RGB_WIDTH, -pixel_height, YUV2RGB_WIDTH*2, pixel_height * 2);
Alexey Marinichev6294a392010-03-02 16:53:36 -0800547 vertex_buffer = SetupVBO(GL_ARRAY_BUFFER, sizeof(vertices), vertices);
548
Alexey Marinichev8919b6e2010-03-04 16:21:02 -0800549 program = YuvToRgbShaderProgram(type, vertex_buffer,
Alexey Marinicheve5b107a2010-03-10 17:51:04 -0800550 YUV2RGB_WIDTH, pixel_height);
551
552 if (program) {
553 float coeff = 1.f *
554 (YUV2RGB_WIDTH < g_width ?
555 static_cast<float>(YUV2RGB_WIDTH) / g_width : 1.f) *
556 (pixel_height < g_height ?
557 static_cast<float>(pixel_height) / g_height : 1.f);
558 FillRateTestNormal(name, coeff);
559 } else {
Alexey Marinichev6dfea312010-03-03 14:53:12 -0800560 printf("# Could not set up YUV shader.\n");
Alexey Marinicheve5b107a2010-03-10 17:51:04 -0800561 }
Alexey Marinichev6294a392010-03-02 16:53:36 -0800562
563done:
Alexey Marinichev3c199732010-03-11 10:33:35 -0800564 glDeleteProgram(program);
Alexey Marinichev6dfea312010-03-03 14:53:12 -0800565 glDeleteTextures(2, texture);
566 glDeleteBuffers(1, &vertex_buffer);
Alexey Marinichev6294a392010-03-02 16:53:36 -0800567 munmap(pixels, size);
568}
569
Alexey Marinichev8919b6e2010-03-04 16:21:02 -0800570void YuvToRgbShaderTest1() {
571 YuvToRgbShaderTestHelper(1, "yuv_shader_1");
572}
573
574void YuvToRgbShaderTest2() {
575 YuvToRgbShaderTestHelper(2, "yuv_shader_2");
576}
577
Matthew Papakipos1efe8bb2010-03-24 13:57:49 -0700578static GLuint compositing_textures[5];
579static uint32_t texture_base[WINDOW_HEIGHT*WINDOW_WIDTH];
580static uint32_t texture_update[WINDOW_HEIGHT*WINDOW_WIDTH];
581static ShaderProgram compositing_background_program = 0;
582static ShaderProgram compositing_foreground_program = 0;
583
584void InitBaseTexture() {
585 for (int y = 0; y < WINDOW_HEIGHT; y++) {
586 for (int x = 0; x < WINDOW_WIDTH; x++) {
587 // This color is gray, half alpha.
588 texture_base[y*WINDOW_WIDTH+x] = 0x80808080;
589 }
590 }
591}
592
593// UpdateTexture simulates Chrome updating tab contents.
594// We cause a bunch of read and write cpu memory bandwidth.
595// It's a very rough approximation.
596void UpdateTexture() {
597 memcpy(texture_update, texture_base, sizeof(texture_base));
598}
599
600void LoadTexture() {
601 // Use GL_RGBA for compatibility with GLES2.0.
602 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
603 WINDOW_WIDTH, WINDOW_HEIGHT, 0,
604 GL_RGBA, GL_UNSIGNED_BYTE, texture_update);
605}
606
607// Test how fast we can do full-screen compositing of images
608// continuously updated from the CPU.
609// This tests both GPU compositing performance and also
610// CPU -> GPU data transfer speed.
611// It is a basic perf test to make sure we have enough performance
612// to run a compositing window manager.
613void CompositingTestFunc(int iter) {
614 for (int i = 0 ; i < iter; ++i) {
615 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
616
617 // Draw the background
618 glDisable(GL_BLEND);
619 glDisable(GL_DEPTH_TEST);
620 // We have to blend three textures, but we use multi-texture for this
621 // blending, not fb blend, to avoid the external memory traffic
622 glActiveTexture(GL_TEXTURE0);
623 glBindTexture(GL_TEXTURE_2D, compositing_textures[0]);
624 glActiveTexture(GL_TEXTURE1);
625 glBindTexture(GL_TEXTURE_2D, compositing_textures[1]);
626 glActiveTexture(GL_TEXTURE2);
627 glBindTexture(GL_TEXTURE_2D, compositing_textures[2]);
628 // Set up the texture coordinate arrays
629 glClientActiveTexture(GL_TEXTURE0);
630 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
631 glClientActiveTexture(GL_TEXTURE1);
632 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
633 glClientActiveTexture(GL_TEXTURE2);
634 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
635 // Use the right shader
636 glUseProgram(compositing_background_program);
637 // Draw the quad
638 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
639
640 // Set up one texture coordinate array
641 glClientActiveTexture(GL_TEXTURE0);
642 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
643 glClientActiveTexture(GL_TEXTURE1);
644 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
645 glClientActiveTexture(GL_TEXTURE2);
646 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
647 // Use the right shader
648 glUseProgram(compositing_foreground_program);
649
650 // Compositing is blending, so we shall blend.
651 glEnable(GL_BLEND);
652 // Depth test is on for window occlusion
653 glEnable(GL_DEPTH_TEST);
654
655 // Draw window number one
656 // This update acts like a chrome webkit sw rendering update.
657 glActiveTexture(GL_TEXTURE0);
658 glBindTexture(GL_TEXTURE_2D, compositing_textures[3]);
659 UpdateTexture();
660 // TODO(papakipos): this LoadTexture is likely doing more CPU memory copies
661 // than we would like.
662 LoadTexture();
663 // TODO(papakipos): add color interpolation here, and modulate
664 // texture against it.
665 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
666
667 // Draw window number two
668 // This is a static window, so we don't update it.
669 glActiveTexture(GL_TEXTURE0);
670 glBindTexture(GL_TEXTURE_2D, compositing_textures[4]);
671 // TODO(papakipos): add color interpolation here, and modulate
672 // texture against it.
673 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
674 }
675}
676
677void InitializeCompositing() {
678 InitBaseTexture();
679
680 glClearColor(0.f, 0.f, 0.f, 0.f);
681 glDisable(GL_DEPTH_TEST);
682 glDisable(GL_BLEND);
683 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
684 glDepthFunc(GL_LEQUAL);
685
686 glGenTextures(5, compositing_textures);
687 glActiveTexture(GL_TEXTURE0);
688 for (int i = 0; i < 5; i++) {
689 glBindTexture(GL_TEXTURE_2D, compositing_textures[i]);
690 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
691 GL_LINEAR);
692 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
693 GL_LINEAR);
694 }
695
696 glColor4f(1.f, 1.f, 1.f, 1.f);
697
698 // Set up the vertex arrays for drawing textured quads later on.
699 glEnableClientState(GL_VERTEX_ARRAY);
700 GLfloat buffer_vertex[8] = {
701 -1.f, -1.f,
702 1.f, -1.f,
703 -1.f, 1.f,
704 1.f, 1.f,
705 };
706 GLuint vbo_vertex = SetupVBO(GL_ARRAY_BUFFER,
707 sizeof(buffer_vertex), buffer_vertex);
708 if (!vbo_vertex)
709 printf("# Not Using VBO!\n");
710 glVertexPointer(2, GL_FLOAT, 0, vbo_vertex ? 0 : buffer_vertex);
711
712 GLfloat buffer_texture[8] = {
713 0.f, 0.f,
714 1.f, 0.f,
715 0.f, 1.f,
716 1.f, 1.f,
717 };
718 GLuint vbo_texture = SetupVBO(GL_ARRAY_BUFFER,
719 sizeof(buffer_texture), buffer_texture);
720 for (int i = 0; i < 3; i++) {
721 glClientActiveTexture(GL_TEXTURE0 + i);
722 glTexCoordPointer(2, GL_FLOAT, 0, vbo_texture ? 0 : buffer_texture);
723 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
724 }
725
726 // Set up the static background textures.
727 UpdateTexture();
728 UpdateTexture();
729 UpdateTexture();
730 // Load these textures into bound texture ids and keep using them
731 // from there to avoid having to reload this texture every frame
732 glActiveTexture(GL_TEXTURE0);
733 glBindTexture(GL_TEXTURE_2D, compositing_textures[0]);
734 LoadTexture();
735 glActiveTexture(GL_TEXTURE1);
736 glBindTexture(GL_TEXTURE_2D, compositing_textures[1]);
737 LoadTexture();
738 glActiveTexture(GL_TEXTURE2);
739 glBindTexture(GL_TEXTURE_2D, compositing_textures[2]);
740 LoadTexture();
741
742 glActiveTexture(GL_TEXTURE0);
743 glBindTexture(GL_TEXTURE_2D, compositing_textures[3]);
744 UpdateTexture();
745 LoadTexture();
746
747 glActiveTexture(GL_TEXTURE0);
748 glBindTexture(GL_TEXTURE_2D, compositing_textures[4]);
749 UpdateTexture();
750 LoadTexture();
751
752 // Set up vertex & fragment shaders.
753 compositing_background_program =
754 TripleTextureBlendShaderProgram(vbo_vertex,
755 vbo_texture, vbo_texture, vbo_texture);
756 compositing_foreground_program =
757 BasicTextureShaderProgram(vbo_vertex, vbo_texture);
758 if ((!compositing_background_program) ||
759 (!compositing_foreground_program)) {
760 printf("# Could not set up compositing shader.\n");
761 }
762
763 if (!vbo_vertex)
764 printf("# Not Using VBO!\n");
765 glVertexPointer(2, GL_FLOAT, 0, vbo_vertex ? 0 : buffer_vertex);
766}
767
768void TeardownCompositing() {
769 glDeleteProgram(compositing_background_program);
770 glDeleteProgram(compositing_foreground_program);
771}
772
773// Notes on the window manager compositing test:
774// Depth
775// Depth complexity = 3: background, active window, static window
776// Background: may be a tex-blend of three images (2.5d effect)
777// The windows -- at most two, fullscreen
778// Depth test is on, passing most of the time.
779// A lot of texture min-filtering -- not modelled
780// One of the two windows is getting live browser frame updates -- not mod
781// The live window runs at x/2 and y/2 size -- not modelled
782// The two windows are modulated by color interpolation to get gradient
783static float screen_scale_factor = (1e6f*
784 (WINDOW_WIDTH*WINDOW_HEIGHT)/
785 (1280.f*768));
786
787void WindowManagerCompositingTest() {
788 InitializeCompositing();
789 RunTest(CompositingTestFunc, "1280x768_fps_compositing",
790 screen_scale_factor, true);
791 TeardownCompositing();
792}
793
794void NoFillWindowManagerCompositingTest() {
795 glScissor(0, 0, 1, 1);
796 glEnable(GL_SCISSOR_TEST);
797 InitializeCompositing();
798 RunTest(CompositingTestFunc, "1280x768_fps_no_fill_compositing",
799 screen_scale_factor, true);
800 TeardownCompositing();
801}
Alexey Marinichev6294a392010-03-02 16:53:36 -0800802
Alexey Marinichev3c199732010-03-11 10:33:35 -0800803// TODO: get resources file from a command line option or something.
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -0800804// TODO: use proper command line parsing library.
805static void ParseArgs(int argc, char *argv[]) {
806 const char **enabled_tests_ptr = enabled_tests;
807 bool test_name_arg = false;
808 bool duration_arg = false;
809 for (int i = 0; i < argc; i++) {
810 if (test_name_arg) {
811 test_name_arg = false;
812 *enabled_tests_ptr++ = argv[i];
813 if (enabled_tests_ptr - enabled_tests >= enabled_tests_max)
814 break;
815 } else if (duration_arg) {
816 duration_arg = false;
817 seconds_to_run = atoi(argv[i]);
818 } else if (strcmp("-t", argv[i]) == 0) {
819 test_name_arg = true;
820 } else if (strcmp("-d", argv[i]) == 0) {
821 duration_arg = true;
822 }
823 }
824 *enabled_tests_ptr++ = NULL;
825}
826
827
Alexey Marinichev592b8622010-02-04 15:20:10 -0800828int main(int argc, char *argv[]) {
Antoine Labourec7eb532010-03-12 11:01:34 -0800829 SetBasePathFromArgv0(argv[0], "src");
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -0800830 ParseArgs(argc, argv);
Alexey Marinichev592b8622010-02-04 15:20:10 -0800831 if (!Init()) {
832 printf("# Failed to initialize.\n");
833 return 1;
834 }
835
836 void (*test[])() = {
837 SwapTest,
838 ClearTest,
839 FillRateTest,
840 TriangleSetupTest,
Alexey Marinichevaf0b26d2010-02-24 13:03:13 -0800841 AttributeFetchShaderTest,
Alexey Marinichevc24aa232010-02-24 18:15:54 -0800842 VaryingsAndDdxyShaderTest,
Alexey Marinichev8919b6e2010-03-04 16:21:02 -0800843 YuvToRgbShaderTest1,
844 YuvToRgbShaderTest2,
Matthew Papakipos1efe8bb2010-03-24 13:57:49 -0700845 NoFillWindowManagerCompositingTest,
846 WindowManagerCompositingTest,
Alexey Marinichev592b8622010-02-04 15:20:10 -0800847 };
848
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -0800849 uint64_t done = GetUTime() + 1000000ULL * seconds_to_run;
850 do {
851 for (unsigned int i = 0; i < sizeof(test) / sizeof(*test); i++) {
852 InitContext();
853 test[i]();
Alexey Marinichev9b818772010-02-23 12:07:48 -0800854 GLenum err = glGetError();
855 if (err != 0)
Alexey Marinichev8919b6e2010-03-04 16:21:02 -0800856 printf("# glGetError returned non-zero: 0x%x\n", err);
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -0800857 DestroyContext();
858 }
859 } while (GetUTime() < done);
Alexey Marinichev592b8622010-02-04 15:20:10 -0800860
861 return 0;
862}