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 VBO upload speed. |
| 24 | * That is, measure glBufferDataARB() and glBufferSubDataARB(). |
| 25 | * |
| 26 | * Brian Paul |
| 27 | * 16 Sep 2009 |
| 28 | */ |
| 29 | |
| 30 | #include <string.h> |
| 31 | #include "glmain.h" |
| 32 | #include "common.h" |
| 33 | |
| 34 | |
| 35 | int WinWidth = 100, WinHeight = 100; |
| 36 | |
| 37 | static GLuint VBO; |
| 38 | |
| 39 | static GLsizei VBOSize = 0; |
| 40 | static GLubyte *VBOData = NULL; |
| 41 | |
| 42 | static const GLboolean DrawPoint = GL_TRUE; |
| 43 | static const GLboolean BufferSubDataInHalves = GL_TRUE; |
| 44 | |
| 45 | static const GLfloat Vertex0[2] = { 0.0, 0.0 }; |
| 46 | |
| 47 | |
| 48 | /** Called from test harness/main */ |
| 49 | void |
| 50 | PerfInit(void) |
| 51 | { |
| 52 | /* setup VBO */ |
| 53 | glGenBuffersARB(1, &VBO); |
| 54 | glBindBufferARB(GL_ARRAY_BUFFER_ARB, VBO); |
| 55 | glVertexPointer(2, GL_FLOAT, sizeof(Vertex0), (void *) 0); |
| 56 | glEnableClientState(GL_VERTEX_ARRAY); |
| 57 | } |
| 58 | |
| 59 | |
| 60 | static void |
| 61 | UploadVBO(unsigned count) |
| 62 | { |
| 63 | unsigned i; |
| 64 | for (i = 0; i < count; i++) { |
| 65 | glBufferDataARB(GL_ARRAY_BUFFER, VBOSize, VBOData, GL_STREAM_DRAW_ARB); |
| 66 | |
| 67 | if (DrawPoint) |
| 68 | glDrawArrays(GL_POINTS, 0, 1); |
| 69 | } |
| 70 | glFinish(); |
| 71 | } |
| 72 | |
| 73 | |
| 74 | static void |
| 75 | UploadSubVBO(unsigned count) |
| 76 | { |
| 77 | unsigned i; |
| 78 | for (i = 0; i < count; i++) { |
| 79 | if (BufferSubDataInHalves) { |
| 80 | GLsizei half = VBOSize / 2; |
| 81 | glBufferSubDataARB(GL_ARRAY_BUFFER, 0, half, VBOData); |
| 82 | glBufferSubDataARB(GL_ARRAY_BUFFER, half, half, VBOData + half); |
| 83 | } |
| 84 | else { |
| 85 | glBufferSubDataARB(GL_ARRAY_BUFFER, 0, VBOSize, VBOData); |
| 86 | } |
| 87 | |
| 88 | if (DrawPoint) |
| 89 | glDrawArrays(GL_POINTS, 0, 1); |
| 90 | } |
| 91 | glFinish(); |
| 92 | } |
| 93 | |
| 94 | |
| 95 | static const GLsizei Sizes[] = { |
| 96 | 64, |
| 97 | 1024, |
| 98 | 16*1024, |
| 99 | 256*1024, |
| 100 | 1024*1024, |
| 101 | 16*1024*1024, |
| 102 | 0 /* end of list */ |
| 103 | }; |
| 104 | |
| 105 | |
| 106 | /** Called from test harness/main */ |
| 107 | void |
| 108 | PerfDraw(void) |
| 109 | { |
| 110 | double rate, mbPerSec; |
| 111 | int sub, sz; |
| 112 | |
| 113 | /* loop over whole/sub buffer upload */ |
| 114 | for (sub = 0; sub < 2; sub++) { |
| 115 | |
| 116 | /* loop over VBO sizes */ |
| 117 | for (sz = 0; Sizes[sz]; sz++) { |
| 118 | VBOSize = Sizes[sz]; |
| 119 | |
| 120 | VBOData = malloc(VBOSize); |
| 121 | memcpy(VBOData, Vertex0, sizeof(Vertex0)); |
| 122 | |
| 123 | if (sub) |
| 124 | rate = PerfMeasureRate(UploadSubVBO); |
| 125 | else |
| 126 | rate = PerfMeasureRate(UploadVBO); |
| 127 | |
| 128 | mbPerSec = rate * VBOSize / (1024.0 * 1024.0); |
| 129 | |
| 130 | perf_printf(" glBuffer%sDataARB(size = %d): %.1f MB/sec\n", |
| 131 | (sub ? "Sub" : ""), VBOSize, mbPerSec); |
| 132 | |
| 133 | free(VBOData); |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | exit(0); |
| 138 | } |