[Mesa-dev] [PATCH 71/77] glsl/mesa: make a copy of attribute bindings in case of cache fallback
Timothy Arceri
timothy.arceri at collabora.com
Mon Oct 3 06:05:30 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 fca65cb..ac03283 100644
--- a/src/compiler/glsl/linker.cpp
+++ b/src/compiler/glsl/linker.cpp
@@ -2520,7 +2520,10 @@ assign_attribute_or_color_locations(void *mem_ctx,
} 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 95e932a..af053a9 100644
--- a/src/compiler/glsl/shader_cache.cpp
+++ b/src/compiler/glsl/shader_cache.cpp
@@ -726,9 +726,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);
}
@@ -737,6 +746,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 0b2e5ec..efcd50e 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2747,6 +2747,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 005756a..f95f423 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