Mesa (mesa_7_2_branch): mesa: update the shader programs-> TexturesUsed array at link time

Brian Paul brianp at kemper.freedesktop.org
Thu Nov 6 22:25:04 UTC 2008


Module: Mesa
Branch: mesa_7_2_branch
Commit: 0ffdc7ec54d6e6b0ee7bcb6a52bd650d0497f96a
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=0ffdc7ec54d6e6b0ee7bcb6a52bd650d0497f96a

Author: Brian Paul <brian.paul at tungstengraphics.com>
Date:   Thu Nov  6 15:04:11 2008 -0700

mesa: update the shader programs->TexturesUsed array at link time

If an application never calls glUniform() to set sampler variable values
they'll remain 0 (the default value/unit).
Now call _mesa_update_shader_textures_used() at link time in case glUniform()
is never called.  program->TextureUsed[] will then be correct for state
validation.

---

 src/mesa/shader/shader_api.c       |   20 ++++++++++++++++----
 src/mesa/shader/shader_api.h       |    4 ++++
 src/mesa/shader/slang/slang_link.c |    6 ++++++
 3 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/src/mesa/shader/shader_api.c b/src/mesa/shader/shader_api.c
index 430d165..b668e1f 100644
--- a/src/mesa/shader/shader_api.c
+++ b/src/mesa/shader/shader_api.c
@@ -1200,10 +1200,22 @@ _mesa_use_program(GLcontext *ctx, GLuint program)
 
 
 /**
- * Update the vertex and fragment program's TexturesUsed arrays.
+ * Update the vertex/fragment program's TexturesUsed array.
+ *
+ * This needs to be called after glUniform(set sampler var) is called.
+ * A call to glUniform(samplerVar, value) causes a sampler to point to a
+ * particular texture unit.  We know the sampler's texture target
+ * (1D/2D/3D/etc) from compile time but the sampler's texture unit is
+ * set by glUniform() calls.
+ *
+ * So, scan the program->SamplerUnits[] and program->SamplerTargets[]
+ * information to update the prog->TexturesUsed[] values.
+ * Each value of TexturesUsed[unit] is one of zero, TEXTURE_1D_INDEX,
+ * TEXTURE_2D_INDEX, TEXTURE_3D_INDEX, etc.
+ * We'll use that info for state validation before rendering.
  */
-static void
-update_textures_used(struct gl_program *prog)
+void
+_mesa_update_shader_textures_used(struct gl_program *prog)
 {
    GLuint s;
 
@@ -1317,7 +1329,7 @@ set_program_uniform(GLcontext *ctx, struct gl_program *program, GLint location,
 
       /* This maps a sampler to a texture unit: */
       program->SamplerUnits[sampler] = texUnit;
-      update_textures_used(program);
+      _mesa_update_shader_textures_used(program);
 
       FLUSH_VERTICES(ctx, _NEW_TEXTURE);
    }
diff --git a/src/mesa/shader/shader_api.h b/src/mesa/shader/shader_api.h
index 5521c58..284e97f 100644
--- a/src/mesa/shader/shader_api.h
+++ b/src/mesa/shader/shader_api.h
@@ -80,6 +80,10 @@ _mesa_lookup_shader(GLcontext *ctx, GLuint name);
 
 
 extern void
+_mesa_update_shader_textures_used(struct gl_program *prog);
+
+
+extern void
 _mesa_use_program(GLcontext *ctx, GLuint program);
 
 
diff --git a/src/mesa/shader/slang/slang_link.c b/src/mesa/shader/slang/slang_link.c
index f2e964d..a361703 100644
--- a/src/mesa/shader/slang/slang_link.c
+++ b/src/mesa/shader/slang/slang_link.c
@@ -539,6 +539,9 @@ _slang_link(GLcontext *ctx,
 
 
    if (fragProg && shProg->FragmentProgram) {
+      /* Compute initial program's TexturesUsed info */
+      _mesa_update_shader_textures_used(&shProg->FragmentProgram->Base);
+
       /* notify driver that a new fragment program has been compiled/linked */
       ctx->Driver.ProgramStringNotify(ctx, GL_FRAGMENT_PROGRAM_ARB,
                                       &shProg->FragmentProgram->Base);
@@ -554,6 +557,9 @@ _slang_link(GLcontext *ctx,
    }
 
    if (vertProg && shProg->VertexProgram) {
+      /* Compute initial program's TexturesUsed info */
+      _mesa_update_shader_textures_used(&shProg->VertexProgram->Base);
+
       /* notify driver that a new vertex program has been compiled/linked */
       ctx->Driver.ProgramStringNotify(ctx, GL_VERTEX_PROGRAM_ARB,
                                       &shProg->VertexProgram->Base);




More information about the mesa-commit mailing list