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

Jordan Justen jordan.l.justen at intel.com
Sat Aug 19 07:44:19 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 FragData 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 |  8 ++++++++
 src/mesa/main/mtypes.h             |  2 ++
 src/mesa/main/shaderobj.c          | 12 ++++++++++++
 3 files changed, 22 insertions(+)

diff --git a/src/compiler/glsl/shader_cache.cpp b/src/compiler/glsl/shader_cache.cpp
index 6b45813cee..0d4a93c879 100644
--- a/src/compiler/glsl/shader_cache.cpp
+++ b/src/compiler/glsl/shader_cache.cpp
@@ -848,7 +848,11 @@ write_hash_tables(struct blob *metadata, struct gl_shader_program *prog)
    prog->AttributeBindings->iterate(copy_hash_entry,
                                     prog->data->FallbackAttributeBindings);
    write_hash_table(metadata, prog->FragDataBindings);
+   prog->FragDataBindings->iterate(copy_hash_entry,
+                                   prog->data->FallbackFragDataBindings);
    write_hash_table(metadata, prog->FragDataIndexBindings);
+   prog->FragDataIndexBindings->
+      iterate(copy_hash_entry, prog->data->FallbackFragDataIndexBindings);
 }
 
 static void
@@ -858,7 +862,11 @@ read_hash_tables(struct blob_reader *metadata, struct gl_shader_program *prog)
    prog->AttributeBindings->iterate(copy_hash_entry,
                                     prog->data->FallbackAttributeBindings);
    read_hash_table(metadata, prog->FragDataBindings);
+   prog->FragDataBindings->iterate(copy_hash_entry,
+                                   prog->data->FallbackFragDataBindings);
    read_hash_table(metadata, prog->FragDataIndexBindings);
+   prog->FragDataIndexBindings->
+      iterate(copy_hash_entry, prog->data->FallbackFragDataIndexBindings);
 }
 
 static void
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index e2c95d48e9..d7996a15bd 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2879,6 +2879,8 @@ struct gl_shader_program_data
     * was first linked.
     */
    struct string_to_uint_map *FallbackAttributeBindings;
+   struct string_to_uint_map *FallbackFragDataBindings;
+   struct string_to_uint_map *FallbackFragDataIndexBindings;
 
    /** List of all active resources after linking. */
    struct gl_program_resource *ProgramResourceList;
diff --git a/src/mesa/main/shaderobj.c b/src/mesa/main/shaderobj.c
index 185093b117..999a389c53 100644
--- a/src/mesa/main/shaderobj.c
+++ b/src/mesa/main/shaderobj.c
@@ -279,7 +279,9 @@ init_shader_program(struct gl_shader_program *prog)
    prog->AttributeBindings = string_to_uint_map_ctor();
    prog->data->FallbackAttributeBindings = string_to_uint_map_ctor();
    prog->FragDataBindings = string_to_uint_map_ctor();
+   prog->data->FallbackFragDataBindings = string_to_uint_map_ctor();
    prog->FragDataIndexBindings = string_to_uint_map_ctor();
+   prog->data->FallbackFragDataIndexBindings = string_to_uint_map_ctor();
 
    prog->Geom.UsesEndPrimitive = false;
    prog->Geom.UsesStreams = false;
@@ -405,11 +407,21 @@ _mesa_free_shader_program_data(struct gl_context *ctx,
       shProg->FragDataBindings = NULL;
    }
 
+   if (shProg->data->FallbackFragDataBindings) {
+      string_to_uint_map_dtor(shProg->data->FallbackFragDataBindings);
+      shProg->data->FallbackFragDataBindings = NULL;
+   }
+
    if (shProg->FragDataIndexBindings) {
       string_to_uint_map_dtor(shProg->FragDataIndexBindings);
       shProg->FragDataIndexBindings = NULL;
    }
 
+   if (shProg->data->FallbackFragDataIndexBindings) {
+      string_to_uint_map_dtor(shProg->data->FallbackFragDataIndexBindings);
+      shProg->data->FallbackFragDataIndexBindings = NULL;
+   }
+
    /* detach shaders */
    for (i = 0; i < shProg->NumShaders; i++) {
       _mesa_reference_shader(ctx, &shProg->Shaders[i], NULL);
-- 
2.14.0



More information about the mesa-dev mailing list