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

Jordan Justen jordan.l.justen at intel.com
Sat Aug 19 07:44:18 UTC 2017


From: Timothy Arceri <timothy.arceri at collabora.com>

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.

[jordan.l.justen at intel.com: Use string_to_uint_map::iterate method]
Signed-off-by: Jordan Justen <jordan.l.justen at intel.com>
---
 src/compiler/glsl/shader_cache.cpp | 10 ++++++++++
 src/mesa/main/mtypes.h             |  7 +++++++
 src/mesa/main/shaderobj.c          |  6 ++++++
 3 files changed, 23 insertions(+)

diff --git a/src/compiler/glsl/shader_cache.cpp b/src/compiler/glsl/shader_cache.cpp
index cc4d24482d..6b45813cee 100644
--- a/src/compiler/glsl/shader_cache.cpp
+++ b/src/compiler/glsl/shader_cache.cpp
@@ -835,10 +835,18 @@ read_hash_table(struct blob_reader *metadata, struct string_to_uint_map *hash)
    }
 }
 
+static void
+copy_hash_entry(const char *key, unsigned data, void *closure)
+{
+   ((struct string_to_uint_map *) closure)->put(data, key);
+}
+
 static void
 write_hash_tables(struct blob *metadata, struct gl_shader_program *prog)
 {
    write_hash_table(metadata, prog->AttributeBindings);
+   prog->AttributeBindings->iterate(copy_hash_entry,
+                                    prog->data->FallbackAttributeBindings);
    write_hash_table(metadata, prog->FragDataBindings);
    write_hash_table(metadata, prog->FragDataIndexBindings);
 }
@@ -847,6 +855,8 @@ static void
 read_hash_tables(struct blob_reader *metadata, struct gl_shader_program *prog)
 {
    read_hash_table(metadata, prog->AttributeBindings);
+   prog->AttributeBindings->iterate(copy_hash_entry,
+                                    prog->data->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 49eb7d54bd..e2c95d48e9 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2873,6 +2873,13 @@ struct gl_shader_program_data
     */
    bool skip_cache;
 
+   /**
+    * 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;
+
    /** List of all active resources after linking. */
    struct gl_program_resource *ProgramResourceList;
    unsigned NumProgramResourceList;
diff --git a/src/mesa/main/shaderobj.c b/src/mesa/main/shaderobj.c
index 8a5fa5e2df..185093b117 100644
--- a/src/mesa/main/shaderobj.c
+++ b/src/mesa/main/shaderobj.c
@@ -277,6 +277,7 @@ init_shader_program(struct gl_shader_program *prog)
    prog->RefCount = 1;
 
    prog->AttributeBindings = string_to_uint_map_ctor();
+   prog->data->FallbackAttributeBindings = string_to_uint_map_ctor();
    prog->FragDataBindings = string_to_uint_map_ctor();
    prog->FragDataIndexBindings = string_to_uint_map_ctor();
 
@@ -394,6 +395,11 @@ _mesa_free_shader_program_data(struct gl_context *ctx,
       shProg->AttributeBindings = NULL;
    }
 
+   if (shProg->data->FallbackAttributeBindings) {
+      string_to_uint_map_dtor(shProg->data->FallbackAttributeBindings);
+      shProg->data->FallbackAttributeBindings = NULL;
+   }
+
    if (shProg->FragDataBindings) {
       string_to_uint_map_dtor(shProg->FragDataBindings);
       shProg->FragDataBindings = NULL;
-- 
2.14.0



More information about the mesa-dev mailing list