Keith Whitwell | a7b2659 | 2009-09-21 16:55:12 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2009 VMware, Inc. All Rights Reserved. |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice shall be included |
| 12 | * in all copies or substantial portions of the Software. |
| 13 | * |
| 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 17 | * VMWARE BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
| 18 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 19 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 20 | */ |
| 21 | |
| 22 | /** |
| 23 | * Measure drawing overhead |
| 24 | * |
| 25 | * This is the first in a series of simple performance benchmarks. |
| 26 | * The code in this file should be as simple as possible to make it |
| 27 | * easily portable to other APIs. |
| 28 | * |
| 29 | * All the window-system stuff should be contained in glmain.c (or TBDmain.c). |
| 30 | * All the re-usable, generic code should be in common.c (XXX not done yet). |
| 31 | * |
| 32 | * Brian Paul |
| 33 | * 15 Sep 2009 |
| 34 | */ |
| 35 | |
| 36 | #include "glmain.h" |
| 37 | #include "common.h" |
| 38 | |
| 39 | |
| 40 | int WinWidth = 100, WinHeight = 100; |
| 41 | int real_WinWidth, real_WinHeight; /* don't know whats going on here */ |
| 42 | |
| 43 | static GLuint VBO; |
| 44 | |
| 45 | struct vertex |
| 46 | { |
| 47 | GLfloat x, y; |
| 48 | }; |
| 49 | |
| 50 | static const struct vertex vertices[4] = { |
| 51 | { -1.0, -1.0 }, |
| 52 | { 1.0, -1.0 }, |
| 53 | { 1.0, 1.0 }, |
| 54 | { -1.0, 1.0 } |
| 55 | }; |
| 56 | |
| 57 | |
| 58 | /** Called from test harness/main */ |
| 59 | void |
| 60 | PerfInit(void) |
| 61 | { |
| 62 | /* setup VBO w/ vertex data */ |
| 63 | glGenBuffersARB(1, &VBO); |
| 64 | glBindBufferARB(GL_ARRAY_BUFFER_ARB, VBO); |
| 65 | glBufferDataARB(GL_ARRAY_BUFFER_ARB, |
| 66 | sizeof(vertices), vertices, GL_STATIC_DRAW_ARB); |
| 67 | glVertexPointer(2, GL_FLOAT, sizeof(struct vertex), (void *) 0); |
| 68 | glEnableClientState(GL_VERTEX_ARRAY); |
| 69 | |
| 70 | /* misc GL state */ |
| 71 | glAlphaFunc(GL_ALWAYS, 0.0); |
| 72 | } |
| 73 | |
| 74 | static void |
| 75 | SwapNaked(unsigned count) |
| 76 | { |
| 77 | unsigned i; |
| 78 | for (i = 0; i < count; i++) { |
| 79 | PerfSwapBuffers(); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | |
| 84 | static void |
| 85 | SwapClear(unsigned count) |
| 86 | { |
| 87 | unsigned i; |
| 88 | for (i = 0; i < count; i++) { |
| 89 | glClear(GL_COLOR_BUFFER_BIT); |
| 90 | PerfSwapBuffers(); |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | static void |
| 95 | SwapClearPoint(unsigned count) |
| 96 | { |
| 97 | unsigned i; |
| 98 | for (i = 0; i < count; i++) { |
| 99 | glClear(GL_COLOR_BUFFER_BIT); |
| 100 | glDrawArrays(GL_POINTS, 0, 4); |
| 101 | PerfSwapBuffers(); |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | |
| 106 | static const struct { |
| 107 | unsigned w; |
| 108 | unsigned h; |
| 109 | } sizes[] = { |
| 110 | { 320, 240 }, |
| 111 | { 640, 480 }, |
| 112 | { 1024, 768 }, |
| 113 | { 1200, 1024 }, |
| 114 | { 1600, 1200 } |
| 115 | }; |
| 116 | |
| 117 | void |
| 118 | PerfNextRound(void) |
| 119 | { |
| 120 | static unsigned i; |
| 121 | |
| 122 | if (i < sizeof(sizes) / sizeof(sizes[0])) { |
| 123 | perf_printf("Reshape %dx%d\n", sizes[i].w, sizes[i].h); |
| 124 | PerfReshapeWindow( sizes[i].w, sizes[i].h ); |
| 125 | real_WinWidth = sizes[i].w; |
| 126 | real_WinHeight = sizes[i].h; |
| 127 | i++; |
| 128 | } |
| 129 | else { |
| 130 | exit(0); |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | /** Called from test harness/main */ |
| 138 | void |
| 139 | PerfDraw(void) |
| 140 | { |
| 141 | double rate0; |
| 142 | |
| 143 | rate0 = PerfMeasureRate(SwapNaked); |
| 144 | perf_printf(" Swapbuffers (Bare) %dx%d: %s swaps/second", |
| 145 | real_WinWidth, real_WinHeight, |
| 146 | PerfHumanFloat(rate0)); |
| 147 | perf_printf(" %s pixels/second\n", |
| 148 | PerfHumanFloat(rate0 * real_WinWidth * real_WinHeight)); |
| 149 | |
| 150 | |
| 151 | |
| 152 | rate0 = PerfMeasureRate(SwapClear); |
| 153 | perf_printf(" Swapbuffers + Clear %dx%d: %s swaps/second", |
| 154 | real_WinWidth, real_WinHeight, |
| 155 | PerfHumanFloat(rate0)); |
| 156 | perf_printf(" %s pixels/second\n", |
| 157 | PerfHumanFloat(rate0 * real_WinWidth * real_WinHeight)); |
| 158 | |
| 159 | |
| 160 | rate0 = PerfMeasureRate(SwapClearPoint); |
| 161 | perf_printf(" Swapbuffers + Clear + DrawPoint %dx%d: %s swaps/second", |
| 162 | real_WinWidth, real_WinHeight, |
| 163 | PerfHumanFloat(rate0)); |
| 164 | perf_printf(" %s pixels/second\n", |
| 165 | PerfHumanFloat(rate0 * real_WinWidth * real_WinHeight)); |
| 166 | } |
| 167 | |