[Mesa-dev] [PATCH 42/88] glsl: use reproducible name for lowered const arrays

Kenneth Graunke kenneth at whitecape.org
Mon Sep 26 02:14:49 UTC 2016


On Saturday, September 24, 2016 3:25:23 PM PDT Timothy Arceri wrote:
> Otherwise we can end up with mismatching names between the cached
> binary and the cached metadata.
> ---
>  src/compiler/glsl/ir_optimization.h                  |  2 +-
>  src/compiler/glsl/linker.cpp                         |  2 +-
>  src/compiler/glsl/lower_const_arrays_to_uniforms.cpp | 16 ++++++++++++----
>  3 files changed, 14 insertions(+), 6 deletions(-)
> 
> diff --git a/src/compiler/glsl/ir_optimization.h b/src/compiler/glsl/ir_optimization.h
> index 3bd6928..6f2bc32 100644
> --- a/src/compiler/glsl/ir_optimization.h
> +++ b/src/compiler/glsl/ir_optimization.h
> @@ -126,7 +126,7 @@ bool lower_variable_index_to_cond_assign(gl_shader_stage stage,
>      exec_list *instructions, bool lower_input, bool lower_output,
>      bool lower_temp, bool lower_uniform);
>  bool lower_quadop_vector(exec_list *instructions, bool dont_lower_swz);
> -bool lower_const_arrays_to_uniforms(exec_list *instructions);
> +bool lower_const_arrays_to_uniforms(exec_list *instructions, unsigned stage);
>  bool lower_clip_cull_distance(struct gl_shader_program *prog,
>                                gl_linked_shader *shader);
>  void lower_output_reads(unsigned stage, exec_list *instructions);
> diff --git a/src/compiler/glsl/linker.cpp b/src/compiler/glsl/linker.cpp
> index 13336f8..3362bce 100644
> --- a/src/compiler/glsl/linker.cpp
> +++ b/src/compiler/glsl/linker.cpp
> @@ -4921,7 +4921,7 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog,
>                                      ctx->Const.NativeIntegers))
>  	 ;
>  
> -      lower_const_arrays_to_uniforms(prog->_LinkedShaders[i]->ir);
> +      lower_const_arrays_to_uniforms(prog->_LinkedShaders[i]->ir, i);
>        propagate_invariance(prog->_LinkedShaders[i]->ir);
>     }
>  
> diff --git a/src/compiler/glsl/lower_const_arrays_to_uniforms.cpp b/src/compiler/glsl/lower_const_arrays_to_uniforms.cpp
> index 665a9ad..a46d84c 100644
> --- a/src/compiler/glsl/lower_const_arrays_to_uniforms.cpp
> +++ b/src/compiler/glsl/lower_const_arrays_to_uniforms.cpp
> @@ -45,9 +45,11 @@
>  namespace {
>  class lower_const_array_visitor : public ir_rvalue_visitor {
>  public:
> -   lower_const_array_visitor(exec_list *insts)
> +   lower_const_array_visitor(exec_list *insts, unsigned s)
>     {
>        instructions = insts;
> +      stage = s;
> +      const_count = 0;
>        progress = false;
>     }
>  
> @@ -62,6 +64,8 @@ public:
>  
>  private:
>     exec_list *instructions;
> +   unsigned stage;
> +   unsigned const_count;
>     bool progress;
>  };
>  
> @@ -83,7 +87,11 @@ lower_const_array_visitor::handle_rvalue(ir_rvalue **rvalue)
>  
>     void *mem_ctx = ralloc_parent(con);
>  
> -   char *uniform_name = ralloc_asprintf(mem_ctx, "constarray__%p", con);
> +   char *uniform_name = ralloc_asprintf(mem_ctx, "constarray_%x_%u",
> +                                        const_count, stage);
> +   unsigned limit = ~0;
> +   assert(const_count != limit);
> +   const_count++;

Obviously, we're not likely to hit 4294967295 constant arrays in a
single shader, but it's really easy to degrade gracefully - just don't
promote this to a uniform.

   if (const_count == ~0)
      return;

   char *uniform_name = ralloc_asprintf(mem_ctx, "constarray_%x_%u",
                                        const_count, stage);

   const_count++;

With that improved,
Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: This is a digitally signed message part.
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20160925/84a78e6e/attachment.sig>


More information about the mesa-dev mailing list