[Mesa-dev] [PATCH 5/9] glsl: explicitly zero out padding to gl_shader_variable bitfield

Ian Romanick idr at freedesktop.org
Thu Jun 29 21:01:54 UTC 2017


On 06/26/2017 02:40 AM, Nicolai Hähnle wrote:
> From: Nicolai Hähnle <nicolai.haehnle at amd.com>
> 
> Otherwise, the padding bits remain undefined, which leads to valgrind
> errors when storing the gl_shader_variable in the disk cache.

libdrm used to use VG_CLEAR() for things like this.  Having explicitly
sized padding fields is, as Timothy points out, difficult to maintain.
Could we just memset() the whole thing first and let GCC optimize?

> ---
>  src/compiler/glsl/linker.cpp | 1 +
>  src/mesa/main/mtypes.h       | 2 ++
>  2 files changed, 3 insertions(+)
> 
> diff --git a/src/compiler/glsl/linker.cpp b/src/compiler/glsl/linker.cpp
> index cfda263..691c4cb 100644
> --- a/src/compiler/glsl/linker.cpp
> +++ b/src/compiler/glsl/linker.cpp
> @@ -3755,20 +3755,21 @@ create_shader_variable(struct gl_shader_program *shProg,
>     out->type = type;
>     out->outermost_struct_type = outermost_struct_type;
>     out->interface_type = interface_type;
>     out->component = in->data.location_frac;
>     out->index = in->data.index;
>     out->patch = in->data.patch;
>     out->mode = in->data.mode;
>     out->interpolation = in->data.interpolation;
>     out->explicit_location = in->data.explicit_location;
>     out->precision = in->data.precision;
> +   out->padding = 0;
>  
>     return out;
>  }
>  
>  static bool
>  add_shader_variable(const struct gl_context *ctx,
>                      struct gl_shader_program *shProg,
>                      struct set *resource_set,
>                      unsigned stage_mask,
>                      GLenum programInterface, ir_variable *var,
> diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
> index 0cb0024..a1fc743 100644
> --- a/src/mesa/main/mtypes.h
> +++ b/src/mesa/main/mtypes.h
> @@ -2813,20 +2813,22 @@ struct gl_shader_variable
>      * If the location is explicitly set in the shader, it \b cannot be changed
>      * by the linker or by the API (e.g., calls to \c glBindAttribLocation have
>      * no effect).
>      */
>     unsigned explicit_location:1;
>  
>     /**
>      * Precision qualifier.
>      */
>     unsigned precision:2;
> +
> +   unsigned padding:19;
>  };
>  
>  /**
>   * Active resource in a gl_shader_program
>   */
>  struct gl_program_resource
>  {
>     GLenum Type; /** Program interface type. */
>     const void *Data; /** Pointer to resource associated data structure. */
>     uint8_t StageReferences; /** Bitmask of shader stage references. */
> 



More information about the mesa-dev mailing list