Create a gist now

Instantly share code, notes, and snippets.

@zeux /textureuploadperf.cpp Secret
Last active Aug 29, 2015

What would you like to do?
OSX 10.10 texture array upload performance
// Format 83f1: time to upload: 37.6 msec (1134.9 Mb/sec)
// Format 83f2: time to upload: 2109.5 msec (40.5 Mb/sec)
// Format 83f3: time to upload: 1984.0 msec (43.0 Mb/sec)
// Format 8dbb: time to upload: 22.7 msec (1876.9 Mb/sec)
// Format 8dbd: time to upload: 1942.0 msec (43.9 Mb/sec)
#include <sys/time.h>
#include <OpenGL/gl3ext.h>
double timestamp()
{
struct timeval tv;
if (gettimeofday(&tv, 0) == 0)
return tv.tv_sec + tv.tv_usec * 1e-6;
else
return 0;
}
void testTextureUploadPerf()
{
static char dummydata[1024*1024];
GLenum formats[] =
{
GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
GL_COMPRESSED_RGBA_S3TC_DXT3_EXT,
GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,
GL_COMPRESSED_RED_RGTC1,
GL_COMPRESSED_RG_RGTC2,
};
for (unsigned int f = 0; f < sizeof(formats) / sizeof(formats[0]); ++f)
{
GLenum format = formats[f];
double start = timestamp();
GLuint texid;
glGenTextures(1, &texid);
glBindTexture(GL_TEXTURE_2D_ARRAY, texid);
glTexStorage3D(GL_TEXTURE_2D_ARRAY, 11, format, 1024, 1024, 64);
unsigned int total = 0;
for (int z = 0; z < 64; ++z)
{
for (int mip = 0; mip < 11; ++mip)
{
int mipd = 1024 >> mip;
int mipbits = (format == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT || format == GL_COMPRESSED_RED_RGTC1) ? 8 : 16;
int mipsize = ((mipd + 3) / 4) * ((mipd + 3) / 4) * mipbits;
glCompressedTexSubImage3D(GL_TEXTURE_2D_ARRAY, mip, 0, 0, z, mipd, mipd, 1, format, mipsize, dummydata);
total += mipsize;
}
}
glDeleteTextures(1, &texid);
double end = timestamp();
printf("Format %x: time to upload: %.1f msec (%.1f Mb/sec)\n", format, (end - start) * 1000.0, (double)total / (end - start) / 1048576);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment