[Mesa-dev] [PATCH 56/70] mesa/glsl: set sampler units directly in gl_program

Timothy Arceri timothy.arceri at collabora.com
Fri Nov 11 00:46:38 UTC 2016


Now that we create gl_program earlier there is no need to mess about
copying things to gl_linked_shader then to gl_program.
---
 src/compiler/glsl/link_uniform_initializers.cpp | 5 +++--
 src/mesa/main/mtypes.h                          | 8 --------
 src/mesa/main/uniform_query.cpp                 | 8 +++-----
 src/mesa/main/uniforms.c                        | 3 +--
 4 files changed, 7 insertions(+), 17 deletions(-)

diff --git a/src/compiler/glsl/link_uniform_initializers.cpp b/src/compiler/glsl/link_uniform_initializers.cpp
index 6f05a3a..7439fd3 100644
--- a/src/compiler/glsl/link_uniform_initializers.cpp
+++ b/src/compiler/glsl/link_uniform_initializers.cpp
@@ -134,7 +134,8 @@ set_opaque_binding(void *mem_ctx, gl_shader_program *prog,
                 storage->opaque[sh].active) {
                for (unsigned i = 0; i < elements; i++) {
                   const unsigned index = storage->opaque[sh].index + i;
-                  shader->SamplerUnits[index] = storage->storage[i].i;
+                  shader->Program->SamplerUnits[index] =
+                     storage->storage[i].i;
                }
 
             } else if (storage->type->base_type == GLSL_TYPE_IMAGE &&
@@ -242,7 +243,7 @@ set_uniform_initializer(void *mem_ctx, gl_shader_program *prog,
             if (shader && storage->opaque[sh].active) {
                unsigned index = storage->opaque[sh].index;
 
-               shader->SamplerUnits[index] = storage->storage[0].i;
+               shader->Program->SamplerUnits[index] = storage->storage[0].i;
             }
          }
       }
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 8067de7..8fe80eb 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2351,14 +2351,6 @@ struct gl_linked_shader
    GLbitfield shadow_samplers;	/**< Samplers used for shadow sampling. */
    /*@}*/
 
-   /**
-    * Map from sampler unit to texture unit (set by glUniform1i())
-    *
-    * A sampler unit is associated with each sampler uniform by the linker.
-    * The sampler unit associated with each uniform is stored in the
-    * \c gl_uniform_storage::sampler field.
-    */
-   GLubyte SamplerUnits[MAX_SAMPLERS];
    /** Which texture target is being sampled (TEXTURE_1D/2D/3D/etc_INDEX) */
    gl_texture_index SamplerTargets[MAX_SAMPLERS];
 
diff --git a/src/mesa/main/uniform_query.cpp b/src/mesa/main/uniform_query.cpp
index ffb20ca..047d21a 100644
--- a/src/mesa/main/uniform_query.cpp
+++ b/src/mesa/main/uniform_query.cpp
@@ -866,8 +866,8 @@ _mesa_uniform(struct gl_context *ctx, struct gl_shader_program *shProg,
          bool changed = false;
          for (int j = 0; j < count; j++) {
             unsigned unit = uni->opaque[i].index + offset + j;
-            if (sh->SamplerUnits[unit] != ((unsigned *) values)[j]) {
-               sh->SamplerUnits[unit] = ((unsigned *) values)[j];
+            if (sh->Program->SamplerUnits[unit] != ((unsigned *) values)[j]) {
+               sh->Program->SamplerUnits[unit] = ((unsigned *) values)[j];
                changed = true;
             }
          }
@@ -879,8 +879,6 @@ _mesa_uniform(struct gl_context *ctx, struct gl_shader_program *shProg,
 	    }
 
             struct gl_program *const prog = sh->Program;
-            assert(sizeof(prog->SamplerUnits) == sizeof(sh->SamplerUnits));
-
 	    _mesa_update_shader_textures_used(shProg, prog);
             if (ctx->Driver.SamplerUniformChange)
 	       ctx->Driver.SamplerUniformChange(ctx, prog->Target, prog);
@@ -1108,7 +1106,7 @@ _mesa_sampler_uniforms_pipeline_are_valid(struct gl_pipeline_object *pipeline)
       mask = shader->Program->SamplersUsed;
       while (mask) {
          const int s = u_bit_scan(&mask);
-         GLuint unit = shader->SamplerUnits[s];
+         GLuint unit = shader->Program->SamplerUnits[s];
          GLuint tgt = shader->SamplerTargets[s];
 
          /* FIXME: Samplers are initialized to 0 and Mesa doesn't do a
diff --git a/src/mesa/main/uniforms.c b/src/mesa/main/uniforms.c
index 25cd7db..335320f 100644
--- a/src/mesa/main/uniforms.c
+++ b/src/mesa/main/uniforms.c
@@ -73,14 +73,13 @@ _mesa_update_shader_textures_used(struct gl_shader_program *shProg,
 
    assert(shader);
 
-   memcpy(prog->SamplerUnits, shader->SamplerUnits, sizeof(prog->SamplerUnits));
    memset(prog->TexturesUsed, 0, sizeof(prog->TexturesUsed));
 
    shProg->SamplersValidated = GL_TRUE;
 
    while (mask) {
       const int s = u_bit_scan(&mask);
-      GLuint unit = shader->SamplerUnits[s];
+      GLuint unit = prog->SamplerUnits[s];
       GLuint tgt = shader->SamplerTargets[s];
       assert(unit < ARRAY_SIZE(prog->TexturesUsed));
       assert(tgt < NUM_TEXTURE_TARGETS);
-- 
2.7.4



More information about the mesa-dev mailing list