[Mesa-dev] [PATCH 12/17] mesa/st: make sure the const buffer is large enough for packed uniforms

Nicolai Hähnle nhaehnle at gmail.com
Mon Jun 26 09:27:30 UTC 2017


On 25.06.2017 03:31, Timothy Arceri wrote:
> ---
>   src/mesa/state_tracker/st_atom_constbuf.c | 8 +++++++-
>   1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/src/mesa/state_tracker/st_atom_constbuf.c b/src/mesa/state_tracker/st_atom_constbuf.c
> index 7f17546..eb8f6b3 100644
> --- a/src/mesa/state_tracker/st_atom_constbuf.c
> +++ b/src/mesa/state_tracker/st_atom_constbuf.c
> @@ -83,21 +83,27 @@ void st_upload_constants(struct st_context *st, struct gl_program *prog)
>   
>      /* Make all bindless samplers/images bound texture/image units resident in
>       * the context.
>       */
>      st_make_bound_samplers_resident(st, prog);
>      st_make_bound_images_resident(st, prog);
>   
>      /* update constants */
>      if (params && params->NumParameters) {
>         struct pipe_constant_buffer cb;
> -      const uint paramBytes = params->NumParameters * sizeof(GLfloat) * 4;
> +
> +      /* We need to align to 4 as the driver will expect to load four values
> +       * regardless of how many values the last param has. It's safe to do the
> +       * align as the param list always allocates extra memory.
> +       */
> +      const uint paramBytes =
> +         align((params->NumParameterValues * sizeof(GLfloat)) + 1, 4);

This looks broken.

First of all, I would say that it shouldn't actually be required. A 
driver that supports packed uniforms should only load as much as the 
shader actually requests.

Second, even if it were needed, the code doesn't do what it says.

Cheers,
Nicolai


>   
>         /* Update the constants which come from fixed-function state, such as
>          * transformation matrices, fog factors, etc.  The rest of the values in
>          * the parameters list are explicitly set by the user with glUniform,
>          * glProgramParameter(), etc.
>          */
>         if (params->StateFlags)
>            _mesa_load_state_parameters(st->ctx, params);
>   
>         _mesa_shader_write_subroutine_indices(st->ctx, stage);
> 


-- 
Lerne, wie die Welt wirklich ist,
Aber vergiss niemals, wie sie sein sollte.


More information about the mesa-dev mailing list