Stefan Dösinger : wined3d: Use the shader backend to enable / disable atifs and nvts.

Alexandre Julliard julliard at winehq.org
Thu Apr 24 06:23:07 CDT 2008


Module: wine
Branch: master
Commit: e3bd5b6dcdae9018f4f148aa6c964d0bb3be21d1
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=e3bd5b6dcdae9018f4f148aa6c964d0bb3be21d1

Author: Stefan Dösinger <stefan at codeweavers.com>
Date:   Fri Apr 11 08:19:04 2008 +0200

wined3d: Use the shader backend to enable / disable atifs and nvts.

The previous logic assumed that if NVTS or ATIFS are available they
will be used. This happens to be true for NVTS, but ATIFS is only used
if neither ARBFP nor GLSL are supported. This breaks fixed function
fragment processing on ATI r300 and newer cards

---

 dlls/wined3d/arb_program_shader.c  |    5 +++
 dlls/wined3d/ati_fragment_shader.c |   11 ++++++++
 dlls/wined3d/baseshader.c          |   17 ++++++++++++
 dlls/wined3d/context.c             |   50 ++++++-----------------------------
 dlls/wined3d/glsl_shader.c         |    5 +++
 dlls/wined3d/wined3d_private.h     |    1 +
 6 files changed, 48 insertions(+), 41 deletions(-)

diff --git a/dlls/wined3d/arb_program_shader.c b/dlls/wined3d/arb_program_shader.c
index a165b9c..6bed3c5 100644
--- a/dlls/wined3d/arb_program_shader.c
+++ b/dlls/wined3d/arb_program_shader.c
@@ -2081,6 +2081,10 @@ static void shader_arb_get_caps(WINED3DDEVTYPE devtype, WineD3D_GL_Info *gl_info
 static void shader_arb_load_init(void) {
 }
 
+static void shader_arb_fragment_enable(IWineD3DDevice *iface, BOOL enable) {
+    none_shader_backend.shader_fragment_enable(iface, enable);
+}
+
 const shader_backend_t arb_program_shader_backend = {
     &shader_arb_select,
     &shader_arb_select_depth_blt,
@@ -2096,5 +2100,6 @@ const shader_backend_t arb_program_shader_backend = {
     &shader_arb_generate_vshader,
     &shader_arb_get_caps,
     &shader_arb_load_init,
+    &shader_arb_fragment_enable,
     FFPStateTable
 };
diff --git a/dlls/wined3d/ati_fragment_shader.c b/dlls/wined3d/ati_fragment_shader.c
index cd5a11b..0d3687e 100644
--- a/dlls/wined3d/ati_fragment_shader.c
+++ b/dlls/wined3d/ati_fragment_shader.c
@@ -1026,6 +1026,16 @@ static void shader_atifs_generate_vshader(IWineD3DVertexShader *iface, SHADER_BU
     arb_program_shader_backend.shader_generate_vshader(iface, buffer);
 }
 
+static void shader_atifs_fragment_enable(IWineD3DDevice *iface, BOOL enable) {
+    if(enable) {
+        glEnable(GL_FRAGMENT_SHADER_ATI);
+        checkGLcall("glEnable(GL_FRAGMENT_SHADER_ATI)");
+    } else {
+        glDisable(GL_FRAGMENT_SHADER_ATI);
+        checkGLcall("glDisable(GL_FRAGMENT_SHADER_ATI)");
+    }
+}
+
 const shader_backend_t atifs_shader_backend = {
     shader_atifs_select,
     shader_atifs_select_depth_blt,
@@ -1041,5 +1051,6 @@ const shader_backend_t atifs_shader_backend = {
     shader_atifs_generate_vshader,
     shader_atifs_get_caps,
     shader_atifs_load_init,
+    shader_atifs_fragment_enable,
     ATIFSStateTable
 };
diff --git a/dlls/wined3d/baseshader.c b/dlls/wined3d/baseshader.c
index 37ddd78..174f2ea 100644
--- a/dlls/wined3d/baseshader.c
+++ b/dlls/wined3d/baseshader.c
@@ -1182,6 +1182,22 @@ static void shader_none_get_caps(WINED3DDEVTYPE devtype, WineD3D_GL_Info *gl_inf
 #endif
 
 }
+
+static void shader_none_fragment_enable(IWineD3DDevice *iface, BOOL enable) {
+    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *) iface;
+    WineD3D_GL_Info *gl_info = &This->adapter->gl_info;
+
+    if(GL_SUPPORT(NV_TEXTURE_SHADER2)) {
+        if(enable) {
+            glEnable(GL_TEXTURE_SHADER_NV);
+            checkGLcall("glEnable(GL_TEXTURE_SHADER_NV)");
+        } else {
+            glDisable(GL_TEXTURE_SHADER_NV);
+            checkGLcall("glDisable(GL_TEXTURE_SHADER_NV)");
+        }
+    }
+}
+
 #undef GLINFO_LOCATION
 
 const shader_backend_t none_shader_backend = {
@@ -1199,6 +1215,7 @@ const shader_backend_t none_shader_backend = {
     &shader_none_generate_vshader,
     &shader_none_get_caps,
     &shader_none_load_init,
+    &shader_none_fragment_enable,
     FFPStateTable
 };
 
diff --git a/dlls/wined3d/context.c b/dlls/wined3d/context.c
index 67baee5..6e19cae 100644
--- a/dlls/wined3d/context.c
+++ b/dlls/wined3d/context.c
@@ -351,10 +351,9 @@ WineD3DContext *CreateContext(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *tar
     /* Set up the context defaults */
     oldCtx  = pwglGetCurrentContext();
     oldDrawable = pwglGetCurrentDC();
-    if(oldCtx && oldDrawable && GL_SUPPORT(ATI_FRAGMENT_SHADER)) {
+    if(oldCtx && oldDrawable) {
         /* See comment in ActivateContext context switching */
-        glDisable(GL_FRAGMENT_SHADER_ATI);
-        checkGLcall("glEnable(GL_FRAGMENT_SHADER_ATI)");
+        This->shader_backend->shader_fragment_enable((IWineD3DDevice *) This, FALSE);
     }
     if(pwglMakeCurrent(hdc, ctx) == FALSE) {
         ERR("Cannot activate context to set up defaults\n");
@@ -439,10 +438,7 @@ WineD3DContext *CreateContext(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *tar
     if(oldDrawable && oldCtx) {
         pwglMakeCurrent(oldDrawable, oldCtx);
     }
-    if(GL_SUPPORT(ATI_FRAGMENT_SHADER)) {
-        glEnable(GL_FRAGMENT_SHADER_ATI);
-        checkGLcall("glEnable(GL_FRAGMENT_SHADER_ATI)");
-    }
+    This->shader_backend->shader_fragment_enable((IWineD3DDevice *) This, TRUE);
 
 out:
     return ret;
@@ -687,13 +683,7 @@ static inline void SetupForBlit(IWineD3DDeviceImpl *This, WineD3DContext *contex
     checkGLcall("glViewport");
     Context_MarkStateDirty(context, STATE_VIEWPORT, StateTable);
 
-    if(GL_SUPPORT(NV_TEXTURE_SHADER2)) {
-        glDisable(GL_TEXTURE_SHADER_NV);
-        checkGLcall("glDisable(GL_TEXTURE_SHADER_NV)");
-    } else if(GL_SUPPORT(ATI_FRAGMENT_SHADER)) {
-        glDisable(GL_FRAGMENT_SHADER_ATI);
-        checkGLcall("glDisable(GL_FRAGMENT_SHADER_ATI)");
-    }
+    This->shader_backend->shader_fragment_enable((IWineD3DDevice *) This, FALSE);
 }
 
 /*****************************************************************************
@@ -941,22 +931,12 @@ 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)");
-            }
-
+            This->shader_backend->shader_fragment_enable((IWineD3DDevice *) This, FALSE);
             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)");
+            } else if(!context->last_was_blit) {
+                This->shader_backend->shader_fragment_enable((IWineD3DDevice *) This, TRUE);
             }
         }
         if(This->activeContext->vshader_const_dirty) {
@@ -988,13 +968,7 @@ void ActivateContext(IWineD3DDeviceImpl *This, IWineD3DSurface *target, ContextU
 
         case CTXUSAGE_CLEAR:
             if(context->last_was_blit) {
-                if(GL_SUPPORT(NV_TEXTURE_SHADER2)) {
-                    glEnable(GL_TEXTURE_SHADER_NV);
-                    checkGLcall("glEnable(GL_TEXTURE_SHADER_NV)");
-                } else if(GL_SUPPORT(ATI_FRAGMENT_SHADER)) {
-                    glEnable(GL_FRAGMENT_SHADER_ATI);
-                    checkGLcall("glEnable(GL_FRAGMENT_SHADER_ATI)");
-                }
+                This->shader_backend->shader_fragment_enable((IWineD3DDevice *) This, TRUE);
             }
 
             /* Blending and clearing should be orthogonal, but tests on the nvidia driver show that disabling
@@ -1013,13 +987,7 @@ void ActivateContext(IWineD3DDeviceImpl *This, IWineD3DSurface *target, ContextU
         case CTXUSAGE_DRAWPRIM:
             /* This needs all dirty states applied */
             if(context->last_was_blit) {
-                if(GL_SUPPORT(NV_TEXTURE_SHADER2)) {
-                    glEnable(GL_TEXTURE_SHADER_NV);
-                    checkGLcall("glEnable(GL_TEXTURE_SHADER_NV)");
-                } else if(GL_SUPPORT(ATI_FRAGMENT_SHADER)) {
-                    glEnable(GL_FRAGMENT_SHADER_ATI);
-                    checkGLcall("glEnable(GL_FRAGMENT_SHADER_ATI)");
-                }
+                This->shader_backend->shader_fragment_enable((IWineD3DDevice *) This, TRUE);
             }
 
             IWineD3DDeviceImpl_FindTexUnitMap(This);
diff --git a/dlls/wined3d/glsl_shader.c b/dlls/wined3d/glsl_shader.c
index 1c5a97f..cc0c2e0 100644
--- a/dlls/wined3d/glsl_shader.c
+++ b/dlls/wined3d/glsl_shader.c
@@ -3583,6 +3583,10 @@ static void shader_glsl_get_caps(WINED3DDEVTYPE devtype, WineD3D_GL_Info *gl_inf
 
 static void shader_glsl_load_init(void) {}
 
+static void shader_glsl_fragment_enable(IWineD3DDevice *iface, BOOL enable) {
+    none_shader_backend.shader_fragment_enable(iface, enable);
+}
+
 const shader_backend_t glsl_shader_backend = {
     &shader_glsl_select,
     &shader_glsl_select_depth_blt,
@@ -3598,5 +3602,6 @@ const shader_backend_t glsl_shader_backend = {
     &shader_glsl_generate_vshader,
     &shader_glsl_get_caps,
     &shader_glsl_load_init,
+    &shader_glsl_fragment_enable,
     FFPStateTable
 };
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 92387ed..bdad91b 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -300,6 +300,7 @@ typedef struct {
     void (*shader_generate_vshader)(IWineD3DVertexShader *iface, SHADER_BUFFER *buffer);
     void (*shader_get_caps)(WINED3DDEVTYPE devtype, WineD3D_GL_Info *gl_info, struct shader_caps *caps);
     void (*shader_dll_load_init)(void);
+    void (*shader_fragment_enable)(IWineD3DDevice *iface, BOOL enable);
     const struct StateEntry *StateTable;
 } shader_backend_t;
 




More information about the wine-cvs mailing list