Mesa (gallium-0.2): mesa: new _mesa_set_vp_override() function for driver-override of vertex program

Keith Whitwell keithw at kemper.freedesktop.org
Wed Oct 15 16:25:20 UTC 2008


Module: Mesa
Branch: gallium-0.2
Commit: 6d4d51d647c27288aa625560bc080231099c0b01
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=6d4d51d647c27288aa625560bc080231099c0b01

Author: Brian Paul <brian.paul at tungstengraphics.com>
Date:   Fri Oct 10 13:39:14 2008 -0600

mesa: new _mesa_set_vp_override() function for driver-override of vertex program

Patch provide by Keith.
Used in state tracker by DrawPixels to indicate that the state tracker (driver)
is using its own vertex program.  This prevents the texenvprogram code from
replacing conventional shader inputs with state vars.
Fixes glDraw/CopyPixels regressions.

---

 src/mesa/main/mtypes.h                    |    2 ++
 src/mesa/main/state.c                     |   29 ++++++++++++++++++++++++++---
 src/mesa/main/state.h                     |   17 +++++++++++------
 src/mesa/main/texenvprogram.c             |   14 ++++++++++++--
 src/mesa/state_tracker/st_cb_drawpixels.c |    6 ++++++
 5 files changed, 57 insertions(+), 11 deletions(-)

diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index dff474d..fab6ad0 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2007,6 +2007,8 @@ struct gl_vertex_program_state
    GLboolean CallbackEnabled;
    GLuint CurrentPosition;
 #endif
+
+   GLboolean _Overriden;
 };
 
 
diff --git a/src/mesa/main/state.c b/src/mesa/main/state.c
index b124d48..a962f1c 100644
--- a/src/mesa/main/state.c
+++ b/src/mesa/main/state.c
@@ -1,6 +1,6 @@
 /*
  * Mesa 3-D graphics library
- * Version:  7.1
+ * Version:  7.3
  *
  * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
  *
@@ -466,10 +466,12 @@ _mesa_update_state_locked( GLcontext *ctx )
 
    if (ctx->FragmentProgram._MaintainTexEnvProgram) {
       prog_flags |= (_NEW_ARRAY | _NEW_TEXTURE_MATRIX | _NEW_LIGHT |
+                     _NEW_RENDERMODE |
                      _NEW_TEXTURE | _NEW_FOG | _DD_NEW_SEPARATE_SPECULAR);
    }
    if (ctx->VertexProgram._MaintainTnlProgram) {
       prog_flags |= (_NEW_ARRAY | _NEW_TEXTURE | _NEW_TEXTURE_MATRIX |
+                     _NEW_RENDERMODE |
                      _NEW_TRANSFORM | _NEW_POINT |
                      _NEW_FOG | _NEW_LIGHT |
                      _MESA_NEW_NEED_EYE_COORDS);
@@ -509,7 +511,8 @@ _mesa_update_state( GLcontext *ctx )
 
 
 
-/* Want to figure out which fragment program inputs are actually
+/**
+ * Want to figure out which fragment program inputs are actually
  * constant/current values from ctx->Current.  These should be
  * referenced as a tracked state variable rather than a fragment
  * program input, to save the overhead of putting a constant value in
@@ -537,6 +540,26 @@ _mesa_set_varying_vp_inputs( GLcontext *ctx,
    if (ctx->varying_vp_inputs != varying_inputs) {
       ctx->varying_vp_inputs = varying_inputs;
       ctx->NewState |= _NEW_ARRAY;
-      //_mesa_printf("%s %x\n", __FUNCTION__, varying_inputs);
+      /*_mesa_printf("%s %x\n", __FUNCTION__, varying_inputs);*/
+   }
+}
+
+
+/**
+ * Used by drivers to tell core Mesa that the driver is going to
+ * install/ use its own vertex program.  In particular, this will
+ * prevent generated fragment programs from using state vars instead
+ * of ordinary varyings/inputs.
+ */
+void
+_mesa_set_vp_override(GLcontext *ctx, GLboolean flag)
+{
+   if (ctx->VertexProgram._Overriden != flag) {
+      ctx->VertexProgram._Overriden = flag;
+
+      /* Set one of the bits which will trigger fragment program
+       * regeneration:
+       */
+      ctx->NewState |= _NEW_ARRAY; 
    }
 }
diff --git a/src/mesa/main/state.h b/src/mesa/main/state.h
index 79f2f6b..29db08a 100644
--- a/src/mesa/main/state.h
+++ b/src/mesa/main/state.h
@@ -1,6 +1,6 @@
 /*
  * Mesa 3-D graphics library
- * Version:  7.1
+ * Version:  7.3
  *
  * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
  *
@@ -29,16 +29,21 @@
 #include "mtypes.h"
 
 extern void
-_mesa_update_state( GLcontext *ctx );
+_mesa_update_state(GLcontext *ctx);
 
 /* As above but can only be called between _mesa_lock_context_textures() and 
  * _mesa_unlock_context_textures().
  */
 extern void
-_mesa_update_state_locked( GLcontext *ctx );
+_mesa_update_state_locked(GLcontext *ctx);
+
+
+extern void
+_mesa_set_varying_vp_inputs(GLcontext *ctx, GLbitfield varying_inputs);
+
+
+extern void
+_mesa_set_vp_override(GLcontext *ctx, GLboolean flag);
 
-void
-_mesa_set_varying_vp_inputs( GLcontext *ctx,
-                             GLbitfield varying_inputs );
 
 #endif
diff --git a/src/mesa/main/texenvprogram.c b/src/mesa/main/texenvprogram.c
index 638d6be..f3bac86 100644
--- a/src/mesa/main/texenvprogram.c
+++ b/src/mesa/main/texenvprogram.c
@@ -205,8 +205,18 @@ static GLbitfield get_fp_input_mask( GLcontext *ctx )
 {
    GLbitfield fp_inputs = 0x0;
 
-   if (!ctx->VertexProgram._Enabled ||
-       !ctx->VertexProgram._Current) {
+   if (ctx->VertexProgram._Overriden) {
+      /* Somebody's messing with the vertex program and we don't have
+       * a clue what's happening.  Assume that it could be producing
+       * all possible outputs.
+       */
+      fp_inputs = ~0;
+   }
+   else if (ctx->RenderMode == GL_FEEDBACK) {
+      fp_inputs = (FRAG_BIT_COL0 | FRAG_BIT_TEX0);
+   }
+   else if (!ctx->VertexProgram._Enabled ||
+            !ctx->VertexProgram._Current) {
 
       /* Fixed function logic */
       GLbitfield varying_inputs = ctx->varying_vp_inputs;
diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c
index 00bbcae..5b24b9f 100644
--- a/src/mesa/state_tracker/st_cb_drawpixels.c
+++ b/src/mesa/state_tracker/st_cb_drawpixels.c
@@ -35,6 +35,7 @@
 #include "main/bufferobj.h"
 #include "main/macros.h"
 #include "main/texformat.h"
+#include "main/state.h"
 #include "shader/program.h"
 #include "shader/prog_parameter.h"
 #include "shader/prog_print.h"
@@ -835,6 +836,9 @@ st_DrawPixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height,
       return;
    }
 
+   _mesa_set_vp_override( ctx, TRUE );
+   _mesa_update_state( ctx );
+
    st_validate_state(st);
 
    if (format == GL_DEPTH_COMPONENT) {
@@ -874,6 +878,8 @@ st_DrawPixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height,
       /* blit */
       draw_blit(st, width, height, format, type, pixels);
    }
+
+   _mesa_set_vp_override( ctx, FALSE );
 }
 
 




More information about the mesa-commit mailing list