[Mesa-dev] [PATCH] mesa: declare UniformBufferBindings as an array with a static size
Jose Fonseca
jfonseca at vmware.com
Tue May 14 09:13:43 PDT 2013
This looks a good way to address the problem. Thanks.
I didn't know you were already looking at this and I was in a rush to fix the regression, I went ahead and pushed a temporary workaround. You'll need to rebase or revert my workaround -- eitherway it will be trivial.
Jose
----- Original Message -----
> Some Gallium drivers were crashing, because the array was not large enough.
>
> NOTE: This is a candidate for the stable branches.
> ---
> src/mesa/main/bufferobj.c | 10 ++--------
> src/mesa/main/config.h | 2 ++
> src/mesa/main/mtypes.h | 3 ++-
> src/mesa/state_tracker/st_extensions.c | 7 ++++---
> 4 files changed, 10 insertions(+), 12 deletions(-)
>
> diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c
> index 1566cb4..ffb67b9 100644
> --- a/src/mesa/main/bufferobj.c
> +++ b/src/mesa/main/bufferobj.c
> @@ -619,13 +619,10 @@ _mesa_init_buffer_objects( struct gl_context *ctx )
> _mesa_reference_buffer_object(ctx, &ctx->CopyWriteBuffer,
> ctx->Shared->NullBufferObj);
>
> - ctx->UniformBufferBindings = calloc(ctx->Const.MaxUniformBufferBindings,
> - sizeof(*ctx->UniformBufferBindings));
> -
> _mesa_reference_buffer_object(ctx, &ctx->UniformBuffer,
> ctx->Shared->NullBufferObj);
>
> - for (i = 0; i < ctx->Const.MaxUniformBufferBindings; i++) {
> + for (i = 0; i < MAX_COMBINED_UNIFORM_BUFFERS; i++) {
> _mesa_reference_buffer_object(ctx,
> &ctx->UniformBufferBindings[i].BufferObject,
> ctx->Shared->NullBufferObj);
> @@ -647,14 +644,11 @@ _mesa_free_buffer_objects( struct gl_context *ctx )
>
> _mesa_reference_buffer_object(ctx, &ctx->UniformBuffer, NULL);
>
> - for (i = 0; i < ctx->Const.MaxUniformBufferBindings; i++) {
> + for (i = 0; i < MAX_COMBINED_UNIFORM_BUFFERS; i++) {
> _mesa_reference_buffer_object(ctx,
> &ctx->UniformBufferBindings[i].BufferObject,
> NULL);
> }
> -
> - free(ctx->UniformBufferBindings);
> - ctx->UniformBufferBindings = NULL;
> }
>
> static bool
> diff --git a/src/mesa/main/config.h b/src/mesa/main/config.h
> index ea87b75..134c88a 100644
> --- a/src/mesa/main/config.h
> +++ b/src/mesa/main/config.h
> @@ -168,6 +168,8 @@
> /*@{*/
> #define MAX_PROGRAM_LOCAL_PARAMS 4096
> #define MAX_UNIFORMS 4096
> +/* 6 is for vertex, hull, domain, geometry, fragment, and compute shader. */
> +#define MAX_COMBINED_UNIFORM_BUFFERS (16 * 6)
> /*@}*/
>
> /**
> diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
> index bce1e6c..c3a0ff4 100644
> --- a/src/mesa/main/mtypes.h
> +++ b/src/mesa/main/mtypes.h
> @@ -3526,7 +3526,8 @@ struct gl_context
> * associated with uniform blocks by glUniformBlockBinding()'s state in
> the
> * shader program.
> */
> - struct gl_uniform_buffer_binding *UniformBufferBindings;
> + struct gl_uniform_buffer_binding
> + UniformBufferBindings[MAX_COMBINED_UNIFORM_BUFFERS];
>
> /*@}*/
>
> diff --git a/src/mesa/state_tracker/st_extensions.c
> b/src/mesa/state_tracker/st_extensions.c
> index b64d363..259421a 100644
> --- a/src/mesa/state_tracker/st_extensions.c
> +++ b/src/mesa/state_tracker/st_extensions.c
> @@ -280,9 +280,10 @@ void st_init_limits(struct st_context *st)
> c->UniformBufferOffsetAlignment =
> screen->get_param(screen,
> PIPE_CAP_CONSTANT_BUFFER_OFFSET_ALIGNMENT);
> c->MaxCombinedUniformBlocks = c->MaxUniformBufferBindings =
> - c->VertexProgram.MaxUniformBlocks +
> - c->GeometryProgram.MaxUniformBlocks +
> - c->FragmentProgram.MaxUniformBlocks;
> + _min(c->VertexProgram.MaxUniformBlocks +
> + c->GeometryProgram.MaxUniformBlocks +
> + c->FragmentProgram.MaxUniformBlocks,
> + MAX_COMBINED_UNIFORM_BUFFERS);
> }
> }
>
> --
> 1.7.10.4
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev
>
More information about the mesa-dev
mailing list