OLD | NEW |
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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 if (Bench(f, &slope, &bias)) { | 61 if (Bench(f, &slope, &bias)) { |
62 printf("%s: %g\n", name, coefficient * (inverse ? 1.f / slope : slope)); | 62 printf("%s: %g\n", name, coefficient * (inverse ? 1.f / slope : slope)); |
63 } else { | 63 } else { |
64 printf("# %s is too slow, returning zero.\n", name); | 64 printf("# %s is too slow, returning zero.\n", name); |
65 printf("%s: 0\n", name); | 65 printf("%s: 0\n", name); |
66 } | 66 } |
67 } | 67 } |
68 } | 68 } |
69 | 69 |
70 static int arg1 = 0; | 70 static int arg1 = 0; |
| 71 static void *arg2 = NULL; |
71 | 72 |
72 void SwapTestFunc(int iter) { | 73 void SwapTestFunc(int iter) { |
73 for (int i = 0 ; i < iter; ++i) { | 74 for (int i = 0 ; i < iter; ++i) { |
74 SwapBuffers(); | 75 SwapBuffers(); |
75 } | 76 } |
76 } | 77 } |
77 | 78 |
78 void SwapTest() { | 79 void SwapTest() { |
79 RunTest(SwapTestFunc, "us_swap_swap", 1.f, false); | 80 RunTest(SwapTestFunc, "us_swap_swap", 1.f, false); |
80 } | 81 } |
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
782 | 783 |
783 void NoFillWindowManagerCompositingTest() { | 784 void NoFillWindowManagerCompositingTest() { |
784 glScissor(0, 0, 1, 1); | 785 glScissor(0, 0, 1, 1); |
785 glEnable(GL_SCISSOR_TEST); | 786 glEnable(GL_SCISSOR_TEST); |
786 InitializeCompositing(); | 787 InitializeCompositing(); |
787 RunTest(CompositingTestFunc, "1280x768_fps_no_fill_compositing", | 788 RunTest(CompositingTestFunc, "1280x768_fps_no_fill_compositing", |
788 screen_scale_factor, true); | 789 screen_scale_factor, true); |
789 TeardownCompositing(); | 790 TeardownCompositing(); |
790 } | 791 } |
791 | 792 |
792 // TODO: get resources file from a command line option or something. | 793 void 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. |
| 801 void 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 |
793 // TODO: use proper command line parsing library. | 826 // TODO: use proper command line parsing library. |
794 static void ParseArgs(int argc, char *argv[]) { | 827 static void ParseArgs(int argc, char *argv[]) { |
795 const char **enabled_tests_ptr = enabled_tests; | 828 const char **enabled_tests_ptr = enabled_tests; |
796 bool test_name_arg = false; | 829 bool test_name_arg = false; |
797 bool duration_arg = false; | 830 bool duration_arg = false; |
798 for (int i = 0; i < argc; i++) { | 831 for (int i = 0; i < argc; i++) { |
799 if (test_name_arg) { | 832 if (test_name_arg) { |
800 test_name_arg = false; | 833 test_name_arg = false; |
801 *enabled_tests_ptr++ = argv[i]; | 834 *enabled_tests_ptr++ = argv[i]; |
802 if (enabled_tests_ptr - enabled_tests >= enabled_tests_max) | 835 if (enabled_tests_ptr - enabled_tests >= enabled_tests_max) |
(...skipping 23 matching lines...) Expand all Loading... |
826 SwapTest, | 859 SwapTest, |
827 ClearTest, | 860 ClearTest, |
828 FillRateTest, | 861 FillRateTest, |
829 TriangleSetupTest, | 862 TriangleSetupTest, |
830 AttributeFetchShaderTest, | 863 AttributeFetchShaderTest, |
831 VaryingsAndDdxyShaderTest, | 864 VaryingsAndDdxyShaderTest, |
832 YuvToRgbShaderTest1, | 865 YuvToRgbShaderTest1, |
833 YuvToRgbShaderTest2, | 866 YuvToRgbShaderTest2, |
834 NoFillWindowManagerCompositingTest, | 867 NoFillWindowManagerCompositingTest, |
835 WindowManagerCompositingTest, | 868 WindowManagerCompositingTest, |
| 869 ReadPixelTest, |
836 }; | 870 }; |
837 | 871 |
838 uint64_t done = GetUTime() + 1000000ULL * seconds_to_run; | 872 uint64_t done = GetUTime() + 1000000ULL * seconds_to_run; |
839 do { | 873 do { |
840 for (unsigned int i = 0; i < sizeof(test) / sizeof(*test); i++) { | 874 for (unsigned int i = 0; i < sizeof(test) / sizeof(*test); i++) { |
841 InitContext(); | 875 InitContext(); |
842 test[i](); | 876 test[i](); |
843 GLenum err = glGetError(); | 877 GLenum err = glGetError(); |
844 if (err != 0) | 878 if (err != 0) |
845 printf("# glGetError returned non-zero: 0x%x\n", err); | 879 printf("# glGetError returned non-zero: 0x%x\n", err); |
846 DestroyContext(); | 880 DestroyContext(); |
847 } | 881 } |
848 } while (GetUTime() < done); | 882 } while (GetUTime() < done); |
849 | 883 |
850 return 0; | 884 return 0; |
851 } | 885 } |
OLD | NEW |