glsl: Initialize samplers to 0, propagate sampler values to the gl_program
authorIan Romanick <ian.d.romanick@intel.com>
Tue, 10 Apr 2012 17:40:11 +0000 (10:40 -0700)
committerIan Romanick <ian.d.romanick@intel.com>
Wed, 23 May 2012 18:42:07 +0000 (11:42 -0700)
The spec requires that samplers be initialized to 0.  Since this
differs from the 1-to-1 mapping of samplers to texture units assumed
by ARB assembly shaders (and the gl_program structure), be sure to
propagate this date from the gl_shader_program to the gl_program.

Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
CC: Vadim Girlin <vadimgirlin@gmail.com>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=49088

src/glsl/link_uniforms.cpp
src/mesa/main/uniforms.c

index 81a995e92bdad57a09e769416a921b8ecd1d25dd..92e2a1fa548ee17299234cdc355991a14dbf844c 100644 (file)
@@ -329,9 +329,16 @@ link_assign_uniform_locations(struct gl_shader_program *prog)
       prog->UniformHash = new string_to_uint_map;
    }
 
-   for (unsigned i = 0; i < Elements(prog->SamplerUnits); i++) {
-      prog->SamplerUnits[i] = i;
-   }
+   /* Uniforms that lack an initializer in the shader code have an initial
+    * value of zero.  This includes sampler uniforms.
+    *
+    * Page 24 (page 30 of the PDF) of the GLSL 1.20 spec says:
+    *
+    *     "The link time initial value is either the value of the variable's
+    *     initializer, if present, or 0 if no initializer is present. Sampler
+    *     types cannot have initializers."
+    */
+   memset(prog->SamplerUnits, 0, sizeof(prog->SamplerUnits));
 
    /* First pass: Count the uniform resources used by the user-defined
     * uniforms.  While this happens, each active uniform will have an index
index be1e1728d305a4bac937c0441f5fbeadd6608fa7..e6604b1a4c65c08609f654913f2d409cdd319298 100644 (file)
@@ -65,6 +65,7 @@ _mesa_update_shader_textures_used(struct gl_shader_program *shProg,
 {
    GLuint s;
 
+   memcpy(prog->SamplerUnits, shProg->SamplerUnits, sizeof(prog->SamplerUnits));
    memset(prog->TexturesUsed, 0, sizeof(prog->TexturesUsed));
 
    for (s = 0; s < MAX_SAMPLERS; s++) {