diff --git a/src/vrend_renderer.c b/src/vrend_renderer.c index 0719447..cc97ca4 100644 --- a/src/vrend_renderer.c +++ b/src/vrend_renderer.c @@ -420,6 +420,7 @@ struct vrend_vertex_element_array { struct vrend_constants { unsigned int *consts; uint32_t num_consts; + uint32_t num_allocated_consts; }; struct vrend_shader_view { @@ -2379,18 +2380,21 @@ void vrend_set_constants(struct vrend_context *ctx, float *data) { struct vrend_constants *consts; - uint i; consts = &ctx->sub->consts[shader]; ctx->sub->const_dirty[shader] = true; - consts->consts = realloc(consts->consts, num_constant * sizeof(float)); - if (!consts->consts) - return; + /* avoid reallocations by only growing the buffer */ + if (consts->num_allocated_consts < num_constant) { + free(consts->consts); + consts->consts = malloc(num_constant * sizeof(float)); + if (!consts->consts) + return; + consts->num_allocated_consts = num_constant; + } + memcpy(consts->consts, data, num_constant * sizeof(unsigned int)); consts->num_consts = num_constant; - for (i = 0; i < num_constant; i++) - consts->consts[i] = ((unsigned int *)data)[i]; } void vrend_set_uniform_buffer(struct vrend_context *ctx,