1
commit b610881317a7775a7ffe5f032099d8b2dc45eff0
2
Author: Ian Romanick <ian.d.romanick@intel.com>
3
Date: Tue Apr 10 10:40:11 2012 -0700
5
glsl: Initialize samplers to 0, propagate sampler values to the gl_program
7
The spec requires that samplers be initialized to 0. Since this
8
differs from the 1-to-1 mapping of samplers to texture units assumed
9
by ARB assembly shaders (and the gl_program structure), be sure to
10
propagate this date from the gl_shader_program to the gl_program.
12
Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
13
Reviewed-by: Eric Anholt <eric@anholt.net>
14
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
15
CC: Vadim Girlin <vadimgirlin@gmail.com>
16
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=49088
18
diff --git a/src/glsl/link_uniforms.cpp b/src/glsl/link_uniforms.cpp
19
index 81a995e..92e2a1f 100644
20
--- a/src/glsl/link_uniforms.cpp
21
+++ b/src/glsl/link_uniforms.cpp
22
@@ -329,9 +329,16 @@ link_assign_uniform_locations(struct gl_shader_program *prog)
23
prog->UniformHash = new string_to_uint_map;
26
- for (unsigned i = 0; i < Elements(prog->SamplerUnits); i++) {
27
- prog->SamplerUnits[i] = i;
29
+ /* Uniforms that lack an initializer in the shader code have an initial
30
+ * value of zero. This includes sampler uniforms.
32
+ * Page 24 (page 30 of the PDF) of the GLSL 1.20 spec says:
34
+ * "The link time initial value is either the value of the variable's
35
+ * initializer, if present, or 0 if no initializer is present. Sampler
36
+ * types cannot have initializers."
38
+ memset(prog->SamplerUnits, 0, sizeof(prog->SamplerUnits));
40
/* First pass: Count the uniform resources used by the user-defined
41
* uniforms. While this happens, each active uniform will have an index
42
diff --git a/src/mesa/main/uniforms.c b/src/mesa/main/uniforms.c
43
index be1e172..e6604b1 100644
44
--- a/src/mesa/main/uniforms.c
45
+++ b/src/mesa/main/uniforms.c
46
@@ -65,6 +65,7 @@ _mesa_update_shader_textures_used(struct gl_shader_program *shProg,
50
+ memcpy(prog->SamplerUnits, shProg->SamplerUnits, sizeof(prog->SamplerUnits));
51
memset(prog->TexturesUsed, 0, sizeof(prog->TexturesUsed));
53
for (s = 0; s < MAX_SAMPLERS; s++) {