From f56b2ba5c826dcfcb1a3278968e0600ea31b4a71 Mon Sep 17 00:00:00 2001 From: Marc Di Luzio Date: Fri, 5 May 2017 10:55:09 +0100 Subject: [PATCH] Add support for robust GL context creation Currently only implemented on the GLX platform using GLX_ARB_create_context_robustnessand GLX_NV_robustness_video_memory_purge --- include/SDL_video.h | 9 ++++++++- src/video/SDL_sysvideo.h | 2 ++ src/video/SDL_video.c | 8 ++++++++ src/video/x11/SDL_x11opengl.c | 34 ++++++++++++++++++++++++++++++++-- src/video/x11/SDL_x11opengl.h | 2 ++ 5 files changed, 52 insertions(+), 3 deletions(-) diff --git a/include/SDL_video.h b/include/SDL_video.h index cd20f9b94..1cea5ed5c 100644 --- a/include/SDL_video.h +++ b/include/SDL_video.h @@ -200,7 +200,9 @@ typedef enum SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_SHARE_WITH_CURRENT_CONTEXT, SDL_GL_FRAMEBUFFER_SRGB_CAPABLE, - SDL_GL_CONTEXT_RELEASE_BEHAVIOR + SDL_GL_CONTEXT_RELEASE_BEHAVIOR, + SDL_GL_CONTEXT_RESET_NOTIFICATION, + SDL_GL_CONTEXT_ROBUSTNESS_VIDEO_PURGE } SDL_GLattr; typedef enum @@ -224,6 +226,11 @@ typedef enum SDL_GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH = 0x0001 } SDL_GLcontextReleaseFlag; +typedef enum +{ + SDL_GL_CONTEXT_NO_RESET_NOTIFICATION = 0x0000, + SDL_GL_CONTEXT_LOSE_CONTEXT_ON_RESET = 0x0001, +} SDL_GLcontextResetNotification; /* Function prototypes */ diff --git a/src/video/SDL_sysvideo.h b/src/video/SDL_sysvideo.h index 1827019d4..d8f5155b2 100644 --- a/src/video/SDL_sysvideo.h +++ b/src/video/SDL_sysvideo.h @@ -329,6 +329,8 @@ struct SDL_VideoDevice int profile_mask; int share_with_current_context; int release_behavior; + int robustness_video_purge; + int reset_notification; int framebuffer_srgb_capable; int retained_backing; int driver_loaded; diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index 8a76c19d7..baae85a7a 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -2970,6 +2970,8 @@ SDL_GL_ResetAttributes() _this->gl_config.flags = 0; _this->gl_config.framebuffer_srgb_capable = 0; _this->gl_config.release_behavior = SDL_GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH; + _this->gl_config.reset_notification = SDL_GL_CONTEXT_NO_RESET_NOTIFICATION; + _this->gl_config.robustness_video_purge = SDL_FALSE; _this->gl_config.share_with_current_context = 0; } @@ -3079,6 +3081,12 @@ SDL_GL_SetAttribute(SDL_GLattr attr, int value) case SDL_GL_CONTEXT_RELEASE_BEHAVIOR: _this->gl_config.release_behavior = value; break; + case SDL_GL_CONTEXT_RESET_NOTIFICATION: + _this->gl_config.reset_notification = value; + break; + case SDL_GL_CONTEXT_ROBUSTNESS_VIDEO_PURGE: + _this->gl_config.robustness_video_purge = value; + break; default: retval = SDL_SetError("Unknown OpenGL attribute"); break; diff --git a/src/video/x11/SDL_x11opengl.c b/src/video/x11/SDL_x11opengl.c index 07564841c..2ed56755e 100644 --- a/src/video/x11/SDL_x11opengl.c +++ b/src/video/x11/SDL_x11opengl.c @@ -100,6 +100,10 @@ typedef GLXContext(*PFNGLXCREATECONTEXTATTRIBSARBPROC) (Display * dpy, #define GLX_LOSE_CONTEXT_ON_RESET_ARB 0x8252 #endif +#ifndef GLX_NV_robustness_video_memory_purge +#define GLX_GENERATE_RESET_ON_VIDEO_MEMORY_PURGE_NV 0x20F7 +#endif + #ifndef GLX_EXT_create_context_es2_profile #define GLX_EXT_create_context_es2_profile #ifndef GLX_CONTEXT_ES2_PROFILE_BIT_EXT @@ -394,6 +398,16 @@ X11_GL_InitExtensions(_THIS) if (HasExtension("GLX_ARB_context_flush_control", extensions)) { _this->gl_data->HAS_GLX_ARB_context_flush_control = SDL_TRUE; } + + /* Check for GLX_ARB_create_context_robustness */ + if (HasExtension("GLX_ARB_create_context_robustness", extensions)) { + _this->gl_data->HAS_GLX_ARB_create_context_robustness = SDL_TRUE; + } + + /* Check for GLX_NV_robustness_video_memory_purge */ + if (HasExtension("GLX_NV_robustness_video_memory_purge", extensions)) { + _this->gl_data->HAS_GLX_NV_robustness_video_memory_purge =SDL_TRUE; + } } /* glXChooseVisual and glXChooseFBConfig have some small differences in @@ -621,8 +635,8 @@ X11_GL_CreateContext(_THIS, SDL_Window * window) context = _this->gl_data->glXCreateContext(display, vinfo, share_context, True); } else { - /* max 10 attributes plus terminator */ - int attribs[11] = { + /* max 7 attribute pairs plus terminator */ + int attribs[15] = { GLX_CONTEXT_MAJOR_VERSION_ARB, _this->gl_config.major_version, GLX_CONTEXT_MINOR_VERSION_ARB, @@ -652,6 +666,22 @@ X11_GL_CreateContext(_THIS, SDL_Window * window) GLX_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB; } + /* only set if glx extension is available */ + if( _this->gl_data->HAS_GLX_ARB_create_context_robustness ) { + attribs[iattr++] = GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB; + attribs[iattr++] = + _this->gl_config.reset_notification ? + GLX_LOSE_CONTEXT_ON_RESET_ARB : + GLX_NO_RESET_NOTIFICATION_ARB; + } + + /* only set if glx extension is available */ + if( _this->gl_data->HAS_GLX_NV_robustness_video_memory_purge + && _this->gl_config.robustness_video_purge ) { + attribs[iattr++] = GLX_GENERATE_RESET_ON_VIDEO_MEMORY_PURGE_NV; + attribs[iattr++] = GL_TRUE; + } + attribs[iattr++] = 0; /* Get a pointer to the context creation function for GL 3.0 */ diff --git a/src/video/x11/SDL_x11opengl.h b/src/video/x11/SDL_x11opengl.h index 7e5654d94..4958b71b4 100644 --- a/src/video/x11/SDL_x11opengl.h +++ b/src/video/x11/SDL_x11opengl.h @@ -35,6 +35,8 @@ struct SDL_GLDriverData SDL_bool HAS_GLX_EXT_visual_info; SDL_bool HAS_GLX_EXT_swap_control_tear; SDL_bool HAS_GLX_ARB_context_flush_control; + SDL_bool HAS_GLX_ARB_create_context_robustness; + SDL_bool HAS_GLX_NV_robustness_video_memory_purge; /* Max version of OpenGL ES context that can be created if the implementation supports GLX_EXT_create_context_es2_profile. -- 2.12.2