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

Timothy Arceri tarceri at itsqueeze.com
Sun Aug 13 23:49:06 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 | 31 +++++++++++++++++++++++++------
 1 file changed, 25 insertions(+), 6 deletions(-)

diff --git a/src/compiler/glsl/shader_cache.cpp b/src/compiler/glsl/shader_cache.cpp
index 0e7744bb0b..aa63bdcf01 100644
--- a/src/compiler/glsl/shader_cache.cpp
+++ b/src/compiler/glsl/shader_cache.cpp
@@ -1289,43 +1289,56 @@ 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);
 }
 
 static void
+get_shader_info_and_pointer_sizes(size_t *s_info_size, size_t *s_info_ptrs,
+                                  shader_info *info)
+{
+   *s_info_size = sizeof(shader_info);
+   *s_info_ptrs = sizeof(info->name) + sizeof(info->label);
+}
+
+static void
 create_linked_shader_and_program(struct gl_context *ctx,
                                  gl_shader_stage stage,
                                  struct gl_shader_program *prog,
                                  struct blob_reader *metadata)
 {
    struct gl_program *glprog;
 
    struct gl_linked_shader *linked = rzalloc(NULL, struct gl_linked_shader);
    linked->Stage = stage;
 
    glprog = ctx->Driver.NewProgram(ctx, _mesa_shader_stage_to_program(stage),
                                    prog->Name, false);
    glprog->info.stage = stage;
    linked->Program = glprog;
 
    read_shader_metadata(metadata, glprog, linked);
 
-   /* Restore shader info */
-   blob_copy_bytes(metadata, (uint8_t *) &glprog->info, sizeof(shader_info));
-
    glprog->info.name = ralloc_strdup(glprog, blob_read_string(metadata));
    glprog->info.label = ralloc_strdup(glprog, blob_read_string(metadata));
 
+   size_t s_info_size, s_info_ptrs;
+   get_shader_info_and_pointer_sizes(&s_info_size, &s_info_ptrs,
+                                     &glprog->info);
+
+   /* Restore shader info */
+   blob_copy_bytes(metadata, ((uint8_t *) &glprog->info) + s_info_ptrs,
+                   s_info_size - s_info_ptrs);
+
    _mesa_reference_shader_program_data(ctx, &glprog->sh.data, prog->data);
    _mesa_reference_program(ctx, &linked->Program, glprog);
    prog->_LinkedShaders[stage] = linked;
 }
 
 void
 shader_cache_write_program_metadata(struct gl_context *ctx,
                                     struct gl_shader_program *prog)
 {
    struct disk_cache *cache = ctx->Cache;
@@ -1349,32 +1362,38 @@ shader_cache_write_program_metadata(struct gl_context *ctx,
    write_hash_tables(metadata, prog);
 
    blob_write_uint32(metadata, prog->data->Version);
    blob_write_uint32(metadata, prog->data->linked_stages);
 
    for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
       struct gl_linked_shader *sh = prog->_LinkedShaders[i];
       if (sh) {
          write_shader_metadata(metadata, sh);
 
-         /* Store nir shader info */
-         blob_write_bytes(metadata, &sh->Program->info, sizeof(shader_info));
-
          if (sh->Program->info.name)
             blob_write_string(metadata, sh->Program->info.name);
          else
             blob_write_string(metadata, "");
 
          if (sh->Program->info.label)
             blob_write_string(metadata, sh->Program->info.label);
          else
             blob_write_string(metadata, "");
+
+         size_t s_info_size, s_info_ptrs;
+         get_shader_info_and_pointer_sizes(&s_info_size, &s_info_ptrs,
+                                           &sh->Program->info);
+
+         /* Store shader info */
+         blob_write_bytes(metadata,
+                          ((char *) &sh->Program->info) + s_info_ptrs,
+                          s_info_size - s_info_ptrs);
       }
    }
 
    write_xfb(metadata, prog);
 
    write_uniform_remap_tables(metadata, prog);
 
    write_atomic_buffers(metadata, prog);
 
    write_buffer_blocks(metadata, prog);
-- 
2.13.4



More information about the mesa-dev mailing list