Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 1 | // 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 Marinichev | 6294a39 | 2010-03-02 16:53:36 -0800 | [diff] [blame] | 5 | #include <fcntl.h> |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 6 | #include <stdio.h> |
| 7 | #include <stdlib.h> |
Alexey Marinichev | 19b5a5d | 2010-02-18 11:37:26 -0800 | [diff] [blame] | 8 | #include <string.h> |
Alexey Marinichev | 6294a39 | 2010-03-02 16:53:36 -0800 | [diff] [blame] | 9 | #include <sys/mman.h> |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 10 | |
Alexey Marinichev | af0b26d | 2010-02-24 13:03:13 -0800 | [diff] [blame] | 11 | #include "base/logging.h" |
| 12 | |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 13 | #include "main.h" |
Alexey Marinichev | 96e2869 | 2010-02-18 16:59:59 -0800 | [diff] [blame] | 14 | #include "shaders.h" |
Alexey Marinichev | 3c19973 | 2010-03-11 10:33:35 -0800 | [diff] [blame] | 15 | #include "utils.h" |
Alexey Marinichev | 6294a39 | 2010-03-02 16:53:36 -0800 | [diff] [blame] | 16 | #include "yuv2rgb.h" |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 17 | |
| 18 | |
Darin Petkov | dd31496 | 2010-02-18 16:21:29 -0800 | [diff] [blame] | 19 | const int enabled_tests_max = 8; |
Alexey Marinichev | 19b5a5d | 2010-02-18 11:37:26 -0800 | [diff] [blame] | 20 | const char *enabled_tests[enabled_tests_max+1] = {NULL}; |
| 21 | int seconds_to_run = 0; |
| 22 | |
Alexey Marinichev | a991f2b | 2010-03-11 09:59:51 -0800 | [diff] [blame] | 23 | // 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 Marinichev | 19b5a5d | 2010-02-18 11:37:26 -0800 | [diff] [blame] | 40 | void RunTest(BenchFunc f, const char *name, float coefficient, bool inverse) { |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 41 | float slope; |
| 42 | int64_t bias; |
Alexey Marinichev | 19b5a5d | 2010-02-18 11:37:26 -0800 | [diff] [blame] | 43 | |
| 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 Marinichev | c24aa23 | 2010-02-24 18:15:54 -0800 | [diff] [blame] | 55 | 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 Marinichev | 8919b6e | 2010-03-04 16:21:02 -0800 | [diff] [blame] | 61 | if (Bench(f, &slope, &bias)) { |
Alexey Marinichev | e5b107a | 2010-03-10 17:51:04 -0800 | [diff] [blame] | 62 | printf("%s: %g\n", name, coefficient * (inverse ? 1.f / slope : slope)); |
Alexey Marinichev | 8919b6e | 2010-03-04 16:21:02 -0800 | [diff] [blame] | 63 | } else { |
| 64 | printf("# %s is too slow, returning zero.\n", name); |
| 65 | printf("%s: 0\n", name); |
| 66 | } |
Alexey Marinichev | c24aa23 | 2010-02-24 18:15:54 -0800 | [diff] [blame] | 67 | } |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | static int arg1 = 0; |
| 71 | static void *arg2 = NULL; |
| 72 | |
| 73 | |
| 74 | void SwapTestFunc(int iter) { |
| 75 | for (int i = 0 ; i < iter; ++i) { |
| 76 | SwapBuffers(); |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | void SwapTest() { |
Alexey Marinichev | e5b107a | 2010-03-10 17:51:04 -0800 | [diff] [blame] | 81 | RunTest(SwapTestFunc, "us_swap_swap", 1.f, false); |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | |
| 85 | void ClearTestFunc(int iter) { |
| 86 | GLbitfield mask = arg1; |
| 87 | glClear(mask); |
| 88 | glFlush(); // Kick GPU as soon as possible |
| 89 | for (int i = 0 ; i < iter-1; ++i) { |
| 90 | glClear(mask); |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | |
| 95 | void ClearTest() { |
| 96 | arg1 = GL_COLOR_BUFFER_BIT; |
Alexey Marinichev | 19b5a5d | 2010-02-18 11:37:26 -0800 | [diff] [blame] | 97 | RunTest(ClearTestFunc, "mpixels_sec_clear_color", g_width * g_height, true); |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 98 | |
| 99 | arg1 = GL_DEPTH_BUFFER_BIT; |
Alexey Marinichev | 19b5a5d | 2010-02-18 11:37:26 -0800 | [diff] [blame] | 100 | RunTest(ClearTestFunc, "mpixels_sec_clear_depth", g_width * g_height, true); |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 101 | |
| 102 | arg1 = GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT; |
Alexey Marinichev | 19b5a5d | 2010-02-18 11:37:26 -0800 | [diff] [blame] | 103 | RunTest(ClearTestFunc, "mpixels_sec_clear_colordepth", |
| 104 | g_width * g_height, true); |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 105 | |
| 106 | arg1 = GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT; |
Alexey Marinichev | 19b5a5d | 2010-02-18 11:37:26 -0800 | [diff] [blame] | 107 | RunTest(ClearTestFunc, "mpixels_sec_clear_depthstencil", |
| 108 | g_width * g_height, true); |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 109 | |
| 110 | arg1 = GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT; |
Alexey Marinichev | 19b5a5d | 2010-02-18 11:37:26 -0800 | [diff] [blame] | 111 | RunTest(ClearTestFunc, "mpixels_sec_clear_colordepthstencil", |
| 112 | g_width * g_height, true); |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | |
| 116 | GLuint SetupVBO(GLenum target, GLsizeiptr size, const GLvoid *data) { |
| 117 | GLuint buf = ~0; |
| 118 | glGenBuffers(1, &buf); |
| 119 | glBindBuffer(target, buf); |
| 120 | glBufferData(target, size, data, GL_STATIC_DRAW); |
| 121 | |
| 122 | return glGetError() == 0 ? buf : 0; |
| 123 | } |
| 124 | |
| 125 | |
Alexey Marinichev | d4a0f07 | 2010-02-09 17:50:12 -0800 | [diff] [blame] | 126 | GLuint SetupTexture(GLsizei size_log2) { |
| 127 | GLsizei size = 1 << size_log2; |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 128 | GLuint name = ~0; |
| 129 | glGenTextures(1, &name); |
| 130 | glBindTexture(GL_TEXTURE_2D, name); |
| 131 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 132 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 133 | |
Alexey Marinichev | d4a0f07 | 2010-02-09 17:50:12 -0800 | [diff] [blame] | 134 | unsigned char *pixels = new unsigned char[size * size * 4]; |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 135 | if (!pixels) |
| 136 | return 0; |
| 137 | |
Alexey Marinichev | d4a0f07 | 2010-02-09 17:50:12 -0800 | [diff] [blame] | 138 | for (GLint level = 0; size > 0; level++, size /= 2) { |
| 139 | unsigned char *p = pixels; |
| 140 | for (int i = 0; i < size; i++) { |
| 141 | for (int j = 0; j < size; j++) { |
| 142 | *p++ = level %3 != 0 ? (i ^ j) << level : 0; |
| 143 | *p++ = level %3 != 1 ? (i ^ j) << level : 0; |
| 144 | *p++ = level %3 != 2 ? (i ^ j) << level : 0; |
| 145 | *p++ = 255; |
| 146 | } |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 147 | } |
Alexey Marinichev | d4a0f07 | 2010-02-09 17:50:12 -0800 | [diff] [blame] | 148 | if (size == 1) { |
| 149 | unsigned char *p = pixels; |
| 150 | *p++ = 255; |
| 151 | *p++ = 255; |
| 152 | *p++ = 255; |
| 153 | *p++ = 255; |
| 154 | } |
| 155 | glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, |
| 156 | GL_RGBA, GL_UNSIGNED_BYTE, pixels); |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 157 | } |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 158 | delete[] pixels; |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 159 | return name; |
| 160 | } |
| 161 | |
| 162 | |
Alexey Marinichev | 96e2869 | 2010-02-18 16:59:59 -0800 | [diff] [blame] | 163 | static void DrawArraysTestFunc(int iter); |
Alexey Marinichev | d4a0f07 | 2010-02-09 17:50:12 -0800 | [diff] [blame] | 164 | static void FillRateTestNormal(const char *name, float coeff=1.f); |
| 165 | static void FillRateTestBlendDepth(const char *name); |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 166 | |
| 167 | void FillRateTest() { |
| 168 | glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); |
| 169 | glDisable(GL_DEPTH_TEST); |
| 170 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
| 171 | |
Alexey Marinichev | d4a0f07 | 2010-02-09 17:50:12 -0800 | [diff] [blame] | 172 | GLfloat buffer_vertex[8] = { |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 173 | -1.f, -1.f, |
| 174 | 1.f, -1.f, |
| 175 | -1.f, 1.f, |
| 176 | 1.f, 1.f, |
| 177 | }; |
Alexey Marinichev | d4a0f07 | 2010-02-09 17:50:12 -0800 | [diff] [blame] | 178 | GLfloat buffer_texture[8] = { |
| 179 | 0.f, 0.f, |
| 180 | 1.f, 0.f, |
| 181 | 0.f, 1.f, |
| 182 | 1.f, 1.f, |
| 183 | }; |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 184 | glEnableClientState(GL_VERTEX_ARRAY); |
| 185 | |
Alexey Marinichev | d4a0f07 | 2010-02-09 17:50:12 -0800 | [diff] [blame] | 186 | GLuint vbo_vertex = SetupVBO(GL_ARRAY_BUFFER, |
| 187 | sizeof(buffer_vertex), buffer_vertex); |
Alexey Marinichev | 19b5a5d | 2010-02-18 11:37:26 -0800 | [diff] [blame] | 188 | if (!vbo_vertex) |
| 189 | printf("# Not Using VBO!\n"); |
Alexey Marinichev | d4a0f07 | 2010-02-09 17:50:12 -0800 | [diff] [blame] | 190 | glVertexPointer(2, GL_FLOAT, 0, vbo_vertex ? 0 : buffer_vertex); |
| 191 | |
| 192 | GLuint vbo_texture = SetupVBO(GL_ARRAY_BUFFER, |
| 193 | sizeof(buffer_texture), buffer_texture); |
| 194 | glTexCoordPointer(2, GL_FLOAT, 0, vbo_texture ? 0 : buffer_texture); |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 195 | |
| 196 | glColor4f(1.f, 0.f, 0.f, 1.f); |
Alexey Marinichev | d4a0f07 | 2010-02-09 17:50:12 -0800 | [diff] [blame] | 197 | FillRateTestNormal("fill_solid"); |
| 198 | FillRateTestBlendDepth("fill_solid"); |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 199 | |
| 200 | glColor4f(1.f, 1.f, 1.f, 1.f); |
| 201 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
| 202 | glEnable(GL_TEXTURE_2D); |
| 203 | |
Alexey Marinichev | d4a0f07 | 2010-02-09 17:50:12 -0800 | [diff] [blame] | 204 | GLuint texture = SetupTexture(9); |
| 205 | FillRateTestNormal("fill_tex_nearest"); |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 206 | |
| 207 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 208 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
Alexey Marinichev | d4a0f07 | 2010-02-09 17:50:12 -0800 | [diff] [blame] | 209 | FillRateTestNormal("fill_tex_bilinear"); |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 210 | |
Alexey Marinichev | d4a0f07 | 2010-02-09 17:50:12 -0800 | [diff] [blame] | 211 | // lod = 0.5 |
| 212 | glScalef(0.7071f, 0.7071f, 1.f); |
| 213 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, |
| 214 | GL_LINEAR_MIPMAP_NEAREST); |
| 215 | FillRateTestNormal("fill_tex_trilinear_nearest_05", 0.7071f * 0.7071f); |
| 216 | |
| 217 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, |
| 218 | GL_LINEAR_MIPMAP_LINEAR); |
| 219 | FillRateTestNormal("fill_tex_trilinear_linear_05", 0.7071f * 0.7071f); |
| 220 | |
| 221 | // lod = 0.4 |
| 222 | glLoadIdentity(); |
| 223 | glScalef(0.758f, 0.758f, 1.f); |
| 224 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, |
| 225 | GL_LINEAR_MIPMAP_LINEAR); |
| 226 | FillRateTestNormal("fill_tex_trilinear_linear_04", 0.758f * 0.758f); |
| 227 | |
| 228 | // lod = 0.1 |
| 229 | glLoadIdentity(); |
| 230 | glScalef(0.933f, 0.933f, 1.f); |
| 231 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, |
| 232 | GL_LINEAR_MIPMAP_LINEAR); |
| 233 | FillRateTestNormal("fill_tex_trilinear_linear_01", 0.933f * 0.933f); |
| 234 | |
| 235 | glDeleteBuffers(1, &vbo_vertex); |
| 236 | glDeleteBuffers(1, &vbo_texture); |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 237 | glDeleteTextures(1, &texture); |
| 238 | } |
| 239 | |
| 240 | |
Alexey Marinichev | d4a0f07 | 2010-02-09 17:50:12 -0800 | [diff] [blame] | 241 | static void FillRateTestNormal(const char *name, float coeff) { |
Alexey Marinichev | 19b5a5d | 2010-02-18 11:37:26 -0800 | [diff] [blame] | 242 | const int buffer_len = 64; |
| 243 | char buffer[buffer_len]; |
| 244 | snprintf(buffer, buffer_len, "mpixels_sec_%s", name); |
Alexey Marinichev | 96e2869 | 2010-02-18 16:59:59 -0800 | [diff] [blame] | 245 | RunTest(DrawArraysTestFunc, buffer, coeff * g_width * g_height, true); |
Alexey Marinichev | d4a0f07 | 2010-02-09 17:50:12 -0800 | [diff] [blame] | 246 | } |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 247 | |
Alexey Marinichev | d4a0f07 | 2010-02-09 17:50:12 -0800 | [diff] [blame] | 248 | static void FillRateTestBlendDepth(const char *name) { |
Alexey Marinichev | 19b5a5d | 2010-02-18 11:37:26 -0800 | [diff] [blame] | 249 | const int buffer_len = 64; |
| 250 | char buffer[buffer_len]; |
| 251 | |
Alexey Marinichev | 6d01484 | 2010-02-10 19:21:39 -0800 | [diff] [blame] | 252 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
| 253 | glEnable(GL_BLEND); |
Alexey Marinichev | 19b5a5d | 2010-02-18 11:37:26 -0800 | [diff] [blame] | 254 | snprintf(buffer, buffer_len, "mpixels_sec_%s_blended", name); |
Alexey Marinichev | 96e2869 | 2010-02-18 16:59:59 -0800 | [diff] [blame] | 255 | RunTest(DrawArraysTestFunc, buffer, g_width * g_height, true); |
Alexey Marinichev | 6d01484 | 2010-02-10 19:21:39 -0800 | [diff] [blame] | 256 | glDisable(GL_BLEND); |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 257 | |
Alexey Marinichev | 6d01484 | 2010-02-10 19:21:39 -0800 | [diff] [blame] | 258 | glEnable(GL_DEPTH_TEST); |
| 259 | glDepthFunc(GL_NOTEQUAL); |
Alexey Marinichev | 19b5a5d | 2010-02-18 11:37:26 -0800 | [diff] [blame] | 260 | snprintf(buffer, buffer_len, "mpixels_sec_%s_depth_neq", name); |
Alexey Marinichev | 96e2869 | 2010-02-18 16:59:59 -0800 | [diff] [blame] | 261 | RunTest(DrawArraysTestFunc, buffer, g_width * g_height, true); |
Alexey Marinichev | 6d01484 | 2010-02-10 19:21:39 -0800 | [diff] [blame] | 262 | glDepthFunc(GL_NEVER); |
Alexey Marinichev | 19b5a5d | 2010-02-18 11:37:26 -0800 | [diff] [blame] | 263 | snprintf(buffer, buffer_len, "mpixels_sec_%s_depth_never", name); |
Alexey Marinichev | 96e2869 | 2010-02-18 16:59:59 -0800 | [diff] [blame] | 264 | RunTest(DrawArraysTestFunc, buffer, g_width * g_height, true); |
Alexey Marinichev | 6d01484 | 2010-02-10 19:21:39 -0800 | [diff] [blame] | 265 | glDisable(GL_DEPTH_TEST); |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | |
Alexey Marinichev | 96e2869 | 2010-02-18 16:59:59 -0800 | [diff] [blame] | 269 | static void DrawArraysTestFunc(int iter) { |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 270 | glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); |
| 271 | glFlush(); |
| 272 | for (int i = 0; i < iter-1; ++i) { |
| 273 | glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | |
Alexey Marinichev | 96e2869 | 2010-02-18 16:59:59 -0800 | [diff] [blame] | 278 | static void DrawElementsTestFunc(int iter) { |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 279 | glDrawElements(GL_TRIANGLES, arg1, GL_UNSIGNED_INT, arg2); |
| 280 | glFlush(); |
| 281 | for (int i = 0 ; i < iter-1; ++i) { |
| 282 | glDrawElements(GL_TRIANGLES, arg1, GL_UNSIGNED_INT, arg2); |
| 283 | } |
| 284 | } |
| 285 | |
Alexey Marinichev | 6d01484 | 2010-02-10 19:21:39 -0800 | [diff] [blame] | 286 | // Generates a tautological lattice. |
Alexey Marinichev | bf88d1f | 2010-02-12 12:49:16 -0800 | [diff] [blame] | 287 | static void CreateLattice(GLfloat **vertices, GLsizeiptr *size, |
| 288 | GLfloat size_x, GLfloat size_y, |
Alexey Marinichev | 6d01484 | 2010-02-10 19:21:39 -0800 | [diff] [blame] | 289 | int width, int height) |
| 290 | { |
Alexey Marinichev | bf88d1f | 2010-02-12 12:49:16 -0800 | [diff] [blame] | 291 | GLfloat *vptr = *vertices = new GLfloat[2 * (width + 1) * (height + 1)]; |
Alexey Marinichev | 6d01484 | 2010-02-10 19:21:39 -0800 | [diff] [blame] | 292 | for (int j = 0; j <= height; j++) { |
| 293 | for (int i = 0; i <= width; i++) { |
Alexey Marinichev | bf88d1f | 2010-02-12 12:49:16 -0800 | [diff] [blame] | 294 | *vptr++ = i * size_x; |
| 295 | *vptr++ = j * size_y; |
Alexey Marinichev | 6d01484 | 2010-02-10 19:21:39 -0800 | [diff] [blame] | 296 | } |
| 297 | } |
Alexey Marinichev | bf88d1f | 2010-02-12 12:49:16 -0800 | [diff] [blame] | 298 | *size = (vptr - *vertices) * sizeof(GLfloat); |
Alexey Marinichev | 6d01484 | 2010-02-10 19:21:39 -0800 | [diff] [blame] | 299 | } |
| 300 | |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 301 | // Generates a mesh of 2*width*height triangles. The ratio of front facing to |
| 302 | // back facing triangles is culled_ratio/RAND_MAX. Returns the number of |
| 303 | // vertices in the mesh. |
Alexey Marinichev | 6d01484 | 2010-02-10 19:21:39 -0800 | [diff] [blame] | 304 | static int CreateMesh(GLuint **indices, GLsizeiptr *size, |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 305 | int width, int height, int culled_ratio) { |
| 306 | srand(0); |
| 307 | |
Alexey Marinichev | 6d01484 | 2010-02-10 19:21:39 -0800 | [diff] [blame] | 308 | GLuint *iptr = *indices = new GLuint[2 * 3 * (width * height)]; |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 309 | const int swath_height = 4; |
Alexey Marinichev | af0b26d | 2010-02-24 13:03:13 -0800 | [diff] [blame] | 310 | |
| 311 | CHECK(width % swath_height == 0 && height % swath_height == 0); |
| 312 | |
Alexey Marinichev | bf88d1f | 2010-02-12 12:49:16 -0800 | [diff] [blame] | 313 | for (int j = 0; j < height; j += swath_height) { |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 314 | for (int i = 0; i < width; i++) { |
| 315 | for (int j2 = 0; j2 < swath_height; j2++) { |
Alexey Marinichev | 6d01484 | 2010-02-10 19:21:39 -0800 | [diff] [blame] | 316 | GLuint first = (j + j2) * (width + 1) + i; |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 317 | GLuint second = first + 1; |
Alexey Marinichev | 6d01484 | 2010-02-10 19:21:39 -0800 | [diff] [blame] | 318 | GLuint third = first + (width + 1); |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 319 | GLuint fourth = third + 1; |
| 320 | |
| 321 | bool flag = rand() < culled_ratio; |
| 322 | *iptr++ = first; |
| 323 | *iptr++ = flag ? second : third; |
| 324 | *iptr++ = flag ? third : second; |
| 325 | |
| 326 | *iptr++ = fourth; |
| 327 | *iptr++ = flag ? third : second; |
| 328 | *iptr++ = flag ? second : third; |
| 329 | } |
| 330 | } |
| 331 | } |
Alexey Marinichev | 6d01484 | 2010-02-10 19:21:39 -0800 | [diff] [blame] | 332 | *size = (iptr - *indices) * sizeof(GLuint); |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 333 | |
Alexey Marinichev | 6d01484 | 2010-02-10 19:21:39 -0800 | [diff] [blame] | 334 | return iptr - *indices; |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | void TriangleSetupTest() { |
| 338 | glViewport(-g_width, -g_height, g_width*2, g_height*2); |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 339 | |
| 340 | // Larger meshes make this test too slow for devices that do 1 mtri/sec. |
| 341 | GLint width = 64; |
| 342 | GLint height = 64; |
| 343 | |
Alexey Marinichev | bf88d1f | 2010-02-12 12:49:16 -0800 | [diff] [blame] | 344 | GLfloat *vertices = NULL; |
Alexey Marinichev | 6d01484 | 2010-02-10 19:21:39 -0800 | [diff] [blame] | 345 | GLsizeiptr vertex_buffer_size = 0; |
Alexey Marinichev | bf88d1f | 2010-02-12 12:49:16 -0800 | [diff] [blame] | 346 | CreateLattice(&vertices, &vertex_buffer_size, 1.f / g_width, 1.f / g_height, |
| 347 | width, height); |
Alexey Marinichev | 6d01484 | 2010-02-10 19:21:39 -0800 | [diff] [blame] | 348 | GLuint vertex_buffer = SetupVBO(GL_ARRAY_BUFFER, |
| 349 | vertex_buffer_size, vertices); |
Alexey Marinichev | bf88d1f | 2010-02-12 12:49:16 -0800 | [diff] [blame] | 350 | glVertexPointer(2, GL_FLOAT, 0, vertex_buffer != 0 ? 0 : vertices); |
Alexey Marinichev | 96e2869 | 2010-02-18 16:59:59 -0800 | [diff] [blame] | 351 | glEnableClientState(GL_VERTEX_ARRAY); |
Alexey Marinichev | 6d01484 | 2010-02-10 19:21:39 -0800 | [diff] [blame] | 352 | |
| 353 | GLuint *indices = NULL; |
| 354 | GLuint index_buffer = 0; |
| 355 | GLsizeiptr index_buffer_size = 0; |
| 356 | |
Alexey Marinichev | 6d01484 | 2010-02-10 19:21:39 -0800 | [diff] [blame] | 357 | { |
| 358 | arg1 = CreateMesh(&indices, &index_buffer_size, width, height, 0); |
| 359 | |
Alexey Marinichev | 6d01484 | 2010-02-10 19:21:39 -0800 | [diff] [blame] | 360 | index_buffer = SetupVBO(GL_ELEMENT_ARRAY_BUFFER, |
| 361 | index_buffer_size, indices); |
| 362 | arg2 = index_buffer ? 0 : indices; |
| 363 | |
Alexey Marinichev | 96e2869 | 2010-02-18 16:59:59 -0800 | [diff] [blame] | 364 | RunTest(DrawElementsTestFunc, "mtri_sec_triangle_setup", arg1 / 3, true); |
Alexey Marinichev | 6d01484 | 2010-02-10 19:21:39 -0800 | [diff] [blame] | 365 | glEnable(GL_CULL_FACE); |
Alexey Marinichev | 96e2869 | 2010-02-18 16:59:59 -0800 | [diff] [blame] | 366 | RunTest(DrawElementsTestFunc, "mtri_sec_triangle_setup_all_culled", |
Alexey Marinichev | 19b5a5d | 2010-02-18 11:37:26 -0800 | [diff] [blame] | 367 | arg1 / 3, true); |
Alexey Marinichev | 96e2869 | 2010-02-18 16:59:59 -0800 | [diff] [blame] | 368 | glDisable(GL_CULL_FACE); |
Alexey Marinichev | 6d01484 | 2010-02-10 19:21:39 -0800 | [diff] [blame] | 369 | |
Alexey Marinichev | 6d01484 | 2010-02-10 19:21:39 -0800 | [diff] [blame] | 370 | glDeleteBuffers(1, &index_buffer); |
Alexey Marinichev | 96e2869 | 2010-02-18 16:59:59 -0800 | [diff] [blame] | 371 | delete[] indices; |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 372 | } |
| 373 | |
Alexey Marinichev | 6d01484 | 2010-02-10 19:21:39 -0800 | [diff] [blame] | 374 | { |
| 375 | glColor4f(0.f, 1.f, 1.f, 1.f); |
| 376 | arg1 = CreateMesh(&indices, &index_buffer_size, width, height, |
| 377 | RAND_MAX / 2); |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 378 | |
Alexey Marinichev | 6d01484 | 2010-02-10 19:21:39 -0800 | [diff] [blame] | 379 | index_buffer = SetupVBO(GL_ELEMENT_ARRAY_BUFFER, |
| 380 | index_buffer_size, indices); |
| 381 | arg2 = index_buffer ? 0 : indices; |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 382 | |
Alexey Marinichev | 96e2869 | 2010-02-18 16:59:59 -0800 | [diff] [blame] | 383 | glEnable(GL_CULL_FACE); |
| 384 | RunTest(DrawElementsTestFunc, "mtri_sec_triangle_setup_half_culled", |
Alexey Marinichev | 19b5a5d | 2010-02-18 11:37:26 -0800 | [diff] [blame] | 385 | arg1 / 3, true); |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 386 | |
Alexey Marinichev | 6d01484 | 2010-02-10 19:21:39 -0800 | [diff] [blame] | 387 | glDeleteBuffers(1, &index_buffer); |
Alexey Marinichev | 96e2869 | 2010-02-18 16:59:59 -0800 | [diff] [blame] | 388 | delete[] indices; |
Alexey Marinichev | 6d01484 | 2010-02-10 19:21:39 -0800 | [diff] [blame] | 389 | } |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 390 | |
Alexey Marinichev | 6d01484 | 2010-02-10 19:21:39 -0800 | [diff] [blame] | 391 | glDeleteBuffers(1, &vertex_buffer); |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 392 | delete[] vertices; |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | |
Alexey Marinichev | af0b26d | 2010-02-24 13:03:13 -0800 | [diff] [blame] | 396 | void AttributeFetchShaderTest() { |
Alexey Marinichev | 96e2869 | 2010-02-18 16:59:59 -0800 | [diff] [blame] | 397 | GLint width = 64; |
| 398 | GLint height = 64; |
| 399 | |
| 400 | glViewport(-g_width, -g_height, g_width*2, g_height*2); |
| 401 | |
| 402 | GLfloat *vertices = NULL; |
| 403 | GLsizeiptr vertex_buffer_size = 0; |
| 404 | CreateLattice(&vertices, &vertex_buffer_size, 1.f / g_width, 1.f / g_height, |
| 405 | width, height); |
| 406 | GLuint vertex_buffer = SetupVBO(GL_ARRAY_BUFFER, |
| 407 | vertex_buffer_size, vertices); |
| 408 | |
| 409 | GLuint *indices = NULL; |
| 410 | GLuint index_buffer = 0; |
| 411 | GLsizeiptr index_buffer_size = 0; |
| 412 | |
| 413 | // Everything will be back-face culled. |
| 414 | arg1 = CreateMesh(&indices, &index_buffer_size, width, height, 0); |
| 415 | index_buffer = SetupVBO(GL_ELEMENT_ARRAY_BUFFER, |
| 416 | index_buffer_size, indices); |
| 417 | |
| 418 | glEnable(GL_CULL_FACE); |
| 419 | |
| 420 | GLuint vertex_buffers[8]; |
| 421 | for (GLuint i = 0; i < sizeof(vertex_buffers)/sizeof(vertex_buffers[0]); i++) |
| 422 | vertex_buffers[i] = vertex_buffer; |
| 423 | |
| 424 | ShaderProgram program = AttributeFetchShaderProgram(1, vertex_buffers); |
| 425 | RunTest(DrawElementsTestFunc, |
| 426 | "mvtx_sec_attribute_fetch_shader", arg1, true); |
Alexey Marinichev | 3c19973 | 2010-03-11 10:33:35 -0800 | [diff] [blame] | 427 | glDeleteProgram(program); |
Alexey Marinichev | 96e2869 | 2010-02-18 16:59:59 -0800 | [diff] [blame] | 428 | |
Alexey Marinichev | 9b81877 | 2010-02-23 12:07:48 -0800 | [diff] [blame] | 429 | program = AttributeFetchShaderProgram(2, vertex_buffers); |
Alexey Marinichev | 96e2869 | 2010-02-18 16:59:59 -0800 | [diff] [blame] | 430 | RunTest(DrawElementsTestFunc, |
| 431 | "mvtx_sec_attribute_fetch_shader_2_attr", arg1, true); |
Alexey Marinichev | 3c19973 | 2010-03-11 10:33:35 -0800 | [diff] [blame] | 432 | glDeleteProgram(program); |
Alexey Marinichev | 96e2869 | 2010-02-18 16:59:59 -0800 | [diff] [blame] | 433 | |
Alexey Marinichev | 9b81877 | 2010-02-23 12:07:48 -0800 | [diff] [blame] | 434 | program = AttributeFetchShaderProgram(4, vertex_buffers); |
Alexey Marinichev | 96e2869 | 2010-02-18 16:59:59 -0800 | [diff] [blame] | 435 | RunTest(DrawElementsTestFunc, |
| 436 | "mvtx_sec_attribute_fetch_shader_4_attr", arg1, true); |
Alexey Marinichev | 3c19973 | 2010-03-11 10:33:35 -0800 | [diff] [blame] | 437 | glDeleteProgram(program); |
Alexey Marinichev | 96e2869 | 2010-02-18 16:59:59 -0800 | [diff] [blame] | 438 | |
Alexey Marinichev | 9b81877 | 2010-02-23 12:07:48 -0800 | [diff] [blame] | 439 | program = AttributeFetchShaderProgram(8, vertex_buffers); |
Alexey Marinichev | 96e2869 | 2010-02-18 16:59:59 -0800 | [diff] [blame] | 440 | RunTest(DrawElementsTestFunc, |
| 441 | "mvtx_sec_attribute_fetch_shader_8_attr", arg1, true); |
Alexey Marinichev | 3c19973 | 2010-03-11 10:33:35 -0800 | [diff] [blame] | 442 | glDeleteProgram(program); |
Alexey Marinichev | 96e2869 | 2010-02-18 16:59:59 -0800 | [diff] [blame] | 443 | |
| 444 | glDeleteBuffers(1, &index_buffer); |
| 445 | delete[] indices; |
| 446 | |
| 447 | glDeleteBuffers(1, &vertex_buffer); |
| 448 | delete[] vertices; |
| 449 | } |
| 450 | |
Alexey Marinichev | af0b26d | 2010-02-24 13:03:13 -0800 | [diff] [blame] | 451 | |
Alexey Marinichev | c24aa23 | 2010-02-24 18:15:54 -0800 | [diff] [blame] | 452 | void VaryingsAndDdxyShaderTest() { |
Alexey Marinichev | af0b26d | 2010-02-24 13:03:13 -0800 | [diff] [blame] | 453 | glViewport(-g_width, -g_height, g_width*2, g_height*2); |
| 454 | |
| 455 | const int c = 4; |
| 456 | GLfloat *vertices = NULL; |
| 457 | GLsizeiptr vertex_buffer_size = 0; |
| 458 | CreateLattice(&vertices, &vertex_buffer_size, 1.f / c, 1.f / c, c, c); |
| 459 | GLuint vertex_buffer = SetupVBO(GL_ARRAY_BUFFER, |
| 460 | vertex_buffer_size, vertices); |
| 461 | |
| 462 | GLuint *indices = NULL; |
| 463 | GLuint index_buffer = 0; |
| 464 | GLsizeiptr index_buffer_size = 0; |
| 465 | |
| 466 | arg1 = CreateMesh(&indices, &index_buffer_size, c, c, 0); |
| 467 | index_buffer = SetupVBO(GL_ELEMENT_ARRAY_BUFFER, |
| 468 | index_buffer_size, indices); |
| 469 | |
| 470 | ShaderProgram program = VaryingsShaderProgram(1, vertex_buffer); |
| 471 | RunTest(DrawElementsTestFunc, |
| 472 | "mpixels_sec_varyings_shader_1", g_width * g_height, true); |
Alexey Marinichev | 3c19973 | 2010-03-11 10:33:35 -0800 | [diff] [blame] | 473 | glDeleteProgram(program); |
Alexey Marinichev | af0b26d | 2010-02-24 13:03:13 -0800 | [diff] [blame] | 474 | |
| 475 | program = VaryingsShaderProgram(2, vertex_buffer); |
| 476 | RunTest(DrawElementsTestFunc, |
| 477 | "mpixels_sec_varyings_shader_2", g_width * g_height, true); |
Alexey Marinichev | 3c19973 | 2010-03-11 10:33:35 -0800 | [diff] [blame] | 478 | glDeleteProgram(program); |
Alexey Marinichev | af0b26d | 2010-02-24 13:03:13 -0800 | [diff] [blame] | 479 | |
| 480 | program = VaryingsShaderProgram(4, vertex_buffer); |
| 481 | RunTest(DrawElementsTestFunc, |
| 482 | "mpixels_sec_varyings_shader_4", g_width * g_height, true); |
Alexey Marinichev | 3c19973 | 2010-03-11 10:33:35 -0800 | [diff] [blame] | 483 | glDeleteProgram(program); |
Alexey Marinichev | af0b26d | 2010-02-24 13:03:13 -0800 | [diff] [blame] | 484 | |
| 485 | program = VaryingsShaderProgram(8, vertex_buffer); |
| 486 | RunTest(DrawElementsTestFunc, |
| 487 | "mpixels_sec_varyings_shader_8", g_width * g_height, true); |
Alexey Marinichev | 3c19973 | 2010-03-11 10:33:35 -0800 | [diff] [blame] | 488 | glDeleteProgram(program); |
Alexey Marinichev | af0b26d | 2010-02-24 13:03:13 -0800 | [diff] [blame] | 489 | |
Alexey Marinichev | c24aa23 | 2010-02-24 18:15:54 -0800 | [diff] [blame] | 490 | program = DdxDdyShaderProgram(true, vertex_buffer); |
| 491 | RunTest(DrawElementsTestFunc, |
| 492 | "mpixels_sec_ddx_shader", g_width * g_height, true); |
Alexey Marinichev | 3c19973 | 2010-03-11 10:33:35 -0800 | [diff] [blame] | 493 | glDeleteProgram(program); |
Alexey Marinichev | c24aa23 | 2010-02-24 18:15:54 -0800 | [diff] [blame] | 494 | |
| 495 | program = DdxDdyShaderProgram(false, vertex_buffer); |
| 496 | RunTest(DrawElementsTestFunc, |
| 497 | "mpixels_sec_ddy_shader", g_width * g_height, true); |
Alexey Marinichev | 3c19973 | 2010-03-11 10:33:35 -0800 | [diff] [blame] | 498 | glDeleteProgram(program); |
Alexey Marinichev | c24aa23 | 2010-02-24 18:15:54 -0800 | [diff] [blame] | 499 | |
Alexey Marinichev | af0b26d | 2010-02-24 13:03:13 -0800 | [diff] [blame] | 500 | glDeleteBuffers(1, &index_buffer); |
| 501 | delete[] indices; |
| 502 | |
| 503 | glDeleteBuffers(1, &vertex_buffer); |
| 504 | delete[] vertices; |
| 505 | } |
| 506 | |
Alexey Marinichev | 8919b6e | 2010-03-04 16:21:02 -0800 | [diff] [blame] | 507 | |
| 508 | void YuvToRgbShaderTestHelper(int type, const char *name) { |
Alexey Marinichev | 6294a39 | 2010-03-02 16:53:36 -0800 | [diff] [blame] | 509 | size_t size = 0; |
Alexey Marinichev | 6dfea31 | 2010-03-03 14:53:12 -0800 | [diff] [blame] | 510 | GLuint texture[2]; |
Alexey Marinichev | 6294a39 | 2010-03-02 16:53:36 -0800 | [diff] [blame] | 511 | ShaderProgram program = 0; |
| 512 | GLuint vertex_buffer = 0; |
| 513 | GLfloat vertices[8] = { |
| 514 | 0.f, 0.f, |
| 515 | 1.f, 0.f, |
Alexey Marinichev | e5b107a | 2010-03-10 17:51:04 -0800 | [diff] [blame] | 516 | 0.f, 1.f, |
| 517 | 1.f, 1.f, |
Alexey Marinichev | 6294a39 | 2010-03-02 16:53:36 -0800 | [diff] [blame] | 518 | }; |
Alexey Marinichev | 6dfea31 | 2010-03-03 14:53:12 -0800 | [diff] [blame] | 519 | char evenodd[2] = {0, 255}; |
Alexey Marinichev | e5b107a | 2010-03-10 17:51:04 -0800 | [diff] [blame] | 520 | const int pixel_height = YUV2RGB_HEIGHT * 2 / 3; |
Alexey Marinichev | 6294a39 | 2010-03-02 16:53:36 -0800 | [diff] [blame] | 521 | |
| 522 | char *pixels = static_cast<char *>(MmapFile(YUV2RGB_NAME, &size)); |
| 523 | if (!pixels) { |
| 524 | printf("# Could not open image file: %s\n", YUV2RGB_NAME); |
| 525 | goto done; |
| 526 | } |
| 527 | if (size != YUV2RGB_SIZE) { |
Alexey Marinichev | 6dfea31 | 2010-03-03 14:53:12 -0800 | [diff] [blame] | 528 | printf("# Image file of wrong size, got %d, expected %d\n", |
| 529 | static_cast<int>(size), YUV2RGB_SIZE); |
Alexey Marinichev | 6294a39 | 2010-03-02 16:53:36 -0800 | [diff] [blame] | 530 | goto done; |
| 531 | } |
| 532 | |
Alexey Marinichev | 6dfea31 | 2010-03-03 14:53:12 -0800 | [diff] [blame] | 533 | glGenTextures(2, texture); |
| 534 | glActiveTexture(GL_TEXTURE0); |
| 535 | glBindTexture(GL_TEXTURE_2D, texture[0]); |
Alexey Marinichev | 6294a39 | 2010-03-02 16:53:36 -0800 | [diff] [blame] | 536 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 537 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 538 | glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, YUV2RGB_WIDTH, YUV2RGB_HEIGHT, |
| 539 | 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, pixels); |
| 540 | |
Alexey Marinichev | 6dfea31 | 2010-03-03 14:53:12 -0800 | [diff] [blame] | 541 | glActiveTexture(GL_TEXTURE1); |
| 542 | glBindTexture(GL_TEXTURE_2D, texture[1]); |
| 543 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 544 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 545 | glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 2, 1, |
| 546 | 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, evenodd); |
| 547 | |
Alexey Marinichev | e5b107a | 2010-03-10 17:51:04 -0800 | [diff] [blame] | 548 | glViewport(-YUV2RGB_WIDTH, -pixel_height, YUV2RGB_WIDTH*2, pixel_height * 2); |
Alexey Marinichev | 6294a39 | 2010-03-02 16:53:36 -0800 | [diff] [blame] | 549 | vertex_buffer = SetupVBO(GL_ARRAY_BUFFER, sizeof(vertices), vertices); |
| 550 | |
Alexey Marinichev | 8919b6e | 2010-03-04 16:21:02 -0800 | [diff] [blame] | 551 | program = YuvToRgbShaderProgram(type, vertex_buffer, |
Alexey Marinichev | e5b107a | 2010-03-10 17:51:04 -0800 | [diff] [blame] | 552 | YUV2RGB_WIDTH, pixel_height); |
| 553 | |
| 554 | if (program) { |
| 555 | float coeff = 1.f * |
| 556 | (YUV2RGB_WIDTH < g_width ? |
| 557 | static_cast<float>(YUV2RGB_WIDTH) / g_width : 1.f) * |
| 558 | (pixel_height < g_height ? |
| 559 | static_cast<float>(pixel_height) / g_height : 1.f); |
| 560 | FillRateTestNormal(name, coeff); |
| 561 | } else { |
Alexey Marinichev | 6dfea31 | 2010-03-03 14:53:12 -0800 | [diff] [blame] | 562 | printf("# Could not set up YUV shader.\n"); |
Alexey Marinichev | e5b107a | 2010-03-10 17:51:04 -0800 | [diff] [blame] | 563 | } |
Alexey Marinichev | 6294a39 | 2010-03-02 16:53:36 -0800 | [diff] [blame] | 564 | |
| 565 | done: |
Alexey Marinichev | 3c19973 | 2010-03-11 10:33:35 -0800 | [diff] [blame] | 566 | glDeleteProgram(program); |
Alexey Marinichev | 6dfea31 | 2010-03-03 14:53:12 -0800 | [diff] [blame] | 567 | glDeleteTextures(2, texture); |
| 568 | glDeleteBuffers(1, &vertex_buffer); |
Alexey Marinichev | 6294a39 | 2010-03-02 16:53:36 -0800 | [diff] [blame] | 569 | munmap(pixels, size); |
| 570 | } |
| 571 | |
Alexey Marinichev | 8919b6e | 2010-03-04 16:21:02 -0800 | [diff] [blame] | 572 | void YuvToRgbShaderTest1() { |
| 573 | YuvToRgbShaderTestHelper(1, "yuv_shader_1"); |
| 574 | } |
| 575 | |
| 576 | void YuvToRgbShaderTest2() { |
| 577 | YuvToRgbShaderTestHelper(2, "yuv_shader_2"); |
| 578 | } |
| 579 | |
Alexey Marinichev | 6294a39 | 2010-03-02 16:53:36 -0800 | [diff] [blame] | 580 | |
Alexey Marinichev | 3c19973 | 2010-03-11 10:33:35 -0800 | [diff] [blame] | 581 | // TODO: get resources file from a command line option or something. |
Alexey Marinichev | 19b5a5d | 2010-02-18 11:37:26 -0800 | [diff] [blame] | 582 | // TODO: use proper command line parsing library. |
| 583 | static void ParseArgs(int argc, char *argv[]) { |
| 584 | const char **enabled_tests_ptr = enabled_tests; |
| 585 | bool test_name_arg = false; |
| 586 | bool duration_arg = false; |
| 587 | for (int i = 0; i < argc; i++) { |
| 588 | if (test_name_arg) { |
| 589 | test_name_arg = false; |
| 590 | *enabled_tests_ptr++ = argv[i]; |
| 591 | if (enabled_tests_ptr - enabled_tests >= enabled_tests_max) |
| 592 | break; |
| 593 | } else if (duration_arg) { |
| 594 | duration_arg = false; |
| 595 | seconds_to_run = atoi(argv[i]); |
| 596 | } else if (strcmp("-t", argv[i]) == 0) { |
| 597 | test_name_arg = true; |
| 598 | } else if (strcmp("-d", argv[i]) == 0) { |
| 599 | duration_arg = true; |
| 600 | } |
| 601 | } |
| 602 | *enabled_tests_ptr++ = NULL; |
| 603 | } |
| 604 | |
| 605 | |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 606 | int main(int argc, char *argv[]) { |
Antoine Labour | ec7eb53 | 2010-03-12 11:01:34 -0800 | [diff] [blame^] | 607 | SetBasePathFromArgv0(argv[0], "src"); |
Alexey Marinichev | 19b5a5d | 2010-02-18 11:37:26 -0800 | [diff] [blame] | 608 | ParseArgs(argc, argv); |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 609 | if (!Init()) { |
| 610 | printf("# Failed to initialize.\n"); |
| 611 | return 1; |
| 612 | } |
| 613 | |
| 614 | void (*test[])() = { |
| 615 | SwapTest, |
| 616 | ClearTest, |
| 617 | FillRateTest, |
| 618 | TriangleSetupTest, |
Alexey Marinichev | af0b26d | 2010-02-24 13:03:13 -0800 | [diff] [blame] | 619 | AttributeFetchShaderTest, |
Alexey Marinichev | c24aa23 | 2010-02-24 18:15:54 -0800 | [diff] [blame] | 620 | VaryingsAndDdxyShaderTest, |
Alexey Marinichev | 8919b6e | 2010-03-04 16:21:02 -0800 | [diff] [blame] | 621 | YuvToRgbShaderTest1, |
| 622 | YuvToRgbShaderTest2, |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 623 | }; |
| 624 | |
Alexey Marinichev | 19b5a5d | 2010-02-18 11:37:26 -0800 | [diff] [blame] | 625 | uint64_t done = GetUTime() + 1000000ULL * seconds_to_run; |
| 626 | do { |
| 627 | for (unsigned int i = 0; i < sizeof(test) / sizeof(*test); i++) { |
| 628 | InitContext(); |
| 629 | test[i](); |
Alexey Marinichev | 9b81877 | 2010-02-23 12:07:48 -0800 | [diff] [blame] | 630 | GLenum err = glGetError(); |
| 631 | if (err != 0) |
Alexey Marinichev | 8919b6e | 2010-03-04 16:21:02 -0800 | [diff] [blame] | 632 | printf("# glGetError returned non-zero: 0x%x\n", err); |
Alexey Marinichev | 19b5a5d | 2010-02-18 11:37:26 -0800 | [diff] [blame] | 633 | DestroyContext(); |
| 634 | } |
| 635 | } while (GetUTime() < done); |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 636 | |
| 637 | return 0; |
| 638 | } |