blob: bb5ff50733dd1d6c92e06c0e85509ca72b63d6d6 [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;
Alexey Marinichev0f9aa1b2010-03-30 14:38:16 -070071static void *arg2 = NULL;
Alexey Marinichev592b8622010-02-04 15:20:10 -080072
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);
Matthew Papakiposef4f4632010-03-25 16:45:42 -0700119 CHECK(!glGetError());
120 return buf;
Alexey Marinichev592b8622010-02-04 15:20:10 -0800121}
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);
Matthew Papakiposef4f4632010-03-25 16:45:42 -0700186 glVertexPointer(2, GL_FLOAT, 0, 0);
Alexey Marinichevd4a0f072010-02-09 17:50:12 -0800187
188 GLuint vbo_texture = SetupVBO(GL_ARRAY_BUFFER,
189 sizeof(buffer_texture), buffer_texture);
Matthew Papakiposef4f4632010-03-25 16:45:42 -0700190 glTexCoordPointer(2, GL_FLOAT, 0, 0);
Alexey Marinichev592b8622010-02-04 15:20:10 -0800191
192 glColor4f(1.f, 0.f, 0.f, 1.f);
Alexey Marinichevd4a0f072010-02-09 17:50:12 -0800193 FillRateTestNormal("fill_solid");
194 FillRateTestBlendDepth("fill_solid");
Alexey Marinichev592b8622010-02-04 15:20:10 -0800195
196 glColor4f(1.f, 1.f, 1.f, 1.f);
197 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
198 glEnable(GL_TEXTURE_2D);
199
Alexey Marinichevd4a0f072010-02-09 17:50:12 -0800200 GLuint texture = SetupTexture(9);
201 FillRateTestNormal("fill_tex_nearest");
Alexey Marinichev592b8622010-02-04 15:20:10 -0800202
203 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
204 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
Alexey Marinichevd4a0f072010-02-09 17:50:12 -0800205 FillRateTestNormal("fill_tex_bilinear");
Alexey Marinichev592b8622010-02-04 15:20:10 -0800206
Alexey Marinichevd4a0f072010-02-09 17:50:12 -0800207 // lod = 0.5
208 glScalef(0.7071f, 0.7071f, 1.f);
209 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
210 GL_LINEAR_MIPMAP_NEAREST);
211 FillRateTestNormal("fill_tex_trilinear_nearest_05", 0.7071f * 0.7071f);
212
213 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
214 GL_LINEAR_MIPMAP_LINEAR);
215 FillRateTestNormal("fill_tex_trilinear_linear_05", 0.7071f * 0.7071f);
216
217 // lod = 0.4
218 glLoadIdentity();
219 glScalef(0.758f, 0.758f, 1.f);
220 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
221 GL_LINEAR_MIPMAP_LINEAR);
222 FillRateTestNormal("fill_tex_trilinear_linear_04", 0.758f * 0.758f);
223
224 // lod = 0.1
225 glLoadIdentity();
226 glScalef(0.933f, 0.933f, 1.f);
227 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
228 GL_LINEAR_MIPMAP_LINEAR);
229 FillRateTestNormal("fill_tex_trilinear_linear_01", 0.933f * 0.933f);
230
231 glDeleteBuffers(1, &vbo_vertex);
232 glDeleteBuffers(1, &vbo_texture);
Alexey Marinichev592b8622010-02-04 15:20:10 -0800233 glDeleteTextures(1, &texture);
234}
235
236
Alexey Marinichevd4a0f072010-02-09 17:50:12 -0800237static void FillRateTestNormal(const char *name, float coeff) {
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -0800238 const int buffer_len = 64;
239 char buffer[buffer_len];
240 snprintf(buffer, buffer_len, "mpixels_sec_%s", name);
Alexey Marinichev96e28692010-02-18 16:59:59 -0800241 RunTest(DrawArraysTestFunc, buffer, coeff * g_width * g_height, true);
Alexey Marinichevd4a0f072010-02-09 17:50:12 -0800242}
Alexey Marinichev592b8622010-02-04 15:20:10 -0800243
Alexey Marinichevd4a0f072010-02-09 17:50:12 -0800244static void FillRateTestBlendDepth(const char *name) {
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -0800245 const int buffer_len = 64;
246 char buffer[buffer_len];
247
Alexey Marinichev6d014842010-02-10 19:21:39 -0800248 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
249 glEnable(GL_BLEND);
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -0800250 snprintf(buffer, buffer_len, "mpixels_sec_%s_blended", name);
Alexey Marinichev96e28692010-02-18 16:59:59 -0800251 RunTest(DrawArraysTestFunc, buffer, g_width * g_height, true);
Alexey Marinichev6d014842010-02-10 19:21:39 -0800252 glDisable(GL_BLEND);
Alexey Marinichev592b8622010-02-04 15:20:10 -0800253
Alexey Marinichev6d014842010-02-10 19:21:39 -0800254 glEnable(GL_DEPTH_TEST);
255 glDepthFunc(GL_NOTEQUAL);
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -0800256 snprintf(buffer, buffer_len, "mpixels_sec_%s_depth_neq", name);
Alexey Marinichev96e28692010-02-18 16:59:59 -0800257 RunTest(DrawArraysTestFunc, buffer, g_width * g_height, true);
Alexey Marinichev6d014842010-02-10 19:21:39 -0800258 glDepthFunc(GL_NEVER);
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -0800259 snprintf(buffer, buffer_len, "mpixels_sec_%s_depth_never", name);
Alexey Marinichev96e28692010-02-18 16:59:59 -0800260 RunTest(DrawArraysTestFunc, buffer, g_width * g_height, true);
Alexey Marinichev6d014842010-02-10 19:21:39 -0800261 glDisable(GL_DEPTH_TEST);
Alexey Marinichev592b8622010-02-04 15:20:10 -0800262}
263
264
Alexey Marinichev96e28692010-02-18 16:59:59 -0800265static void DrawArraysTestFunc(int iter) {
Alexey Marinichev592b8622010-02-04 15:20:10 -0800266 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
267 glFlush();
268 for (int i = 0; i < iter-1; ++i) {
269 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
270 }
271}
272
273
Alexey Marinichev96e28692010-02-18 16:59:59 -0800274static void DrawElementsTestFunc(int iter) {
Matthew Papakiposef4f4632010-03-25 16:45:42 -0700275 glDrawElements(GL_TRIANGLES, arg1, GL_UNSIGNED_INT, 0);
Alexey Marinichev592b8622010-02-04 15:20:10 -0800276 glFlush();
277 for (int i = 0 ; i < iter-1; ++i) {
Matthew Papakiposef4f4632010-03-25 16:45:42 -0700278 glDrawElements(GL_TRIANGLES, arg1, GL_UNSIGNED_INT, 0);
Alexey Marinichev592b8622010-02-04 15:20:10 -0800279 }
280}
281
Alexey Marinichev6d014842010-02-10 19:21:39 -0800282// Generates a tautological lattice.
Alexey Marinichevbf88d1f2010-02-12 12:49:16 -0800283static void CreateLattice(GLfloat **vertices, GLsizeiptr *size,
284 GLfloat size_x, GLfloat size_y,
Alexey Marinichev6d014842010-02-10 19:21:39 -0800285 int width, int height)
286{
Alexey Marinichevbf88d1f2010-02-12 12:49:16 -0800287 GLfloat *vptr = *vertices = new GLfloat[2 * (width + 1) * (height + 1)];
Alexey Marinichev6d014842010-02-10 19:21:39 -0800288 for (int j = 0; j <= height; j++) {
289 for (int i = 0; i <= width; i++) {
Alexey Marinichevbf88d1f2010-02-12 12:49:16 -0800290 *vptr++ = i * size_x;
291 *vptr++ = j * size_y;
Alexey Marinichev6d014842010-02-10 19:21:39 -0800292 }
293 }
Alexey Marinichevbf88d1f2010-02-12 12:49:16 -0800294 *size = (vptr - *vertices) * sizeof(GLfloat);
Alexey Marinichev6d014842010-02-10 19:21:39 -0800295}
296
Alexey Marinichev592b8622010-02-04 15:20:10 -0800297// Generates a mesh of 2*width*height triangles. The ratio of front facing to
298// back facing triangles is culled_ratio/RAND_MAX. Returns the number of
299// vertices in the mesh.
Alexey Marinichev6d014842010-02-10 19:21:39 -0800300static int CreateMesh(GLuint **indices, GLsizeiptr *size,
Alexey Marinichev592b8622010-02-04 15:20:10 -0800301 int width, int height, int culled_ratio) {
302 srand(0);
303
Alexey Marinichev6d014842010-02-10 19:21:39 -0800304 GLuint *iptr = *indices = new GLuint[2 * 3 * (width * height)];
Alexey Marinichev592b8622010-02-04 15:20:10 -0800305 const int swath_height = 4;
Alexey Marinichevaf0b26d2010-02-24 13:03:13 -0800306
307 CHECK(width % swath_height == 0 && height % swath_height == 0);
308
Alexey Marinichevbf88d1f2010-02-12 12:49:16 -0800309 for (int j = 0; j < height; j += swath_height) {
Alexey Marinichev592b8622010-02-04 15:20:10 -0800310 for (int i = 0; i < width; i++) {
311 for (int j2 = 0; j2 < swath_height; j2++) {
Alexey Marinichev6d014842010-02-10 19:21:39 -0800312 GLuint first = (j + j2) * (width + 1) + i;
Alexey Marinichev592b8622010-02-04 15:20:10 -0800313 GLuint second = first + 1;
Alexey Marinichev6d014842010-02-10 19:21:39 -0800314 GLuint third = first + (width + 1);
Alexey Marinichev592b8622010-02-04 15:20:10 -0800315 GLuint fourth = third + 1;
316
317 bool flag = rand() < culled_ratio;
318 *iptr++ = first;
319 *iptr++ = flag ? second : third;
320 *iptr++ = flag ? third : second;
321
322 *iptr++ = fourth;
323 *iptr++ = flag ? third : second;
324 *iptr++ = flag ? second : third;
325 }
326 }
327 }
Alexey Marinichev6d014842010-02-10 19:21:39 -0800328 *size = (iptr - *indices) * sizeof(GLuint);
Alexey Marinichev592b8622010-02-04 15:20:10 -0800329
Alexey Marinichev6d014842010-02-10 19:21:39 -0800330 return iptr - *indices;
Alexey Marinichev592b8622010-02-04 15:20:10 -0800331}
332
333void TriangleSetupTest() {
334 glViewport(-g_width, -g_height, g_width*2, g_height*2);
Alexey Marinichev592b8622010-02-04 15:20:10 -0800335
336 // Larger meshes make this test too slow for devices that do 1 mtri/sec.
337 GLint width = 64;
338 GLint height = 64;
339
Alexey Marinichevbf88d1f2010-02-12 12:49:16 -0800340 GLfloat *vertices = NULL;
Alexey Marinichev6d014842010-02-10 19:21:39 -0800341 GLsizeiptr vertex_buffer_size = 0;
Alexey Marinichevbf88d1f2010-02-12 12:49:16 -0800342 CreateLattice(&vertices, &vertex_buffer_size, 1.f / g_width, 1.f / g_height,
343 width, height);
Alexey Marinichev6d014842010-02-10 19:21:39 -0800344 GLuint vertex_buffer = SetupVBO(GL_ARRAY_BUFFER,
345 vertex_buffer_size, vertices);
Matthew Papakiposef4f4632010-03-25 16:45:42 -0700346 glVertexPointer(2, GL_FLOAT, 0, 0);
Alexey Marinichev96e28692010-02-18 16:59:59 -0800347 glEnableClientState(GL_VERTEX_ARRAY);
Alexey Marinichev6d014842010-02-10 19:21:39 -0800348
349 GLuint *indices = NULL;
350 GLuint index_buffer = 0;
351 GLsizeiptr index_buffer_size = 0;
352
Alexey Marinichev6d014842010-02-10 19:21:39 -0800353 {
354 arg1 = CreateMesh(&indices, &index_buffer_size, width, height, 0);
355
Alexey Marinichev6d014842010-02-10 19:21:39 -0800356 index_buffer = SetupVBO(GL_ELEMENT_ARRAY_BUFFER,
357 index_buffer_size, indices);
Alexey Marinichev96e28692010-02-18 16:59:59 -0800358 RunTest(DrawElementsTestFunc, "mtri_sec_triangle_setup", arg1 / 3, true);
Alexey Marinichev6d014842010-02-10 19:21:39 -0800359 glEnable(GL_CULL_FACE);
Alexey Marinichev96e28692010-02-18 16:59:59 -0800360 RunTest(DrawElementsTestFunc, "mtri_sec_triangle_setup_all_culled",
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -0800361 arg1 / 3, true);
Alexey Marinichev96e28692010-02-18 16:59:59 -0800362 glDisable(GL_CULL_FACE);
Alexey Marinichev6d014842010-02-10 19:21:39 -0800363
Alexey Marinichev6d014842010-02-10 19:21:39 -0800364 glDeleteBuffers(1, &index_buffer);
Alexey Marinichev96e28692010-02-18 16:59:59 -0800365 delete[] indices;
Alexey Marinichev592b8622010-02-04 15:20:10 -0800366 }
367
Alexey Marinichev6d014842010-02-10 19:21:39 -0800368 {
369 glColor4f(0.f, 1.f, 1.f, 1.f);
370 arg1 = CreateMesh(&indices, &index_buffer_size, width, height,
371 RAND_MAX / 2);
Alexey Marinichev592b8622010-02-04 15:20:10 -0800372
Alexey Marinichev6d014842010-02-10 19:21:39 -0800373 index_buffer = SetupVBO(GL_ELEMENT_ARRAY_BUFFER,
374 index_buffer_size, indices);
Alexey Marinichev96e28692010-02-18 16:59:59 -0800375 glEnable(GL_CULL_FACE);
376 RunTest(DrawElementsTestFunc, "mtri_sec_triangle_setup_half_culled",
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -0800377 arg1 / 3, true);
Alexey Marinichev592b8622010-02-04 15:20:10 -0800378
Alexey Marinichev6d014842010-02-10 19:21:39 -0800379 glDeleteBuffers(1, &index_buffer);
Alexey Marinichev96e28692010-02-18 16:59:59 -0800380 delete[] indices;
Alexey Marinichev6d014842010-02-10 19:21:39 -0800381 }
Alexey Marinichev592b8622010-02-04 15:20:10 -0800382
Alexey Marinichev6d014842010-02-10 19:21:39 -0800383 glDeleteBuffers(1, &vertex_buffer);
Alexey Marinichev592b8622010-02-04 15:20:10 -0800384 delete[] vertices;
Alexey Marinichev592b8622010-02-04 15:20:10 -0800385}
386
387
Alexey Marinichevaf0b26d2010-02-24 13:03:13 -0800388void AttributeFetchShaderTest() {
Alexey Marinichev96e28692010-02-18 16:59:59 -0800389 GLint width = 64;
390 GLint height = 64;
391
392 glViewport(-g_width, -g_height, g_width*2, g_height*2);
393
394 GLfloat *vertices = NULL;
395 GLsizeiptr vertex_buffer_size = 0;
396 CreateLattice(&vertices, &vertex_buffer_size, 1.f / g_width, 1.f / g_height,
397 width, height);
398 GLuint vertex_buffer = SetupVBO(GL_ARRAY_BUFFER,
399 vertex_buffer_size, vertices);
400
401 GLuint *indices = NULL;
402 GLuint index_buffer = 0;
403 GLsizeiptr index_buffer_size = 0;
404
405 // Everything will be back-face culled.
406 arg1 = CreateMesh(&indices, &index_buffer_size, width, height, 0);
407 index_buffer = SetupVBO(GL_ELEMENT_ARRAY_BUFFER,
408 index_buffer_size, indices);
409
410 glEnable(GL_CULL_FACE);
411
412 GLuint vertex_buffers[8];
413 for (GLuint i = 0; i < sizeof(vertex_buffers)/sizeof(vertex_buffers[0]); i++)
414 vertex_buffers[i] = vertex_buffer;
415
416 ShaderProgram program = AttributeFetchShaderProgram(1, vertex_buffers);
417 RunTest(DrawElementsTestFunc,
418 "mvtx_sec_attribute_fetch_shader", arg1, true);
Alexey Marinichev3c199732010-03-11 10:33:35 -0800419 glDeleteProgram(program);
Alexey Marinichev96e28692010-02-18 16:59:59 -0800420
Alexey Marinichev9b818772010-02-23 12:07:48 -0800421 program = AttributeFetchShaderProgram(2, vertex_buffers);
Alexey Marinichev96e28692010-02-18 16:59:59 -0800422 RunTest(DrawElementsTestFunc,
423 "mvtx_sec_attribute_fetch_shader_2_attr", arg1, true);
Alexey Marinichev3c199732010-03-11 10:33:35 -0800424 glDeleteProgram(program);
Alexey Marinichev96e28692010-02-18 16:59:59 -0800425
Alexey Marinichev9b818772010-02-23 12:07:48 -0800426 program = AttributeFetchShaderProgram(4, vertex_buffers);
Alexey Marinichev96e28692010-02-18 16:59:59 -0800427 RunTest(DrawElementsTestFunc,
428 "mvtx_sec_attribute_fetch_shader_4_attr", arg1, true);
Alexey Marinichev3c199732010-03-11 10:33:35 -0800429 glDeleteProgram(program);
Alexey Marinichev96e28692010-02-18 16:59:59 -0800430
Alexey Marinichev9b818772010-02-23 12:07:48 -0800431 program = AttributeFetchShaderProgram(8, vertex_buffers);
Alexey Marinichev96e28692010-02-18 16:59:59 -0800432 RunTest(DrawElementsTestFunc,
433 "mvtx_sec_attribute_fetch_shader_8_attr", arg1, true);
Alexey Marinichev3c199732010-03-11 10:33:35 -0800434 glDeleteProgram(program);
Alexey Marinichev96e28692010-02-18 16:59:59 -0800435
436 glDeleteBuffers(1, &index_buffer);
437 delete[] indices;
438
439 glDeleteBuffers(1, &vertex_buffer);
440 delete[] vertices;
441}
442
Alexey Marinichevaf0b26d2010-02-24 13:03:13 -0800443
Alexey Marinichevc24aa232010-02-24 18:15:54 -0800444void VaryingsAndDdxyShaderTest() {
Alexey Marinichevaf0b26d2010-02-24 13:03:13 -0800445 glViewport(-g_width, -g_height, g_width*2, g_height*2);
446
447 const int c = 4;
448 GLfloat *vertices = NULL;
449 GLsizeiptr vertex_buffer_size = 0;
450 CreateLattice(&vertices, &vertex_buffer_size, 1.f / c, 1.f / c, c, c);
451 GLuint vertex_buffer = SetupVBO(GL_ARRAY_BUFFER,
452 vertex_buffer_size, vertices);
453
454 GLuint *indices = NULL;
455 GLuint index_buffer = 0;
456 GLsizeiptr index_buffer_size = 0;
457
458 arg1 = CreateMesh(&indices, &index_buffer_size, c, c, 0);
459 index_buffer = SetupVBO(GL_ELEMENT_ARRAY_BUFFER,
460 index_buffer_size, indices);
461
462 ShaderProgram program = VaryingsShaderProgram(1, vertex_buffer);
463 RunTest(DrawElementsTestFunc,
464 "mpixels_sec_varyings_shader_1", g_width * g_height, true);
Alexey Marinichev3c199732010-03-11 10:33:35 -0800465 glDeleteProgram(program);
Alexey Marinichevaf0b26d2010-02-24 13:03:13 -0800466
467 program = VaryingsShaderProgram(2, vertex_buffer);
468 RunTest(DrawElementsTestFunc,
469 "mpixels_sec_varyings_shader_2", g_width * g_height, true);
Alexey Marinichev3c199732010-03-11 10:33:35 -0800470 glDeleteProgram(program);
Alexey Marinichevaf0b26d2010-02-24 13:03:13 -0800471
472 program = VaryingsShaderProgram(4, vertex_buffer);
473 RunTest(DrawElementsTestFunc,
474 "mpixels_sec_varyings_shader_4", g_width * g_height, true);
Alexey Marinichev3c199732010-03-11 10:33:35 -0800475 glDeleteProgram(program);
Alexey Marinichevaf0b26d2010-02-24 13:03:13 -0800476
477 program = VaryingsShaderProgram(8, vertex_buffer);
478 RunTest(DrawElementsTestFunc,
479 "mpixels_sec_varyings_shader_8", g_width * g_height, true);
Alexey Marinichev3c199732010-03-11 10:33:35 -0800480 glDeleteProgram(program);
Alexey Marinichevaf0b26d2010-02-24 13:03:13 -0800481
Alexey Marinichevc24aa232010-02-24 18:15:54 -0800482 program = DdxDdyShaderProgram(true, vertex_buffer);
483 RunTest(DrawElementsTestFunc,
484 "mpixels_sec_ddx_shader", g_width * g_height, true);
Alexey Marinichev3c199732010-03-11 10:33:35 -0800485 glDeleteProgram(program);
Alexey Marinichevc24aa232010-02-24 18:15:54 -0800486
487 program = DdxDdyShaderProgram(false, vertex_buffer);
488 RunTest(DrawElementsTestFunc,
489 "mpixels_sec_ddy_shader", g_width * g_height, true);
Alexey Marinichev3c199732010-03-11 10:33:35 -0800490 glDeleteProgram(program);
Alexey Marinichevc24aa232010-02-24 18:15:54 -0800491
Alexey Marinichevaf0b26d2010-02-24 13:03:13 -0800492 glDeleteBuffers(1, &index_buffer);
493 delete[] indices;
494
495 glDeleteBuffers(1, &vertex_buffer);
496 delete[] vertices;
497}
498
Alexey Marinichev8919b6e2010-03-04 16:21:02 -0800499
500void YuvToRgbShaderTestHelper(int type, const char *name) {
Alexey Marinichev6294a392010-03-02 16:53:36 -0800501 size_t size = 0;
Alexey Marinichev6dfea312010-03-03 14:53:12 -0800502 GLuint texture[2];
Alexey Marinichev6294a392010-03-02 16:53:36 -0800503 ShaderProgram program = 0;
504 GLuint vertex_buffer = 0;
505 GLfloat vertices[8] = {
506 0.f, 0.f,
507 1.f, 0.f,
Alexey Marinicheve5b107a2010-03-10 17:51:04 -0800508 0.f, 1.f,
509 1.f, 1.f,
Alexey Marinichev6294a392010-03-02 16:53:36 -0800510 };
Alexey Marinichev6dfea312010-03-03 14:53:12 -0800511 char evenodd[2] = {0, 255};
Alexey Marinicheve5b107a2010-03-10 17:51:04 -0800512 const int pixel_height = YUV2RGB_HEIGHT * 2 / 3;
Alexey Marinichev6294a392010-03-02 16:53:36 -0800513
514 char *pixels = static_cast<char *>(MmapFile(YUV2RGB_NAME, &size));
515 if (!pixels) {
516 printf("# Could not open image file: %s\n", YUV2RGB_NAME);
517 goto done;
518 }
519 if (size != YUV2RGB_SIZE) {
Alexey Marinichev6dfea312010-03-03 14:53:12 -0800520 printf("# Image file of wrong size, got %d, expected %d\n",
521 static_cast<int>(size), YUV2RGB_SIZE);
Alexey Marinichev6294a392010-03-02 16:53:36 -0800522 goto done;
523 }
524
Alexey Marinichev6dfea312010-03-03 14:53:12 -0800525 glGenTextures(2, texture);
526 glActiveTexture(GL_TEXTURE0);
527 glBindTexture(GL_TEXTURE_2D, texture[0]);
Alexey Marinichev6294a392010-03-02 16:53:36 -0800528 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
529 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
530 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, YUV2RGB_WIDTH, YUV2RGB_HEIGHT,
531 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, pixels);
532
Alexey Marinichev6dfea312010-03-03 14:53:12 -0800533 glActiveTexture(GL_TEXTURE1);
534 glBindTexture(GL_TEXTURE_2D, texture[1]);
535 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
536 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
537 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 2, 1,
538 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, evenodd);
539
Alexey Marinicheve5b107a2010-03-10 17:51:04 -0800540 glViewport(-YUV2RGB_WIDTH, -pixel_height, YUV2RGB_WIDTH*2, pixel_height * 2);
Alexey Marinichev6294a392010-03-02 16:53:36 -0800541 vertex_buffer = SetupVBO(GL_ARRAY_BUFFER, sizeof(vertices), vertices);
542
Alexey Marinichev8919b6e2010-03-04 16:21:02 -0800543 program = YuvToRgbShaderProgram(type, vertex_buffer,
Alexey Marinicheve5b107a2010-03-10 17:51:04 -0800544 YUV2RGB_WIDTH, pixel_height);
545
546 if (program) {
547 float coeff = 1.f *
548 (YUV2RGB_WIDTH < g_width ?
549 static_cast<float>(YUV2RGB_WIDTH) / g_width : 1.f) *
550 (pixel_height < g_height ?
551 static_cast<float>(pixel_height) / g_height : 1.f);
552 FillRateTestNormal(name, coeff);
553 } else {
Alexey Marinichev6dfea312010-03-03 14:53:12 -0800554 printf("# Could not set up YUV shader.\n");
Alexey Marinicheve5b107a2010-03-10 17:51:04 -0800555 }
Alexey Marinichev6294a392010-03-02 16:53:36 -0800556
557done:
Alexey Marinichev3c199732010-03-11 10:33:35 -0800558 glDeleteProgram(program);
Alexey Marinichev6dfea312010-03-03 14:53:12 -0800559 glDeleteTextures(2, texture);
560 glDeleteBuffers(1, &vertex_buffer);
Alexey Marinichev6294a392010-03-02 16:53:36 -0800561 munmap(pixels, size);
562}
563
Alexey Marinichev8919b6e2010-03-04 16:21:02 -0800564void YuvToRgbShaderTest1() {
565 YuvToRgbShaderTestHelper(1, "yuv_shader_1");
566}
567
568void YuvToRgbShaderTest2() {
569 YuvToRgbShaderTestHelper(2, "yuv_shader_2");
570}
571
Matthew Papakipos1efe8bb2010-03-24 13:57:49 -0700572static GLuint compositing_textures[5];
573static uint32_t texture_base[WINDOW_HEIGHT*WINDOW_WIDTH];
574static uint32_t texture_update[WINDOW_HEIGHT*WINDOW_WIDTH];
575static ShaderProgram compositing_background_program = 0;
576static ShaderProgram compositing_foreground_program = 0;
577
578void InitBaseTexture() {
579 for (int y = 0; y < WINDOW_HEIGHT; y++) {
580 for (int x = 0; x < WINDOW_WIDTH; x++) {
581 // This color is gray, half alpha.
582 texture_base[y*WINDOW_WIDTH+x] = 0x80808080;
583 }
584 }
585}
586
587// UpdateTexture simulates Chrome updating tab contents.
588// We cause a bunch of read and write cpu memory bandwidth.
589// It's a very rough approximation.
590void UpdateTexture() {
591 memcpy(texture_update, texture_base, sizeof(texture_base));
592}
593
594void LoadTexture() {
595 // Use GL_RGBA for compatibility with GLES2.0.
596 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
597 WINDOW_WIDTH, WINDOW_HEIGHT, 0,
598 GL_RGBA, GL_UNSIGNED_BYTE, texture_update);
599}
600
601// Test how fast we can do full-screen compositing of images
602// continuously updated from the CPU.
603// This tests both GPU compositing performance and also
604// CPU -> GPU data transfer speed.
605// It is a basic perf test to make sure we have enough performance
606// to run a compositing window manager.
607void CompositingTestFunc(int iter) {
608 for (int i = 0 ; i < iter; ++i) {
609 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
610
611 // Draw the background
612 glDisable(GL_BLEND);
613 glDisable(GL_DEPTH_TEST);
614 // We have to blend three textures, but we use multi-texture for this
615 // blending, not fb blend, to avoid the external memory traffic
616 glActiveTexture(GL_TEXTURE0);
617 glBindTexture(GL_TEXTURE_2D, compositing_textures[0]);
618 glActiveTexture(GL_TEXTURE1);
619 glBindTexture(GL_TEXTURE_2D, compositing_textures[1]);
620 glActiveTexture(GL_TEXTURE2);
621 glBindTexture(GL_TEXTURE_2D, compositing_textures[2]);
622 // Set up the texture coordinate arrays
623 glClientActiveTexture(GL_TEXTURE0);
624 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
625 glClientActiveTexture(GL_TEXTURE1);
626 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
627 glClientActiveTexture(GL_TEXTURE2);
628 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
629 // Use the right shader
630 glUseProgram(compositing_background_program);
631 // Draw the quad
632 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
633
634 // Set up one texture coordinate array
635 glClientActiveTexture(GL_TEXTURE0);
636 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
637 glClientActiveTexture(GL_TEXTURE1);
638 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
639 glClientActiveTexture(GL_TEXTURE2);
640 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
641 // Use the right shader
642 glUseProgram(compositing_foreground_program);
643
644 // Compositing is blending, so we shall blend.
645 glEnable(GL_BLEND);
646 // Depth test is on for window occlusion
647 glEnable(GL_DEPTH_TEST);
648
649 // Draw window number one
650 // This update acts like a chrome webkit sw rendering update.
651 glActiveTexture(GL_TEXTURE0);
652 glBindTexture(GL_TEXTURE_2D, compositing_textures[3]);
653 UpdateTexture();
654 // TODO(papakipos): this LoadTexture is likely doing more CPU memory copies
655 // than we would like.
656 LoadTexture();
657 // TODO(papakipos): add color interpolation here, and modulate
658 // texture against it.
659 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
660
661 // Draw window number two
662 // This is a static window, so we don't update it.
663 glActiveTexture(GL_TEXTURE0);
664 glBindTexture(GL_TEXTURE_2D, compositing_textures[4]);
665 // TODO(papakipos): add color interpolation here, and modulate
666 // texture against it.
667 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
668 }
669}
670
671void InitializeCompositing() {
672 InitBaseTexture();
673
674 glClearColor(0.f, 0.f, 0.f, 0.f);
675 glDisable(GL_DEPTH_TEST);
676 glDisable(GL_BLEND);
677 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
678 glDepthFunc(GL_LEQUAL);
679
680 glGenTextures(5, compositing_textures);
681 glActiveTexture(GL_TEXTURE0);
682 for (int i = 0; i < 5; i++) {
683 glBindTexture(GL_TEXTURE_2D, compositing_textures[i]);
684 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
685 GL_LINEAR);
686 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
687 GL_LINEAR);
688 }
689
690 glColor4f(1.f, 1.f, 1.f, 1.f);
691
692 // Set up the vertex arrays for drawing textured quads later on.
693 glEnableClientState(GL_VERTEX_ARRAY);
694 GLfloat buffer_vertex[8] = {
695 -1.f, -1.f,
696 1.f, -1.f,
697 -1.f, 1.f,
698 1.f, 1.f,
699 };
700 GLuint vbo_vertex = SetupVBO(GL_ARRAY_BUFFER,
701 sizeof(buffer_vertex), buffer_vertex);
Matthew Papakiposef4f4632010-03-25 16:45:42 -0700702 glVertexPointer(2, GL_FLOAT, 0, 0);
Matthew Papakipos1efe8bb2010-03-24 13:57:49 -0700703
704 GLfloat buffer_texture[8] = {
705 0.f, 0.f,
706 1.f, 0.f,
707 0.f, 1.f,
708 1.f, 1.f,
709 };
710 GLuint vbo_texture = SetupVBO(GL_ARRAY_BUFFER,
711 sizeof(buffer_texture), buffer_texture);
712 for (int i = 0; i < 3; i++) {
713 glClientActiveTexture(GL_TEXTURE0 + i);
Matthew Papakiposef4f4632010-03-25 16:45:42 -0700714 glTexCoordPointer(2, GL_FLOAT, 0, 0);
Matthew Papakipos1efe8bb2010-03-24 13:57:49 -0700715 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
716 }
717
718 // Set up the static background textures.
719 UpdateTexture();
720 UpdateTexture();
721 UpdateTexture();
722 // Load these textures into bound texture ids and keep using them
723 // from there to avoid having to reload this texture every frame
724 glActiveTexture(GL_TEXTURE0);
725 glBindTexture(GL_TEXTURE_2D, compositing_textures[0]);
726 LoadTexture();
727 glActiveTexture(GL_TEXTURE1);
728 glBindTexture(GL_TEXTURE_2D, compositing_textures[1]);
729 LoadTexture();
730 glActiveTexture(GL_TEXTURE2);
731 glBindTexture(GL_TEXTURE_2D, compositing_textures[2]);
732 LoadTexture();
733
734 glActiveTexture(GL_TEXTURE0);
735 glBindTexture(GL_TEXTURE_2D, compositing_textures[3]);
736 UpdateTexture();
737 LoadTexture();
738
739 glActiveTexture(GL_TEXTURE0);
740 glBindTexture(GL_TEXTURE_2D, compositing_textures[4]);
741 UpdateTexture();
742 LoadTexture();
743
744 // Set up vertex & fragment shaders.
745 compositing_background_program =
746 TripleTextureBlendShaderProgram(vbo_vertex,
747 vbo_texture, vbo_texture, vbo_texture);
748 compositing_foreground_program =
749 BasicTextureShaderProgram(vbo_vertex, vbo_texture);
750 if ((!compositing_background_program) ||
751 (!compositing_foreground_program)) {
752 printf("# Could not set up compositing shader.\n");
753 }
754
Matthew Papakiposef4f4632010-03-25 16:45:42 -0700755 glVertexPointer(2, GL_FLOAT, 0, 0);
Matthew Papakipos1efe8bb2010-03-24 13:57:49 -0700756}
757
758void TeardownCompositing() {
759 glDeleteProgram(compositing_background_program);
760 glDeleteProgram(compositing_foreground_program);
761}
762
763// Notes on the window manager compositing test:
764// Depth
765// Depth complexity = 3: background, active window, static window
766// Background: may be a tex-blend of three images (2.5d effect)
767// The windows -- at most two, fullscreen
768// Depth test is on, passing most of the time.
769// A lot of texture min-filtering -- not modelled
770// One of the two windows is getting live browser frame updates -- not mod
771// The live window runs at x/2 and y/2 size -- not modelled
772// The two windows are modulated by color interpolation to get gradient
773static float screen_scale_factor = (1e6f*
774 (WINDOW_WIDTH*WINDOW_HEIGHT)/
775 (1280.f*768));
776
777void WindowManagerCompositingTest() {
778 InitializeCompositing();
779 RunTest(CompositingTestFunc, "1280x768_fps_compositing",
780 screen_scale_factor, true);
781 TeardownCompositing();
782}
783
784void NoFillWindowManagerCompositingTest() {
785 glScissor(0, 0, 1, 1);
786 glEnable(GL_SCISSOR_TEST);
787 InitializeCompositing();
788 RunTest(CompositingTestFunc, "1280x768_fps_no_fill_compositing",
789 screen_scale_factor, true);
790 TeardownCompositing();
791}
Alexey Marinichev6294a392010-03-02 16:53:36 -0800792
Alexey Marinichev0f9aa1b2010-03-30 14:38:16 -0700793void ReadPixelTestFunc(int iter) {
794 glReadPixels(0, 0, g_width, g_height, GL_RGBA, GL_UNSIGNED_BYTE, arg2);
795 CHECK(glGetError() == 0);
796 for (int i = 0; i < iter; i++)
797 glReadPixels(0, 0, g_width, g_height, GL_RGBA, GL_UNSIGNED_BYTE, arg2);
798}
799
800// TODO: better test names.
801void ReadPixelTest() {
802 // One GL_RGBA pixel takes 4 bytes.
803 const int row_size = g_width * 4;
804 // Default GL_PACK_ALIGNMENT is 4, round up pixel row size to multiple of 4.
805 // This is a no-op because row_size is already divisible by 4.
806 // One is added so that we can test reads into unaligned location.
807 char* pixels = new char[((row_size + 3) & ~3) * g_height + 1];
808
809 arg2 = pixels;
810 RunTest(ReadPixelTestFunc, "mpixels_sec_pixel_read",
811 g_width * g_height, true);
812
813 // Reducing GL_PACK_ALIGNMENT can only make rows smaller. No need to
814 // reallocate the buffer.
815 glPixelStorei(GL_PACK_ALIGNMENT, 1);
816 RunTest(ReadPixelTestFunc, "mpixels_sec_pixel_read_2",
817 g_width * g_height, true);
818
819 arg2 = static_cast<void*>(pixels + 1);
820 RunTest(ReadPixelTestFunc, "mpixels_sec_pixel_read_3",
821 g_width * g_height, true);
822
823 delete[] pixels;
824}
825
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -0800826// TODO: use proper command line parsing library.
827static void ParseArgs(int argc, char *argv[]) {
828 const char **enabled_tests_ptr = enabled_tests;
829 bool test_name_arg = false;
830 bool duration_arg = false;
831 for (int i = 0; i < argc; i++) {
832 if (test_name_arg) {
833 test_name_arg = false;
834 *enabled_tests_ptr++ = argv[i];
835 if (enabled_tests_ptr - enabled_tests >= enabled_tests_max)
836 break;
837 } else if (duration_arg) {
838 duration_arg = false;
839 seconds_to_run = atoi(argv[i]);
840 } else if (strcmp("-t", argv[i]) == 0) {
841 test_name_arg = true;
842 } else if (strcmp("-d", argv[i]) == 0) {
843 duration_arg = true;
844 }
845 }
846 *enabled_tests_ptr++ = NULL;
847}
848
849
Alexey Marinichev592b8622010-02-04 15:20:10 -0800850int main(int argc, char *argv[]) {
Antoine Labourec7eb532010-03-12 11:01:34 -0800851 SetBasePathFromArgv0(argv[0], "src");
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -0800852 ParseArgs(argc, argv);
Alexey Marinichev592b8622010-02-04 15:20:10 -0800853 if (!Init()) {
854 printf("# Failed to initialize.\n");
855 return 1;
856 }
857
858 void (*test[])() = {
859 SwapTest,
860 ClearTest,
861 FillRateTest,
862 TriangleSetupTest,
Alexey Marinichevaf0b26d2010-02-24 13:03:13 -0800863 AttributeFetchShaderTest,
Alexey Marinichevc24aa232010-02-24 18:15:54 -0800864 VaryingsAndDdxyShaderTest,
Alexey Marinichev8919b6e2010-03-04 16:21:02 -0800865 YuvToRgbShaderTest1,
866 YuvToRgbShaderTest2,
Matthew Papakipos1efe8bb2010-03-24 13:57:49 -0700867 NoFillWindowManagerCompositingTest,
868 WindowManagerCompositingTest,
Alexey Marinichev0f9aa1b2010-03-30 14:38:16 -0700869 ReadPixelTest,
Alexey Marinichev592b8622010-02-04 15:20:10 -0800870 };
871
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -0800872 uint64_t done = GetUTime() + 1000000ULL * seconds_to_run;
873 do {
874 for (unsigned int i = 0; i < sizeof(test) / sizeof(*test); i++) {
875 InitContext();
876 test[i]();
Alexey Marinichev9b818772010-02-23 12:07:48 -0800877 GLenum err = glGetError();
878 if (err != 0)
Alexey Marinichev8919b6e2010-03-04 16:21:02 -0800879 printf("# glGetError returned non-zero: 0x%x\n", err);
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -0800880 DestroyContext();
881 }
882 } while (GetUTime() < done);
Alexey Marinichev592b8622010-02-04 15:20:10 -0800883
884 return 0;
885}