summaryrefslogtreecommitdiff
path: root/progs/perf/teximage.c
diff options
context:
space:
mode:
authorMichal Krol <michal@vmware.com>2009-12-12 16:48:32 +0100
committerMichal Krol <michal@vmware.com>2009-12-12 16:48:32 +0100
commita3eb0f718e19653a2ad8e49396c904183be456f3 (patch)
tree0092574c469ea586a6cab8b8ebb7ac62b8221a2a /progs/perf/teximage.c
parent491f384c3958067e6c4c994041f5d8d413b806bc (diff)
parent784cca9fa527de771754d76545970f78094b9adf (diff)
Merge branch 'master' into glsl-pp-rework-2
Conflicts: progs/perf/drawoverhead.c progs/perf/teximage.c progs/perf/vbo.c progs/perf/vertexrate.c src/mesa/shader/slang/library/slang_common_builtin_gc.h
Diffstat (limited to 'progs/perf/teximage.c')
-rw-r--r--progs/perf/teximage.c183
1 files changed, 152 insertions, 31 deletions
diff --git a/progs/perf/teximage.c b/progs/perf/teximage.c
index a0ce2604e0..a3005d0bef 100644
--- a/progs/perf/teximage.c
+++ b/progs/perf/teximage.c
@@ -20,7 +20,7 @@
*/
/**
- * Measure glTexSubImage2D rate
+ * Measure glTex[Sub]Image2D() and glGetTexImage() rate
*
* Brian Paul
* 16 Sep 2009
@@ -36,10 +36,28 @@ static GLuint VBO;
static GLuint TexObj = 0;
static GLubyte *TexImage = NULL;
static GLsizei TexSize;
-static GLenum TexSrcFormat, TexSrcType;
+static GLenum TexIntFormat, TexSrcFormat, TexSrcType;
static const GLboolean DrawPoint = GL_TRUE;
-static const GLboolean TexSubImage4 = GL_TRUE;
+static const GLboolean TexSubImage4 = GL_FALSE;
+
+enum {
+ MODE_CREATE_TEXIMAGE,
+ MODE_TEXIMAGE,
+ MODE_TEXSUBIMAGE,
+ MODE_GETTEXIMAGE,
+ MODE_COUNT
+};
+
+static const char *mode_name[MODE_COUNT] =
+{
+ "Create_TexImage",
+ "TexImage",
+ "TexSubImage",
+ "GetTexImage"
+};
+
+
struct vertex
{
@@ -50,9 +68,9 @@ static const struct vertex vertices[1] = {
{ 0.0, 0.0, 0.5, 0.5 },
};
-
#define VOFFSET(F) ((void *) offsetof(struct vertex, F))
+
/** Called from test harness/main */
void
PerfInit(void)
@@ -76,6 +94,32 @@ PerfInit(void)
}
+
+
+static void
+CreateUploadTexImage2D(unsigned count)
+{
+ unsigned i;
+ for (i = 0; i < count; i++) {
+ if (TexObj)
+ glDeleteTextures(1, &TexObj);
+
+ glGenTextures(1, &TexObj);
+ glBindTexture(GL_TEXTURE_2D, TexObj);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+
+ glTexImage2D(GL_TEXTURE_2D, 0, TexIntFormat,
+ TexSize, TexSize, 0,
+ TexSrcFormat, TexSrcType, TexImage);
+
+ if (DrawPoint)
+ glDrawArrays(GL_POINTS, 0, 1);
+ }
+ glFinish();
+}
+
+
static void
UploadTexImage2D(unsigned count)
{
@@ -86,7 +130,7 @@ UploadTexImage2D(unsigned count)
* in Mesa but may be optimized in other drivers. Note sure how
* much difference that might make.
*/
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
+ glTexImage2D(GL_TEXTURE_2D, 0, TexIntFormat,
TexSize, TexSize, 0,
TexSrcFormat, TexSrcType, TexImage);
if (DrawPoint)
@@ -129,8 +173,8 @@ UploadTexSubImage2D(unsigned count)
TexSrcFormat, TexSrcType, TexImage);
/* reset the unpacking state */
glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
- glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
+ glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
}
else {
/* replace whole texture image at once */
@@ -145,17 +189,43 @@ UploadTexSubImage2D(unsigned count)
}
+static void
+GetTexImage2D(unsigned count)
+{
+ unsigned i;
+ GLubyte *buf = (GLubyte *) malloc(TexSize * TexSize * 4);
+ for (i = 0; i < count; i++) {
+ glGetTexImage(GL_TEXTURE_2D, 0,
+ TexSrcFormat, TexSrcType, buf);
+ }
+ glFinish();
+ free(buf);
+}
+
+
/* XXX any other formats to measure? */
static const struct {
GLenum format, type;
+ GLenum internal_format;
const char *name;
+ GLuint texel_size;
+ GLboolean full_test;
} SrcFormats[] = {
- { GL_RGBA, GL_UNSIGNED_BYTE, "GL_RGBA/GLubyte" },
- { GL_BGRA, GL_UNSIGNED_BYTE, "GL_BGRA/GLubyte" },
- { 0, 0, NULL }
+ { GL_RGBA, GL_UNSIGNED_BYTE, GL_RGBA, "RGBA/ubyte", 4, GL_TRUE },
+ { GL_RGB, GL_UNSIGNED_BYTE, GL_RGB, "RGB/ubyte", 3, GL_FALSE },
+ { GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_RGB, "RGB/565", 2, GL_FALSE },
+ { GL_BGRA, GL_UNSIGNED_BYTE, GL_RGBA, "BGRA/ubyte", 4, GL_FALSE },
+ { GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_LUMINANCE, "L/ubyte", 1, GL_FALSE },
+ { 0, 0, 0, NULL, 0, 0 }
};
+/** Called from test harness/main */
+void
+PerfNextRound(void)
+{
+}
+
/** Called from test harness/main */
void
@@ -163,46 +233,97 @@ PerfDraw(void)
{
GLint maxSize;
double rate;
- GLint fmt, subImage;
+ GLint fmt, mode;
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxSize);
/* loop over source data formats */
for (fmt = 0; SrcFormats[fmt].format; fmt++) {
+ TexIntFormat = SrcFormats[fmt].internal_format;
TexSrcFormat = SrcFormats[fmt].format;
TexSrcType = SrcFormats[fmt].type;
/* loop over glTexImage, glTexSubImage */
- for (subImage = 0; subImage < 2; subImage++) {
+ for (mode = 0; mode < MODE_COUNT; mode++) {
+ GLuint minsz, maxsz;
- /* loop over texture sizes */
- for (TexSize = 16; TexSize <= maxSize; TexSize *= 2) {
- GLint bytesPerImage;
+ if (SrcFormats[fmt].full_test) {
+ minsz = 16;
+ maxsz = 4096;
+ }
+ else {
+ minsz = maxsz = 256;
+ if (mode == MODE_CREATE_TEXIMAGE)
+ continue;
+ }
+
+ /* loop over a defined range of texture sizes, test only the
+ * ones which are legal for this driver.
+ */
+ for (TexSize = minsz; TexSize <= maxsz; TexSize *= 4) {
double mbPerSec;
- bytesPerImage = TexSize * TexSize * 4;
- TexImage = malloc(bytesPerImage);
+ if (TexSize <= maxSize) {
+ GLint bytesPerImage;
+
+ bytesPerImage = TexSize * TexSize * SrcFormats[fmt].texel_size;
+ TexImage = malloc(bytesPerImage);
+
+ switch (mode) {
+ case MODE_TEXIMAGE:
+ rate = PerfMeasureRate(UploadTexImage2D);
+ break;
+
+ case MODE_CREATE_TEXIMAGE:
+ rate = PerfMeasureRate(CreateUploadTexImage2D);
+ break;
+
+ case MODE_TEXSUBIMAGE:
+ /* create initial, empty texture */
+ glTexImage2D(GL_TEXTURE_2D, 0, TexIntFormat,
+ TexSize, TexSize, 0,
+ TexSrcFormat, TexSrcType, NULL);
+ rate = PerfMeasureRate(UploadTexSubImage2D);
+ break;
+
+ case MODE_GETTEXIMAGE:
+ glTexImage2D(GL_TEXTURE_2D, 0, TexIntFormat,
+ TexSize, TexSize, 0,
+ TexSrcFormat, TexSrcType, TexImage);
+ rate = PerfMeasureRate(GetTexImage2D);
+ break;
+
+ default:
+ exit(1);
+ }
+
+ mbPerSec = rate * bytesPerImage / (1024.0 * 1024.0);
+ free(TexImage);
+
+
+ {
+ unsigned err;
+ err = glGetError();
+ if (err) {
+ perf_printf("non-zero glGetError() %d\n", err);
+ exit(1);
+ }
+ }
- if (subImage) {
- /* create initial, empty texture */
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
- TexSize, TexSize, 0,
- TexSrcFormat, TexSrcType, NULL);
- rate = PerfMeasureRate(UploadTexSubImage2D);
}
else {
- rate = PerfMeasureRate(UploadTexImage2D);
+ rate = 0;
+ mbPerSec = 0;
}
- mbPerSec = rate * bytesPerImage / (1024.0 * 1024.0);
-
- printf(" glTex%sImage2D(%s %d x %d): "
- "%.1f images/sec, %.1f MB/sec\n",
- (subImage ? "Sub" : ""),
- SrcFormats[fmt].name, TexSize, TexSize, rate, mbPerSec);
-
- free(TexImage);
+ perf_printf(" %s(%s %d x %d): "
+ "%.1f images/sec, %.1f MB/sec\n",
+ mode_name[mode],
+ SrcFormats[fmt].name, TexSize, TexSize, rate, mbPerSec);
}
+
+ if (SrcFormats[fmt].full_test)
+ perf_printf("\n");
}
}