From ddf52dda15e83eae639ef2ce0ec4071b321ce34f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20D=C3=B6singer?= Date: Sun, 30 Mar 2008 14:52:18 +0200 Subject: [PATCH] wined3d: Deactivate GL_FRAGMENT_SHADER_ATI before deactivating a context. Mesa has a bug that causes a crash due to a NULL pointer dereference with the R200 driver when making a context current that has GL_FRAGMENT_SHADER_ATI enabled. This patch works around this bug by making sure that GL_FRAGMENT_SHADER_ATI is disabled before deactivating a context, and reactivates it afterwards. The context manager keeps GL_ATI_FRAGMENT_SHADER generally enabled, except if the context is in 2D blit mode. --- dlls/wined3d/context.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/dlls/wined3d/context.c b/dlls/wined3d/context.c index 0934180b6c..d20f5f2010 100644 --- a/dlls/wined3d/context.c +++ b/dlls/wined3d/context.c @@ -351,6 +351,11 @@ WineD3DContext *CreateContext(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *tar /* Set up the context defaults */ oldCtx = pwglGetCurrentContext(); oldDrawable = pwglGetCurrentDC(); + if(oldCtx && oldDrawable && GL_SUPPORT(ATI_FRAGMENT_SHADER)) { + /* See comment in ActivateContext context switching */ + glDisable(GL_FRAGMENT_SHADER_ATI); + checkGLcall("glEnable(GL_FRAGMENT_SHADER_ATI)"); + } if(pwglMakeCurrent(hdc, ctx) == FALSE) { ERR("Cannot activate context to set up defaults\n"); goto out; @@ -414,9 +419,6 @@ WineD3DContext *CreateContext(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *tar glTexEnvi(GL_TEXTURE_SHADER_NV, GL_PREVIOUS_TEXTURE_INPUT_NV, GL_TEXTURE0_ARB + s - 1); checkGLcall("glTexEnvi(GL_TEXTURE_SHADER_NV, GL_PREVIOUS_TEXTURE_INPUT_NV, ...\n"); } - } else if(GL_SUPPORT(ATI_FRAGMENT_SHADER)) { - glEnable(GL_FRAGMENT_SHADER_ATI); - checkGLcall("glEnable(GL_FRAGMENT_SHADER_ATI)"); } if(GL_SUPPORT(ARB_POINT_SPRITE)) { @@ -428,9 +430,16 @@ WineD3DContext *CreateContext(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *tar } LEAVE_GL(); + /* Never keep GL_FRAGMENT_SHADER_ATI enabled on a context that we switch away from, + * but enable it for the first context we create, and reenable it on the old context + */ if(oldDrawable && oldCtx) { pwglMakeCurrent(oldDrawable, oldCtx); } + if(GL_SUPPORT(ATI_FRAGMENT_SHADER)) { + glEnable(GL_FRAGMENT_SHADER_ATI); + checkGLcall("glEnable(GL_FRAGMENT_SHADER_ATI)"); + } out: return ret; @@ -928,9 +937,23 @@ void ActivateContext(IWineD3DDeviceImpl *This, IWineD3DSurface *target, ContextU } else { TRACE("Switching gl ctx to %p, hdc=%p ctx=%p\n", context, context->hdc, context->glCtx); + + if(GL_SUPPORT(ATI_FRAGMENT_SHADER)) { + /* Mesa crashes when enabling a context with GL_FRAGMENT_SHADER_ATI enabled. + * Thus we disable it before deactivating any context, and re-enable it afterwards. + * + * This bug is filed as bug #15269 on bugs.freedesktop.org + */ + glDisable(GL_FRAGMENT_SHADER_ATI); + checkGLcall("glEnable(GL_FRAGMENT_SHADER_ATI)"); + } + ret = pwglMakeCurrent(context->hdc, context->glCtx); if(ret == FALSE) { ERR("Failed to activate the new context\n"); + } else if(GL_SUPPORT(ATI_FRAGMENT_SHADER) && !context->last_was_blit) { + glEnable(GL_FRAGMENT_SHADER_ATI); + checkGLcall("glEnable(GL_FRAGMENT_SHADER_ATI)"); } } if(This->activeContext->vshader_const_dirty) {