diff mbox

[Branch,~glmark2-dev/glmark2/trunk] Rev 94: gl: Disable VSync manually (work around an SDL bug).

Message ID 20110721123636.17019.9080.launchpad@loganberry.canonical.com
State Accepted
Headers show

Commit Message

alexandros.frantzis@linaro.org July 21, 2011, 12:36 p.m. UTC
------------------------------------------------------------
revno: 94
committer: Alexandros Frantzis <alexandros.frantzis@linaro.org>
timestamp: Fri 2011-06-24 14:47:33 +0300
message:
  gl: Disable VSync manually (work around an SDL bug).
added:
  src/glx-disable-vsync.cpp
  src/glx-disable-vsync.h
modified:
  NEWS
  src/screen-sdl-gl.cpp


--
lp:glmark2
https://code.launchpad.net/~glmark2-dev/glmark2/trunk

You are subscribed to branch lp:glmark2.
To unsubscribe from this branch go to https://code.launchpad.net/~glmark2-dev/glmark2/trunk/+edit-subscription
diff mbox

Patch

=== modified file 'NEWS'
--- NEWS	2011-06-24 09:25:13 +0000
+++ NEWS	2011-06-24 11:47:33 +0000
@@ -10,6 +10,7 @@ 
 * Add basic output validation functionality (--validate).
 * Add command line option to call glFinish() instead of swapping
   the front and back buffers (--no-swap-buffers).
+* Manually disable VSync for GL/GLX (work around an SDL bug).
 * Replace custom math and shader infrastructure with functionality
   provided by LibMatrix (lp:libmatrix).
 * Improve user documentation (--help and man page).

=== added file 'src/glx-disable-vsync.cpp'
--- src/glx-disable-vsync.cpp	1970-01-01 00:00:00 +0000
+++ src/glx-disable-vsync.cpp	2011-06-24 11:47:33 +0000
@@ -0,0 +1,86 @@ 
+/*
+ * Copyright © 2010-2011 Linaro Limited
+ *
+ * This file is part of the glmark2 OpenGL (ES) 2.0 benchmark.
+ *
+ * glmark2 is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later
+ * version.
+ *
+ * glmark2 is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * glmark2.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ *  Alexandros Frantzis (glmark2)
+ */
+
+#if USE_GL
+
+#include "glx-disable-vsync.h"
+#include <SDL_syswm.h>
+#include <GL/gl.h>
+#include <GL/glx.h>
+#include <X11/Xlib.h>
+
+#include <string>
+#include "log.h"
+
+PFNGLXSWAPINTERVALEXTPROC glXSwapIntervalEXT_ = 0;
+PFNGLXSWAPINTERVALMESAPROC glXSwapIntervalMESA_ = 0;
+
+void
+glx_disable_vsync()
+{
+    SDL_SysWMinfo info;
+    SDL_VERSION(&info.version);
+
+    if (SDL_GetWMInfo(&info) != 1) {
+        Log::error("Couldn't get windowing system info from SDL.\n");
+        return;
+    }
+
+    Display *display = info.info.x11.gfxdisplay;
+    Window window = info.info.x11.window;
+
+    std::string extString;
+    const char* exts = glXQueryExtensionsString(display, 0);
+    if (exts) {
+        extString = exts;
+    }
+
+    /*
+     * GLX_EXT_swap_control or GL_MESA_swap_control. Note that
+     * GLX_SGI_swap_control is not enough because it doesn't allow 0 as a valid
+     * value (i.e. we can't turn off VSync).
+     */
+    if (extString.find("GLX_EXT_swap_control") != std::string::npos) {
+        glXSwapIntervalEXT_ =
+            reinterpret_cast<PFNGLXSWAPINTERVALEXTPROC>(
+                glXGetProcAddress((const GLubyte *)"glXSwapIntervalEXT"));
+    }
+    else if (extString.find("GLX_MESA_swap_control") != std::string::npos) {
+        glXSwapIntervalMESA_ =
+            reinterpret_cast<PFNGLXSWAPINTERVALMESAPROC>(
+                glXGetProcAddress((const GLubyte *)"glXSwapIntervalMESA"));
+    }
+
+
+    if (!glXSwapIntervalEXT_ && !glXSwapIntervalMESA_) {
+        Log::info("** GLX does not support GLX_EXT_swap_control or GLX_MESA_swap_control!\n");
+    }
+
+    /* Turn off VSync */
+    if ((!glXSwapIntervalEXT_ || glXSwapIntervalEXT_(display, window, 0)) &&
+        (!glXSwapIntervalMESA_ || glXSwapIntervalMESA_(0)))
+    {
+        Log::info("** Failed to set swap interval. Results may be bounded above by refresh rate.\n");
+    }
+}
+
+#endif

=== added file 'src/glx-disable-vsync.h'
--- src/glx-disable-vsync.h	1970-01-01 00:00:00 +0000
+++ src/glx-disable-vsync.h	2011-06-24 11:47:33 +0000
@@ -0,0 +1,28 @@ 
+/*
+ * Copyright © 2010-2011 Linaro Limited
+ *
+ * This file is part of the glmark2 OpenGL (ES) 2.0 benchmark.
+ *
+ * glmark2 is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later
+ * version.
+ *
+ * glmark2 is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * glmark2.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ *  Alexandros Frantzis (glmark2)
+ */
+
+#ifndef GLMARK2_GLX_DISABLE_VSYNC_H_
+#define GLMARK2_GLX_DISABLE_VSYNC_H_
+
+void glx_disable_vsync();
+
+#endif

=== modified file 'src/screen-sdl-gl.cpp'
--- src/screen-sdl-gl.cpp	2011-06-15 10:11:13 +0000
+++ src/screen-sdl-gl.cpp	2011-06-24 11:47:33 +0000
@@ -23,6 +23,7 @@ 
  */
 #include "screen-sdl-gl.h"
 #include "options.h"
+#include "glx-disable-vsync.h"
 #include <fstream>
 
 ScreenSDLGL::ScreenSDLGL(int pWidth, int pHeight, int pBpp, int pFullScreen, int pFlags)
@@ -37,6 +38,13 @@ 
 
     glViewport(0, 0, mWidth, mHeight);
 
+    /*
+     * There is a bug in SDL that prevents us from setting the swap
+     * interval using the SDL_GL_SWAP_CONTROL attribute. We take care
+     * of this manually for now.
+     */
+    glx_disable_vsync();
+    
     clear();
 }