[Mesa-dev] [PATCH 85/87] glsl/mesa: make a copy of attribute bindings in case of cache fallback

Timothy Arceri timothy.arceri at collabora.com
Wed Jul 13 02:48:20 UTC 2016


If the shader cache falls back to doing a compile and link we need the
original attribute bindings as they could have changed after the program
was first linked.
---
 src/compiler/glsl/linker.cpp       |  5 ++++-
 src/compiler/glsl/shader_cache.cpp | 11 +++++++++++
 src/mesa/main/mtypes.h             |  7 +++++++
 src/mesa/main/shaderobj.c          |  6 ++++++
 4 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/src/compiler/glsl/linker.cpp b/src/compiler/glsl/linker.cpp
index f782210..6851881 100644
--- a/src/compiler/glsl/linker.cpp
+++ b/src/compiler/glsl/linker.cpp
@@ -2676,7 +2676,10 @@ assign_attribute_or_color_locations(gl_shader_program *prog,
       } else if (target_index == MESA_SHADER_VERTEX) {
 	 unsigned binding;
 
-	 if (prog->AttributeBindings->get(binding, var->name)) {
+         bool has_binding = sh->Program && sh->Program->cache_fallback ?
+            prog->FallbackAttributeBindings->get(binding, var->name) :
+            prog->AttributeBindings->get(binding, var->name);
+	 if (has_binding) {
 	    assert(binding >= VERT_ATTRIB_GENERIC0);
 	    var->data.location = binding;
             var->data.is_unmatched_generic_inout = 0;
diff --git a/src/compiler/glsl/shader_cache.cpp b/src/compiler/glsl/shader_cache.cpp
index d27bc18..f214040 100644
--- a/src/compiler/glsl/shader_cache.cpp
+++ b/src/compiler/glsl/shader_cache.cpp
@@ -654,9 +654,18 @@ read_hash_table(struct blob_reader *metadata, struct string_to_uint_map *hash)
 }
 
 static void
+copy_hash_entry(const void *key, void *data, void *closure)
+{
+   struct string_to_uint_map *ht = (struct string_to_uint_map *) closure;
+   ht->put((intptr_t) data, strdup((const char *) key));
+}
+
+static void
 write_hash_tables(struct blob *metadata, struct gl_shader_program *prog)
 {
    write_hash_table(metadata, prog->AttributeBindings);
+   hash_table_call_foreach(prog->AttributeBindings->ht, copy_hash_entry,
+                           prog->FallbackAttributeBindings);
    write_hash_table(metadata, prog->FragDataBindings);
    write_hash_table(metadata, prog->FragDataIndexBindings);
 }
@@ -665,6 +674,8 @@ static void
 read_hash_tables(struct blob_reader *metadata, struct gl_shader_program *prog)
 {
    read_hash_table(metadata, prog->AttributeBindings);
+   hash_table_call_foreach(prog->AttributeBindings->ht, copy_hash_entry,
+                           prog->FallbackAttributeBindings);
    read_hash_table(metadata, prog->FragDataBindings);
    read_hash_table(metadata, prog->FragDataIndexBindings);
 }
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index f2cb020..e22853e 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2712,6 +2712,13 @@ struct gl_shader_program
    struct string_to_uint_map *AttributeBindings;
 
    /**
+    * If the shader cache falls back to doing a compile and link we need the
+    * original attribute bindings as they could have changed after the program
+    * was first linked.
+    */
+   struct string_to_uint_map *FallbackAttributeBindings;
+
+   /**
     * User-defined fragment data bindings
     *
     * These are set via \c glBindFragDataLocation and are used to direct the
diff --git a/src/mesa/main/shaderobj.c b/src/mesa/main/shaderobj.c
index f114cf5..574b8cf 100644
--- a/src/mesa/main/shaderobj.c
+++ b/src/mesa/main/shaderobj.c
@@ -257,6 +257,7 @@ init_shader_program(struct gl_shader_program *prog)
    prog->RefCount = 1;
 
    prog->AttributeBindings = string_to_uint_map_ctor();
+   prog->FallbackAttributeBindings = string_to_uint_map_ctor();
    prog->FragDataBindings = string_to_uint_map_ctor();
    prog->FragDataIndexBindings = string_to_uint_map_ctor();
 
@@ -362,6 +363,11 @@ _mesa_free_shader_program_data(struct gl_context *ctx,
       shProg->AttributeBindings = NULL;
    }
 
+   if (shProg->FallbackAttributeBindings) {
+      string_to_uint_map_dtor(shProg->FallbackAttributeBindings);
+      shProg->FallbackAttributeBindings = NULL;
+   }
+
    if (shProg->FragDataBindings) {
       string_to_uint_map_dtor(shProg->FragDataBindings);
       shProg->FragDataBindings = NULL;
-- 
2.7.4



More information about the mesa-dev mailing list