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

Timothy Arceri tarceri at itsqueeze.com
Tue Feb 7 03:42:33 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.
---
 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 ddcd530..5180725 100644
--- a/src/compiler/glsl/shader_cache.cpp
+++ b/src/compiler/glsl/shader_cache.cpp
@@ -825,7 +825,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
@@ -835,7 +839,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 d1dde0c..7647b09 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2694,6 +2694,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 245a0b9..e3004f6 100644
--- a/src/mesa/main/shaderobj.c
+++ b/src/mesa/main/shaderobj.c
@@ -278,7 +278,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;
@@ -404,11 +406,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.9.3



More information about the mesa-dev mailing list