summaryrefslogtreecommitdiffstats
path: root/src/mesa
diff options
context:
space:
mode:
authorMarek Olšák <[email protected]>2013-05-14 17:58:32 +0200
committerIan Romanick <[email protected]>2013-06-25 14:24:56 -0700
commit7c719e867dbafc851db744dd6d0e514a63c2b4bf (patch)
treec11b1425a7df081cc3a61e4a72f87127670f0f30 /src/mesa
parent1b350311be19c8cd743600b4752f4341b3c7d8a5 (diff)
mesa: declare UniformBufferBindings as an array with a static size
Some Gallium drivers were crashing, because the array was not large enough. v2: clamp the per-shader maximum in st/mesa, then sum them all up NOTE: This is a candidate for the stable branches. (cherry picked from commit 15a4b6db2192b0adc05c3dc07cf043316c556f2e)
Diffstat (limited to 'src/mesa')
-rw-r--r--src/mesa/main/bufferobj.c10
-rw-r--r--src/mesa/main/config.h3
-rw-r--r--src/mesa/main/mtypes.h3
-rw-r--r--src/mesa/state_tracker/st_extensions.c2
4 files changed, 9 insertions, 9 deletions
diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c
index b82ba7b4c6b..a3590485c23 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 99910d7f36f..5a229775101 100644
--- a/src/mesa/main/config.h
+++ b/src/mesa/main/config.h
@@ -170,6 +170,9 @@
/*@{*/
#define MAX_PROGRAM_LOCAL_PARAMS 4096
#define MAX_UNIFORMS 4096
+#define MAX_UNIFORM_BUFFERS 15 /* + 1 default uniform buffer */
+/* 6 is for vertex, hull, domain, geometry, fragment, and compute shader. */
+#define MAX_COMBINED_UNIFORM_BUFFERS (MAX_UNIFORM_BUFFERS * 6)
/*@}*/
/**
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 8ed65273995..23c3a0d08b9 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -3623,7 +3623,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 73511be7a9a..b51416dc702 100644
--- a/src/mesa/state_tracker/st_extensions.c
+++ b/src/mesa/state_tracker/st_extensions.c
@@ -208,6 +208,7 @@ void st_init_limits(struct st_context *st)
screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_CONST_BUFFERS);
if (pc->MaxUniformBlocks)
pc->MaxUniformBlocks -= 1; /* The first one is for ordinary uniforms. */
+ pc->MaxUniformBlocks = _min(pc->MaxUniformBlocks, MAX_UNIFORM_BUFFERS);
pc->MaxCombinedUniformComponents = (pc->MaxUniformComponents +
c->MaxUniformBlockSize / 4 *
@@ -287,6 +288,7 @@ void st_init_limits(struct st_context *st)
c->VertexProgram.MaxUniformBlocks +
c->GeometryProgram.MaxUniformBlocks +
c->FragmentProgram.MaxUniformBlocks;
+ assert(c->MaxCombinedUniformBlocks <= MAX_COMBINED_UNIFORM_BUFFERS);
}
}