[Mesa-dev] [PATCH 06/14] linker: Calculate the sampler to texture target mapping during linking

Ian Romanick idr at freedesktop.org
Fri Jan 6 16:49:57 PST 2012


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

Track the calculated data in gl_shader_program instead of the
individual assembly shaders.

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
---
 src/glsl/link_uniforms.cpp                 |   15 ++++++++++++++-
 src/mesa/main/ff_fragment_shader.cpp       |    2 +-
 src/mesa/main/mtypes.h                     |    2 --
 src/mesa/main/uniform_query.cpp            |    2 +-
 src/mesa/main/uniforms.c                   |    7 ++++---
 src/mesa/main/uniforms.h                   |    3 ++-
 src/mesa/program/ir_to_mesa.cpp            |    8 +++-----
 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |    4 +---
 8 files changed, 26 insertions(+), 17 deletions(-)

diff --git a/src/glsl/link_uniforms.cpp b/src/glsl/link_uniforms.cpp
index b331db7..47d34cf 100644
--- a/src/glsl/link_uniforms.cpp
+++ b/src/glsl/link_uniforms.cpp
@@ -209,7 +209,7 @@ public:
 			      union gl_constant_value *values)
       : map(map), uniforms(uniforms), next_sampler(0), values(values)
    {
-      /* empty */
+      memset(this->targets, 0, sizeof(this->targets));
    }
 
 private:
@@ -249,6 +249,14 @@ private:
 	  * array elements for arrays.
 	  */
 	 this->next_sampler += MAX2(1, this->uniforms[id].array_elements);
+
+	 const gl_texture_index target = base_type->sampler_index();
+	 for (unsigned i = this->uniforms[id].sampler
+		 ; i < this->next_sampler
+		 ; i++) {
+	    this->targets[i] = target;
+	 }
+
       } else {
 	 this->uniforms[id].sampler = ~0;
       }
@@ -270,6 +278,8 @@ private:
 
 public:
    union gl_constant_value *values;
+
+   gl_texture_index targets[MAX_SAMPLERS];
 };
 
 void
@@ -361,6 +371,9 @@ link_assign_uniform_locations(struct gl_shader_program *prog)
       }
    }
 
+   assert(sizeof(prog->SamplerTargets) == sizeof(parcel.targets));
+   memcpy(prog->SamplerTargets, parcel.targets, sizeof(prog->SamplerTargets));
+
 #ifndef NDEBUG
    for (unsigned i = 0; i < num_user_uniforms; i++) {
       assert(uniforms[i].storage != NULL);
diff --git a/src/mesa/main/ff_fragment_shader.cpp b/src/mesa/main/ff_fragment_shader.cpp
index 165230c..3596a3d 100644
--- a/src/mesa/main/ff_fragment_shader.cpp
+++ b/src/mesa/main/ff_fragment_shader.cpp
@@ -1540,7 +1540,7 @@ create_new_program(struct gl_context *ctx, struct state_key *key)
 	 _mesa_propagate_uniforms_to_driver_storage(storage, 0, 1);
       }
    }
-   _mesa_update_shader_textures_used(fp);
+   _mesa_update_shader_textures_used(p.shader_program, fp);
    (void) ctx->Driver.ProgramStringNotify(ctx, fp->Target, fp);
 
    if (!p.shader_program->LinkStatus)
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index bc0ffaa..7e71a4f 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -1894,8 +1894,6 @@ struct gl_program
 
    /** Map from sampler unit to texture unit (set by glUniform1i()) */
    GLubyte SamplerUnits[MAX_SAMPLERS];
-   /** Which texture target is being sampled (TEXTURE_1D/2D/3D/etc_INDEX) */
-   gl_texture_index SamplerTargets[MAX_SAMPLERS];
 
    /** Bitmask of which register files are read/written with indirect
     * addressing.  Mask of (1 << PROGRAM_x) bits.
diff --git a/src/mesa/main/uniform_query.cpp b/src/mesa/main/uniform_query.cpp
index a5a85cd..d156cae 100644
--- a/src/mesa/main/uniform_query.cpp
+++ b/src/mesa/main/uniform_query.cpp
@@ -728,7 +728,7 @@ _mesa_uniform(struct gl_context *ctx, struct gl_shader_program *shProg,
 		   shProg->SamplerUnits,
 		   sizeof(shProg->SamplerUnits));
 
-	    _mesa_update_shader_textures_used(prog);
+	    _mesa_update_shader_textures_used(shProg, prog);
 	    (void) ctx->Driver.ProgramStringNotify(ctx, prog->Target, prog);
 	 }
       }
diff --git a/src/mesa/main/uniforms.c b/src/mesa/main/uniforms.c
index 685c0f1..e0214a8 100644
--- a/src/mesa/main/uniforms.c
+++ b/src/mesa/main/uniforms.c
@@ -60,7 +60,8 @@
  * We'll use that info for state validation before rendering.
  */
 void
-_mesa_update_shader_textures_used(struct gl_program *prog)
+_mesa_update_shader_textures_used(struct gl_shader_program *shProg,
+				  struct gl_program *prog)
 {
    GLuint s;
 
@@ -68,8 +69,8 @@ _mesa_update_shader_textures_used(struct gl_program *prog)
 
    for (s = 0; s < MAX_SAMPLERS; s++) {
       if (prog->SamplersUsed & (1 << s)) {
-         GLuint unit = prog->SamplerUnits[s];
-         GLuint tgt = prog->SamplerTargets[s];
+         GLuint unit = shProg->SamplerUnits[s];
+         GLuint tgt = shProg->SamplerTargets[s];
          assert(unit < Elements(prog->TexturesUsed));
          assert(tgt < NUM_TEXTURE_TARGETS);
          prog->TexturesUsed[unit] |= (1 << tgt);
diff --git a/src/mesa/main/uniforms.h b/src/mesa/main/uniforms.h
index f796f82..7b512a5 100644
--- a/src/mesa/main/uniforms.h
+++ b/src/mesa/main/uniforms.h
@@ -212,7 +212,8 @@ _mesa_propagate_uniforms_to_driver_storage(struct gl_uniform_storage *uni,
 					   unsigned count);
 
 extern void
-_mesa_update_shader_textures_used(struct gl_program *prog);
+_mesa_update_shader_textures_used(struct gl_shader_program *shProg,
+				  struct gl_program *prog);
 
 extern bool
 _mesa_sampler_uniforms_are_valid(const struct gl_shader_program *shProg,
diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp
index 5a68fc5..8280efe 100644
--- a/src/mesa/program/ir_to_mesa.cpp
+++ b/src/mesa/program/ir_to_mesa.cpp
@@ -2496,7 +2496,7 @@ print_program(struct prog_instruction *mesa_instructions,
  * samplers, etc).
  */
 static void
-count_resources(struct gl_program *prog)
+count_resources(struct gl_shader_program *shProg, struct gl_program *prog)
 {
    unsigned int i;
 
@@ -2506,8 +2506,6 @@ count_resources(struct gl_program *prog)
       struct prog_instruction *inst = &prog->Instructions[i];
 
       if (_mesa_is_tex_instruction(inst->Opcode)) {
-	 prog->SamplerTargets[inst->TexSrcUnit] =
-	    (gl_texture_index)inst->TexSrcTarget;
 	 prog->SamplersUsed |= 1 << inst->TexSrcUnit;
 	 if (inst->TexShadow) {
 	    prog->ShadowSamplers |= 1 << inst->TexSrcUnit;
@@ -2515,7 +2513,7 @@ count_resources(struct gl_program *prog)
       }
    }
 
-   _mesa_update_shader_textures_used(prog);
+   _mesa_update_shader_textures_used(shProg, prog);
 }
 
 class add_uniform_to_shader : public uniform_field_visitor {
@@ -3197,7 +3195,7 @@ get_mesa_program(struct gl_context *ctx,
    mesa_instructions = NULL;
 
    do_set_program_inouts(shader->ir, prog, shader->Type == GL_FRAGMENT_SHADER);
-   count_resources(prog);
+   count_resources(shader_program, prog);
 
    /* Set the gl_FragDepth layout. */
    if (target == GL_FRAGMENT_PROGRAM_ARB) {
diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index 73d956e..21774f2 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -2841,8 +2841,6 @@ count_resources(glsl_to_tgsi_visitor *v, gl_program *prog)
       if (is_tex_instruction(inst->op)) {
          v->samplers_used |= 1 << inst->sampler;
 
-         prog->SamplerTargets[inst->sampler] =
-            (gl_texture_index)inst->tex_target;
          if (inst->tex_shadow) {
             prog->ShadowSamplers |= 1 << inst->sampler;
          }
@@ -2850,7 +2848,7 @@ count_resources(glsl_to_tgsi_visitor *v, gl_program *prog)
    }
    
    prog->SamplersUsed = v->samplers_used;
-   _mesa_update_shader_textures_used(prog);
+   _mesa_update_shader_textures_used(v->shader_program, prog);
 }
 
 static void
-- 
1.7.6.4



More information about the mesa-dev mailing list