[Mesa-dev] [PATCH 01/13] mesa: Provide an alternative to get_vp_mode()

2018-02-21 Thread Mathias . Froehlich
From: Mathias Fröhlich 

To get equivalent information than get_vp_mode(), track the vertex
processing mode in a per context variable at
gl_vertex_program_state::_VPMode.
This aims to replace get_vp_mode() as seen in the vbo module.
But instead of the get_vp_mode() implementation which only gives correct
answers past calling _mesa_update_state() this context variable is
immediately tracked when the vertex processing state is modified. The
correctness of this value is asserted on state validation.

With this in place we should be able to untangle the dependency with
varying_vp_inputs and state invalidation.

Signed-off-by: Mathias Fröhlich 
---
 src/mesa/drivers/common/meta.c |  2 ++
 src/mesa/main/arbprogram.c |  5 +
 src/mesa/main/context.c|  3 +++
 src/mesa/main/enable.c |  2 ++
 src/mesa/main/mtypes.h | 24 
 src/mesa/main/pipelineobj.c|  3 +++
 src/mesa/main/shaderapi.c  |  5 +
 src/mesa/main/state.c  | 23 +++
 src/mesa/main/state.h  |  7 +++
 src/mesa/program/program.c |  1 +
 10 files changed, 75 insertions(+)

diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c
index cd898e26f6..0cb2ef450e 100644
--- a/src/mesa/drivers/common/meta.c
+++ b/src/mesa/drivers/common/meta.c
@@ -1012,6 +1012,8 @@ _mesa_meta_end(struct gl_context *ctx)
 
  _mesa_reference_pipeline_object(ctx, >Pipeline, NULL);
   }
+
+  _mesa_update_vertex_processing_mode(ctx);
}
 
if (state & MESA_META_STENCIL_TEST) {
diff --git a/src/mesa/main/arbprogram.c b/src/mesa/main/arbprogram.c
index 625dc667f8..b169bce0c5 100644
--- a/src/mesa/main/arbprogram.c
+++ b/src/mesa/main/arbprogram.c
@@ -37,6 +37,7 @@
 #include "main/mtypes.h"
 #include "main/arbprogram.h"
 #include "main/shaderapi.h"
+#include "main/state.h"
 #include "program/arbprogparse.h"
 #include "program/program.h"
 #include "program/prog_print.h"
@@ -133,6 +134,8 @@ _mesa_BindProgramARB(GLenum target, GLuint id)
   _mesa_reference_program(ctx, >FragmentProgram.Current, newProg);
}
 
+   _mesa_update_vertex_processing_mode(ctx);
+
/* Never null pointers */
assert(ctx->VertexProgram.Current);
assert(ctx->FragmentProgram.Current);
@@ -369,6 +372,8 @@ _mesa_ProgramStringARB(GLenum target, GLenum format, 
GLsizei len,
   }
}
 
+   _mesa_update_vertex_processing_mode(ctx);
+
if (ctx->_Shader->Flags & GLSL_DUMP) {
   const char *shader_type =
  target == GL_FRAGMENT_PROGRAM_ARB ? "fragment" : "vertex";
diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c
index 79d3e39e92..0aa2e3639f 100644
--- a/src/mesa/main/context.c
+++ b/src/mesa/main/context.c
@@ -123,6 +123,7 @@
 #include "shared.h"
 #include "shaderobj.h"
 #include "shaderimage.h"
+#include "state.h"
 #include "util/debug.h"
 #include "util/disk_cache.h"
 #include "util/strtod.h"
@@ -1579,6 +1580,8 @@ handle_first_current(struct gl_context *ctx)
 
check_context_limits(ctx);
 
+   _mesa_update_vertex_processing_mode(ctx);
+
/* According to GL_MESA_configless_context the default value of
 * glDrawBuffers depends on the config of the first surface it is bound to.
 * For GLES it is always GL_BACK which has a magic interpretation.
diff --git a/src/mesa/main/enable.c b/src/mesa/main/enable.c
index f23673a6cd..868b73ac68 100644
--- a/src/mesa/main/enable.c
+++ b/src/mesa/main/enable.c
@@ -39,6 +39,7 @@
 #include "light.h"
 #include "mtypes.h"
 #include "enums.h"
+#include "state.h"
 #include "texstate.h"
 #include "varray.h"
 
@@ -919,6 +920,7 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap, 
GLboolean state)
 return;
  FLUSH_VERTICES(ctx, _NEW_PROGRAM);
  ctx->VertexProgram.Enabled = state;
+ _mesa_update_vertex_processing_mode(ctx);
  break;
   case GL_VERTEX_PROGRAM_POINT_SIZE_ARB:
  /* This was added with ARB_vertex_program, but it is also used with
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 7da3240da7..41df04d38d 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2136,6 +2136,19 @@ typedef enum
 } gl_register_file;
 
 
+/**
+ * Current vertex processing mode: fixed function vs. shader.
+ * In reality, fixed function is probably implemented by a shader but that's
+ * not what we care about here.
+ */
+typedef enum
+{
+   VP_MODE_FF, /**< legacy / fixed function */
+   VP_MODE_SHADER, /**< ARB vertex program or GLSL vertex shader */
+   VP_MODE_MAX /**< for sizing arrays */
+} gl_vertex_processing_mode;
+
+
 /**
  * Base class for any kind of program object
  */
@@ -2362,6 +2375,17 @@ struct gl_vertex_program_state
struct gl_program_cache *Cache;
 
GLboolean _Overriden;
+
+   /**
+* If we have a vertex program, a TNL program or no program at all.
+* Note that this value should be kept up to date all the time,
+* 

[Mesa-dev] [PATCH 01/13] mesa: Provide an alternative to get_vp_mode()

2018-02-15 Thread Mathias . Froehlich
From: Mathias Fröhlich 

To get equivalent information than get_vp_mode(), track the
vertex processing mode in a per context variable at
gl_vertex_program_state::_VPMode.
This aims to replace get_vp_mode() as seen in the vbo module.
But instead of the get_vp_mode() implementation which only
gives correct answers past calling _mesa_update_state() this
context variable is immediately tracked when the vertex
processing state is modified. The correctness of this value
is asserted on state validation.

With this in place we should be able to untangle the
dependency with varying_vp_inputs and state invalidation.

Signed-off-by: Mathias Fröhlich 
---
 src/mesa/drivers/common/meta.c |  2 ++
 src/mesa/main/arbprogram.c |  5 +
 src/mesa/main/context.c|  3 +++
 src/mesa/main/enable.c |  2 ++
 src/mesa/main/mtypes.h | 24 
 src/mesa/main/pipelineobj.c|  3 +++
 src/mesa/main/shaderapi.c  |  5 +
 src/mesa/main/state.c  | 23 +++
 src/mesa/main/state.h  |  7 +++
 src/mesa/program/program.c |  1 +
 10 files changed, 75 insertions(+)

diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c
index cd898e26f6..0cb2ef450e 100644
--- a/src/mesa/drivers/common/meta.c
+++ b/src/mesa/drivers/common/meta.c
@@ -1012,6 +1012,8 @@ _mesa_meta_end(struct gl_context *ctx)
 
  _mesa_reference_pipeline_object(ctx, >Pipeline, NULL);
   }
+
+  _mesa_update_vertex_processing_mode(ctx);
}
 
if (state & MESA_META_STENCIL_TEST) {
diff --git a/src/mesa/main/arbprogram.c b/src/mesa/main/arbprogram.c
index 625dc667f8..b169bce0c5 100644
--- a/src/mesa/main/arbprogram.c
+++ b/src/mesa/main/arbprogram.c
@@ -37,6 +37,7 @@
 #include "main/mtypes.h"
 #include "main/arbprogram.h"
 #include "main/shaderapi.h"
+#include "main/state.h"
 #include "program/arbprogparse.h"
 #include "program/program.h"
 #include "program/prog_print.h"
@@ -133,6 +134,8 @@ _mesa_BindProgramARB(GLenum target, GLuint id)
   _mesa_reference_program(ctx, >FragmentProgram.Current, newProg);
}
 
+   _mesa_update_vertex_processing_mode(ctx);
+
/* Never null pointers */
assert(ctx->VertexProgram.Current);
assert(ctx->FragmentProgram.Current);
@@ -369,6 +372,8 @@ _mesa_ProgramStringARB(GLenum target, GLenum format, 
GLsizei len,
   }
}
 
+   _mesa_update_vertex_processing_mode(ctx);
+
if (ctx->_Shader->Flags & GLSL_DUMP) {
   const char *shader_type =
  target == GL_FRAGMENT_PROGRAM_ARB ? "fragment" : "vertex";
diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c
index 79d3e39e92..0aa2e3639f 100644
--- a/src/mesa/main/context.c
+++ b/src/mesa/main/context.c
@@ -123,6 +123,7 @@
 #include "shared.h"
 #include "shaderobj.h"
 #include "shaderimage.h"
+#include "state.h"
 #include "util/debug.h"
 #include "util/disk_cache.h"
 #include "util/strtod.h"
@@ -1579,6 +1580,8 @@ handle_first_current(struct gl_context *ctx)
 
check_context_limits(ctx);
 
+   _mesa_update_vertex_processing_mode(ctx);
+
/* According to GL_MESA_configless_context the default value of
 * glDrawBuffers depends on the config of the first surface it is bound to.
 * For GLES it is always GL_BACK which has a magic interpretation.
diff --git a/src/mesa/main/enable.c b/src/mesa/main/enable.c
index f23673a6cd..868b73ac68 100644
--- a/src/mesa/main/enable.c
+++ b/src/mesa/main/enable.c
@@ -39,6 +39,7 @@
 #include "light.h"
 #include "mtypes.h"
 #include "enums.h"
+#include "state.h"
 #include "texstate.h"
 #include "varray.h"
 
@@ -919,6 +920,7 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap, 
GLboolean state)
 return;
  FLUSH_VERTICES(ctx, _NEW_PROGRAM);
  ctx->VertexProgram.Enabled = state;
+ _mesa_update_vertex_processing_mode(ctx);
  break;
   case GL_VERTEX_PROGRAM_POINT_SIZE_ARB:
  /* This was added with ARB_vertex_program, but it is also used with
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 7da3240da7..41df04d38d 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2136,6 +2136,19 @@ typedef enum
 } gl_register_file;
 
 
+/**
+ * Current vertex processing mode: fixed function vs. shader.
+ * In reality, fixed function is probably implemented by a shader but that's
+ * not what we care about here.
+ */
+typedef enum
+{
+   VP_MODE_FF, /**< legacy / fixed function */
+   VP_MODE_SHADER, /**< ARB vertex program or GLSL vertex shader */
+   VP_MODE_MAX /**< for sizing arrays */
+} gl_vertex_processing_mode;
+
+
 /**
  * Base class for any kind of program object
  */
@@ -2362,6 +2375,17 @@ struct gl_vertex_program_state
struct gl_program_cache *Cache;
 
GLboolean _Overriden;
+
+   /**
+* If we have a vertex program, a TNL program or no program at all.
+* Note that this value should be kept up to date all the time,
+*