OSDN Git Service

mesa: Use uniform interfaces in fixed-function fragment shader code
authorIan Romanick <ian.d.romanick@intel.com>
Mon, 14 Nov 2011 22:32:39 +0000 (14:32 -0800)
committerIan Romanick <ian.d.romanick@intel.com>
Wed, 11 Jan 2012 20:51:23 +0000 (12:51 -0800)
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@intel.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
Acked-by: Kenneth Graunke <kenneth@whitecape.org>
src/mesa/main/ff_fragment_shader.cpp

index 3e736fa..49a8af0 100644 (file)
@@ -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);