[Mesa-dev] [PATCH 01/15] mesa: Refactor per-stage link check to its own function

Ian Romanick idr at freedesktop.org
Fri Feb 7 22:00:11 PST 2014


From: Ian Romanick <ian.d.romanick at intel.com>

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
---
 src/mesa/main/context.c | 102 ++++++++++++++++--------------------------------
 1 file changed, 34 insertions(+), 68 deletions(-)

diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c
index 458d8e5..8421a25 100644
--- a/src/mesa/main/context.c
+++ b/src/mesa/main/context.c
@@ -1769,93 +1769,59 @@ _mesa_check_blend_func_error(struct gl_context *ctx)
    return GL_TRUE;
 }
 
-/**
- * Prior to drawing anything with glBegin, glDrawArrays, etc. this function
- * is called to see if it's valid to render.  This involves checking that
- * the current shader is valid and the framebuffer is complete.
- * If an error is detected it'll be recorded here.
- * \return GL_TRUE if OK to render, GL_FALSE if not
- */
-GLboolean
-_mesa_valid_to_render(struct gl_context *ctx, const char *where)
+static bool
+shader_linked_or_absent(struct gl_context *ctx,
+                        const struct gl_shader_program *shProg,
+                        bool *shader_present, const char *where)
 {
-   bool vert_from_glsl_shader = false;
-   bool geom_from_glsl_shader = false;
-   bool frag_from_glsl_shader = false;
-
-   /* This depends on having up to date derived state (shaders) */
-   if (ctx->NewState)
-      _mesa_update_state(ctx);
+   if (shProg) {
+      *shader_present = true;
 
-   if (ctx->Shader.CurrentProgram[MESA_SHADER_VERTEX]) {
-      vert_from_glsl_shader = true;
-
-      if (!ctx->Shader.CurrentProgram[MESA_SHADER_VERTEX]->LinkStatus) {
-         _mesa_error(ctx, GL_INVALID_OPERATION,
-                     "%s(shader not linked)", where);
-         return GL_FALSE;
+      if (!shProg->LinkStatus) {
+         _mesa_error(ctx, GL_INVALID_OPERATION, "%s(shader not linked)", where);
+         return false;
       }
 #if 0 /* not normally enabled */
       {
          char errMsg[100];
-         if (!_mesa_validate_shader_program(ctx,
-					    ctx->Shader.CurrentProgram[MESA_SHADER_VERTEX],
-                                            errMsg)) {
+         if (!_mesa_validate_shader_program(ctx, shProg, errMsg)) {
             _mesa_warning(ctx, "Shader program %u is invalid: %s",
-                          ctx->Shader.CurrentProgram[MESA_SHADER_VERTEX]->Name, errMsg);
+                          shProg->Name, errMsg);
          }
       }
 #endif
    }
 
-   if (ctx->Shader.CurrentProgram[MESA_SHADER_GEOMETRY]) {
-      geom_from_glsl_shader = true;
+   return true;
+}
 
-      if (!ctx->Shader.CurrentProgram[MESA_SHADER_GEOMETRY]->LinkStatus) {
-         _mesa_error(ctx, GL_INVALID_OPERATION,
-                     "%s(shader not linked)", where);
-         return GL_FALSE;
-      }
-#if 0 /* not normally enabled */
-      {
-         char errMsg[100];
-         if (!_mesa_validate_shader_program(ctx,
-					    ctx->Shader.CurrentProgram[MESA_SHADER_GEOMETRY],
-                                            errMsg)) {
-            _mesa_warning(ctx, "Shader program %u is invalid: %s",
-                          ctx->Shader.CurrentProgram[MESA_SHADER_GEOMETRY]->Name,
-                          errMsg);
-         }
-      }
-#endif
-   }
+/**
+ * Prior to drawing anything with glBegin, glDrawArrays, etc. this function
+ * is called to see if it's valid to render.  This involves checking that
+ * the current shader is valid and the framebuffer is complete.
+ * If an error is detected it'll be recorded here.
+ * \return GL_TRUE if OK to render, GL_FALSE if not
+ */
+GLboolean
+_mesa_valid_to_render(struct gl_context *ctx, const char *where)
+{
+   bool from_glsl_shader[MESA_SHADER_COMPUTE] = { false };
+   unsigned i;
 
-   if (ctx->Shader.CurrentProgram[MESA_SHADER_FRAGMENT]) {
-      frag_from_glsl_shader = true;
+   /* This depends on having up to date derived state (shaders) */
+   if (ctx->NewState)
+      _mesa_update_state(ctx);
 
-      if (!ctx->Shader.CurrentProgram[MESA_SHADER_FRAGMENT]->LinkStatus) {
-         _mesa_error(ctx, GL_INVALID_OPERATION,
-                     "%s(shader not linked)", where);
+   for (i = 0; i < MESA_SHADER_COMPUTE; i++) {
+      if (!shader_linked_or_absent(ctx, ctx->Shader.CurrentProgram[i],
+                                   &from_glsl_shader[i], where))
          return GL_FALSE;
-      }
-#if 0 /* not normally enabled */
-      {
-         char errMsg[100];
-         if (!_mesa_validate_shader_program(ctx,
-					    ctx->Shader.CurrentProgram[MESA_SHADER_FRAGMENT],
-                                            errMsg)) {
-            _mesa_warning(ctx, "Shader program %u is invalid: %s",
-                          ctx->Shader.CurrentProgram[MESA_SHADER_FRAGMENT]->Name,
-                          errMsg);
-         }
-      }
-#endif
    }
 
    /* Any shader stages that are not supplied by the GLSL shader and have
     * assembly shaders enabled must now be validated.
     */
-   if (!vert_from_glsl_shader
+   if (!from_glsl_shader[MESA_SHADER_VERTEX]
        && ctx->VertexProgram.Enabled && !ctx->VertexProgram._Enabled) {
       _mesa_error(ctx, GL_INVALID_OPERATION,
 		  "%s(vertex program not valid)", where);
@@ -1865,9 +1831,9 @@ _mesa_valid_to_render(struct gl_context *ctx, const char *where)
    /* FINISHME: If GL_NV_geometry_program4 is ever supported, the current
     * FINISHME: geometry program should validated here.
     */
-   (void) geom_from_glsl_shader;
+   (void) from_glsl_shader[MESA_SHADER_GEOMETRY];
 
-   if (!frag_from_glsl_shader) {
+   if (!from_glsl_shader[MESA_SHADER_FRAGMENT]) {
       if (ctx->FragmentProgram.Enabled && !ctx->FragmentProgram._Enabled) {
 	 _mesa_error(ctx, GL_INVALID_OPERATION,
 		     "%s(fragment program not valid)", where);
-- 
1.8.1.4



More information about the mesa-dev mailing list