[Mesa-dev] [PATCH 1/3] mesa: Use uniform interfaces in fixed-function fragment shader code

Ian Romanick idr at freedesktop.org
Wed Nov 16 11:08:21 PST 2011


From: Ian Romanick <ian.d.romanick at intel.com>

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>
Cc: Eric Anholt <eric at anholt.net>
---
 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 2ce81fe..1806adc 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"
@@ -1488,22 +1489,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);
-- 
1.7.6.4



More information about the mesa-dev mailing list