[Mesa-dev] [PATCH 2/8] glsl: stop adding pointers from gl_shader_variable to the cache

Timothy Arceri tarceri at itsqueeze.com
Sun Aug 13 23:49:01 UTC 2017


This is so we always create reproducible cache entries. Consistency
is required for verification of any third party distributed shaders.
---
 src/compiler/glsl/shader_cache.cpp | 40 ++++++++++++++++++++++++++------------
 1 file changed, 28 insertions(+), 12 deletions(-)

diff --git a/src/compiler/glsl/shader_cache.cpp b/src/compiler/glsl/shader_cache.cpp
index 1fd49b82e9..e004ed4f64 100644
--- a/src/compiler/glsl/shader_cache.cpp
+++ b/src/compiler/glsl/shader_cache.cpp
@@ -871,40 +871,55 @@ write_shader_subroutine_index(struct blob *metadata,
    for (unsigned j = 0; j < sh->Program->sh.NumSubroutineFunctions; j++) {
       if (strcmp(((gl_subroutine_function *)res->Data)->name,
                  sh->Program->sh.SubroutineFunctions[j].name) == 0) {
          blob_write_uint32(metadata, j);
          break;
       }
    }
 }
 
 static void
+get_shader_var_and_pointer_sizes(size_t *s_var_size, size_t *s_var_ptrs,
+                                 const gl_shader_variable *var)
+{
+   *s_var_size = sizeof(gl_shader_variable);
+   *s_var_ptrs =
+      sizeof(var->type) +
+      sizeof(var->interface_type) +
+      sizeof(var->outermost_struct_type) +
+      sizeof(var->name);
+}
+
+static void
 write_program_resource_data(struct blob *metadata,
                             struct gl_shader_program *prog,
                             struct gl_program_resource *res)
 {
    struct gl_linked_shader *sh;
 
    switch(res->Type) {
    case GL_PROGRAM_INPUT:
    case GL_PROGRAM_OUTPUT: {
       const gl_shader_variable *var = (gl_shader_variable *)res->Data;
-      blob_write_bytes(metadata, var, sizeof(gl_shader_variable));
+
       encode_type_to_blob(metadata, var->type);
+      encode_type_to_blob(metadata, var->interface_type);
+      encode_type_to_blob(metadata, var->outermost_struct_type);
 
-      if (var->interface_type)
-         encode_type_to_blob(metadata, var->interface_type);
+      blob_write_string(metadata, var->name);
 
-      if (var->outermost_struct_type)
-         encode_type_to_blob(metadata, var->outermost_struct_type);
+      size_t s_var_size, s_var_ptrs;
+      get_shader_var_and_pointer_sizes(&s_var_size, &s_var_ptrs, var);
 
-      blob_write_string(metadata, var->name);
+      /* Write gl_shader_variable skipping over the pointers */
+      blob_write_bytes(metadata, ((char *)var) + s_var_ptrs,
+                       s_var_size - s_var_ptrs);
       break;
    }
    case GL_UNIFORM_BLOCK:
       for (unsigned i = 0; i < prog->data->NumUniformBlocks; i++) {
          if (strcmp(((gl_uniform_block *)res->Data)->Name,
                     prog->data->UniformBlocks[i].Name) == 0) {
             blob_write_uint32(metadata, i);
             break;
          }
       }
@@ -981,30 +996,31 @@ read_program_resource_data(struct blob_reader *metadata,
                            struct gl_shader_program *prog,
                            struct gl_program_resource *res)
 {
    struct gl_linked_shader *sh;
 
    switch(res->Type) {
    case GL_PROGRAM_INPUT:
    case GL_PROGRAM_OUTPUT: {
       gl_shader_variable *var = ralloc(prog, struct gl_shader_variable);
 
-      blob_copy_bytes(metadata, (uint8_t *) var, sizeof(gl_shader_variable));
       var->type = decode_type_from_blob(metadata);
+      var->interface_type = decode_type_from_blob(metadata);
+      var->outermost_struct_type = decode_type_from_blob(metadata);
 
-      if (var->interface_type)
-         var->interface_type = decode_type_from_blob(metadata);
+      var->name = ralloc_strdup(prog, blob_read_string(metadata));
 
-      if (var->outermost_struct_type)
-         var->outermost_struct_type = decode_type_from_blob(metadata);
+      size_t s_var_size, s_var_ptrs;
+      get_shader_var_and_pointer_sizes(&s_var_size, &s_var_ptrs, var);
 
-      var->name = ralloc_strdup(prog, blob_read_string(metadata));
+      blob_copy_bytes(metadata, ((uint8_t *) var) + s_var_ptrs,
+                      s_var_size - s_var_ptrs);
 
       res->Data = var;
       break;
    }
    case GL_UNIFORM_BLOCK:
       res->Data = &prog->data->UniformBlocks[blob_read_uint32(metadata)];
       break;
    case GL_SHADER_STORAGE_BLOCK:
       res->Data = &prog->data->ShaderStorageBlocks[blob_read_uint32(metadata)];
       break;
-- 
2.13.4



More information about the mesa-dev mailing list