Mesa (gallium-mesa-7.4): glsl: new MESA_GLSL env var for GLSL debugging features

Alan Hourihane alanh at kemper.freedesktop.org
Thu Feb 19 17:30:25 PST 2009


Module: Mesa
Branch: gallium-mesa-7.4
Commit: 8f96750837158b1d327785ba60a3b20b33b12be9
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=8f96750837158b1d327785ba60a3b20b33b12be9

Author: Brian Paul <brianp at vmware.com>
Date:   Fri Feb  6 10:21:36 2009 -0700

glsl: new MESA_GLSL env var for GLSL debugging features

Replaces the VERBOSE_GLSL, VERBOSE_GLSL_DUMP flags which only worked in debug
builds.  MESA_GLSL will work both in debug and non-debug builds.
Also add facility to dump glUniform() calls to stdout.

---

 src/mesa/main/debug.c                 |    4 +--
 src/mesa/main/mtypes.h                |   10 ++++-
 src/mesa/shader/shader_api.c          |   62 +++++++++++++++++++++++++++++++++
 src/mesa/shader/slang/slang_compile.c |    6 +++
 src/mesa/shader/slang/slang_link.c    |   19 ++++++----
 src/mesa/shader/slang/slang_log.c     |    4 --
 6 files changed, 88 insertions(+), 17 deletions(-)

diff --git a/src/mesa/main/debug.c b/src/mesa/main/debug.c
index 77fef32..65970a5 100644
--- a/src/mesa/main/debug.c
+++ b/src/mesa/main/debug.c
@@ -164,9 +164,7 @@ static void add_debug_flags( const char *debug )
       { "api",       VERBOSE_API },
       { "list",      VERBOSE_DISPLAY_LIST },
       { "lighting",  VERBOSE_LIGHTING },
-      { "disassem",  VERBOSE_DISASSEM },
-      { "glsl",      VERBOSE_GLSL },     /* report GLSL compile/link errors */
-      { "glsl_dump", VERBOSE_GLSL_DUMP } /* print shader GPU instructions */
+      { "disassem",  VERBOSE_DISASSEM }
    };
    GLuint i;
 
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index a61f970..e7740ec 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2151,6 +2151,13 @@ struct gl_shader_program
 };   
 
 
+#define GLSL_DUMP      0x1  /**< Dump shaders to stdout */
+#define GLSL_LOG       0x2  /**< Write shaders to files */
+#define GLSL_OPT       0x4  /**< Force optimizations (override pragmas) */
+#define GLSL_NO_OPT    0x8  /**< Force no optimizations (override pragmas) */
+#define GLSL_UNIFORMS 0x10  /**< Print glUniform calls */
+
+
 /**
  * Context state for GLSL vertex/fragment shaders.
  */
@@ -2162,6 +2169,7 @@ struct gl_shader_state
    GLboolean EmitCondCodes;             /**< Use condition codes? */
    GLboolean EmitComments;              /**< Annotated instructions */
    void *MemPool;
+   GLbitfield Flags;                    /**< Mask of GLSL_x flags */
 };
 
 
@@ -3145,8 +3153,6 @@ enum _verbose
    VERBOSE_PRIMS		= 0x0400,
    VERBOSE_VERTS		= 0x0800,
    VERBOSE_DISASSEM		= 0x1000,
-   VERBOSE_GLSL			= 0x2000,
-   VERBOSE_GLSL_DUMP		= 0x4000
 };
 
 
diff --git a/src/mesa/shader/shader_api.c b/src/mesa/shader/shader_api.c
index 81d31e6..e03a391 100644
--- a/src/mesa/shader/shader_api.c
+++ b/src/mesa/shader/shader_api.c
@@ -371,6 +371,31 @@ _mesa_lookup_shader_err(GLcontext *ctx, GLuint name, const char *caller)
 }
 
 
+/**
+ * Return mask of GLSL_x flags by examining the MESA_GLSL env var.
+ */
+static GLbitfield
+get_shader_flags(void)
+{
+   GLbitfield flags = 0x0;
+   const char *env = _mesa_getenv("MESA_GLSL");
+
+   if (env) {
+      if (_mesa_strstr(env, "dump"))
+         flags |= GLSL_DUMP;
+      if (_mesa_strstr(env, "log"))
+         flags |= GLSL_LOG;
+      if (_mesa_strstr(env, "nopt"))
+         flags |= GLSL_NO_OPT;
+      else if (_mesa_strstr(env, "opt"))
+         flags |= GLSL_OPT;
+      if (_mesa_strstr(env, "uniform"))
+         flags |= GLSL_UNIFORMS;
+   }
+
+   return flags;
+}
+
 
 /**
  * Initialize context's shader state.
@@ -384,6 +409,7 @@ _mesa_init_shader_state(GLcontext * ctx)
    ctx->Shader.EmitHighLevelInstructions = GL_TRUE;
    ctx->Shader.EmitCondCodes = GL_FALSE;/*GL_TRUE;*/ /* XXX probably want GL_FALSE... */
    ctx->Shader.EmitComments = GL_FALSE;
+   ctx->Shader.Flags = get_shader_flags();
 }
 
 
@@ -1680,6 +1706,7 @@ _mesa_uniform(GLcontext *ctx, GLint location, GLsizei count,
    struct gl_shader_program *shProg = ctx->Shader.CurrentProgram;
    struct gl_uniform *uniform;
    GLint elems, offset;
+   GLenum basicType;
 
    if (!shProg || !shProg->LinkStatus) {
       _mesa_error(ctx, GL_INVALID_OPERATION, "glUniform(program not linked)");
@@ -1708,19 +1735,35 @@ _mesa_uniform(GLcontext *ctx, GLint location, GLsizei count,
 
    switch (type) {
    case GL_FLOAT:
+      basicType = GL_FLOAT;
+      elems = 1;
+      break;
    case GL_INT:
+      basicType = GL_INT;
       elems = 1;
       break;
    case GL_FLOAT_VEC2:
+      basicType = GL_FLOAT;
+      elems = 2;
+      break;
    case GL_INT_VEC2:
+      basicType = GL_INT;
       elems = 2;
       break;
    case GL_FLOAT_VEC3:
+      basicType = GL_FLOAT;
+      elems = 3;
+      break;
    case GL_INT_VEC3:
+      basicType = GL_INT;
       elems = 3;
       break;
    case GL_FLOAT_VEC4:
+      basicType = GL_FLOAT;
+      elems = 4;
+      break;
    case GL_INT_VEC4:
+      basicType = GL_INT;
       elems = 4;
       break;
    default:
@@ -1732,6 +1775,25 @@ _mesa_uniform(GLcontext *ctx, GLint location, GLsizei count,
 
    uniform = &shProg->Uniforms->Uniforms[location];
 
+   if (ctx->Shader.Flags & GLSL_UNIFORMS) {
+      GLint i;
+      _mesa_printf("Mesa: set program %u uniform %s (loc %d) to: ",
+                   shProg->Name, uniform->Name, location);
+      if (basicType == GL_INT) {
+         const GLint *v = (const GLint *) values;
+         for (i = 0; i < count * elems; i++) {
+            _mesa_printf("%d ", v[i]);
+         }
+      }
+      else {
+         const GLfloat *v = (const GLfloat *) values;
+         for (i = 0; i < count * elems; i++) {
+            _mesa_printf("%g ", v[i]);
+         }
+      }
+      _mesa_printf("\n");
+   }
+
    /* A uniform var may be used by both a vertex shader and a fragment
     * shader.  We may need to update one or both shader's uniform here:
     */
diff --git a/src/mesa/shader/slang/slang_compile.c b/src/mesa/shader/slang/slang_compile.c
index 26a0598..ab84857 100644
--- a/src/mesa/shader/slang/slang_compile.c
+++ b/src/mesa/shader/slang/slang_compile.c
@@ -2794,6 +2794,12 @@ _slang_compile(GLcontext *ctx, struct gl_shader *shader)
    _mesa_print_program(shader->Program);
 #endif
 
+   shader->CompileStatus = success;
+
+   if (ctx->Shader.Flags & GLSL_LOG) {
+      _mesa_write_shader_to_file(shader);
+   }
+
    return success;
 }
 
diff --git a/src/mesa/shader/slang/slang_link.c b/src/mesa/shader/slang/slang_link.c
index 585ee84..152e97a 100644
--- a/src/mesa/shader/slang/slang_link.c
+++ b/src/mesa/shader/slang/slang_link.c
@@ -699,12 +699,12 @@ _slang_link(GLcontext *ctx,
       /* notify driver that a new fragment program has been compiled/linked */
       ctx->Driver.ProgramStringNotify(ctx, GL_FRAGMENT_PROGRAM_ARB,
                                       &shProg->FragmentProgram->Base);
-      if (MESA_VERBOSE & VERBOSE_GLSL_DUMP) {
-         printf("Mesa original fragment program:\n");
+      if (ctx->Shader.Flags & GLSL_DUMP) {
+         _mesa_printf("Mesa pre-link fragment program:\n");
          _mesa_print_program(&fragProg->Base);
          _mesa_print_program_parameters(ctx, &fragProg->Base);
 
-         printf("Mesa post-link fragment program:\n");
+         _mesa_printf("Mesa post-link fragment program:\n");
          _mesa_print_program(&shProg->FragmentProgram->Base);
          _mesa_print_program_parameters(ctx, &shProg->FragmentProgram->Base);
       }
@@ -717,20 +717,23 @@ _slang_link(GLcontext *ctx,
       /* notify driver that a new vertex program has been compiled/linked */
       ctx->Driver.ProgramStringNotify(ctx, GL_VERTEX_PROGRAM_ARB,
                                       &shProg->VertexProgram->Base);
-      if (MESA_VERBOSE & VERBOSE_GLSL_DUMP) {
-         printf("Mesa original vertex program:\n");
+      if (ctx->Shader.Flags & GLSL_DUMP) {
+         _mesa_printf("Mesa pre-link vertex program:\n");
          _mesa_print_program(&vertProg->Base);
          _mesa_print_program_parameters(ctx, &vertProg->Base);
 
-         printf("Mesa post-link vertex program:\n");
+         _mesa_printf("Mesa post-link vertex program:\n");
          _mesa_print_program(&shProg->VertexProgram->Base);
          _mesa_print_program_parameters(ctx, &shProg->VertexProgram->Base);
       }
    }
 
-   if (MESA_VERBOSE & VERBOSE_GLSL_DUMP) {
-      printf("Varying vars:\n");
+   if (ctx->Shader.Flags & GLSL_DUMP) {
+      _mesa_printf("Varying vars:\n");
       _mesa_print_parameter_list(shProg->Varying);
+      if (shProg->InfoLog) {
+         _mesa_printf("Info Log: %s\n", shProg->InfoLog);
+      }
    }
 
    shProg->LinkStatus = (shProg->VertexProgram || shProg->FragmentProgram);
diff --git a/src/mesa/shader/slang/slang_log.c b/src/mesa/shader/slang/slang_log.c
index d5576d7..d7d2b4f 100644
--- a/src/mesa/shader/slang/slang_log.c
+++ b/src/mesa/shader/slang/slang_log.c
@@ -77,10 +77,6 @@ slang_info_log_message(slang_info_log * log, const char *prefix,
    slang_string_concat(log->text, msg);
    slang_string_concat(log->text, "\n");
 
-   if (MESA_VERBOSE & VERBOSE_GLSL) {
-      _mesa_printf("Mesa: GLSL %s", log->text);
-   }
-
    return 1;
 }
 



More information about the mesa-commit mailing list