Skip to content

Instantly share code, notes, and snippets.

@zeux
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeux/b00b28724ac35c677e46 to your computer and use it in GitHub Desktop.
Save zeux/b00b28724ac35c677e46 to your computer and use it in GitHub Desktop.
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