[Mesa-dev] [PATCH 20/65] glsl: include bindings when creating sha1 for metadata

Timothy Arceri timothy.arceri at collabora.com
Fri Apr 29 13:33:19 UTC 2016


These bindings change the resulting binary so they are just as
important as the shader source.
---
 src/compiler/glsl/shader_cache.cpp | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/src/compiler/glsl/shader_cache.cpp b/src/compiler/glsl/shader_cache.cpp
index 9c5095c..575c518 100644
--- a/src/compiler/glsl/shader_cache.cpp
+++ b/src/compiler/glsl/shader_cache.cpp
@@ -389,6 +389,13 @@ read_shader_metadata(struct blob_reader *metadata,
    }
 }
 
+static void
+create_binding_str(const char *key, unsigned value, void *closure)
+{
+   char **bindings_str = (char **) closure;
+   ralloc_asprintf_append(bindings_str, "%s:%u,", key, value);
+}
+
 void
 shader_cache_write_program_metadata(struct gl_context *ctx,
                                     struct gl_shader_program *prog)
@@ -443,6 +450,7 @@ shader_cache_read_program_metadata(struct gl_context *ctx,
 {
    const char *stage_name[] = { "vs", "tcs", "tes", "gs", "fs", "cs" };
    char buf[256], sha1buf[41];
+   unsigned char sha1[20];
    int offset = 0;
    uint8_t *buffer;
    struct program_cache *cache;
@@ -463,6 +471,19 @@ shader_cache_read_program_metadata(struct gl_context *ctx,
       }
    }
 
+   char *bindings_str = ralloc_strdup(NULL, "vb: ");
+   prog->AttributeBindings->iterate(create_binding_str, &bindings_str);
+   ralloc_strcat(&bindings_str, "fb: ");
+   prog->FragDataBindings->iterate(create_binding_str, &bindings_str);
+   ralloc_strcat(&bindings_str, "fbi: ");
+   prog->FragDataIndexBindings->iterate(create_binding_str, &bindings_str);
+   _mesa_sha1_compute(bindings_str, strlen(bindings_str), sha1);
+   ralloc_free(bindings_str);
+
+   offset += snprintf(buf + offset, sizeof(buf) - offset,
+                      "bindings: %s\n",
+                      _mesa_sha1_format(sha1buf, sha1));
+
    for (unsigned i = 0; i < prog->NumShaders; i++) {
       if (prog->Shaders[i]->Source == NULL)
          return false;
-- 
2.5.5



More information about the mesa-dev mailing list