aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/mesa/main/shaders.c
diff options
context:
space:
mode:
Diffstat (limited to 'mesalib/src/mesa/main/shaders.c')
-rw-r--r--mesalib/src/mesa/main/shaders.c41
1 files changed, 27 insertions, 14 deletions
diff --git a/mesalib/src/mesa/main/shaders.c b/mesalib/src/mesa/main/shaders.c
index bc76b9129..d0dc7e551 100644
--- a/mesalib/src/mesa/main/shaders.c
+++ b/mesalib/src/mesa/main/shaders.c
@@ -26,6 +26,12 @@
#include "glheader.h"
#include "context.h"
#include "shaders.h"
+#include "shader/shader_api.h"
+
+
+/** Define this to enable shader substitution (see below) */
+#define SHADER_SUBST 0
+
/**
@@ -388,7 +394,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,16 +406,10 @@ _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;
}
-
/**
* Called via glShaderSource() and glShaderSourceARB() API functions.
* Basically, concatenate the source code strings into one long string
@@ -424,6 +423,7 @@ _mesa_ShaderSourceARB(GLhandleARB shaderObj, GLsizei count,
GLint *offsets;
GLsizei i, totalLength;
GLcharARB *source;
+ GLuint checksum;
if (!shaderObj || string == NULL) {
_mesa_error(ctx, GL_INVALID_VALUE, "glShaderSourceARB");
@@ -475,22 +475,35 @@ _mesa_ShaderSourceARB(GLhandleARB shaderObj, GLsizei count,
source[totalLength - 1] = '\0';
source[totalLength - 2] = '\0';
-#if 0
- if (0) {
+ if (SHADER_SUBST) {
+ /* 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.
+ */
+ char filename[100];
GLcharARB *newSource;
- newSource = _mesa_read_shader("newshader.frag");
+ checksum = _mesa_str_checksum(source);
+
+ 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);
+ if (SHADER_SUBST) {
+ struct gl_shader *sh = _mesa_lookup_shader(ctx, shaderObj);
+ if (sh)
+ sh->SourceChecksum = checksum; /* save original checksum */
+ }
+
_mesa_free(offsets);
}