Set swap interval to 0
authorJuan A. Suarez Romero <jasuarez@igalia.com>
Fri, 24 Nov 2017 11:36:19 +0000 (11:36 +0000)
committerAlexander Galazin <Alexander.Galazin@arm.com>
Fri, 11 Oct 2019 09:04:49 +0000 (05:04 -0400)
By default, when swapping front and back frame buffers, this is in sync
with v-blank, which prevents tearing.

So this means the tests does not run at is maximum allowed speed, but it
is restricted somewhat by the attached screen.

When running in a window and X realizes the is no monitor attached, the
server's Present code will vsync at 1 FPS, which artificially slow down
the tests a ton.

To avoid this issue, and also because we want to run things as fast as
possible, set the swap interval to 0, which basically deactivate the
sync.

Test: cmake .. -DDEQP_TARGET=x11_egl

Change-Id: I04bcb814fb289d58f8788e90f5118db0b7175777
(cherry picked from commit 27d658881fe4cc24890b28d3ee0162469b507665)

framework/egl/egluGLContextFactory.cpp
framework/platform/lnx/X11/tcuLnxX11GlxPlatform.cpp
framework/platform/win32/tcuWGL.cpp

index 21d103f..8fbea2a 100644 (file)
@@ -466,6 +466,8 @@ void RenderContext::create (const NativeDisplayFactory* displayFactory, const Na
 
                m_glRenderTarget = tcu::RenderTarget(width, height, pixelFmt, depthBits, stencilBits, numSamples);
        }
+
+       egl.swapInterval(m_eglDisplay, 0);
 }
 
 void RenderContext::destroy (void)
index fd1b2e0..24bb797 100644 (file)
 #define GLX_GLXEXT_PROTOTYPES
 #include <GL/glx.h>
 
+
 #ifndef GLX_CONTEXT_OPENGL_NO_ERROR_ARB
 #define GLX_CONTEXT_OPENGL_NO_ERROR_ARB 0x31B3
 #endif
 
+#ifndef PFNGLXSWAPINTERVALMESAPROC
+#define PFNGLXSWAPINTERVALMESAPROC PFNGLXSWAPINTERVALSGIPROC
+#endif
+
 namespace tcu
 {
 namespace lnx
@@ -181,6 +186,7 @@ public:
        virtual void                                            postIterate                     (void);
        virtual void                                            makeCurrent                     (void);
        void                                                            clearCurrent            (void);
+       void                                                            swapInterval            (int interval);
        virtual const glw::Functions&           getFunctions            (void) const;
        virtual const tcu::RenderTarget&        getRenderTarget         (void) const;
        virtual glw::GenericFuncType            getProcAddress          (const char* name) const;
@@ -245,12 +251,17 @@ GlxDisplay::GlxDisplay (EventState& eventState, const char* name)
        {
                const int screen = XDefaultScreen(m_display);
                // nVidia doesn't seem to report client-side extensions correctly,
-               // so only use server side
-               const char* const extensions =
+               // so use also server side
+               const char* const server_extensions =
                        TCU_CHECK_GLX(glXQueryServerString(m_display, screen, GLX_EXTENSIONS));
-               istringstream extStream(extensions);
-               m_extensions = set<string>(istream_iterator<string>(extStream),
+               const char* const client_extensions =
+                       TCU_CHECK_GLX(glXQueryExtensionsString(m_display, screen));
+               istringstream srvExtStream(server_extensions);
+               istringstream cliExtStream(client_extensions);
+               m_extensions = set<string>(istream_iterator<string>(srvExtStream),
                                                                   istream_iterator<string>());
+               m_extensions.insert(istream_iterator<string>(cliExtStream),
+                                                       istream_iterator<string>());
        }
 }
 
@@ -714,6 +725,7 @@ GlxRenderContext::GlxRenderContext (const GlxContextFactory&        factory,
        const GlxFunctionLoader loader;
        makeCurrent();
        glu::initFunctions(&m_functions, &loader, config.type.getAPI());
+       swapInterval(0);
 }
 
 GlxRenderContext::~GlxRenderContext (void)
@@ -741,6 +753,30 @@ glw::GenericFuncType GlxRenderContext::getProcAddress(const char *name) const
        return glXGetProcAddress(reinterpret_cast<const GLubyte*>(name));
 }
 
+void GlxRenderContext::swapInterval (int interval)
+{
+       if (m_glxVisual.getGlxDisplay().isGlxExtensionSupported("GLX_EXT_swap_control"))
+       {
+               PFNGLXSWAPINTERVALEXTPROC glXSwapIntervalEXT =
+                       reinterpret_cast<PFNGLXSWAPINTERVALEXTPROC>(
+                               TCU_CHECK_GLX(
+                                       glXGetProcAddress(
+                                               reinterpret_cast<const GLubyte*>("glXSwapIntervalEXT"))));
+
+               glXSwapIntervalEXT(m_glxVisual.getXDisplay(), m_glxDrawable->getGLXDrawable(), interval);
+       }
+       else if (m_glxVisual.getGlxDisplay().isGlxExtensionSupported("GLX_MESA_swap_control"))
+       {
+               PFNGLXSWAPINTERVALMESAPROC glXSwapIntervalMESA =
+                       reinterpret_cast<PFNGLXSWAPINTERVALMESAPROC>(
+                               TCU_CHECK_GLX(
+                                       glXGetProcAddress(
+                                               reinterpret_cast<const GLubyte*>("glXSwapIntervalMESA"))));
+
+               glXSwapIntervalMESA(interval);
+       }
+}
+
 ContextType GlxRenderContext::getType (void) const
 {
        return m_type;
index c36ee94..e871b4c 100644 (file)
@@ -136,6 +136,9 @@ typedef BOOL                (WINAPI* wglChoosePixelFormatARBFunc)           (HDC hdc, const int *piAttr
 typedef HGLRC          (WINAPI* wglCreateContextAttribsARBFunc)        (HDC hdc, HGLRC hshareContext, const int* attribList);
 typedef const char*    (WINAPI* wglGetExtensionsStringARBFunc)         (HDC hdc);
 
+// WGL_EXT_swap_control
+typedef BOOL           (WINAPI* wglSwapIntervalEXTFunc)                        (int interval);
+
 DE_END_EXTERN_C
 
 namespace tcu
@@ -163,6 +166,10 @@ struct Functions
        wglCreateContextAttribsARBFunc          createContextAttribsARB;
        wglGetExtensionsStringARBFunc           getExtensionsStringARB;
 
+       // WGL_EXT_swap_control
+       wglSwapIntervalEXTFunc                          swapIntervalEXT;
+
+
        Functions (void)
                : createContext                         (DE_NULL)
                , deleteContext                         (DE_NULL)
@@ -249,6 +256,9 @@ Library::Library (HINSTANCE instance)
        m_functions.createContextAttribsARB             = (wglCreateContextAttribsARBFunc)m_functions.getProcAddress("wglCreateContextAttribsARB");
        m_functions.getExtensionsStringARB              = (wglGetExtensionsStringARBFunc)m_functions.getProcAddress("wglGetExtensionsStringARB");
 
+       // WGL_EXT_swap_control
+       m_functions.swapIntervalEXT                             = (wglSwapIntervalEXTFunc)m_functions.getProcAddress("wglSwapIntervalEXT");
+
        m_functions.makeCurrent(tmpWindow.getDeviceContext(), NULL);
        m_functions.deleteContext(tmpCtx);
 
@@ -525,6 +535,9 @@ Context::Context (const Core*                                               core,
                wgl.deleteContext(m_context);
                TCU_THROW(ResourceError, "wglMakeCurrent() failed");
        }
+
+       if (core->getLibrary()->isWglExtensionSupported("WGL_EXT_swap_control"))
+               core->getLibrary()->getFunctions().swapIntervalEXT(0);
 }
 
 Context::~Context (void)