--- /dev/null
+# progs/demos/Makefile
+
+TOP = ../..
+include $(TOP)/configs/current
+
+INCDIR = $(TOP)/include
+
+LIBS = -L$(TOP)/$(LIB_DIR) -l$(GLUT_LIB) -l$(GLEW_LIB) \
+ -l$(GLU_LIB) -l$(GL_LIB) $(APP_LIB_DEPS)
+
+# using : to avoid APP_CC pointing to CC loop
+CC := $(APP_CC)
+CFLAGS += -I$(INCDIR)
+LDLIBS = $(LIBS)
+
+PROG_SOURCES = \
+ drawoverhead.c \
+ teximage.c \
+ vbo.c \
+ vertexrate.c \
+
+PROG_OBJS = $(PROG_SOURCES:.c=.o)
+
+PROGS = $(PROG_SOURCES:%.c=%)
+
+
+UTIL_SOURCES = \
+ common.c \
+ glmain.c
+
+UTIL_HEADERS = \
+ common.h \
+ glmain.h
+
+UTIL_OBJS = $(UTIL_SOURCES:.c=.o)
+
+
+
+default: $(PROGS)
+
+$(PROG_OBJS): $(UTIL_HEADERS)
+
+$(PROGS): $(UTIL_OBJS)
+
+
+
+clean:
+ -rm -f $(PROGS)
+ -rm -f *.o *~
--- /dev/null
+/*
+ * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * VMWARE BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * Common perf code. This should be re-usable with other APIs.
+ */
+
+#include "common.h"
+#include "glmain.h"
+
+
+/**
+ * Run function 'f' for enough iterations to reach a steady state.
+ * Return the rate (iterations/second).
+ */
+double
+PerfMeasureRate(PerfRateFunc f)
+{
+ const double minDuration = 1.0;
+ double rate = 0.0, prevRate = 0.0;
+ unsigned subiters;
+
+ /* Compute initial number of iterations to try.
+ * If the test function is pretty slow this helps to avoid
+ * extraordarily long run times.
+ */
+ subiters = 2;
+ {
+ const double t0 = PerfGetTime();
+ double t1;
+ do {
+ f(subiters); /* call the rendering function */
+ t1 = PerfGetTime();
+ subiters *= 2;
+ } while (t1 - t0 < 0.1 * minDuration);
+ }
+ /*printf("initial subIters = %u\n", subiters);*/
+
+ while (1) {
+ const double t0 = PerfGetTime();
+ unsigned iters = 0;
+ double t1;
+
+ do {
+ f(subiters); /* call the rendering function */
+ t1 = PerfGetTime();
+ iters += subiters;
+ } while (t1 - t0 < minDuration);
+
+ rate = iters / (t1 - t0);
+
+ if (0)
+ printf("prevRate %f rate %f ratio %f iters %u\n",
+ prevRate, rate, rate/prevRate, iters);
+
+ /* Try and speed the search up by skipping a few steps:
+ */
+ if (rate > prevRate * 1.6)
+ subiters *= 8;
+ else if (rate > prevRate * 1.2)
+ subiters *= 4;
+ else if (rate > prevRate * 1.05)
+ subiters *= 2;
+ else
+ break;
+
+ prevRate = rate;
+ }
+
+ if (0)
+ printf("%s returning iters %u rate %f\n", __FUNCTION__, subiters, rate);
+ return rate;
+}
+
+
--- /dev/null
+/*
+ * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * VMWARE BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+#ifndef COMMON_H
+#define COMMON_H
+
+
+typedef void (*PerfRateFunc)(unsigned count);
+
+
+extern double
+PerfMeasureRate(PerfRateFunc f);
+
+
+#endif /* COMMON_H */
+
--- /dev/null
+/*\r
+ * Copyright (C) 2009 VMware, Inc. All Rights Reserved.\r
+ *\r
+ * Permission is hereby granted, free of charge, to any person obtaining a\r
+ * copy of this software and associated documentation files (the "Software"),\r
+ * to deal in the Software without restriction, including without limitation\r
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
+ * and/or sell copies of the Software, and to permit persons to whom the\r
+ * Software is furnished to do so, subject to the following conditions:\r
+ *\r
+ * The above copyright notice and this permission notice shall be included\r
+ * in all copies or substantial portions of the Software.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\r
+ * VMWARE BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN\r
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+ */\r
+\r
+/**\r
+ * Measure drawing overhead\r
+ *\r
+ * This is the first in a series of simple performance benchmarks.\r
+ * The code in this file should be as simple as possible to make it\r
+ * easily portable to other APIs.\r
+ *\r
+ * All the window-system stuff should be contained in glmain.c (or TBDmain.c).\r
+ * All the re-usable, generic code should be in common.c (XXX not done yet).\r
+ *\r
+ * Brian Paul\r
+ * 15 Sep 2009\r
+ */\r
+\r
+#include "glmain.h"\r
+#include "common.h"\r
+\r
+\r
+int WinWidth = 100, WinHeight = 100;\r
+\r
+static GLuint VBO;\r
+\r
+struct vertex\r
+{\r
+ GLfloat x, y;\r
+};\r
+\r
+static const struct vertex vertices[4] = {\r
+ { -1.0, -1.0 },\r
+ { 1.0, -1.0 },\r
+ { 1.0, 1.0 },\r
+ { -1.0, 1.0 }\r
+};\r
+\r
+\r
+/** Called from test harness/main */\r
+void\r
+PerfInit(void)\r
+{\r
+ /* setup VBO w/ vertex data */\r
+ glGenBuffersARB(1, &VBO);\r
+ glBindBufferARB(GL_ARRAY_BUFFER_ARB, VBO);\r
+ glBufferDataARB(GL_ARRAY_BUFFER_ARB,\r
+ sizeof(vertices), vertices, GL_STATIC_DRAW_ARB);\r
+ glVertexPointer(2, GL_FLOAT, sizeof(struct vertex), (void *) 0);\r
+ glEnableClientState(GL_VERTEX_ARRAY);\r
+\r
+ /* misc GL state */\r
+ glAlphaFunc(GL_ALWAYS, 0.0);\r
+}\r
+\r
+\r
+static void\r
+DrawNoStateChange(unsigned count)\r
+{\r
+ unsigned i;\r
+ for (i = 0; i < count; i++) {\r
+ glDrawArrays(GL_POINTS, 0, 4);\r
+ }\r
+ glFinish();\r
+}\r
+\r
+\r
+static void\r
+DrawNopStateChange(unsigned count)\r
+{\r
+ unsigned i;\r
+ for (i = 0; i < count; i++) {\r
+ glDisable(GL_ALPHA_TEST);\r
+ glDrawArrays(GL_POINTS, 0, 4);\r
+ }\r
+ glFinish();\r
+}\r
+\r
+\r
+static void\r
+DrawStateChange(unsigned count)\r
+{\r
+ unsigned i;\r
+ for (i = 0; i < count; i++) {\r
+ if (i & 1)\r
+ glEnable(GL_TEXTURE_GEN_S);\r
+ else\r
+ glDisable(GL_TEXTURE_GEN_S);\r
+ glDrawArrays(GL_POINTS, 0, 4);\r
+ }\r
+ glFinish();\r
+}\r
+\r
+\r
+/** Called from test harness/main */\r
+void\r
+PerfDraw(void)\r
+{\r
+ double rate0, rate1, rate2, overhead;\r
+\r
+ rate0 = PerfMeasureRate(DrawNoStateChange);\r
+ printf(" Draw only: %.1f draws/second\n", rate0);\r
+\r
+ rate1 = PerfMeasureRate(DrawNopStateChange);\r
+ overhead = 1000.0 * (1.0 / rate1 - 1.0 / rate0);\r
+ printf(" Draw w/ nop state change: %.1f draws/sec (overhead: %f ms/draw)\n",\r
+ rate1, overhead);\r
+\r
+ rate2 = PerfMeasureRate(DrawStateChange);\r
+ overhead = 1000.0 * (1.0 / rate2 - 1.0 / rate0);\r
+ printf(" Draw w/ state change: %.1f draws/sec (overhead: %f ms/draw)\n",\r
+ rate2, overhead);\r
+\r
+ exit(0);\r
+}\r
+\r
--- /dev/null
+/*
+ * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * VMWARE BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * OpenGL/GLUT common code for perf programs.
+ * Brian Paul
+ * 15 Sep 2009
+ */
+
+
+#include "glmain.h"
+#include <GL/glut.h>
+
+
+static int Win;
+static GLfloat Xrot = 0, Yrot = 0, Zrot = 0;
+static GLboolean Anim = GL_FALSE;
+
+
+/** Return time in seconds */
+double
+PerfGetTime(void)
+{
+ return glutGet(GLUT_ELAPSED_TIME) * 0.001;
+}
+
+
+void
+PerfSwapBuffers(void)
+{
+ glutSwapBuffers();
+}
+
+
+static void
+Idle(void)
+{
+ Xrot += 3.0;
+ Yrot += 4.0;
+ Zrot += 2.0;
+ glutPostRedisplay();
+}
+
+
+static void
+Draw(void)
+{
+ PerfDraw();
+ glutSwapBuffers();
+}
+
+
+static void
+Reshape(int width, int height)
+{
+ WinWidth = width;
+ WinHeight = height;
+ glViewport(0, 0, width, height);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0);
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ glTranslatef(0.0, 0.0, -15.0);
+}
+
+
+static void
+Key(unsigned char key, int x, int y)
+{
+ const GLfloat step = 3.0;
+ (void) x;
+ (void) y;
+ switch (key) {
+ case 'a':
+ Anim = !Anim;
+ if (Anim)
+ glutIdleFunc(Idle);
+ else
+ glutIdleFunc(NULL);
+ break;
+ case 'z':
+ Zrot -= step;
+ break;
+ case 'Z':
+ Zrot += step;
+ break;
+ case 27:
+ glutDestroyWindow(Win);
+ exit(0);
+ break;
+ }
+ glutPostRedisplay();
+}
+
+
+static void
+SpecialKey(int key, int x, int y)
+{
+ const GLfloat step = 3.0;
+ (void) x;
+ (void) y;
+ switch (key) {
+ case GLUT_KEY_UP:
+ Xrot -= step;
+ break;
+ case GLUT_KEY_DOWN:
+ Xrot += step;
+ break;
+ case GLUT_KEY_LEFT:
+ Yrot -= step;
+ break;
+ case GLUT_KEY_RIGHT:
+ Yrot += step;
+ break;
+ }
+ glutPostRedisplay();
+}
+
+
+int
+main(int argc, char *argv[])
+{
+ glutInit(&argc, argv);
+ glutInitWindowSize(WinWidth, WinHeight);
+ glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
+ Win = glutCreateWindow(argv[0]);
+ glewInit();
+ glutReshapeFunc(Reshape);
+ glutKeyboardFunc(Key);
+ glutSpecialFunc(SpecialKey);
+ glutDisplayFunc(Draw);
+ if (Anim)
+ glutIdleFunc(Idle);
+ PerfInit();
+ glutMainLoop();
+ return 0;
+}
--- /dev/null
+/*
+ * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * VMWARE BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+#ifndef GLMAIN_H
+#define GLMAIN_H
+
+
+#define GL_GLEXT_PROTOTYPES
+#include <GL/glew.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+
+
+/** Test programs can use these vars/functions */
+
+extern int WinWidth, WinHeight;
+
+extern double
+PerfGetTime(void);
+
+extern void
+PerfSwapBuffers(void);
+
+
+/** Test programs must implement these functions **/
+
+extern void
+PerfInit(void);
+
+extern void
+PerfDraw(void);
+
+
+#endif /* GLMAIN_H */
--- /dev/null
+/*\r
+ * Copyright (C) 2009 VMware, Inc. All Rights Reserved.\r
+ *\r
+ * Permission is hereby granted, free of charge, to any person obtaining a\r
+ * copy of this software and associated documentation files (the "Software"),\r
+ * to deal in the Software without restriction, including without limitation\r
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
+ * and/or sell copies of the Software, and to permit persons to whom the\r
+ * Software is furnished to do so, subject to the following conditions:\r
+ *\r
+ * The above copyright notice and this permission notice shall be included\r
+ * in all copies or substantial portions of the Software.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\r
+ * VMWARE BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN\r
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+ */\r
+\r
+/**\r
+ * Measure glTexSubImage2D rate\r
+ *\r
+ * Brian Paul\r
+ * 16 Sep 2009\r
+ */\r
+\r
+#include "glmain.h"\r
+#include "common.h"\r
+\r
+\r
+int WinWidth = 100, WinHeight = 100;\r
+\r
+static GLuint VBO;\r
+static GLuint TexObj = 0;\r
+static GLubyte *TexImage = NULL;\r
+static GLsizei TexSize;\r
+static GLenum TexSrcFormat, TexSrcType;\r
+\r
+static const GLboolean DrawPoint = GL_TRUE;\r
+static const GLboolean TexSubImage4 = GL_TRUE;\r
+\r
+struct vertex\r
+{\r
+ GLfloat x, y, s, t;\r
+};\r
+\r
+static const struct vertex vertices[1] = {\r
+ { 0.0, 0.0, 0.5, 0.5 },\r
+};\r
+\r
+\r
+#define VOFFSET(F) ((void *) offsetof(struct vertex, F))\r
+\r
+/** Called from test harness/main */\r
+void\r
+PerfInit(void)\r
+{\r
+ /* setup VBO w/ vertex data */\r
+ glGenBuffersARB(1, &VBO);\r
+ glBindBufferARB(GL_ARRAY_BUFFER_ARB, VBO);\r
+ glBufferDataARB(GL_ARRAY_BUFFER_ARB,\r
+ sizeof(vertices), vertices, GL_STATIC_DRAW_ARB);\r
+ glVertexPointer(2, GL_FLOAT, sizeof(struct vertex), VOFFSET(x));\r
+ glTexCoordPointer(2, GL_FLOAT, sizeof(struct vertex), VOFFSET(s));\r
+ glEnableClientState(GL_VERTEX_ARRAY);\r
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);\r
+\r
+ /* texture */\r
+ glGenTextures(1, &TexObj);\r
+ glBindTexture(GL_TEXTURE_2D, TexObj);\r
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);\r
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);\r
+ glEnable(GL_TEXTURE_2D);\r
+}\r
+\r
+\r
+static void\r
+UploadTexImage2D(unsigned count)\r
+{\r
+ unsigned i;\r
+ for (i = 0; i < count; i++) {\r
+ /* XXX is this equivalent to a glTexSubImage call since we're\r
+ * always specifying the same image size? That case isn't optimized\r
+ * in Mesa but may be optimized in other drivers. Note sure how\r
+ * much difference that might make.\r
+ */\r
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,\r
+ TexSize, TexSize, 0,\r
+ TexSrcFormat, TexSrcType, TexImage);\r
+ if (DrawPoint)\r
+ glDrawArrays(GL_POINTS, 0, 1);\r
+ }\r
+ glFinish();\r
+}\r
+\r
+\r
+static void\r
+UploadTexSubImage2D(unsigned count)\r
+{\r
+ unsigned i;\r
+ for (i = 0; i < count; i++) {\r
+ if (TexSubImage4) {\r
+ GLsizei halfSize = (TexSize == 1) ? 1 : TexSize / 2;\r
+ GLsizei halfPos = TexSize - halfSize;\r
+ /* do glTexSubImage2D in four pieces */\r
+ /* lower-left */\r
+ glPixelStorei(GL_UNPACK_ROW_LENGTH, TexSize);\r
+ glTexSubImage2D(GL_TEXTURE_2D, 0,\r
+ 0, 0, halfSize, halfSize,\r
+ TexSrcFormat, TexSrcType, TexImage);\r
+ /* lower-right */\r
+ glPixelStorei(GL_UNPACK_SKIP_PIXELS, halfPos);\r
+ glTexSubImage2D(GL_TEXTURE_2D, 0,\r
+ halfPos, 0, halfSize, halfSize,\r
+ TexSrcFormat, TexSrcType, TexImage);\r
+ /* upper-left */\r
+ glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);\r
+ glPixelStorei(GL_UNPACK_SKIP_ROWS, halfPos);\r
+ glTexSubImage2D(GL_TEXTURE_2D, 0,\r
+ 0, halfPos, halfSize, halfSize,\r
+ TexSrcFormat, TexSrcType, TexImage);\r
+ /* upper-right */\r
+ glPixelStorei(GL_UNPACK_SKIP_PIXELS, halfPos);\r
+ glPixelStorei(GL_UNPACK_SKIP_ROWS, halfPos);\r
+ glTexSubImage2D(GL_TEXTURE_2D, 0,\r
+ halfPos, halfPos, halfSize, halfSize,\r
+ TexSrcFormat, TexSrcType, TexImage);\r
+ /* reset the unpacking state */\r
+ glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);\r
+ glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);\r
+ glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);\r
+ }\r
+ else {\r
+ /* replace whole texture image at once */\r
+ glTexSubImage2D(GL_TEXTURE_2D, 0,\r
+ 0, 0, TexSize, TexSize,\r
+ TexSrcFormat, TexSrcType, TexImage);\r
+ }\r
+ if (DrawPoint)\r
+ glDrawArrays(GL_POINTS, 0, 1);\r
+ }\r
+ glFinish();\r
+}\r
+\r
+\r
+/* XXX any other formats to measure? */\r
+static const struct {\r
+ GLenum format, type;\r
+ const char *name;\r
+} SrcFormats[] = {\r
+ { GL_RGBA, GL_UNSIGNED_BYTE, "GL_RGBA/GLubyte" },\r
+ { GL_BGRA, GL_UNSIGNED_BYTE, "GL_BGRA/GLubyte" },\r
+ { 0, 0, NULL }\r
+};\r
+\r
+\r
+\r
+/** Called from test harness/main */\r
+void\r
+PerfDraw(void)\r
+{\r
+ GLint maxSize;\r
+ double rate;\r
+ GLint fmt, subImage;\r
+\r
+ glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxSize);\r
+\r
+ /* loop over source data formats */\r
+ for (fmt = 0; SrcFormats[fmt].format; fmt++) {\r
+ TexSrcFormat = SrcFormats[fmt].format;\r
+ TexSrcType = SrcFormats[fmt].type;\r
+\r
+ /* loop over glTexImage, glTexSubImage */\r
+ for (subImage = 0; subImage < 2; subImage++) {\r
+\r
+ /* loop over texture sizes */\r
+ for (TexSize = 16; TexSize <= maxSize; TexSize *= 2) {\r
+ GLint bytesPerImage;\r
+ double mbPerSec;\r
+\r
+ bytesPerImage = TexSize * TexSize * 4;\r
+ TexImage = malloc(bytesPerImage);\r
+\r
+ if (subImage) {\r
+ /* create initial, empty texture */\r
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,\r
+ TexSize, TexSize, 0,\r
+ TexSrcFormat, TexSrcType, NULL);\r
+ rate = PerfMeasureRate(UploadTexSubImage2D);\r
+ }\r
+ else {\r
+ rate = PerfMeasureRate(UploadTexImage2D);\r
+ }\r
+\r
+ mbPerSec = rate * bytesPerImage / (1024.0 * 1024.0);\r
+\r
+ printf(" glTex%sImage2D(%s %d x %d): "\r
+ "%.1f images/sec, %.1f MB/sec\n",\r
+ (subImage ? "Sub" : ""),\r
+ SrcFormats[fmt].name, TexSize, TexSize, rate, mbPerSec);\r
+\r
+ free(TexImage);\r
+ }\r
+ }\r
+ }\r
+\r
+ exit(0);\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (C) 2009 VMware, Inc. All Rights Reserved.\r
+ *\r
+ * Permission is hereby granted, free of charge, to any person obtaining a\r
+ * copy of this software and associated documentation files (the "Software"),\r
+ * to deal in the Software without restriction, including without limitation\r
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
+ * and/or sell copies of the Software, and to permit persons to whom the\r
+ * Software is furnished to do so, subject to the following conditions:\r
+ *\r
+ * The above copyright notice and this permission notice shall be included\r
+ * in all copies or substantial portions of the Software.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\r
+ * VMWARE BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN\r
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+ */\r
+\r
+/**\r
+ * Measure VBO upload speed.\r
+ * That is, measure glBufferDataARB() and glBufferSubDataARB().\r
+ *\r
+ * Brian Paul\r
+ * 16 Sep 2009\r
+ */\r
+\r
+#include <string.h>\r
+#include "glmain.h"\r
+#include "common.h"\r
+\r
+\r
+int WinWidth = 100, WinHeight = 100;\r
+\r
+static GLuint VBO;\r
+\r
+static GLsizei VBOSize = 0;\r
+static GLubyte *VBOData = NULL;\r
+\r
+static const GLboolean DrawPoint = GL_TRUE;\r
+static const GLboolean BufferSubDataInHalves = GL_TRUE;\r
+\r
+static const GLfloat Vertex0[2] = { 0.0, 0.0 };\r
+\r
+\r
+/** Called from test harness/main */\r
+void\r
+PerfInit(void)\r
+{\r
+ /* setup VBO */\r
+ glGenBuffersARB(1, &VBO);\r
+ glBindBufferARB(GL_ARRAY_BUFFER_ARB, VBO);\r
+ glVertexPointer(2, GL_FLOAT, sizeof(Vertex0), (void *) 0);\r
+ glEnableClientState(GL_VERTEX_ARRAY);\r
+}\r
+\r
+\r
+static void\r
+UploadVBO(unsigned count)\r
+{\r
+ unsigned i;\r
+ for (i = 0; i < count; i++) {\r
+ glBufferDataARB(GL_ARRAY_BUFFER, VBOSize, VBOData, GL_STREAM_DRAW_ARB);\r
+\r
+ if (DrawPoint)\r
+ glDrawArrays(GL_POINTS, 0, 1);\r
+ }\r
+ glFinish();\r
+}\r
+\r
+\r
+static void\r
+UploadSubVBO(unsigned count)\r
+{\r
+ unsigned i;\r
+ for (i = 0; i < count; i++) {\r
+ if (BufferSubDataInHalves) {\r
+ GLsizei half = VBOSize / 2;\r
+ glBufferSubDataARB(GL_ARRAY_BUFFER, 0, half, VBOData);\r
+ glBufferSubDataARB(GL_ARRAY_BUFFER, half, half, VBOData + half);\r
+ }\r
+ else {\r
+ glBufferSubDataARB(GL_ARRAY_BUFFER, 0, VBOSize, VBOData);\r
+ }\r
+\r
+ if (DrawPoint)\r
+ glDrawArrays(GL_POINTS, 0, 1);\r
+ }\r
+ glFinish();\r
+}\r
+\r
+\r
+static const GLsizei Sizes[] = {\r
+ 64,\r
+ 1024,\r
+ 16*1024,\r
+ 256*1024,\r
+ 1024*1024,\r
+ 16*1024*1024,\r
+ 0 /* end of list */\r
+};\r
+\r
+\r
+/** Called from test harness/main */\r
+void\r
+PerfDraw(void)\r
+{\r
+ double rate, mbPerSec;\r
+ int sub, sz;\r
+\r
+ /* loop over whole/sub buffer upload */\r
+ for (sub = 0; sub < 2; sub++) {\r
+\r
+ /* loop over VBO sizes */\r
+ for (sz = 0; Sizes[sz]; sz++) {\r
+ VBOSize = Sizes[sz];\r
+\r
+ VBOData = malloc(VBOSize);\r
+ memcpy(VBOData, Vertex0, sizeof(Vertex0));\r
+\r
+ if (sub)\r
+ rate = PerfMeasureRate(UploadSubVBO);\r
+ else\r
+ rate = PerfMeasureRate(UploadVBO);\r
+\r
+ mbPerSec = rate * VBOSize / (1024.0 * 1024.0);\r
+\r
+ printf(" glBuffer%sDataARB(size = %d): %.1f MB/sec\n",\r
+ (sub ? "Sub" : ""), VBOSize, mbPerSec);\r
+\r
+ free(VBOData);\r
+ }\r
+ }\r
+\r
+ exit(0);\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (C) 2009 VMware, Inc. All Rights Reserved.\r
+ *\r
+ * Permission is hereby granted, free of charge, to any person obtaining a\r
+ * copy of this software and associated documentation files (the "Software"),\r
+ * to deal in the Software without restriction, including without limitation\r
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
+ * and/or sell copies of the Software, and to permit persons to whom the\r
+ * Software is furnished to do so, subject to the following conditions:\r
+ *\r
+ * The above copyright notice and this permission notice shall be included\r
+ * in all copies or substantial portions of the Software.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\r
+ * VMWARE BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN\r
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+ */\r
+\r
+/**\r
+ * Measure simple vertex processing rate via:\r
+ * - immediate mode\r
+ * - vertex arrays\r
+ * - VBO vertex arrays\r
+ * - glDrawElements\r
+ * - VBO glDrawElements\r
+ * - glDrawRangeElements\r
+ * - VBO glDrawRangeElements\r
+ *\r
+ * Brian Paul\r
+ * 16 Sep 2009\r
+ */\r
+\r
+#include <assert.h>\r
+#include <string.h>\r
+#include "glmain.h"\r
+#include "common.h"\r
+\r
+\r
+#define MAX_VERTS (100 * 100)\r
+\r
+/** glVertex2/3/4 size */\r
+#define VERT_SIZE 4\r
+\r
+int WinWidth = 500, WinHeight = 500;\r
+\r
+static GLuint VertexBO, ElementBO;\r
+\r
+static unsigned NumVerts = MAX_VERTS;\r
+static unsigned VertBytes = VERT_SIZE * sizeof(float);\r
+static float *VertexData = NULL;\r
+\r
+static unsigned NumElements = MAX_VERTS;\r
+static GLuint *Elements = NULL;\r
+\r
+\r
+/**\r
+ * Load VertexData buffer with a 2-D grid of points in the range [-1,1]^2.\r
+ */\r
+static void\r
+InitializeVertexData(void)\r
+{\r
+ unsigned i;\r
+ float x = -1.0, y = -1.0;\r
+ float dx = 2.0 / 100;\r
+ float dy = 2.0 / 100;\r
+\r
+ VertexData = (float *) malloc(NumVerts * VertBytes);\r
+\r
+ for (i = 0; i < NumVerts; i++) {\r
+ VertexData[i * VERT_SIZE + 0] = x;\r
+ VertexData[i * VERT_SIZE + 1] = y;\r
+ VertexData[i * VERT_SIZE + 2] = 0.0;\r
+ VertexData[i * VERT_SIZE + 3] = 1.0;\r
+ x += dx;\r
+ if (x > 1.0) {\r
+ x = -1.0;\r
+ y += dy;\r
+ }\r
+ }\r
+\r
+ Elements = (GLuint *) malloc(NumVerts * sizeof(GLuint));\r
+\r
+ for (i = 0; i < NumVerts; i++) {\r
+ Elements[i] = NumVerts - i - 1;\r
+ }\r
+}\r
+\r
+\r
+/** Called from test harness/main */\r
+void\r
+PerfInit(void)\r
+{\r
+ InitializeVertexData();\r
+\r
+ /* setup VertexBO */\r
+ glGenBuffersARB(1, &VertexBO);\r
+ glBindBufferARB(GL_ARRAY_BUFFER_ARB, VertexBO);\r
+ glBufferDataARB(GL_ARRAY_BUFFER_ARB,\r
+ NumVerts * VertBytes, VertexData, GL_STATIC_DRAW_ARB);\r
+ glEnableClientState(GL_VERTEX_ARRAY);\r
+\r
+ /* setup ElementBO */\r
+ glGenBuffersARB(1, &ElementBO);\r
+ glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, ElementBO);\r
+ glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB,\r
+ NumElements * sizeof(GLuint), Elements, GL_STATIC_DRAW_ARB);\r
+}\r
+\r
+\r
+static void\r
+DrawImmediate(unsigned count)\r
+{\r
+ unsigned i;\r
+ glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, 0);\r
+ glBindBufferARB(GL_ARRAY_BUFFER, 0);\r
+ for (i = 0; i < count; i++) {\r
+ unsigned j;\r
+ glBegin(GL_POINTS);\r
+ for (j = 0; j < NumVerts; j++) {\r
+#if VERT_SIZE == 4\r
+ glVertex4fv(VertexData + j * 4);\r
+#elif VERT_SIZE == 3\r
+ glVertex3fv(VertexData + j * 3);\r
+#elif VERT_SIZE == 2\r
+ glVertex2fv(VertexData + j * 2);\r
+#else\r
+ abort();\r
+#endif\r
+ }\r
+ glEnd();\r
+ }\r
+ glFinish();\r
+ PerfSwapBuffers();\r
+}\r
+\r
+\r
+static void\r
+DrawArraysMem(unsigned count)\r
+{\r
+ unsigned i;\r
+ glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, 0);\r
+ glBindBufferARB(GL_ARRAY_BUFFER, 0);\r
+ glVertexPointer(VERT_SIZE, GL_FLOAT, VertBytes, VertexData);\r
+ for (i = 0; i < count; i++) {\r
+ glDrawArrays(GL_POINTS, 0, NumVerts);\r
+ }\r
+ glFinish();\r
+ PerfSwapBuffers();\r
+}\r
+\r
+\r
+static void\r
+DrawArraysVBO(unsigned count)\r
+{\r
+ unsigned i;\r
+ glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, 0);\r
+ glBindBufferARB(GL_ARRAY_BUFFER, VertexBO);\r
+ glVertexPointer(VERT_SIZE, GL_FLOAT, VertBytes, (void *) 0);\r
+ for (i = 0; i < count; i++) {\r
+ glDrawArrays(GL_POINTS, 0, NumVerts);\r
+ }\r
+ glFinish();\r
+ PerfSwapBuffers();\r
+}\r
+\r
+\r
+static void\r
+DrawElementsMem(unsigned count)\r
+{\r
+ unsigned i;\r
+ glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, 0);\r
+ glBindBufferARB(GL_ARRAY_BUFFER, 0);\r
+ glVertexPointer(VERT_SIZE, GL_FLOAT, VertBytes, VertexData);\r
+ for (i = 0; i < count; i++) {\r
+ glDrawElements(GL_POINTS, NumVerts, GL_UNSIGNED_INT, Elements);\r
+ }\r
+ glFinish();\r
+ PerfSwapBuffers();\r
+}\r
+\r
+\r
+static void\r
+DrawElementsBO(unsigned count)\r
+{\r
+ unsigned i;\r
+ glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, ElementBO);\r
+ glBindBufferARB(GL_ARRAY_BUFFER, VertexBO);\r
+ glVertexPointer(VERT_SIZE, GL_FLOAT, VertBytes, (void *) 0);\r
+ for (i = 0; i < count; i++) {\r
+ glDrawElements(GL_POINTS, NumVerts, GL_UNSIGNED_INT, (void *) 0);\r
+ }\r
+ glFinish();\r
+ PerfSwapBuffers();\r
+}\r
+\r
+\r
+static void\r
+DrawRangeElementsMem(unsigned count)\r
+{\r
+ unsigned i;\r
+ glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, 0);\r
+ glBindBufferARB(GL_ARRAY_BUFFER, 0);\r
+ glVertexPointer(VERT_SIZE, GL_FLOAT, VertBytes, VertexData);\r
+ for (i = 0; i < count; i++) {\r
+ glDrawRangeElements(GL_POINTS, 0, NumVerts - 1,\r
+ NumVerts, GL_UNSIGNED_INT, Elements);\r
+ }\r
+ glFinish();\r
+ PerfSwapBuffers();\r
+}\r
+\r
+\r
+static void\r
+DrawRangeElementsBO(unsigned count)\r
+{\r
+ unsigned i;\r
+ glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, ElementBO);\r
+ glBindBufferARB(GL_ARRAY_BUFFER, VertexBO);\r
+ glVertexPointer(VERT_SIZE, GL_FLOAT, VertBytes, (void *) 0);\r
+ for (i = 0; i < count; i++) {\r
+ glDrawRangeElements(GL_POINTS, 0, NumVerts - 1,\r
+ NumVerts, GL_UNSIGNED_INT, (void *) 0);\r
+ }\r
+ glFinish();\r
+ PerfSwapBuffers();\r
+}\r
+\r
+\r
+/** Called from test harness/main */\r
+void\r
+PerfDraw(void)\r
+{\r
+ double rate;\r
+\r
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);\r
+\r
+ printf("Vertex rate (%d x Vertex%df)\n", NumVerts, VERT_SIZE);\r
+\r
+ rate = PerfMeasureRate(DrawImmediate);\r
+ rate *= NumVerts;\r
+ printf(" Immediate mode: %.1f verts/sec\n", rate);\r
+\r
+ rate = PerfMeasureRate(DrawArraysMem);\r
+ rate *= NumVerts;\r
+ printf(" glDrawArrays: %.1f verts/sec\n", rate);\r
+\r
+ rate = PerfMeasureRate(DrawArraysVBO);\r
+ rate *= NumVerts;\r
+ printf(" VBO glDrawArrays: %.1f verts/sec\n", rate);\r
+\r
+ rate = PerfMeasureRate(DrawElementsMem);\r
+ rate *= NumVerts;\r
+ printf(" glDrawElements: %.1f verts/sec\n", rate);\r
+\r
+ rate = PerfMeasureRate(DrawElementsBO);\r
+ rate *= NumVerts;\r
+ printf(" VBO glDrawElements: %.1f verts/sec\n", rate);\r
+\r
+ rate = PerfMeasureRate(DrawRangeElementsMem);\r
+ rate *= NumVerts;\r
+ printf(" glDrawRangeElements: %.1f verts/sec\n", rate);\r
+\r
+ rate = PerfMeasureRate(DrawRangeElementsBO);\r
+ rate *= NumVerts;\r
+ printf(" VBO glDrawRangeElements: %.1f verts/sec\n", rate);\r
+\r
+ exit(0);\r
+}\r