Mesa (master): mesa: rework _mesa_read_shader() debug hook

Brian Paul brianp at kemper.freedesktop.org
Tue Oct 13 22:34:34 UTC 2009


Module: Mesa
Branch: master
Commit: 435623b3f0b2d2db5b107ef177693ccafc591a29
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=435623b3f0b2d2db5b107ef177693ccafc591a29

Author: Brian Paul <brianp at vmware.com>
Date:   Tue Oct 13 16:32:15 2009 -0600

mesa: rework _mesa_read_shader() debug hook

Look for shaders named "newshader_<CHECKSUM>" to replace the incoming
shader text.  For debug purposes.

---

 src/mesa/main/shaders.c |   24 ++++++++++++------------
 1 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/src/mesa/main/shaders.c b/src/mesa/main/shaders.c
index bc76b91..96fd869 100644
--- a/src/mesa/main/shaders.c
+++ b/src/mesa/main/shaders.c
@@ -388,7 +388,6 @@ _mesa_read_shader(const char *fname)
    int len;
 
    if (!f) {
-      _mesa_fprintf(stderr, "Unable to open shader file %s\n", fname);
       return NULL;
    }
 
@@ -401,11 +400,6 @@ _mesa_read_shader(const char *fname)
    shader = _mesa_strdup(buffer);
    free(buffer);
 
-   if (0) {
-      _mesa_fprintf(stderr, "Read shader %s:\n", fname);
-      _mesa_fprintf(stderr, "%s\n", shader);
-   }
-
    return shader;
 }
 
@@ -475,19 +469,25 @@ _mesa_ShaderSourceARB(GLhandleARB shaderObj, GLsizei count,
    source[totalLength - 1] = '\0';
    source[totalLength - 2] = '\0';
 
-#if 0
    if (0) {
+      /* Compute the shader's source code checksum then try to open a file
+       * named newshader_<CHECKSUM>.  If it exists, use it in place of the
+       * original shader source code.  For debugging.
+       */
+      const GLuint checksum = _mesa_str_checksum(source);
+      char filename[100];
       GLcharARB *newSource;
 
-      newSource = _mesa_read_shader("newshader.frag");
+      sprintf(filename, "newshader_%d", checksum);
+
+      newSource = _mesa_read_shader(filename);
       if (newSource) {
+         _mesa_fprintf(stderr, "Mesa: Replacing shader %u chksum=%d with %s\n",
+                       shaderObj, checksum, filename);
          _mesa_free(source);
          source = newSource;
       }
-   }
-#else
-   (void) _mesa_read_shader;
-#endif
+   }      
 
    ctx->Driver.ShaderSource(ctx, shaderObj, source);
 




More information about the mesa-commit mailing list