Mesa (master): mesa: Use uniform interfaces in fixed-function fragment shader code

Ian Romanick idr at kemper.freedesktop.org
Wed Jan 11 20:52:21 UTC 2012


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

Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Mon Nov 14 14:32:39 2011 -0800

mesa: Use uniform interfaces in fixed-function fragment shader code

Poking directly at the backing resources works only by luck.  Core
Mesa code should only know about the gl_uniform_storage structure.
Soon other code that looks at samplers will use the gl_uniform_storage
structures instead of the data in the gl_program.

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
Reviewed-by: Eric Anholt <eric at anholt.net>
Acked-by: Kenneth Graunke <kenneth at whitecape.org>

---

 src/mesa/main/ff_fragment_shader.cpp |   29 ++++++++++++++++++++++++-----
 1 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/src/mesa/main/ff_fragment_shader.cpp b/src/mesa/main/ff_fragment_shader.cpp
index 3e736fa..49a8af0 100644
--- a/src/mesa/main/ff_fragment_shader.cpp
+++ b/src/mesa/main/ff_fragment_shader.cpp
@@ -42,6 +42,7 @@ extern "C" {
 #include "program/programopt.h"
 #include "texenvprogram.h"
 }
+#include "main/uniforms.h"
 #include "../glsl/glsl_types.h"
 #include "../glsl/ir.h"
 #include "../glsl/glsl_symbol_table.h"
@@ -1498,22 +1499,40 @@ create_new_program(struct gl_context *ctx, struct state_key *key)
    /* Set the sampler uniforms, and relink to get them into the linked
     * program.
     */
-   struct gl_program *fp;
-   fp = p.shader_program->_LinkedShaders[MESA_SHADER_FRAGMENT]->Program;
+   struct gl_shader *const fs =
+      p.shader_program->_LinkedShaders[MESA_SHADER_FRAGMENT];
+   struct gl_program *const fp = fs->Program;
+
+   _mesa_generate_parameters_list_for_uniforms(p.shader_program, fs,
+					       fp->Parameters);
+
+   _mesa_associate_uniform_storage(ctx, p.shader_program, fp->Parameters);
 
    for (unsigned int i = 0; i < MAX_TEXTURE_UNITS; i++) {
       char *name = ralloc_asprintf(p.mem_ctx, "sampler_%d", i);
       int loc = _mesa_get_uniform_location(ctx, p.shader_program, name);
       if (loc != -1) {
+	 unsigned base;
+	 unsigned idx;
+
 	 /* Avoid using _mesa_uniform() because it flags state
 	  * updates, so if we're generating this shader_program in a
 	  * state update, we end up recursing.  Instead, just set the
 	  * value, which is picked up at re-link.
 	  */
-	 loc = (loc & 0xffff) + (loc >> 16);
-	 int sampler = fp->Parameters->ParameterValues[loc][0].f;
+	 _mesa_uniform_split_location_offset(loc, &base, &idx);
+	 assert(idx == 0);
+
+	 struct gl_uniform_storage *const storage =
+	    &p.shader_program->UniformStorage[base];
 
-	 fp->SamplerUnits[sampler] = i;
+	 /* Update the storage, the SamplerUnits in the shader program, and
+	  * the SamplerUnits in the assembly shader.
+	  */
+	 storage->storage[idx].i = i;
+	 fp->SamplerUnits[storage->sampler] = i;
+	 p.shader_program->SamplerUnits[storage->sampler] = i;
+	 _mesa_propagate_uniforms_to_driver_storage(storage, 0, 1);
       }
    }
    _mesa_update_shader_textures_used(fp);




More information about the mesa-commit mailing list