Keith Whitwell | 2884c31 | 2009-09-17 12:09:16 +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). |
Keith Whitwell | 2884c31 | 2009-09-17 12:09:16 +0100 | [diff] [blame] | 30 | * |
| 31 | * Brian Paul |
| 32 | * 15 Sep 2009 |
| 33 | */ |
| 34 | |
| 35 | #include "glmain.h" |
| 36 | #include "common.h" |
| 37 | |
| 38 | |
| 39 | int WinWidth = 100, WinHeight = 100; |
| 40 | |
| 41 | static GLuint VBO; |
| 42 | |
| 43 | struct vertex |
| 44 | { |
| 45 | GLfloat x, y; |
| 46 | }; |
| 47 | |
| 48 | static const struct vertex vertices[4] = { |
| 49 | { -1.0, -1.0 }, |
| 50 | { 1.0, -1.0 }, |
| 51 | { 1.0, 1.0 }, |
| 52 | { -1.0, 1.0 } |
| 53 | }; |
| 54 | |
| 55 | |
| 56 | /** Called from test harness/main */ |
| 57 | void |
| 58 | PerfInit(void) |
| 59 | { |
| 60 | /* setup VBO w/ vertex data */ |
| 61 | glGenBuffersARB(1, &VBO); |
| 62 | glBindBufferARB(GL_ARRAY_BUFFER_ARB, VBO); |
| 63 | glBufferDataARB(GL_ARRAY_BUFFER_ARB, |
| 64 | sizeof(vertices), vertices, GL_STATIC_DRAW_ARB); |
| 65 | glVertexPointer(2, GL_FLOAT, sizeof(struct vertex), (void *) 0); |
| 66 | glEnableClientState(GL_VERTEX_ARRAY); |
| 67 | |
| 68 | /* misc GL state */ |
| 69 | glAlphaFunc(GL_ALWAYS, 0.0); |
| 70 | } |
| 71 | |
| 72 | |
| 73 | static void |
| 74 | DrawNoStateChange(unsigned count) |
| 75 | { |
| 76 | unsigned i; |
| 77 | for (i = 0; i < count; i++) { |
| 78 | glDrawArrays(GL_POINTS, 0, 4); |
| 79 | } |
| 80 | glFinish(); |
| 81 | } |
| 82 | |
| 83 | |
| 84 | static void |
| 85 | DrawNopStateChange(unsigned count) |
| 86 | { |
| 87 | unsigned i; |
| 88 | for (i = 0; i < count; i++) { |
| 89 | glDisable(GL_ALPHA_TEST); |
| 90 | glDrawArrays(GL_POINTS, 0, 4); |
| 91 | } |
| 92 | glFinish(); |
| 93 | } |
| 94 | |
| 95 | |
| 96 | static void |
| 97 | DrawStateChange(unsigned count) |
| 98 | { |
| 99 | unsigned i; |
| 100 | for (i = 0; i < count; i++) { |
| 101 | if (i & 1) |
| 102 | glEnable(GL_TEXTURE_GEN_S); |
| 103 | else |
| 104 | glDisable(GL_TEXTURE_GEN_S); |
| 105 | glDrawArrays(GL_POINTS, 0, 4); |
| 106 | } |
| 107 | glFinish(); |
| 108 | } |
| 109 | |
Keith Whitwell | a7b2659 | 2009-09-21 16:55:12 +0100 | [diff] [blame] | 110 | void |
| 111 | PerfNextRound(void) |
| 112 | { |
| 113 | } |
Keith Whitwell | 2884c31 | 2009-09-17 12:09:16 +0100 | [diff] [blame] | 114 | |
| 115 | /** Called from test harness/main */ |
| 116 | void |
| 117 | PerfDraw(void) |
| 118 | { |
| 119 | double rate0, rate1, rate2, overhead; |
| 120 | |
| 121 | rate0 = PerfMeasureRate(DrawNoStateChange); |
Keith Whitwell | 25a580c | 2009-09-21 15:54:28 +0100 | [diff] [blame] | 122 | perf_printf(" Draw only: %s draws/second\n", |
| 123 | PerfHumanFloat(rate0)); |
Keith Whitwell | 2884c31 | 2009-09-17 12:09:16 +0100 | [diff] [blame] | 124 | |
Keith Whitwell | 2884c31 | 2009-09-17 12:09:16 +0100 | [diff] [blame] | 125 | rate1 = PerfMeasureRate(DrawNopStateChange); |
| 126 | overhead = 1000.0 * (1.0 / rate1 - 1.0 / rate0); |
Keith Whitwell | 25a580c | 2009-09-21 15:54:28 +0100 | [diff] [blame] | 127 | perf_printf(" Draw w/ nop state change: %s draws/sec (overhead: %f ms/draw)\n", |
| 128 | PerfHumanFloat(rate1), overhead); |
Keith Whitwell | 2884c31 | 2009-09-17 12:09:16 +0100 | [diff] [blame] | 129 | |
| 130 | rate2 = PerfMeasureRate(DrawStateChange); |
| 131 | overhead = 1000.0 * (1.0 / rate2 - 1.0 / rate0); |
Keith Whitwell | 25a580c | 2009-09-21 15:54:28 +0100 | [diff] [blame] | 132 | perf_printf(" Draw w/ state change: %s draws/sec (overhead: %f ms/draw)\n", |
| 133 | PerfHumanFloat(rate2), overhead); |
Keith Whitwell | 2884c31 | 2009-09-17 12:09:16 +0100 | [diff] [blame] | 134 | |
| 135 | exit(0); |
| 136 | } |
| 137 | |