From 0c51b832f59d536513eaa85732bc02ad72b99455 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Wed, 18 Apr 2018 12:23:29 +0200 Subject: Also support reset notification on non-nvidia In 5.11 robustness was added for nvidia drivers, this patch extends that to other opengl drivers, and fixes the reported format. Change-Id: Ia81934c3bcf13e7300fb4e75674ea63317039870 Reviewed-by: Laszlo Agocs --- .../gl_integrations/xcb_glx/qglxintegration.cpp | 40 ++++++++++++++-------- 1 file changed, 25 insertions(+), 15 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp index baf3dbd42a..cc982b3379 100644 --- a/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp +++ b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp @@ -90,10 +90,18 @@ typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXC #define GLX_CONTEXT_ROBUST_ACCESS_BIT_ARB 0x00000004 #endif +#ifndef GL_RESET_NOTIFICATION_STRATEGY_ARB +#define GL_RESET_NOTIFICATION_STRATEGY_ARB 0x8256 +#endif + #ifndef GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB #define GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB 0x8256 #endif +#ifndef GL_LOSE_CONTEXT_ON_RESET_ARB +#define GL_LOSE_CONTEXT_ON_RESET_ARB 0x8252 +#endif + #ifndef GLX_LOSE_CONTEXT_ON_RESET_ARB #define GLX_LOSE_CONTEXT_ON_RESET_ARB 0x8252 #endif @@ -157,6 +165,11 @@ static void updateFormatFromContext(QSurfaceFormat &format) format.setOption(QSurfaceFormat::StereoBuffers); if (format.renderableType() == QSurfaceFormat::OpenGL) { + GLint value = 0; + glGetIntegerv(GL_RESET_NOTIFICATION_STRATEGY_ARB, &value); + if (value == GL_LOSE_CONTEXT_ON_RESET_ARB) + format.setOption(QSurfaceFormat::ResetNotification); + if (format.version() < qMakePair(3, 0)) { format.setOption(QSurfaceFormat::DeprecatedFunctions); return; @@ -164,7 +177,7 @@ static void updateFormatFromContext(QSurfaceFormat &format) // Version 3.0 onwards - check if it includes deprecated functionality or is // a debug context - GLint value = 0; + value = 0; glGetIntegerv(GL_CONTEXT_FLAGS, &value); if (!(value & GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT)) format.setOption(QSurfaceFormat::DeprecatedFunctions); @@ -302,20 +315,17 @@ void QGLXContext::init(QXcbScreen *screen, QPlatformOpenGLContext *share) contextAttributes << GLX_CONTEXT_PROFILE_MASK_ARB << GLX_CONTEXT_ES2_PROFILE_BIT_EXT; } - if (supportsRobustness && supportsVideoMemoryPurge && m_format.testOption(QSurfaceFormat::ResetNotification)) { - QVector contextAttributesWithNvidiaReset = contextAttributes; - - contextAttributesWithNvidiaReset << GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB << GLX_LOSE_CONTEXT_ON_RESET_ARB; - contextAttributesWithNvidiaReset << GLX_GENERATE_RESET_ON_VIDEO_MEMORY_PURGE_NV << GL_TRUE; - - contextAttributesWithNvidiaReset << None; - m_context = glXCreateContextAttribsARB(m_display, config, m_shareContext, true, contextAttributesWithNvidiaReset.data()); - if (!m_context && m_shareContext) { - // re-try without a shared glx context - m_context = glXCreateContextAttribsARB(m_display, config, 0, true, contextAttributesWithNvidiaReset.data()); - if (m_context) - m_shareContext = 0; - } + if (supportsRobustness && m_format.testOption(QSurfaceFormat::ResetNotification)) { + QVector contextAttributesWithRobustness = contextAttributes; + contextAttributesWithRobustness << GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB << GLX_LOSE_CONTEXT_ON_RESET_ARB; + if (supportsVideoMemoryPurge) + contextAttributesWithRobustness << GLX_GENERATE_RESET_ON_VIDEO_MEMORY_PURGE_NV << GL_TRUE; + + contextAttributesWithRobustness << None; + m_context = glXCreateContextAttribsARB(m_display, config, m_shareContext, true, + contextAttributesWithRobustness.data()); + // Context creation against a shared context may fail specifically due to this request, so try + // without before dropping sharing. } if (m_context) { -- cgit v1.2.3