2 * OpenGL ES 2.0 memory performance estimator
3 * Copyright (C) 2009 Nokia
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 * \author Sami Kyöstilä <sami.kyostila@nokia.com>
21 #include <GLES2/gl2.h>
22 #include <GLES2/gl2ext.h>
23 #include <X11/Xutil.h>
38 #include "cleartest.h"
39 #include "pixmapblittest.h"
40 #include "fboblittest.h"
41 #include "shaderblittest.h"
42 #include "cpuinterleavingtest.h"
45 #if defined(HAVE_LIBOSSO)
50 * Command line options
58 std::list<std::string> includedTests;
59 std::list<std::string> excludedTests;
62 /** Shared EGL objects */
65 #if defined(HAVE_LIBOSSO)
66 osso_context_t* ossoContext;
69 bool initializeEgl(int width, int height, const EGLint* configAttrs, const EGLint* contextAttrs)
71 EGLint configCount = 0;
73 #if defined(HAVE_LIBOSSO)
74 ossoContext = osso_initialize("com.nokia.memperf", "1.0", FALSE, NULL);
77 perror("osso_initialize");
82 ctx.dpy = eglGetDisplay(ctx.nativeDisplay);
85 eglInitialize(ctx.dpy, NULL, NULL);
86 eglChooseConfig(ctx.dpy, configAttrs, &ctx.config, 1, &configCount);
91 printf("Config not found\n");
97 printf("Config attributes:\n");
98 dumpConfig(ctx.dpy, ctx.config);
101 if (!nativeCreateWindow(ctx.nativeDisplay, ctx.dpy, ctx.config, __FILE__,
102 width, height, &ctx.win))
104 printf("Unable to create a window\n");
108 ctx.context = eglCreateContext(ctx.dpy, ctx.config, EGL_NO_CONTEXT, contextAttrs);
112 printf("Unable to create a context\n");
116 ctx.surface = eglCreateWindowSurface(ctx.dpy, ctx.config, ctx.win, NULL);
120 printf("Unable to create a surface\n");
124 eglMakeCurrent(ctx.dpy, ctx.surface, ctx.surface, ctx.context);
127 eglSwapInterval(ctx.dpy, 0);
131 eglMakeCurrent(ctx.dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
132 eglDestroySurface(ctx.dpy, ctx.surface);
133 eglDestroyContext(ctx.dpy, ctx.context);
134 eglTerminate(ctx.dpy);
135 nativeDestroyWindow(ctx.nativeDisplay, ctx.win);
136 nativeDestroyDisplay(ctx.nativeDisplay);
142 eglMakeCurrent(ctx.dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
143 eglDestroySurface(ctx.dpy, ctx.surface);
144 eglDestroyContext(ctx.dpy, ctx.context);
145 eglTerminate(ctx.dpy);
146 nativeDestroyWindow(ctx.nativeDisplay, ctx.win);
147 nativeDestroyDisplay(ctx.nativeDisplay);
149 #if defined(HAVE_LIBOSSO)
150 osso_deinitialize(ossoContext);
155 int64_t timeDiff(const struct timespec& start, const struct timespec& end)
157 int64_t s = start.tv_sec * (1000 * 1000 * 1000LL) + start.tv_nsec;
158 int64_t e = end.tv_sec * (1000 * 1000 * 1000LL) + end.tv_nsec;
162 bool shouldRunTest(const std::string& testName)
164 std::list<std::string>::iterator i;
167 if (options.includedTests.size())
170 for (i = options.includedTests.begin(); i != options.includedTests.end(); ++i)
172 if (testName.find(*i) != std::string::npos)
180 for (i = options.excludedTests.begin(); i != options.excludedTests.end(); ++i)
182 if (testName.find(*i) != std::string::npos)
192 void runTest(Test& test)
195 int frameLimit = 100;
197 int64_t minTime = options.minTime * 1000 * 1000 * 1000LL;
198 struct timespec res, start, end;
200 if (options.listTests)
202 printf("%s\n", test.name().c_str());
206 if (!shouldRunTest(test.name()))
211 clock_getres(CLOCK_REALTIME, &res);
212 //printf("Timer resolution: %d.%09d s\n", res.tv_sec, res.tv_nsec);
213 printf("%-40s", (test.name() + ":").c_str());
221 } catch (const std::exception& e)
223 printf("%s\n", e.what());
236 #if defined(HAVE_LIBOSSO)
237 osso_display_blanking_pause(ossoContext);
240 clock_gettime(CLOCK_REALTIME, &start);
241 while (frames < frameLimit)
245 clock_gettime(CLOCK_REALTIME, &end);
247 if (frames >= frameLimit && timeDiff(start, end) < minTime)
260 int64_t diff = timeDiff(start, end);
261 int fps = static_cast<int>((1000 * 1000 * 1000LL * frames) / diff);
262 //printf("%d frames in %6.2f ms (%3d fps) ", frames, diff / (1000.0f * 1000.0f), fps);
263 printf("%3d fps ", fps);
273 void getScreenSize(int& width, int& height)
275 Window rootWindow = DefaultRootWindow(ctx.nativeDisplay);
276 XWindowAttributes rootAttrs;
278 XGetWindowAttributes(ctx.nativeDisplay, rootWindow, &rootAttrs);
280 width = rootAttrs.width;
281 height = rootAttrs.height;
287 "GLMemPerf v" PACKAGE_VERSION " - OpenGL ES 2.0 memory performance benchmark\n"
288 "Copyright (C) 2009 Nokia Corporation. GLMemPerf comes with ABSOLUTELY\n"
289 "NO WARRANTY; This is free software, and you are welcome to redistribute\n"
290 "it under certain conditions.\n"
298 " glmemperf [OPTIONS]\n"
302 " -l List all tests without running them\n"
303 " -i TEST Include a specific test (full name or substring)\n"
304 " -e TEST Exclude a specific test (full name or substring)\n"
305 " -t SECS Minimum time to run each test\n"
306 " -b BPP Bits per pixel\n";
309 void parseArguments(const std::list<std::string>& args)
311 std::list<std::string>::const_iterator i;
314 options.verbose = false;
316 options.bitsPerPixel = 16;
317 options.listTests = false;
319 for (i = args.begin(), i++; i != args.end(); ++i)
321 if (*i == "-h" || *i == "--help")
326 else if (*i == "-i" && ++i != args.end())
328 options.includedTests.push_back(*i);
330 else if (*i == "-e" && ++i != args.end())
332 options.excludedTests.push_back(*i);
334 else if (*i == "-t" && ++i != args.end())
336 options.minTime = atoi((*i).c_str());
338 else if (*i == "-b" && ++i != args.end())
340 options.bitsPerPixel = atoi((*i).c_str());
344 options.verbose = true;
348 options.listTests = true;
352 std::cerr << "Invalid option: " << *i << std::endl;
359 void findDataDirectory()
362 if (stat("data", &st) == 0)
366 chdir(PREFIX "/share/glmemperf/");
367 assert(stat("data", &st) == 0);
370 #define ADD_TEST(TEST) runTest(*std::auto_ptr<Test>(new TEST));
372 int main(int argc, char** argv)
374 std::list<std::string> args(argv, argv + argc);
377 parseArguments(args);
380 const EGLint configAttrs[] =
382 EGL_BUFFER_SIZE, options.bitsPerPixel,
383 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
387 const EGLint configAttrs32[] =
393 const EGLint contextAttrs[] =
395 EGL_CONTEXT_CLIENT_VERSION, 2,
400 const float w = winWidth, h = winHeight;
401 EGLConfig config32 = 0;
402 EGLint configCount = 0;
404 bool result = nativeCreateDisplay(&ctx.nativeDisplay);
407 getScreenSize(winWidth, winHeight);
408 result = initializeEgl(winWidth, winHeight, configAttrs, contextAttrs);
411 eglChooseConfig(ctx.dpy, configAttrs32, &config32, 1, &configCount);
415 printf("32bpp config not found\n");
418 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
422 ADD_TEST(ClearTest());
425 ADD_TEST(BlitTest(GL_RGBA, GL_UNSIGNED_BYTE, 800, 480, "data/water2_800x480_rgba8888.raw"));
426 ADD_TEST(BlitTest(GL_RGB, GL_UNSIGNED_BYTE, 800, 480, "data/water2_800x480_rgb888.raw"));
427 ADD_TEST(BlitTest(GL_RGBA, GL_UNSIGNED_BYTE, 1024, 512, "data/digital_nature2_1024x512_rgba8888.raw", false, 800.0 / 1024, 480.0 / 512));
428 ADD_TEST(BlitTest(GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 800, 480, "data/water2_800x480_rgb565.raw"));
429 ADD_TEST(BlitTest(GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 1024, 512, "data/digital_nature2_1024x512_rgb565.raw", false, 800.0 / 1024, 480.0 / 512));
430 ADD_TEST(BlitTest(GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG, 0, 1024, 512, "data/abstract3_1024x512_pvrtc4.raw", false, 800.0 / 1024, 480.0 / 512));
431 ADD_TEST(BlitTest(GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG, 0, 1024, 512, "data/abstract3_1024x512_pvrtc2.raw", false, 800.0 / 1024, 480.0 / 512));
432 ADD_TEST(BlitTest(GL_ETC1_RGB8_OES, 0, 1024, 512, "data/abstract3_1024x512_etc1.raw", false, 800.0 / 1024, 480.0 / 512));
433 ADD_TEST(PixmapBlitTest(w, h, ctx.config));
434 ADD_TEST(PixmapBlitTest(w, h, config32));
435 ADD_TEST(FBOBlitTest(GL_RGBA, GL_UNSIGNED_BYTE, w, h));
436 ADD_TEST(FBOBlitTest(GL_RGBA, GL_UNSIGNED_BYTE, 1024, 512, false, w / 1024, h / 512));
437 ADD_TEST(FBOBlitTest(GL_RGB, GL_UNSIGNED_SHORT_5_6_5, w, h));
438 ADD_TEST(FBOBlitTest(GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 1024, 512, false, w / 1042, h / 512));
441 ADD_TEST(BlitTest(GL_RGBA, GL_UNSIGNED_BYTE, 480, 800, "data/water2_480x800_rgba8888.raw", true));
442 ADD_TEST(BlitTest(GL_RGB, GL_UNSIGNED_BYTE, 480, 800, "data/water2_480x800_rgb888.raw", true));
443 ADD_TEST(BlitTest(GL_RGBA, GL_UNSIGNED_BYTE, 512, 1024, "data/digital_nature2_512x1024_rgba8888.raw", true, 480.0 / 512, 800.0 / 1024));
444 ADD_TEST(BlitTest(GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 480, 800, "data/water2_480x800_rgb565.raw", true));
445 ADD_TEST(BlitTest(GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 512, 1024, "data/digital_nature2_512x1024_rgb565.raw", true, 480.0 / 512, 800.0 / 1024));
446 ADD_TEST(BlitTest(GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG, 0, 512, 1024, "data/abstract3_512x1024_pvrtc4.raw", true, 480.0 / 512, 800.0 / 1024));
447 ADD_TEST(BlitTest(GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG, 0, 512, 1024, "data/abstract3_512x1024_pvrtc2.raw", true, 480.0 / 512, 800.0 / 1024));
448 ADD_TEST(BlitTest(GL_ETC1_RGB8_OES, 0, 512, 1024, "data/abstract3_512x1024_etc1.raw", true, 480.0 / 512, 800.0 / 1024));
449 ADD_TEST(PixmapBlitTest(h, w, ctx.config, true));
450 ADD_TEST(PixmapBlitTest(h, w, config32, true));
451 ADD_TEST(FBOBlitTest(GL_RGBA, GL_UNSIGNED_BYTE, w, h, true, h / w, w / h));
452 ADD_TEST(FBOBlitTest(GL_RGBA, GL_UNSIGNED_BYTE, 1024, 512, true, h / 512, w / 1024));
453 ADD_TEST(FBOBlitTest(GL_RGB, GL_UNSIGNED_SHORT_5_6_5, w, h, true, h / w, w / h));
454 ADD_TEST(FBOBlitTest(GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 1024, 512, true, h / 512, w / 1024));
458 float w2 = winWidth / gridW;
459 float h2 = winHeight / gridH;
462 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
464 // Small blended blits
465 ADD_TEST(BlitTest(GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, 128, 128, "data/xorg_128x128_rgba4444.raw", false, gridW, gridH, 128.0 / w2, 128.0 / h2));
466 ADD_TEST(BlitTest(GL_RGBA, GL_UNSIGNED_BYTE, 127, 127, "data/xorg_127x127_rgba8888.raw", false, gridW, gridH, 127.0 / w2, 127.0 / h2));
467 ADD_TEST(BlitTest(GL_RGBA, GL_UNSIGNED_BYTE, 128, 128, "data/xorg_128x128_rgba8888.raw", false, gridW, gridH, 128.0 / w2, 128.0 / h2));
468 ADD_TEST(BlitTest(GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 127, 127, "data/xorg_127x127_rgb565.raw", false, gridW, gridH, 127.0 / w2, 127.0 / h2));
469 ADD_TEST(BlitTest(GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 128, 128, "data/xorg_128x128_rgb565.raw", false, gridW, gridH, 128.0 / w2, 128.0 / h2));
470 ADD_TEST(BlitTest(GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, 0, 128, 128, "data/xorg_128x128_pvrtc4.raw", false, gridW, gridH, 128.0 / w2, 128.0 / h2));
471 ADD_TEST(BlitTest(GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG, 0, 128, 128, "data/xorg_128x128_pvrtc2.raw", false, gridW, gridH, 128.0 / w2, 128.0 / h2));
472 ADD_TEST(BlitTest(GL_ETC1_RGB8_OES, 0, 128, 128, "data/xorg_128x128_etc1.raw", false, gridW, gridH, 128.0 / w2, 128.0 / h2));
473 ADD_TEST(ShaderBlitTest("mask", 128, 128, gridW, gridH * 0.5f, 128.0 / w2, 128.0 / h2));
475 // Rotated small blended blits
476 ADD_TEST(BlitTest(GL_RGBA, GL_UNSIGNED_BYTE, 127, 127, "data/xorg_127x127_rgba8888.raw", true, gridH, gridW, 127.0 / w2, 127.0 / h2));
477 ADD_TEST(BlitTest(GL_RGBA, GL_UNSIGNED_BYTE, 128, 128, "data/xorg_128x128_rgba8888.raw", true, gridH, gridW, 128.0 / w2, 128.0 / h2));
478 ADD_TEST(BlitTest(GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 127, 127, "data/xorg_127x127_rgb565.raw", true, gridH, gridW, 127.0 / w2, 127.0 / h2));
479 ADD_TEST(BlitTest(GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 128, 128, "data/xorg_128x128_rgb565.raw", true, gridH, gridW, 128.0 / w2, 128.0 / h2));
480 ADD_TEST(BlitTest(GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, 0, 128, 128, "data/xorg_128x128_pvrtc4.raw", true, gridH, gridW, 128.0 / w2, 128.0 / h2));
481 ADD_TEST(BlitTest(GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG, 0, 128, 128, "data/xorg_128x128_pvrtc2.raw", true, gridH, gridW, 128.0 / w2, 128.0 / h2));
482 ADD_TEST(BlitTest(GL_ETC1_RGB8_OES, 0, 128, 128, "data/xorg_128x128_etc1.raw", true, gridH, gridW, 128.0 / w2, 128.0 / h2));
487 ADD_TEST(ShaderBlitTest("const", w, h));
488 ADD_TEST(ShaderBlitTest("lingrad", w, h));
489 ADD_TEST(ShaderBlitTest("radgrad", w, h));
490 ADD_TEST(ShaderBlitTest("palette", w, h));
493 ADD_TEST(CPUInterleavingTest(CPUI_XSHM_IMAGE, 2, 16, winWidth, winHeight));
494 ADD_TEST(CPUInterleavingTest(CPUI_XSHM_IMAGE, 2, 32, winWidth, winHeight));
495 ADD_TEST(CPUInterleavingTest(CPUI_TEXTURE_UPLOAD, 2, 16, winWidth, winHeight));
496 ADD_TEST(CPUInterleavingTest(CPUI_TEXTURE_UPLOAD, 2, 32, winWidth, winHeight));