Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(252)

Side by Side Diff: client/deps/glbench/src/main.cc

Issue 1732030: Replaced funky state machines with classes. This is in preparation of doing the same to gl_Bench. (Closed) Base URL: ssh://git@chromiumos-git//autotest.git
Patch Set: Got rid of static test list initialization, fixed USE_EGL. Created 10 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « client/deps/glbench/src/main.h ('k') | client/deps/glbench/src/teartest.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <fcntl.h> 5 #include <fcntl.h>
6 #include <stdio.h> 6 #include <stdio.h>
7 #include <stdlib.h> 7 #include <stdlib.h>
8 #include <string.h> 8 #include <string.h>
9 #include <sys/mman.h> 9 #include <sys/mman.h>
10 10
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, 153 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0,
154 GL_RGBA, GL_UNSIGNED_BYTE, pixels); 154 GL_RGBA, GL_UNSIGNED_BYTE, pixels);
155 } 155 }
156 delete[] pixels; 156 delete[] pixels;
157 return name; 157 return name;
158 } 158 }
159 159
160 160
161 static void DrawArraysTestFunc(int iter); 161 static void DrawArraysTestFunc(int iter);
162 static void FillRateTestNormal(const char *name, float coeff=1.f); 162 static void FillRateTestNormal(const char *name, float coeff=1.f);
163
164 #ifndef USE_EGL
163 static void FillRateTestBlendDepth(const char *name); 165 static void FillRateTestBlendDepth(const char *name);
164 166
165 void FillRateTest() { 167 void FillRateTest() {
166 glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); 168 glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
167 glDisable(GL_DEPTH_TEST); 169 glDisable(GL_DEPTH_TEST);
168 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 170 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
169 171
170 GLfloat buffer_vertex[8] = { 172 GLfloat buffer_vertex[8] = {
171 -1.f, -1.f, 173 -1.f, -1.f,
172 1.f, -1.f, 174 1.f, -1.f,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 glLoadIdentity(); 227 glLoadIdentity();
226 glScalef(0.933f, 0.933f, 1.f); 228 glScalef(0.933f, 0.933f, 1.f);
227 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, 229 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
228 GL_LINEAR_MIPMAP_LINEAR); 230 GL_LINEAR_MIPMAP_LINEAR);
229 FillRateTestNormal("fill_tex_trilinear_linear_01", 0.933f * 0.933f); 231 FillRateTestNormal("fill_tex_trilinear_linear_01", 0.933f * 0.933f);
230 232
231 glDeleteBuffers(1, &vbo_vertex); 233 glDeleteBuffers(1, &vbo_vertex);
232 glDeleteBuffers(1, &vbo_texture); 234 glDeleteBuffers(1, &vbo_texture);
233 glDeleteTextures(1, &texture); 235 glDeleteTextures(1, &texture);
234 } 236 }
237 #endif
235 238
236 239
237 static void FillRateTestNormal(const char *name, float coeff) { 240 static void FillRateTestNormal(const char *name, float coeff) {
238 const int buffer_len = 64; 241 const int buffer_len = 64;
239 char buffer[buffer_len]; 242 char buffer[buffer_len];
240 snprintf(buffer, buffer_len, "mpixels_sec_%s", name); 243 snprintf(buffer, buffer_len, "mpixels_sec_%s", name);
241 RunTest(DrawArraysTestFunc, buffer, coeff * g_width * g_height, true); 244 RunTest(DrawArraysTestFunc, buffer, coeff * g_width * g_height, true);
242 } 245 }
243 246
247 #ifndef USE_EGL
244 static void FillRateTestBlendDepth(const char *name) { 248 static void FillRateTestBlendDepth(const char *name) {
245 const int buffer_len = 64; 249 const int buffer_len = 64;
246 char buffer[buffer_len]; 250 char buffer[buffer_len];
247 251
248 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 252 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
249 glEnable(GL_BLEND); 253 glEnable(GL_BLEND);
250 snprintf(buffer, buffer_len, "mpixels_sec_%s_blended", name); 254 snprintf(buffer, buffer_len, "mpixels_sec_%s_blended", name);
251 RunTest(DrawArraysTestFunc, buffer, g_width * g_height, true); 255 RunTest(DrawArraysTestFunc, buffer, g_width * g_height, true);
252 glDisable(GL_BLEND); 256 glDisable(GL_BLEND);
253 257
254 glEnable(GL_DEPTH_TEST); 258 glEnable(GL_DEPTH_TEST);
255 glDepthFunc(GL_NOTEQUAL); 259 glDepthFunc(GL_NOTEQUAL);
256 snprintf(buffer, buffer_len, "mpixels_sec_%s_depth_neq", name); 260 snprintf(buffer, buffer_len, "mpixels_sec_%s_depth_neq", name);
257 RunTest(DrawArraysTestFunc, buffer, g_width * g_height, true); 261 RunTest(DrawArraysTestFunc, buffer, g_width * g_height, true);
258 glDepthFunc(GL_NEVER); 262 glDepthFunc(GL_NEVER);
259 snprintf(buffer, buffer_len, "mpixels_sec_%s_depth_never", name); 263 snprintf(buffer, buffer_len, "mpixels_sec_%s_depth_never", name);
260 RunTest(DrawArraysTestFunc, buffer, g_width * g_height, true); 264 RunTest(DrawArraysTestFunc, buffer, g_width * g_height, true);
261 glDisable(GL_DEPTH_TEST); 265 glDisable(GL_DEPTH_TEST);
262 } 266 }
267 #endif
263 268
264 269
265 static void DrawArraysTestFunc(int iter) { 270 static void DrawArraysTestFunc(int iter) {
266 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 271 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
267 glFlush(); 272 glFlush();
268 for (int i = 0; i < iter-1; ++i) { 273 for (int i = 0; i < iter-1; ++i) {
269 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 274 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
270 } 275 }
271 } 276 }
272 277
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 *iptr++ = flag ? third : second; 328 *iptr++ = flag ? third : second;
324 *iptr++ = flag ? second : third; 329 *iptr++ = flag ? second : third;
325 } 330 }
326 } 331 }
327 } 332 }
328 *size = (iptr - *indices) * sizeof(GLuint); 333 *size = (iptr - *indices) * sizeof(GLuint);
329 334
330 return iptr - *indices; 335 return iptr - *indices;
331 } 336 }
332 337
338 #ifndef USE_EGL
333 void TriangleSetupTest() { 339 void TriangleSetupTest() {
334 glViewport(-g_width, -g_height, g_width*2, g_height*2); 340 glViewport(-g_width, -g_height, g_width*2, g_height*2);
335 341
336 // Larger meshes make this test too slow for devices that do 1 mtri/sec. 342 // Larger meshes make this test too slow for devices that do 1 mtri/sec.
337 GLint width = 64; 343 GLint width = 64;
338 GLint height = 64; 344 GLint height = 64;
339 345
340 GLfloat *vertices = NULL; 346 GLfloat *vertices = NULL;
341 GLsizeiptr vertex_buffer_size = 0; 347 GLsizeiptr vertex_buffer_size = 0;
342 CreateLattice(&vertices, &vertex_buffer_size, 1.f / g_width, 1.f / g_height, 348 CreateLattice(&vertices, &vertex_buffer_size, 1.f / g_width, 1.f / g_height,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 RunTest(DrawElementsTestFunc, "mtri_sec_triangle_setup_half_culled", 382 RunTest(DrawElementsTestFunc, "mtri_sec_triangle_setup_half_culled",
377 arg1 / 3, true); 383 arg1 / 3, true);
378 384
379 glDeleteBuffers(1, &index_buffer); 385 glDeleteBuffers(1, &index_buffer);
380 delete[] indices; 386 delete[] indices;
381 } 387 }
382 388
383 glDeleteBuffers(1, &vertex_buffer); 389 glDeleteBuffers(1, &vertex_buffer);
384 delete[] vertices; 390 delete[] vertices;
385 } 391 }
392 #endif
386 393
387 394
388 void AttributeFetchShaderTest() { 395 void AttributeFetchShaderTest() {
389 GLint width = 64; 396 GLint width = 64;
390 GLint height = 64; 397 GLint height = 64;
391 398
392 glViewport(-g_width, -g_height, g_width*2, g_height*2); 399 glViewport(-g_width, -g_height, g_width*2, g_height*2);
393 400
394 GLfloat *vertices = NULL; 401 GLfloat *vertices = NULL;
395 GLsizeiptr vertex_buffer_size = 0; 402 GLsizeiptr vertex_buffer_size = 0;
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 } 569 }
563 570
564 void YuvToRgbShaderTest1() { 571 void YuvToRgbShaderTest1() {
565 YuvToRgbShaderTestHelper(1, "yuv_shader_1"); 572 YuvToRgbShaderTestHelper(1, "yuv_shader_1");
566 } 573 }
567 574
568 void YuvToRgbShaderTest2() { 575 void YuvToRgbShaderTest2() {
569 YuvToRgbShaderTestHelper(2, "yuv_shader_2"); 576 YuvToRgbShaderTestHelper(2, "yuv_shader_2");
570 } 577 }
571 578
572 static GLuint compositing_textures[5];
573 static uint32_t texture_base[WINDOW_HEIGHT*WINDOW_WIDTH]; 579 static uint32_t texture_base[WINDOW_HEIGHT*WINDOW_WIDTH];
574 static uint32_t texture_update[WINDOW_HEIGHT*WINDOW_WIDTH]; 580 static uint32_t texture_update[WINDOW_HEIGHT*WINDOW_WIDTH];
581 #ifndef USE_EGL
582 static GLuint compositing_textures[5];
575 static ShaderProgram compositing_background_program = 0; 583 static ShaderProgram compositing_background_program = 0;
576 static ShaderProgram compositing_foreground_program = 0; 584 static ShaderProgram compositing_foreground_program = 0;
585 #endif
577 586
578 void InitBaseTexture() { 587 void InitBaseTexture() {
579 for (int y = 0; y < WINDOW_HEIGHT; y++) { 588 for (int y = 0; y < WINDOW_HEIGHT; y++) {
580 for (int x = 0; x < WINDOW_WIDTH; x++) { 589 for (int x = 0; x < WINDOW_WIDTH; x++) {
581 // This color is gray, half alpha. 590 // This color is gray, half alpha.
582 texture_base[y*WINDOW_WIDTH+x] = 0x80808080; 591 texture_base[y*WINDOW_WIDTH+x] = 0x80808080;
583 } 592 }
584 } 593 }
585 } 594 }
586 595
587 // UpdateTexture simulates Chrome updating tab contents. 596 // UpdateTexture simulates Chrome updating tab contents.
588 // We cause a bunch of read and write cpu memory bandwidth. 597 // We cause a bunch of read and write cpu memory bandwidth.
589 // It's a very rough approximation. 598 // It's a very rough approximation.
590 void UpdateTexture() { 599 void UpdateTexture() {
591 memcpy(texture_update, texture_base, sizeof(texture_base)); 600 memcpy(texture_update, texture_base, sizeof(texture_base));
592 } 601 }
593 602
594 void LoadTexture() { 603 void LoadTexture() {
595 // Use GL_RGBA for compatibility with GLES2.0. 604 // Use GL_RGBA for compatibility with GLES2.0.
596 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 605 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
597 WINDOW_WIDTH, WINDOW_HEIGHT, 0, 606 WINDOW_WIDTH, WINDOW_HEIGHT, 0,
598 GL_RGBA, GL_UNSIGNED_BYTE, texture_update); 607 GL_RGBA, GL_UNSIGNED_BYTE, texture_update);
599 } 608 }
600 609
610 #ifndef USE_EGL
601 // Test how fast we can do full-screen compositing of images 611 // Test how fast we can do full-screen compositing of images
602 // continuously updated from the CPU. 612 // continuously updated from the CPU.
603 // This tests both GPU compositing performance and also 613 // This tests both GPU compositing performance and also
604 // CPU -> GPU data transfer speed. 614 // CPU -> GPU data transfer speed.
605 // It is a basic perf test to make sure we have enough performance 615 // It is a basic perf test to make sure we have enough performance
606 // to run a compositing window manager. 616 // to run a compositing window manager.
607 void CompositingTestFunc(int iter) { 617 void CompositingTestFunc(int iter) {
608 for (int i = 0 ; i < iter; ++i) { 618 for (int i = 0 ; i < iter; ++i) {
609 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 619 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
610 620
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 } 792 }
783 793
784 void NoFillWindowManagerCompositingTest() { 794 void NoFillWindowManagerCompositingTest() {
785 glScissor(0, 0, 1, 1); 795 glScissor(0, 0, 1, 1);
786 glEnable(GL_SCISSOR_TEST); 796 glEnable(GL_SCISSOR_TEST);
787 InitializeCompositing(); 797 InitializeCompositing();
788 RunTest(CompositingTestFunc, "1280x768_fps_no_fill_compositing", 798 RunTest(CompositingTestFunc, "1280x768_fps_no_fill_compositing",
789 screen_scale_factor, true); 799 screen_scale_factor, true);
790 TeardownCompositing(); 800 TeardownCompositing();
791 } 801 }
802 #endif
792 803
793 void ReadPixelTestFunc(int iter) { 804 void ReadPixelTestFunc(int iter) {
794 glReadPixels(0, 0, g_width, g_height, GL_RGBA, GL_UNSIGNED_BYTE, arg2); 805 glReadPixels(0, 0, g_width, g_height, GL_RGBA, GL_UNSIGNED_BYTE, arg2);
795 CHECK(glGetError() == 0); 806 CHECK(glGetError() == 0);
796 for (int i = 0; i < iter; i++) 807 for (int i = 0; i < iter; i++)
797 glReadPixels(0, 0, g_width, g_height, GL_RGBA, GL_UNSIGNED_BYTE, arg2); 808 glReadPixels(0, 0, g_width, g_height, GL_RGBA, GL_UNSIGNED_BYTE, arg2);
798 } 809 }
799 810
800 // TODO: better test names. 811 // TODO: better test names.
801 void ReadPixelTest() { 812 void ReadPixelTest() {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 SetBasePathFromArgv0(argv[0], "src"); 862 SetBasePathFromArgv0(argv[0], "src");
852 ParseArgs(argc, argv); 863 ParseArgs(argc, argv);
853 if (!Init()) { 864 if (!Init()) {
854 printf("# Failed to initialize.\n"); 865 printf("# Failed to initialize.\n");
855 return 1; 866 return 1;
856 } 867 }
857 868
858 void (*test[])() = { 869 void (*test[])() = {
859 SwapTest, 870 SwapTest,
860 ClearTest, 871 ClearTest,
861 FillRateTest,
862 TriangleSetupTest,
863 AttributeFetchShaderTest, 872 AttributeFetchShaderTest,
864 VaryingsAndDdxyShaderTest, 873 VaryingsAndDdxyShaderTest,
865 YuvToRgbShaderTest1, 874 YuvToRgbShaderTest1,
866 YuvToRgbShaderTest2, 875 YuvToRgbShaderTest2,
876 #ifndef USE_EGL
877 FillRateTest,
878 TriangleSetupTest,
867 NoFillWindowManagerCompositingTest, 879 NoFillWindowManagerCompositingTest,
868 WindowManagerCompositingTest, 880 WindowManagerCompositingTest,
881 #endif
869 ReadPixelTest, 882 ReadPixelTest,
870 }; 883 };
871 884
872 uint64_t done = GetUTime() + 1000000ULL * seconds_to_run; 885 uint64_t done = GetUTime() + 1000000ULL * seconds_to_run;
873 do { 886 do {
874 for (unsigned int i = 0; i < sizeof(test) / sizeof(*test); i++) { 887 for (unsigned int i = 0; i < sizeof(test) / sizeof(*test); i++) {
875 InitContext(); 888 InitContext();
876 test[i](); 889 test[i]();
877 GLenum err = glGetError(); 890 GLenum err = glGetError();
878 if (err != 0) 891 if (err != 0)
879 printf("# glGetError returned non-zero: 0x%x\n", err); 892 printf("# glGetError returned non-zero: 0x%x\n", err);
880 DestroyContext(); 893 DestroyContext();
881 } 894 }
882 } while (GetUTime() < done); 895 } while (GetUTime() < done);
883 896
884 return 0; 897 return 0;
885 } 898 }
OLDNEW
« no previous file with comments | « client/deps/glbench/src/main.h ('k') | client/deps/glbench/src/teartest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698