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

Timothy Arceri timothy.arceri at collabora.com
Tue Nov 29 03:58:37 UTC 2016


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.
---
 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 34854fe..cdb3665 100644
--- a/src/compiler/glsl/shader_cache.cpp
+++ b/src/compiler/glsl/shader_cache.cpp
@@ -810,7 +810,11 @@ write_hash_tables(struct blob *metadata, struct gl_shader_program *prog)
    hash_table_call_foreach(prog->AttributeBindings->ht, copy_hash_entry,
                            prog->data->FallbackAttributeBindings);
    write_hash_table(metadata, prog->FragDataBindings);
+   hash_table_call_foreach(prog->FragDataBindings->ht, copy_hash_entry,
+                           prog->data->FallbackFragDataBindings);
    write_hash_table(metadata, prog->FragDataIndexBindings);
+   hash_table_call_foreach(prog->FragDataIndexBindings->ht, copy_hash_entry,
+                           prog->data->FallbackFragDataIndexBindings);
 }
 
 static void
@@ -820,7 +824,11 @@ read_hash_tables(struct blob_reader *metadata, struct gl_shader_program *prog)
    hash_table_call_foreach(prog->AttributeBindings->ht, copy_hash_entry,
                            prog->data->FallbackAttributeBindings);
    read_hash_table(metadata, prog->FragDataBindings);
+   hash_table_call_foreach(prog->FragDataBindings->ht, copy_hash_entry,
+                           prog->data->FallbackFragDataBindings);
    read_hash_table(metadata, prog->FragDataIndexBindings);
+   hash_table_call_foreach(prog->FragDataIndexBindings->ht, copy_hash_entry,
+                           prog->data->FallbackFragDataIndexBindings);
 }
 
 static void
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index a9064aa..cf48305 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2666,6 +2666,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 0a0af27..54ae93d 100644
--- a/src/mesa/main/shaderobj.c
+++ b/src/mesa/main/shaderobj.c
@@ -284,7 +284,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;
@@ -408,11 +410,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.7.4



More information about the mesa-dev mailing list