From: Timothy Arceri Date: Fri, 11 Aug 2017 03:55:13 +0000 (+1000) Subject: glsl: stop adding pointers from gl_shader_variable to the cache X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=37d453b55a7b4c1b10d28dba4acfe12de4634bc8;p=mesa.git glsl: stop adding pointers from gl_shader_variable to the cache This is so we always create reproducible cache entries. Consistency is required for verification of any third party distributed shaders. Reviewed-by: Samuel Pitoiset --- diff --git a/src/compiler/glsl/shader_cache.cpp b/src/compiler/glsl/shader_cache.cpp index 1fd49b82e98..e004ed4f64d 100644 --- a/src/compiler/glsl/shader_cache.cpp +++ b/src/compiler/glsl/shader_cache.cpp @@ -877,6 +877,18 @@ write_shader_subroutine_index(struct blob *metadata, } } +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, @@ -888,16 +900,19 @@ write_program_resource_data(struct blob *metadata, 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: @@ -988,16 +1003,17 @@ read_program_resource_data(struct blob_reader *metadata, 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;