[Mesa-dev] [PATCH 05/17] main, glsl: Add UniformDataDefaults which stores uniform defaults

Timothy Arceri tarceri at itsqueeze.com
Fri Nov 10 04:41:56 UTC 2017


On 09/11/17 17:42, Jordan Justen wrote:
> The ARB_get_program_binary extension requires that uniform values in a
> program be restored to their initial value just after linking.
> 
> This patch saves off the initial values just after linking. When the
> program is restored by glProgramBinary, we can use this to copy the
> initial value of uniforms into UniformDataSlots.
> 
> Signed-off-by: Jordan Justen <jordan.l.justen at intel.com>
> ---
>   src/compiler/glsl/link_uniform_initializers.cpp |  2 ++
>   src/compiler/glsl/link_uniforms.cpp             |  3 +++
>   src/compiler/glsl/serialize.cpp                 | 18 ++++++++++++++++--
>   src/mesa/main/mtypes.h                          |  1 +
>   4 files changed, 22 insertions(+), 2 deletions(-)
> 
> diff --git a/src/compiler/glsl/link_uniform_initializers.cpp b/src/compiler/glsl/link_uniform_initializers.cpp
> index f70d9100e12..2395f5cf695 100644
> --- a/src/compiler/glsl/link_uniform_initializers.cpp
> +++ b/src/compiler/glsl/link_uniform_initializers.cpp
> @@ -354,5 +354,7 @@ link_set_uniform_initializers(struct gl_shader_program *prog,
>         }
>      }
>   
> +   memcpy(prog->data->UniformDataDefaults, prog->data->UniformDataSlots,
> +          sizeof(union gl_constant_value) * prog->data->NumUniformDataSlots);
>      ralloc_free(mem_ctx);
>   }
> diff --git a/src/compiler/glsl/link_uniforms.cpp b/src/compiler/glsl/link_uniforms.cpp
> index 7d141549f55..51e02bcf840 100644
> --- a/src/compiler/glsl/link_uniforms.cpp
> +++ b/src/compiler/glsl/link_uniforms.cpp
> @@ -1338,6 +1338,9 @@ link_assign_uniform_storage(struct gl_context *ctx,
>                                                    prog->data->NumUniformStorage);
>         data = rzalloc_array(prog->data->UniformStorage,
>                              union gl_constant_value, num_data_slots);
> +      prog->data->UniformDataDefaults =
> +         rzalloc_array(prog->data->UniformStorage,
> +                       union gl_constant_value, num_data_slots);
>      } else {
>         data = prog->data->UniformDataSlots;
>      }
> diff --git a/src/compiler/glsl/serialize.cpp b/src/compiler/glsl/serialize.cpp
> index b4c9545702e..e55f1680ffc 100644
> --- a/src/compiler/glsl/serialize.cpp
> +++ b/src/compiler/glsl/serialize.cpp
> @@ -449,7 +449,12 @@ write_uniforms(struct blob *metadata, struct gl_shader_program *prog)
>            unsigned vec_size =
>               prog->data->UniformStorage[i].type->component_slots() *
>               MAX2(prog->data->UniformStorage[i].array_elements, 1);
> -         blob_write_bytes(metadata, prog->data->UniformStorage[i].storage,
> +         unsigned slot =
> +            prog->data->UniformStorage[i].storage -
> +            prog->data->UniformDataSlots;
> +         blob_write_bytes(metadata, &prog->data->UniformDataSlots[slot],
> +                          sizeof(union gl_constant_value) * vec_size);
> +         blob_write_bytes(metadata, &prog->data->UniformDataDefaults[slot],
>                             sizeof(union gl_constant_value) * vec_size);
>         }
>      }
> @@ -472,6 +477,9 @@ read_uniforms(struct blob_reader *metadata, struct gl_shader_program *prog)
>      data = rzalloc_array(uniforms, union gl_constant_value,
>                           prog->data->NumUniformDataSlots);
>      prog->data->UniformDataSlots = data;
> +   prog->data->UniformDataDefaults =
> +      rzalloc_array(uniforms, union gl_constant_value,
> +                    prog->data->NumUniformDataSlots);
>   
>      prog->UniformHash = new string_to_uint_map;
>   
> @@ -512,8 +520,14 @@ read_uniforms(struct blob_reader *metadata, struct gl_shader_program *prog)
>            unsigned vec_size =
>               prog->data->UniformStorage[i].type->component_slots() *
>               MAX2(prog->data->UniformStorage[i].array_elements, 1);
> +         unsigned slot =
> +            prog->data->UniformStorage[i].storage -
> +            prog->data->UniformDataSlots;
> +         blob_copy_bytes(metadata,
> +                         (uint8_t *) &prog->data->UniformDataSlots[slot],
> +                         sizeof(union gl_constant_value) * vec_size);
>            blob_copy_bytes(metadata,
> -                         (uint8_t *) prog->data->UniformStorage[i].storage,
> +                         (uint8_t *) &prog->data->UniformDataDefaults[slot],
>                            sizeof(union gl_constant_value) * vec_size);
>   
>           assert(vec_size + prog->data->UniformStorage[i].storage <=
> diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
> index 2acf64eb56d..023692cc0e1 100644
> --- a/src/mesa/main/mtypes.h
> +++ b/src/mesa/main/mtypes.h
> @@ -2871,6 +2871,7 @@ struct gl_shader_program_data
>      /* Shader cache variables used during restore */
>      unsigned NumUniformDataSlots;
>      union gl_constant_value *UniformDataSlots;
> +   union gl_constant_value *UniformDataDefaults;

It really sucks that we need to carry this around in memory just for 
this extension.

Can we separate this from the shader cache vars and add a comment. 
Something like:

/* Used to hold initial uniform values for program binary restores.
  *
  * From the ARB_get_program_binary spec:
  *
  *    "A successful call to ProgramBinary will reset all uniform
  *    variables to their initial values. The initial value is either
  *    the value of the variable's initializer as specified in the
  *    original shader source, or 0 if no initializer was present.
  */

Otherwise this patch is:

Reviewed-by: Timothy Arceri <tarceri at itsqueeze.com>

>   
>      bool cache_fallback;
>   
> 


More information about the mesa-dev mailing list